PracticeManagementController.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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\ProGeneralAvailability;
  9. use App\Models\ProRate;
  10. use App\Models\ProSpecificAvailability;
  11. use App\Models\ProSpecificUnavailability;
  12. use App\Models\ProTextShortcut;
  13. use App\Models\ProTransaction;
  14. use Illuminate\Http\Request;
  15. class PracticeManagementController extends Controller
  16. {
  17. public function dashboard(Request $request)
  18. {
  19. return view('app.practice-management.dashboard');
  20. }
  21. public function rates(Request $request)
  22. {
  23. $proID = $this->performer()->pro->id;
  24. $rates = ProRate::where('pro_id', $proID)->where('is_active', true)->orderBy('created_at', 'desc')->get();
  25. return view('app.practice-management.rates', compact('rates'));
  26. }
  27. public function previousBills(Request $request)
  28. {
  29. return view('app.practice-management.previous-bills');
  30. }
  31. public function financialTransactions(Request $request)
  32. {
  33. $transactions = ProTransaction::where('pro_id', $this->performer()->pro->id)->orderBy('created_at', 'desc')->get();
  34. return view('app.practice-management.financial-transactions', compact('transactions'));
  35. }
  36. public function pendingBillsToSign(Request $request)
  37. {
  38. return view('app.practice-management.pending-bills-to-sign');
  39. }
  40. public function HR(Request $request)
  41. {
  42. return view('app.practice-management.hr');
  43. }
  44. public function directDepositSettings(Request $request)
  45. {
  46. return view('app.practice-management.direct-deposit-settings');
  47. }
  48. public function w9(Request $request)
  49. {
  50. return view('app.practice-management.w9');
  51. }
  52. public function contract(Request $request)
  53. {
  54. return view('app.practice-management.contract');
  55. }
  56. public function notes(Request $request, $filter = '')
  57. {
  58. $proID = $this->performer()->pro->id;
  59. $query = Note::where('hcp_pro_id', $proID);
  60. switch ($filter) {
  61. case 'not-yet-signed':
  62. $query = $query->where('is_signed_by_hcp', false);
  63. break;
  64. // more cases can be added as needed
  65. default:
  66. break;
  67. }
  68. $notes = $query->orderBy('created_at', 'desc')->get();
  69. return view('app.practice-management.notes', compact('notes', 'filter'));
  70. }
  71. public function bills(Request $request, $filter = '')
  72. {
  73. $proID = $this->performer()->pro->id;
  74. $query = Bill::where('is_cancelled', false);
  75. switch ($filter) {
  76. case 'not-yet-signed':
  77. $query = $query
  78. ->where(function ($q) use($proID) {
  79. $q->where(function ($q2) use ($proID) {
  80. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', false);
  81. })
  82. ->orWhere(function ($q2) use ($proID) {
  83. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', false);
  84. })
  85. ->orWhere(function ($q2) use ($proID) {
  86. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', false);
  87. })
  88. ->orWhere(function ($q2) use ($proID) {
  89. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', false);
  90. });
  91. });
  92. break;
  93. case 'previous':
  94. $query = $query
  95. ->where(function ($q) use($proID) {
  96. $q->where(function ($q2) use ($proID) {
  97. $q2->where('hcp_pro_id', $proID)->where('is_signed_by_hcp', true);
  98. })
  99. ->orWhere(function ($q2) use ($proID) {
  100. $q2->where('cm_pro_id', $proID)->where('is_signed_by_cm', true);
  101. })
  102. ->orWhere(function ($q2) use ($proID) {
  103. $q2->where('rme_pro_id', $proID)->where('is_signed_by_rme', true);
  104. })
  105. ->orWhere(function ($q2) use ($proID) {
  106. $q2->where('rmm_pro_id', $proID)->where('is_signed_by_rmm', true);
  107. });
  108. });
  109. break;
  110. // more cases can be added as needed
  111. default:
  112. break;
  113. }
  114. $bills = $query->orderBy('created_at', 'desc')->get();
  115. return view('app.practice-management.bills', compact('bills', 'filter'));
  116. }
  117. public function myTextShortcuts(Request $request)
  118. {
  119. $performer = $this->performer();
  120. $myTextShortcuts = ProTextShortcut::where('pro_id', $performer->pro_id)->where('is_removed', false)->get();
  121. return view('app.practice-management.my-text-shortcuts', compact('myTextShortcuts'));
  122. }
  123. public function myAvailability(Request $request)
  124. {
  125. $performer = $this->performer();
  126. $pro = $performer->pro;
  127. $generalAvailabilitiesList = ProGeneralAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('created_at', 'asc')->get();
  128. $generalAvailabilities = [];
  129. foreach($generalAvailabilitiesList as $ga){
  130. if($ga->day_of_week == 'MONDAY'){
  131. $generalAvailabilities['MONDAY'] = $ga;
  132. }
  133. if($ga->day_of_week == 'TUESDAY'){
  134. $generalAvailabilities['TUESDAY'] = $ga;
  135. }
  136. if($ga->day_of_week == 'WEDNESDAY'){
  137. $generalAvailabilities['WEDNESDAY'] = $ga;
  138. }
  139. if($ga->day_of_week == 'THURSDAY'){
  140. $generalAvailabilities['THURSDAY'] = $ga;
  141. }
  142. if($ga->day_of_week == 'FRIDAY'){
  143. $generalAvailabilities['FRIDAY'] = $ga;
  144. }
  145. if($ga->day_of_week == 'SATURDAY'){
  146. $generalAvailabilities['SATURDAY'] = $ga;
  147. }
  148. if($ga->day_of_week == 'SUNDAY'){
  149. $generalAvailabilities['SUNDAY'] = $ga;
  150. }
  151. }
  152. $specificAvailabilities = ProSpecificAvailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time')->get();
  153. $specificUnavailabilities = ProSpecificUnavailability::where('pro_id', $pro->id)->where('is_cancelled', false)->orderBy('start_time', 'asc')->get();
  154. return view('app.practice-management.my-availability', compact('generalAvailabilities', 'specificAvailabilities', 'specificUnavailabilities'));
  155. }
  156. // video call page (RHS)
  157. // generic call handle (no uid)
  158. // specific call handle (uid of client)
  159. public function meet(Request $request, $uid = false) {
  160. $session = AppSession::where('session_key', $request->cookie('sessionKey'))->first();
  161. $client = !empty($uid) ? Client::where('uid', $uid)->first() : null;
  162. return view('app.video.call', compact('session', 'client'));
  163. }
  164. // ajax ep used by the video page
  165. // this is needed bcoz meet() is used not
  166. // just for the client passed to the view
  167. public function getOpentokSessionKey(Request $request, $uid) {
  168. $client = Client::where('uid', $uid)->first();
  169. return json_encode(["data" => $client ? $client->opentok_session_id : '']);
  170. }
  171. // poll to check if there are patients with active mcp requests
  172. public function getPatientsInQueue(Request $request) {
  173. $requests = McpRequest::where('is_active', true)->limit(3)->get();
  174. $results = [];
  175. if($requests && count($requests)) {
  176. foreach ($requests as $mcpRequest) {
  177. $client = $mcpRequest->client;
  178. $results[] = [
  179. "clientUid" => $client->uid,
  180. "name" => $client->displayName(),
  181. "initials" => substr($client->name_first, 0, 1) . substr($client->name_last, 0, 1)
  182. ];
  183. }
  184. // $results = $requests;
  185. }
  186. return json_encode($results);
  187. }
  188. public function currentWork(Request $request) {
  189. return view('app/current-work');
  190. }
  191. }