PracticeManagementController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\AppSession;
  4. use App\Models\Bill;
  5. use App\Models\Client;
  6. use App\Models\McpRequest;
  7. use App\Models\Note;
  8. use App\Models\Pro;
  9. use App\Models\ProFavorite;
  10. use App\Models\ProGeneralAvailability;
  11. use App\Models\ProRate;
  12. use App\Models\ProSpecificAvailability;
  13. use App\Models\ProSpecificUnavailability;
  14. use App\Models\ProTextShortcut;
  15. use App\Models\ProTransaction;
  16. use App\Models\Ticket;
  17. use DateTime;
  18. use DateTimeZone;
  19. use Illuminate\Http\Request;
  20. class PracticeManagementController extends Controller
  21. {
  22. public function dashboard(Request $request)
  23. {
  24. return view('app.practice-management.dashboard');
  25. }
  26. public function rates(Request $request, $selectedProUid = 'all')
  27. {
  28. $proUid = $selectedProUid ? $selectedProUid : 'all';
  29. $rates = ProRate::where('is_active', true);
  30. if($proUid !== 'all') {
  31. $selectedPro = Pro::where('uid', $proUid)->first();
  32. $rates = $rates->where('pro_id', $selectedPro->id);
  33. }
  34. $rates = $rates->orderBy('pro_id', 'asc')->get();
  35. $pros = $this->pros;
  36. return view('app.practice-management.rates', compact('rates', 'pros', 'selectedProUid'));
  37. }
  38. public function previousBills(Request $request)
  39. {
  40. return view('app.practice-management.previous-bills');
  41. }
  42. public function financialTransactions(Request $request)
  43. {
  44. $transactions = ProTransaction::where('pro_id', $this->performer()->pro->id)->orderBy('created_at', 'desc')->get();
  45. return view('app.practice-management.financial-transactions', compact('transactions'));
  46. }
  47. public function pendingBillsToSign(Request $request)
  48. {
  49. return view('app.practice-management.pending-bills-to-sign');
  50. }
  51. public function HR(Request $request)
  52. {
  53. return view('app.practice-management.hr');
  54. }
  55. public function directDepositSettings(Request $request)
  56. {
  57. return view('app.practice-management.direct-deposit-settings');
  58. }
  59. public function w9(Request $request)
  60. {
  61. return view('app.practice-management.w9');
  62. }
  63. public function contract(Request $request)
  64. {
  65. return view('app.practice-management.contract');
  66. }
  67. public function notes(Request $request, $filter = '')
  68. {
  69. $proID = $this->performer()->pro->id;
  70. $query = Note::where('hcp_pro_id', $proID);
  71. switch ($filter) {
  72. case 'not-yet-signed':
  73. $query = $query->where('is_signed_by_hcp', false);
  74. break;
  75. // more cases can be added as needed
  76. default:
  77. break;
  78. }
  79. $notes = $query->orderBy('created_at', 'desc')->get();
  80. return view('app.practice-management.notes', compact('notes', 'filter'));
  81. }
  82. public function bills(Request $request, $filter = '')
  83. {
  84. $proID = $this->performer()->pro->id;
  85. $query = Bill::where('is_cancelled', false);
  86. switch ($filter) {
  87. case 'not-yet-signed':
  88. $query = $query
  89. ->where(function ($q) use($proID) {
  90. $q->where(function ($q2) use ($proID) {
  91. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', false);
  92. })
  93. ->orWhere(function ($q2) use ($proID) {
  94. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', false);
  95. })
  96. ->orWhere(function ($q2) use ($proID) {
  97. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', false);
  98. })
  99. ->orWhere(function ($q2) use ($proID) {
  100. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', false);
  101. });
  102. });
  103. break;
  104. case 'previous':
  105. $query = $query
  106. ->where(function ($q) use($proID) {
  107. $q->where(function ($q2) use ($proID) {
  108. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', true);
  109. })
  110. ->orWhere(function ($q2) use ($proID) {
  111. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', true);
  112. })
  113. ->orWhere(function ($q2) use ($proID) {
  114. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', true);
  115. })
  116. ->orWhere(function ($q2) use ($proID) {
  117. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', true);
  118. });
  119. });
  120. break;
  121. // more cases can be added as needed
  122. default:
  123. break;
  124. }
  125. $bills = $query->orderBy('created_at', 'desc')->get();
  126. return view('app.practice-management.bills', compact('bills', 'filter'));
  127. }
  128. public function myTickets(Request $request, $filter = 'open')
  129. {
  130. $performer = $this->performer();
  131. $myTickets = Ticket::where(function ($q) use ($performer) {
  132. $q->where('assigned_pro_id', $performer->pro_id)
  133. ->orWhere('manager_pro_id', $performer->pro_id)
  134. ->orWhere('ordering_pro_id', $performer->pro_id)
  135. ->orWhere('initiating_pro_id', $performer->pro_id);
  136. });
  137. if($filter === 'open') {
  138. $myTickets = $myTickets->where('is_open', true);
  139. }
  140. else if($filter === 'closed') {
  141. $myTickets = $myTickets->where('is_open', false);
  142. }
  143. $myTickets = $myTickets->orderBy('created_at', 'desc')->get();
  144. return view('app.practice-management.my-tickets', compact('myTickets', 'filter'));
  145. }
  146. public function myTextShortcuts(Request $request)
  147. {
  148. $performer = $this->performer();
  149. $myTextShortcuts = ProTextShortcut::where('pro_id', $performer->pro_id)->where('is_removed', false)->get();
  150. return view('app.practice-management.my-text-shortcuts', compact('myTextShortcuts'));
  151. }
  152. public function myFavorites(Request $request, $filter = 'all')
  153. {
  154. $performer = $this->performer();
  155. $myFavorites = ProFavorite::where('pro_id', $performer->pro_id)
  156. ->where('is_removed', false);
  157. if($filter !== 'all') {
  158. $myFavorites = $myFavorites->where('category', $filter);
  159. }
  160. $myFavorites = $myFavorites
  161. ->orderBy('category', 'asc')
  162. ->orderBy('position_index', 'asc')
  163. ->get();
  164. return view('app.practice-management.my-favorites', compact('myFavorites', 'filter'));
  165. }
  166. public function proAvailability(Request $request, $proUid = null)
  167. {
  168. $performer = $this->performer();
  169. $pro = $performer->pro;
  170. if($proUid){
  171. $pro = Pro::where('uid', $proUid)->first();
  172. }
  173. if($request->get('pro_uid')){
  174. $proUid = $request->get('pro_uid');
  175. $pro = Pro::where('uid', $proUid)->first();
  176. }
  177. $selectedProUid = $pro->uid;
  178. $pros =$this->pros;
  179. $generalAvailabilitiesList = ProGeneralAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
  180. $generalAvailabilities = [
  181. 'MONDAY'=>[],
  182. 'TUESDAY'=>[],
  183. 'WEDNESDAY'=>[],
  184. 'THURSDAY'=>[],
  185. 'FRIDAY'=>[],
  186. 'SATURDAY'=>[],
  187. 'SUNDAY'=>[],
  188. ];
  189. foreach($generalAvailabilitiesList as $ga){
  190. if($ga->day_of_week == 'MONDAY'){
  191. $generalAvailabilities['MONDAY'][] = $ga;
  192. }
  193. if($ga->day_of_week == 'TUESDAY'){
  194. $generalAvailabilities['TUESDAY'][] = $ga;
  195. }
  196. if($ga->day_of_week == 'WEDNESDAY'){
  197. $generalAvailabilities['WEDNESDAY'][] = $ga;
  198. }
  199. if($ga->day_of_week == 'THURSDAY'){
  200. $generalAvailabilities['THURSDAY'][] = $ga;
  201. }
  202. if($ga->day_of_week == 'FRIDAY'){
  203. $generalAvailabilities['FRIDAY'][] = $ga;
  204. }
  205. if($ga->day_of_week == 'SATURDAY'){
  206. $generalAvailabilities['SATURDAY'][] = $ga;
  207. }
  208. if($ga->day_of_week == 'SUNDAY'){
  209. $generalAvailabilities['SUNDAY'][] = $ga;
  210. }
  211. }
  212. $specificAvailabilities = ProSpecificAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time')->get();
  213. $specificUnavailabilities = ProSpecificUnavailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time', 'asc')->get();
  214. //events for the calendar
  215. $startDate = date('Y-m-d', strtotime("sunday -1 week"));
  216. $endDateTime = new DateTime($startDate);
  217. $endDateTime->modify('+6 day');
  218. $endDate = $endDateTime->format("Y-m-d");
  219. $eventsData = $pro->getAvailabilityEvents($startDate, $endDate);
  220. $events = json_encode($eventsData);
  221. return view('app.practice-management.pro-availability',
  222. compact('pros','generalAvailabilities', 'specificAvailabilities',
  223. 'specificUnavailabilities', 'events', 'selectedProUid'));
  224. }
  225. public function loadAvailability(Request $request, $proUid){
  226. $performer = $this->performer();
  227. $pro = $performer->pro;
  228. $startDate = $request->get('start');
  229. $endDate = $request->get('end');
  230. $selectedPro = Pro::where('uid', $proUid)->first();
  231. return $selectedPro->getAvailabilityEvents($startDate, $endDate);
  232. }
  233. public function proAvailabilityFilter(Request $request){
  234. $proUid = $request->get('proUid');
  235. return ['success'=>true, 'data'=>$proUid];
  236. }
  237. // video call page (RHS)
  238. // generic call handle (no uid)
  239. // specific call handle (uid of client)
  240. public function meet(Request $request, $uid = false) {
  241. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  242. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  243. if(!empty($client)) {
  244. return view('app.video.call-minimal', compact('session', 'client'));
  245. }
  246. return view('app.video.call-agora-v2', compact('session', 'client'));
  247. }
  248. // check video page
  249. public function checkVideo(Request $request, $uid) {
  250. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  251. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  252. $publish = false;
  253. return view('app.video.check-video-minimal', compact('session', 'client'));
  254. }
  255. public function getParticipantInfo(Request $request) {
  256. $sid = intval($request->get('uid')) - 1000000;
  257. $session = AppSession::where('id', $sid)->first();
  258. $result = [
  259. "type" => '',
  260. "name" => ''
  261. ];
  262. if($session) {
  263. $result["type"] = $session->session_type;
  264. switch($session->session_type) {
  265. case 'PRO':
  266. $pro = Pro::where('id', $session->pro_id)->first();
  267. $result["name"] = $pro->displayName();
  268. break;
  269. case 'CLIENT':
  270. $client = Client::where('id', $session->client_id)->first();
  271. $result["name"] = $client->displayName();
  272. break;
  273. }
  274. }
  275. return json_encode($result);
  276. }
  277. // ajax ep used by the video page
  278. // this is needed bcoz meet() is used not
  279. // just for the client passed to the view
  280. public function getOpentokSessionKey(Request $request, $uid) {
  281. $client = Client::where('uid', $uid)->first();
  282. return json_encode(["data" => $client ? $client->opentok_session_id : '']);
  283. }
  284. // poll to check if there are patients with active mcp requests
  285. public function getPatientsInQueue(Request $request) {
  286. $requests = McpRequest::where('is_active', true)->limit(3)->get();
  287. $results = [];
  288. if($requests && count($requests)) {
  289. foreach ($requests as $mcpRequest) {
  290. $client = $mcpRequest->client;
  291. if($client->initiative && strpos($this->performer->pro->initiative,$client->initiative) !== false){
  292. $results[] = [
  293. "clientUid" => $client->uid,
  294. "name" => $client->displayName(),
  295. "initials" => substr($client->name_first, 0, 1) . substr($client->name_last, 0, 1)
  296. ];
  297. }
  298. }
  299. }
  300. return json_encode($results);
  301. }
  302. public function currentWork(Request $request) {
  303. return view('app/current-work');
  304. }
  305. public function calendar(Request $request, $proUid = null) {
  306. return view('app.practice-management.calendar');
  307. }
  308. public function billingManager(Request $request, $proUid = null) {
  309. $notes = Note::orderBy('created_at', 'desc')->paginate();
  310. return view('app.practice-management.billing-manager', compact('notes'));
  311. }
  312. public function tickets(Request $request, $proUid = null) {
  313. $tickets = Ticket::orderBy('created_at', 'desc')->paginate();
  314. return view('app.practice-management.tickets', compact('tickets'));
  315. }
  316. }