PracticeManagementController.php 8.6 KB

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