PatientController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Appointment;
  4. use App\Models\BDTDevice;
  5. use App\Models\CareMonth;
  6. use App\Models\Client;
  7. use App\Models\ClientBDTDevice;
  8. use App\Models\ClientInfoLine;
  9. use App\Models\ClientPrimaryCoverage;
  10. use App\Models\ClientProAccess;
  11. use App\Models\CompanyPro;
  12. use App\Models\Erx;
  13. use App\Models\Facility;
  14. use App\Models\Handout;
  15. use App\Models\HandoutClient;
  16. use App\Models\IncomingReport;
  17. use App\Models\MBClaim;
  18. use App\Models\MBPayer;
  19. use App\Models\Note;
  20. use App\Models\NoteTemplate;
  21. use App\Models\Pro;
  22. use App\Models\Product;
  23. use App\Models\ProProAccess;
  24. use App\Models\SectionTemplate;
  25. use App\Models\Shipment;
  26. use App\Models\SupplyOrder;
  27. use App\Models\Ticket;
  28. use Illuminate\Http\Request;
  29. use Illuminate\Support\Facades\DB;
  30. use Illuminate\Support\Facades\File;
  31. use App\Models\Measurement;
  32. use App\Models\ClientReviewRequest;
  33. use Illuminate\Support\Facades\Http;
  34. use PDF;
  35. class PatientController extends Controller
  36. {
  37. public function claimsResolver(Request $request, Client $patient)
  38. {
  39. $notes = $patient->notesAscending;
  40. $hcpSignedNotesCount = 0;
  41. foreach($notes as $note){
  42. if($note->is_signed_by_hcp){
  43. $hcpSignedNotesCount += 1;
  44. }
  45. }
  46. $data = [
  47. 'dog' => 'bark',
  48. 'patient' => $patient,
  49. 'hcpSignedNotesCount' => $hcpSignedNotesCount
  50. ];
  51. return view('app.patient.claims-resolver', $data);
  52. }
  53. public function dashboard(Request $request, Client $patient )
  54. {
  55. $mcpPros = Pro::where('is_enrolled_as_mcp', true)->get();
  56. $facilities = []; // Facility::where('is_active', true)->get();
  57. // get assigned devices
  58. $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true"));
  59. $assignedDeviceIDs = array_map(function($_x) {
  60. return $_x->device_id;
  61. }, $assignedDeviceIDs);
  62. // get all except assigned ones
  63. $devices = BDTDevice::where('is_active', true)
  64. ->whereNotIn('id', $assignedDeviceIDs)
  65. ->orderBy('imei', 'asc')
  66. ->get();
  67. $assignedDeviceIDs = null;
  68. unset($assignedDeviceIDs);
  69. $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
  70. ->where('category', 'dx')
  71. ->where('is_removed', false)
  72. ->orderBy('content_text', 'asc')
  73. ->get();
  74. return view('app.patient.dashboard',
  75. compact('patient', 'facilities', 'devices', 'dxInfoLines'));
  76. }
  77. public function canvasMigrate(Request $request, Client $patient )
  78. {
  79. $mcpPros = Pro::where('is_enrolled_as_mcp', true)->get();
  80. $facilities = []; // Facility::where('is_active', true)->get();
  81. // get assigned devices
  82. $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true"));
  83. $assignedDeviceIDs = array_map(function($_x) {
  84. return $_x->device_id;
  85. }, $assignedDeviceIDs);
  86. // get all except assigned ones
  87. $devices = BDTDevice::where('is_active', true)
  88. ->whereNotIn('id', $assignedDeviceIDs)
  89. ->orderBy('imei', 'asc')
  90. ->get();
  91. $assignedDeviceIDs = null;
  92. unset($assignedDeviceIDs);
  93. $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
  94. ->where('category', 'dx')
  95. ->where('is_removed', false)
  96. ->orderBy('content_text', 'asc')
  97. ->get();
  98. return view('app.patient.canvas-migrate',
  99. compact('patient', 'facilities', 'devices', 'dxInfoLines'));
  100. }
  101. public function canvas(Request $request, Client $patient){
  102. return view('app.patient.canvas_dump', compact('patient'));
  103. }
  104. public function actionItems(Request $request, Client $patient )
  105. {
  106. $facilities = []; // Facility::where('is_active', true)->get();
  107. return view('app.patient.action-items', compact('patient', 'facilities'));
  108. }
  109. public function actionItemsErx(Request $request, Client $patient, $filter = 'open')
  110. {
  111. $allPros = Pro::all();
  112. $facilities = []; // Facility::where('is_active', true)->get();
  113. return view('app.patient.action-items-erx', compact('patient', 'facilities', 'filter', 'allPros'));
  114. }
  115. public function actionItemsLab(Request $request, Client $patient, $filter = 'open')
  116. {
  117. $allPros = Pro::all();
  118. $facilities = []; // Facility::where('is_active', true)->get();
  119. return view('app.patient.action-items-lab', compact('patient', 'facilities', 'filter', 'allPros'));
  120. }
  121. public function actionItemsImaging(Request $request, Client $patient, $filter = 'open')
  122. {
  123. $allPros = Pro::all();
  124. $facilities = []; // Facility::where('is_active', true)->get();
  125. return view('app.patient.action-items-imaging', compact('patient', 'facilities', 'filter', 'allPros'));
  126. }
  127. public function actionItemsEquipment(Request $request, Client $patient, $filter = 'open')
  128. {
  129. $allPros = Pro::all();
  130. $facilities = []; // Facility::where('is_active', true)->get();
  131. return view('app.patient.action-items-equipment', compact('patient', 'facilities', 'filter', 'allPros'));
  132. }
  133. public function actionItemsOther(Request $request, Client $patient, $filter = 'open')
  134. {
  135. $allPros = Pro::all();
  136. $facilities = []; // Facility::where('is_active', true)->get();
  137. return view('app.patient.action-items-other', compact('patient', 'facilities', 'filter', 'allPros'));
  138. }
  139. public function actionItemsErxSingle(Request $request, Client $patient, Ticket $ticket) {
  140. $allPros = Pro::all();
  141. $facilities = []; // Facility::where('is_active', true)->get();
  142. return view('app.patient.action-items-erx-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  143. }
  144. public function actionItemsLabSingle(Request $request, Client $patient, Ticket $ticket) {
  145. $allPros = Pro::all();
  146. $facilities = []; // Facility::where('is_active', true)->get();
  147. return view('app.patient.action-items-lab-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  148. }
  149. public function actionItemsImagingSingle(Request $request, Client $patient, Ticket $ticket) {
  150. $allPros = Pro::all();
  151. $facilities = []; // Facility::where('is_active', true)->get();
  152. return view('app.patient.action-items-imaging-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  153. }
  154. public function actionItemsEquipmentSingle(Request $request, Client $patient, Ticket $ticket) {
  155. $allPros = Pro::all();
  156. $facilities = []; // Facility::where('is_active', true)->get();
  157. return view('app.patient.action-items-equipment-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  158. }
  159. public function actionItemsOtherSingle(Request $request, Client $patient, Ticket $ticket) {
  160. $allPros = Pro::all();
  161. $facilities = []; // Facility::where('is_active', true)->get();
  162. return view('app.patient.action-items-other-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  163. }
  164. public function intake(Request $request, Client $patient )
  165. {
  166. $files = File::allFiles(resource_path('views/app/intake-templates'));
  167. $templates = [];
  168. foreach ($files as $file) {
  169. $templates[] = str_replace(".blade.php", "", $file->getFilename());
  170. }
  171. return view('app.patient.intake', compact('patient', 'templates'));
  172. }
  173. public function carePlan(Request $request, Client $patient )
  174. {
  175. return view('app.patient.care-plan', compact('patient'));
  176. }
  177. public function medications(Request $request, Client $patient )
  178. {
  179. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  180. ->where('category', 'rx')
  181. ->where('is_removed', false)
  182. ->orderBy('content_text', 'asc')
  183. ->get();
  184. return view('app.patient.medications', compact('patient', 'infoLines'));
  185. }
  186. public function dxAndFocusAreas(Request $request, Client $patient )
  187. {
  188. $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
  189. ->where('category', 'dx')
  190. ->where('is_removed', false)
  191. ->orderBy('content_text', 'asc')
  192. ->get();
  193. return view('app.patient.dx-and-focus-areas', compact('patient', 'dxInfoLines'));
  194. }
  195. public function careTeam(Request $request, Client $patient )
  196. {
  197. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  198. ->where('category', 'care_team')
  199. ->where('is_removed', false)
  200. ->get();
  201. return view('app.patient.care-team', compact('patient', 'infoLines'));
  202. }
  203. public function devices(Request $request, Client $patient )
  204. {
  205. // get assigned devices
  206. $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true"));
  207. $assignedDeviceIDs = array_map(function($_x) {
  208. return $_x->device_id;
  209. }, $assignedDeviceIDs);
  210. // get all except assigned ones
  211. $devices = BDTDevice::where('is_active', true)
  212. ->whereNotIn('id', $assignedDeviceIDs)
  213. ->orderBy('imei', 'asc')
  214. ->get();
  215. $assignedDeviceIDs = null;
  216. unset($assignedDeviceIDs);
  217. return view('app.patient.devices', compact('patient', 'devices'));
  218. }
  219. public function measurements(Request $request, Client $patient )
  220. {
  221. $measurements = Measurement::where('client_id', $patient->id)->where('is_active', true)->orderByRaw('ts DESC NULLS LAST')->paginate(30);
  222. return view('app.patient.measurements', compact('patient', 'measurements'));
  223. }
  224. public function labsAndStudies(Request $request, Client $patient )
  225. {
  226. return view('app.patient.labs-and-studies', compact('patient'));
  227. }
  228. public function history(Request $request, Client $patient )
  229. {
  230. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  231. ->where('category', 'LIKE', 'history_%')
  232. ->where('is_removed', false)
  233. ->get();
  234. return view('app.patient.history', compact('patient', 'infoLines'));
  235. }
  236. public function memos(Request $request, Client $patient )
  237. {
  238. return view('app.patient.memos', compact('patient'));
  239. }
  240. public function memosThread(Request $request, Client $patient )
  241. {
  242. return view('app.patient.memos-thread', compact('patient'));
  243. }
  244. public function messagesThread(Request $request, Client $patient )
  245. {
  246. return view('app.patient.messages-thread', compact('patient'));
  247. }
  248. public function sms(Request $request, Client $patient )
  249. {
  250. return view('app.patient.sms', compact('patient'));
  251. }
  252. public function outgoingSmsLog(Request $request, Client $patient )
  253. {
  254. return view('app.patient.outgoing-sms-log', compact('patient'));
  255. }
  256. public function reviewRequests(Request $request, Client $patient){
  257. $pro = $this->performer->pro;
  258. $reviewRequests = ClientReviewRequest::where('client_id', $patient->id);
  259. if($pro->pro_type !== 'ADMIN'){
  260. $reviewRequests = $reviewRequests->where('pro_id', $pro->id);
  261. }
  262. $reviewRequests = $reviewRequests->orderBy('created_at', 'DESC')->paginate(50);
  263. return view('app.patient.review-requests.list', compact('patient', 'reviewRequests'));
  264. }
  265. public function smsNumbers(Request $request, Client $patient )
  266. {
  267. return view('app.patient.sms-numbers', compact('patient'));
  268. }
  269. public function immunizations(Request $request, Client $patient )
  270. {
  271. return view('app.patient.immunizations', compact('patient'));
  272. }
  273. public function allergies(Request $request, Client $patient )
  274. {
  275. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  276. ->where('category', 'allergy')
  277. ->where('is_removed', false)
  278. ->get();
  279. return view('app.patient.allergies', compact('patient', 'infoLines'));
  280. }
  281. public function notes(Request $request, Client $patient, $filter = 'active')
  282. {
  283. $pros = $this->pros;
  284. return view('app.patient.notes', compact('patient','pros', 'filter'));
  285. }
  286. public function genericBills(Request $request, Client $patient)
  287. {
  288. return view('app.patient.generic-bills', compact('patient'));
  289. }
  290. public function rmSetup(Request $request, Client $patient)
  291. {
  292. return view('app.patient.rm-setup', compact('patient'));
  293. }
  294. public function handouts(Request $request, Client $patient )
  295. {
  296. $clientHandouts = HandoutClient::where('client_id', $patient->id)->get();
  297. $handouts = Handout::where('is_active', true)->orderBy('display_name', 'ASC')->get();
  298. return view('app.patient.handouts', compact('patient', 'clientHandouts', 'handouts'));
  299. }
  300. public function settings(Request $request, Client $patient )
  301. {
  302. return view('app.patient.settings', compact('patient'));
  303. }
  304. public function smsReminders(Request $request, Client $patient )
  305. {
  306. return view('app.patient.sms-reminders', compact('patient'));
  307. }
  308. public function measurementConfirmationNumbers(Request $request, Client $patient )
  309. {
  310. return view('app.patient.measurement-confirmation-numbers', compact('patient'));
  311. }
  312. public function pros(Request $request, Client $patient )
  313. {
  314. return view('app.patient.pros', compact('patient'));
  315. }
  316. public function proChanges(Request $request, Client $patient )
  317. {
  318. return view('app.patient.client-pro-changes', compact('patient'));
  319. }
  320. public function account(Request $request, Client $patient )
  321. {
  322. return view('app.patient.account', compact('patient'));
  323. }
  324. public function careChecklist(Request $request, Client $patient )
  325. {
  326. return view('app.patient.care-checklist', compact('patient'));
  327. }
  328. public function documents(Request $request, Client $patient )
  329. {
  330. return view('app.patient.documents', compact('patient'));
  331. }
  332. public function incomingReports(Request $request, Client $patient, IncomingReport $currentReport = null)
  333. {
  334. return view('app.patient.incoming-reports', compact('patient', 'currentReport'));
  335. }
  336. public function education(Request $request, Client $patient )
  337. {
  338. return view('app.patient.education', compact('patient'));
  339. }
  340. public function messaging(Request $request, Client $patient )
  341. {
  342. return view('app.patient.messaging', compact('patient'));
  343. }
  344. public function duplicate(Request $request, Client $patient )
  345. {
  346. return view('app.patient.duplicate', compact('patient'));
  347. }
  348. public function careMonths(Request $request, Client $patient )
  349. {
  350. $careMonths = CareMonth::where('client_id', $patient->id)->orderBy('start_date', 'desc')->get();
  351. $notes = Note::where('is_cancelled', false)->get();
  352. return view('app.patient.care-months', compact('patient', 'careMonths', 'notes'));
  353. }
  354. public function presence(Request $request, Client $patient )
  355. {
  356. return json_encode([
  357. "online" => $patient->is_online
  358. ]);
  359. }
  360. public function embedSection(Request $request, Client $patient, $section, $selectable) {
  361. return view('app.patient.partials.' . $section, compact('patient', 'selectable'));
  362. }
  363. public function calendar(Request $request, Client $patient, Appointment $currentAppointment) {
  364. $pros = [];
  365. if($this->pro && $this->pro->pro_type != 'ADMIN') {
  366. $accessiblePros = ProProAccess::where('owner_pro_id', $this->pro->id)->get();
  367. $accessibleProIds = [];
  368. foreach($accessiblePros as $accessiblePro){
  369. $accessibleProIds[] = $accessiblePro->accessible_pro_id;
  370. }
  371. $accessibleProIds[] = $this->pro->id;
  372. // for dna, add pros accessible via pro teams
  373. if($this->performer->pro->isDefaultNA()) {
  374. $teams = $this->performer->pro->teamsWhereAssistant;
  375. foreach ($teams as $team) {
  376. if(!in_array($team->mcp_pro_id, $accessibleProIds)) {
  377. $accessibleProIds[] = $team->mcp_pro_id;
  378. }
  379. }
  380. }
  381. $pros = Pro::whereIn('id', $accessibleProIds)->get();
  382. }
  383. $dateLastWeek = date_sub(date_create(), date_interval_create_from_date_string("14 days"));
  384. $dateLastWeek = date_format($dateLastWeek, "Y-m-d");
  385. $appointments = Appointment::where('client_id', $patient->id)
  386. ->orderBy('raw_date', 'desc')->orderBy('raw_start_time', 'desc')
  387. ->where('raw_date', '>=', $dateLastWeek)
  388. ->get();
  389. $appointmentProIDs = $appointments->map(function($_item) {
  390. return $_item->pro_id;
  391. });
  392. $appointmentPros = Pro::whereIn('id', $appointmentProIDs)->get();
  393. return view('app.patient.appointment-calendar',
  394. compact('pros', 'patient', 'currentAppointment', 'appointments', 'appointmentPros'));
  395. }
  396. public function programs(Request $request, Client $patient, $filter = '') {
  397. $pros = $this->pros;
  398. return view('app.patient.programs', compact('patient', 'pros', 'filter'));
  399. }
  400. public function flowsheets(Request $request, Client $patient, $filter = '') {
  401. $pros = $this->pros;
  402. return view('app.patient.flowsheets', compact('patient', 'pros', 'filter'));
  403. }
  404. public function vitalsSettings(Request $request, Client $patient) {
  405. return view('app.patient.vitals-settings', compact('patient'));
  406. }
  407. public function vitalsGraph(Request $request, Client $patient, $filter = '') {
  408. $pros = $this->pros;
  409. return view('app.patient.vitals-graph', compact('patient', 'pros', 'filter'));
  410. }
  411. public function tickets(Request $request, Client $patient, $type = '', String $currentTicket = '') {
  412. $pros = $this->pros;
  413. $allPros = Pro::all();
  414. $qlTicket = $currentTicket;
  415. if(!!$currentTicket) {
  416. $qlTicket = Ticket::where('uid', $currentTicket)->first();
  417. if($qlTicket) {
  418. $currentTicket = $qlTicket;
  419. }
  420. }
  421. return view('app.patient.tickets', compact('patient', 'pros', 'allPros', 'type', 'currentTicket'));
  422. }
  423. public function prescriptions(Request $request, Client $patient, String $type = '', String $currentErx = '') {
  424. if(!!$currentErx) {
  425. $currentErx = Erx::where('uid', $currentErx)->first();
  426. }
  427. $note = $patient->coreNote;
  428. return view('app.patient.prescriptions.index', compact('patient', 'type', 'currentErx', 'note'));
  429. }
  430. public function prescriptionsPopup(Request $request, Client $patient, String $type = '', String $currentErx = '') {
  431. if(!!$currentErx) {
  432. $currentErx = Erx::where('uid', $currentErx)->first();
  433. }
  434. $note = null;
  435. if($request->input('noteUid')) {
  436. $note = Note::where('uid', $request->input('noteUid'))->first();
  437. }
  438. return view('app.patient.prescriptions-popup.list-popup', compact('patient', 'type', 'currentErx', 'note'));
  439. }
  440. public function prescriptionsList(Request $request, Client $patient, String $type = '', String $currentErx = '') {
  441. if(!!$currentErx) {
  442. $currentErx = Erx::where('uid', $currentErx)->first();
  443. }
  444. $note = null;
  445. if($request->input('noteUid')) {
  446. $note = Note::where('uid', $request->input('noteUid'))->first();
  447. }
  448. return view('app.patient.prescriptions.list', compact('patient', 'type', 'currentErx', 'note'));
  449. }
  450. public function downloadPrescriptionAsPdf(Request $request, Erx $prescription){
  451. if($request->input('html')) {
  452. return view('app.patient.prescriptions.pdf.pdf-preview', compact('prescription'));
  453. }
  454. else {
  455. $pdf = PDF::loadView('app.patient.prescriptions.pdf.pdf-preview', compact('prescription'));
  456. return $pdf->download($prescription->created_at .'_' . 'erx.pdf');
  457. }
  458. }
  459. public function transmitPrescription(Request $request, Erx $prescription){
  460. // re-generate pdf with cover sheet as first page and save it to FS
  461. $filePath = config('app.temp_dir') . "/{$prescription->uid}.pdf";
  462. $pdf = PDF::loadView('app.patient.prescriptions.pdf.pdf-preview-with-cover-sheet', compact('prescription'));
  463. $pdf->save($filePath);
  464. // send it along with the rest of the params to /api/erx/transmit [multi-part POST]
  465. $url = config('stag.backendUrl') . '/erx/transmit';
  466. $params = [
  467. "uid" => $request->input('uid'),
  468. "toWho" => $request->input('toWho'),
  469. "toEmail" => $request->input('toEmail'),
  470. "toFaxNumber" => $request->input('toFaxNumber'),
  471. "toFaxNumberAttentionLine" => $request->input('toFaxNumberAttentionLine'),
  472. "toFaxNumberCoverSheetMemo" => $request->input('toFaxNumberCoverSheetMemo'),
  473. ];
  474. if($request->input('copyToPatient')) {
  475. $params["copyToPatientFaxNumber"] = $request->input('copyToPatientFaxNumber');
  476. $params["copyToPatientEmail"] = $request->input('copyToPatientEmail');
  477. }
  478. $pdf = fopen($filePath, 'r');
  479. $response = Http
  480. ::attach('pdfSystemFile', $filePath, "{$prescription->uid}.pdf")
  481. ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
  482. ->post($url, $params)
  483. ->json();
  484. return $response;
  485. }
  486. public function supplyOrders(Request $request, Client $patient, SupplyOrder $supplyOrder = null)
  487. {
  488. $products = Product::where('is_active', true)->orderBy('created_at', 'desc')->get();
  489. return view('app.patient.supply-orders', compact('patient', 'supplyOrder', 'products'));
  490. }
  491. public function shipments(Request $request, Client $patient, Shipment $shipment = null)
  492. {
  493. return view('app.patient.shipments', compact('patient', 'shipment'));
  494. }
  495. public function appointments(Request $request, Client $patient, $forPro = 'all', $status = 'all') {
  496. $pros = $this->pros;
  497. $appointments = $patient->appointmentsForProByStatus($forPro, strtoupper($status));
  498. $appointmentProIDs = $appointments->map(function($_item) {
  499. return $_item->pro_id;
  500. });
  501. $appointmentPros = Pro::whereIn('id', $appointmentProIDs)->get();
  502. return view('app.patient.appointments',
  503. compact('patient', 'pros', 'appointments', 'appointmentPros', 'forPro', 'status'));
  504. }
  505. public function mcpRequests(Request $request, Client $patient) {
  506. return view('app.patient.mcp-requests', compact('patient'));
  507. }
  508. public function eligibleRefreshes(Request $request, Client $patient) {
  509. return view('app.patient.eligible-refreshes', compact('patient'));
  510. }
  511. public function insuranceCoverage(Request $request, Client $patient) {
  512. $mbPayers = MBPayer::all();
  513. return view('app.patient.insurance-coverage', compact('patient', 'mbPayers'));
  514. }
  515. public function clientPrimaryCoverages(Request $request, Client $patient) {
  516. $mbPayers = MBPayer::all();
  517. return view('app.patient.client-primary-coverages', compact('patient', 'mbPayers'));
  518. }
  519. public function primaryCoverage(Request $request, Client $patient) {
  520. $mbPayers = MBPayer::all();
  521. return view('app.patient.primary-coverage', compact('patient', 'mbPayers'));
  522. }
  523. public function primaryCoverageForm(Request $request, Client $patient) {
  524. $mbPayers = MBPayer::all();
  525. return view('app.patient.primary-coverage-form', compact('patient', 'mbPayers'));
  526. }
  527. public function primaryCoverageManualDeterminationModal(Request $request, Client $patient) {
  528. $coverageUid = $request->get('coverageUid');
  529. $coverage = ClientPrimaryCoverage::where('uid', $coverageUid)->first();
  530. if($patient->latestClientPrimaryCoverage->plan_type === 'MEDICARE'){
  531. return view('app.patient.primary-coverage-manual-determination-medicare-modal', compact('patient', 'coverage'));
  532. }
  533. if($patient->latestClientPrimaryCoverage->plan_type === 'MEDICAID'){
  534. return view('app.patient.primary-coverage-manual-determination-medicaid-modal', compact('patient', 'coverage'));
  535. }
  536. if($patient->latestClientPrimaryCoverage->plan_type === 'COMMERCIAL'){
  537. return view('app.patient.primary-coverage-manual-determination-commercial-modal', compact('patient', 'coverage'));
  538. }
  539. return "Plan Type is missing!";
  540. }
  541. public function mbClaim(Request $request, MBClaim $mbClaim) {
  542. return view('app.patient.mb-claim-single', compact('mbClaim'));
  543. }
  544. public function accounts(Request $request, Client $patient) {
  545. return view('app.patient.accounts', compact('patient'));
  546. }
  547. public function careMonthMatrix(Request $request, CareMonth $careMonth) {
  548. return view('app.patient.care-month.matrix', [
  549. 'patient' => $careMonth->patient,
  550. 'careMonth' => $careMonth,
  551. ]);
  552. }
  553. public function clientProAccess(Request $request, Client $patient) {
  554. $rows = ClientProAccess::where('client_id', $patient->id)->get();
  555. return view('app.patient.client-pro-access', compact('patient', 'rows'));
  556. }
  557. public function clientDocuments(Request $request, Client $patient){
  558. $templates = get_doc_templates();
  559. $companyProIDs = DB::select('SELECT company_pro_id FROM company_pro_document WHERE related_client_id = ?', [$patient->id]);
  560. $companyProIDInts = [];
  561. foreach($companyProIDs as $cpId){
  562. $companyProIDInts[] = $cpId->company_pro_id;
  563. }
  564. $companyPros = CompanyPro::whereIn('id', $companyProIDInts)->get();
  565. return view('app.patient.client-documents', compact('templates', 'companyPros', 'patient'));
  566. }
  567. public function insuranceCoverageHistory(Request $request, Client $patient){
  568. $insuranceCoverageHistory = ClientPrimaryCoverage::where('client_id', $patient->id)->orderBy('created_at', 'DESC')->get();
  569. return view('app.patient.insurance-coverage-history', compact('patient', 'insuranceCoverageHistory'));
  570. }
  571. }