PracticeManagementController.php 10.0 KB

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