PatientController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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. $reviewRequests = ClientReviewRequest::where('client_id', $patient->id)->orderBy('created_at', 'DESC')->paginate(50);
  258. return view('app.patient.review-requests.list', compact('patient', 'reviewRequests'));
  259. }
  260. public function smsNumbers(Request $request, Client $patient )
  261. {
  262. return view('app.patient.sms-numbers', compact('patient'));
  263. }
  264. public function immunizations(Request $request, Client $patient )
  265. {
  266. return view('app.patient.immunizations', compact('patient'));
  267. }
  268. public function allergies(Request $request, Client $patient )
  269. {
  270. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  271. ->where('category', 'allergy')
  272. ->where('is_removed', false)
  273. ->get();
  274. return view('app.patient.allergies', compact('patient', 'infoLines'));
  275. }
  276. public function notes(Request $request, Client $patient, $filter = 'active')
  277. {
  278. $pros = $this->pros;
  279. return view('app.patient.notes', compact('patient','pros', 'filter'));
  280. }
  281. public function genericBills(Request $request, Client $patient)
  282. {
  283. return view('app.patient.generic-bills', compact('patient'));
  284. }
  285. public function rmSetup(Request $request, Client $patient)
  286. {
  287. return view('app.patient.rm-setup', compact('patient'));
  288. }
  289. public function handouts(Request $request, Client $patient )
  290. {
  291. $clientHandouts = HandoutClient::where('client_id', $patient->id)->get();
  292. $handouts = Handout::where('is_active', true)->orderBy('display_name', 'ASC')->get();
  293. return view('app.patient.handouts', compact('patient', 'clientHandouts', 'handouts'));
  294. }
  295. public function settings(Request $request, Client $patient )
  296. {
  297. return view('app.patient.settings', compact('patient'));
  298. }
  299. public function smsReminders(Request $request, Client $patient )
  300. {
  301. return view('app.patient.sms-reminders', compact('patient'));
  302. }
  303. public function measurementConfirmationNumbers(Request $request, Client $patient )
  304. {
  305. return view('app.patient.measurement-confirmation-numbers', compact('patient'));
  306. }
  307. public function pros(Request $request, Client $patient )
  308. {
  309. return view('app.patient.pros', compact('patient'));
  310. }
  311. public function proChanges(Request $request, Client $patient )
  312. {
  313. return view('app.patient.client-pro-changes', compact('patient'));
  314. }
  315. public function account(Request $request, Client $patient )
  316. {
  317. return view('app.patient.account', compact('patient'));
  318. }
  319. public function careChecklist(Request $request, Client $patient )
  320. {
  321. return view('app.patient.care-checklist', compact('patient'));
  322. }
  323. public function documents(Request $request, Client $patient )
  324. {
  325. return view('app.patient.documents', compact('patient'));
  326. }
  327. public function incomingReports(Request $request, Client $patient, IncomingReport $currentReport = null)
  328. {
  329. return view('app.patient.incoming-reports', compact('patient', 'currentReport'));
  330. }
  331. public function education(Request $request, Client $patient )
  332. {
  333. return view('app.patient.education', compact('patient'));
  334. }
  335. public function messaging(Request $request, Client $patient )
  336. {
  337. return view('app.patient.messaging', compact('patient'));
  338. }
  339. public function duplicate(Request $request, Client $patient )
  340. {
  341. return view('app.patient.duplicate', compact('patient'));
  342. }
  343. public function careMonths(Request $request, Client $patient )
  344. {
  345. $careMonths = CareMonth::where('client_id', $patient->id)->orderBy('start_date', 'desc')->get();
  346. $notes = Note::where('is_cancelled', false)->get();
  347. return view('app.patient.care-months', compact('patient', 'careMonths', 'notes'));
  348. }
  349. public function presence(Request $request, Client $patient )
  350. {
  351. return json_encode([
  352. "online" => $patient->is_online
  353. ]);
  354. }
  355. public function embedSection(Request $request, Client $patient, $section, $selectable) {
  356. return view('app.patient.partials.' . $section, compact('patient', 'selectable'));
  357. }
  358. public function calendar(Request $request, Client $patient, Appointment $currentAppointment) {
  359. $pros = [];
  360. if($this->pro && $this->pro->pro_type != 'ADMIN') {
  361. $accessiblePros = ProProAccess::where('owner_pro_id', $this->pro->id)->get();
  362. $accessibleProIds = [];
  363. foreach($accessiblePros as $accessiblePro){
  364. $accessibleProIds[] = $accessiblePro->accessible_pro_id;
  365. }
  366. $accessibleProIds[] = $this->pro->id;
  367. // for dna, add pros accessible via pro teams
  368. if($this->performer->pro->isDefaultNA()) {
  369. $teams = $this->performer->pro->teamsWhereAssistant;
  370. foreach ($teams as $team) {
  371. if(!in_array($team->mcp_pro_id, $accessibleProIds)) {
  372. $accessibleProIds[] = $team->mcp_pro_id;
  373. }
  374. }
  375. }
  376. $pros = Pro::whereIn('id', $accessibleProIds)->get();
  377. }
  378. $dateLastWeek = date_sub(date_create(), date_interval_create_from_date_string("14 days"));
  379. $dateLastWeek = date_format($dateLastWeek, "Y-m-d");
  380. $appointments = Appointment::where('client_id', $patient->id)
  381. ->orderBy('raw_date', 'desc')->orderBy('raw_start_time', 'desc')
  382. ->where('raw_date', '>=', $dateLastWeek)
  383. ->get();
  384. $appointmentProIDs = $appointments->map(function($_item) {
  385. return $_item->pro_id;
  386. });
  387. $appointmentPros = Pro::whereIn('id', $appointmentProIDs)->get();
  388. return view('app.patient.appointment-calendar',
  389. compact('pros', 'patient', 'currentAppointment', 'appointments', 'appointmentPros'));
  390. }
  391. public function programs(Request $request, Client $patient, $filter = '') {
  392. $pros = $this->pros;
  393. return view('app.patient.programs', compact('patient', 'pros', 'filter'));
  394. }
  395. public function flowsheets(Request $request, Client $patient, $filter = '') {
  396. $pros = $this->pros;
  397. return view('app.patient.flowsheets', compact('patient', 'pros', 'filter'));
  398. }
  399. public function vitalsSettings(Request $request, Client $patient) {
  400. return view('app.patient.vitals-settings', compact('patient'));
  401. }
  402. public function vitalsGraph(Request $request, Client $patient, $filter = '') {
  403. $pros = $this->pros;
  404. return view('app.patient.vitals-graph', compact('patient', 'pros', 'filter'));
  405. }
  406. public function tickets(Request $request, Client $patient, $type = '', String $currentTicket = '') {
  407. $pros = $this->pros;
  408. $allPros = Pro::all();
  409. $qlTicket = $currentTicket;
  410. if(!!$currentTicket) {
  411. $qlTicket = Ticket::where('uid', $currentTicket)->first();
  412. if($qlTicket) {
  413. $currentTicket = $qlTicket;
  414. }
  415. }
  416. return view('app.patient.tickets', compact('patient', 'pros', 'allPros', 'type', 'currentTicket'));
  417. }
  418. public function prescriptions(Request $request, Client $patient, String $type = '', String $currentErx = '') {
  419. if(!!$currentErx) {
  420. $currentErx = Erx::where('uid', $currentErx)->first();
  421. }
  422. $note = $patient->coreNote;
  423. return view('app.patient.prescriptions.index', compact('patient', 'type', 'currentErx', 'note'));
  424. }
  425. public function prescriptionsPopup(Request $request, Client $patient, String $type = '', String $currentErx = '') {
  426. if(!!$currentErx) {
  427. $currentErx = Erx::where('uid', $currentErx)->first();
  428. }
  429. $note = null;
  430. if($request->input('noteUid')) {
  431. $note = Note::where('uid', $request->input('noteUid'))->first();
  432. }
  433. return view('app.patient.prescriptions-popup.list-popup', compact('patient', 'type', 'currentErx', 'note'));
  434. }
  435. public function prescriptionsList(Request $request, Client $patient, String $type = '', String $currentErx = '') {
  436. if(!!$currentErx) {
  437. $currentErx = Erx::where('uid', $currentErx)->first();
  438. }
  439. $note = null;
  440. if($request->input('noteUid')) {
  441. $note = Note::where('uid', $request->input('noteUid'))->first();
  442. }
  443. return view('app.patient.prescriptions.list', compact('patient', 'type', 'currentErx', 'note'));
  444. }
  445. public function downloadPrescriptionAsPdf(Request $request, Erx $prescription){
  446. if($request->input('html')) {
  447. return view('app.patient.prescriptions.pdf.pdf-preview', compact('prescription'));
  448. }
  449. else {
  450. $pdf = PDF::loadView('app.patient.prescriptions.pdf.pdf-preview', compact('prescription'));
  451. return $pdf->download($prescription->created_at .'_' . 'erx.pdf');
  452. }
  453. }
  454. public function transmitPrescription(Request $request, Erx $prescription){
  455. // re-generate pdf with cover sheet as first page and save it to FS
  456. $filePath = config('app.temp_dir') . "/{$prescription->uid}.pdf";
  457. $pdf = PDF::loadView('app.patient.prescriptions.pdf.pdf-preview-with-cover-sheet', compact('prescription'));
  458. $pdf->save($filePath);
  459. // send it along with the rest of the params to /api/erx/transmit [multi-part POST]
  460. $url = config('stag.backendUrl') . '/erx/transmit';
  461. $params = [
  462. "uid" => $request->input('uid'),
  463. "toWho" => $request->input('toWho'),
  464. "toEmail" => $request->input('toEmail'),
  465. "toFaxNumber" => $request->input('toFaxNumber'),
  466. "toFaxNumberAttentionLine" => $request->input('toFaxNumberAttentionLine'),
  467. "toFaxNumberCoverSheetMemo" => $request->input('toFaxNumberCoverSheetMemo'),
  468. ];
  469. if($request->input('copyToPatient')) {
  470. $params["copyToPatientFaxNumber"] = $request->input('copyToPatientFaxNumber');
  471. $params["copyToPatientEmail"] = $request->input('copyToPatientEmail');
  472. }
  473. $pdf = fopen($filePath, 'r');
  474. $response = Http
  475. ::attach('pdfSystemFile', $filePath, "{$prescription->uid}.pdf")
  476. ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
  477. ->post($url, $params)
  478. ->json();
  479. return $response;
  480. }
  481. public function supplyOrders(Request $request, Client $patient, SupplyOrder $supplyOrder = null)
  482. {
  483. $products = Product::where('is_active', true)->orderBy('created_at', 'desc')->get();
  484. return view('app.patient.supply-orders', compact('patient', 'supplyOrder', 'products'));
  485. }
  486. public function shipments(Request $request, Client $patient, Shipment $shipment = null)
  487. {
  488. return view('app.patient.shipments', compact('patient', 'shipment'));
  489. }
  490. public function appointments(Request $request, Client $patient, $forPro = 'all', $status = 'all') {
  491. $pros = $this->pros;
  492. $appointments = $patient->appointmentsForProByStatus($forPro, strtoupper($status));
  493. $appointmentProIDs = $appointments->map(function($_item) {
  494. return $_item->pro_id;
  495. });
  496. $appointmentPros = Pro::whereIn('id', $appointmentProIDs)->get();
  497. return view('app.patient.appointments',
  498. compact('patient', 'pros', 'appointments', 'appointmentPros', 'forPro', 'status'));
  499. }
  500. public function mcpRequests(Request $request, Client $patient) {
  501. return view('app.patient.mcp-requests', compact('patient'));
  502. }
  503. public function eligibleRefreshes(Request $request, Client $patient) {
  504. return view('app.patient.eligible-refreshes', compact('patient'));
  505. }
  506. public function insuranceCoverage(Request $request, Client $patient) {
  507. $mbPayers = MBPayer::all();
  508. return view('app.patient.insurance-coverage', compact('patient', 'mbPayers'));
  509. }
  510. public function clientPrimaryCoverages(Request $request, Client $patient) {
  511. $mbPayers = MBPayer::all();
  512. return view('app.patient.client-primary-coverages', compact('patient', 'mbPayers'));
  513. }
  514. public function primaryCoverage(Request $request, Client $patient) {
  515. $mbPayers = MBPayer::all();
  516. return view('app.patient.primary-coverage', compact('patient', 'mbPayers'));
  517. }
  518. public function primaryCoverageForm(Request $request, Client $patient) {
  519. $mbPayers = MBPayer::all();
  520. return view('app.patient.primary-coverage-form', compact('patient', 'mbPayers'));
  521. }
  522. public function primaryCoverageManualDeterminationModal(Request $request, Client $patient) {
  523. $coverageUid = $request->get('coverageUid');
  524. $coverage = ClientPrimaryCoverage::where('uid', $coverageUid)->first();
  525. if($patient->latestClientPrimaryCoverage->plan_type === 'MEDICARE'){
  526. return view('app.patient.primary-coverage-manual-determination-medicare-modal', compact('patient', 'coverage'));
  527. }
  528. if($patient->latestClientPrimaryCoverage->plan_type === 'MEDICAID'){
  529. return view('app.patient.primary-coverage-manual-determination-medicaid-modal', compact('patient', 'coverage'));
  530. }
  531. if($patient->latestClientPrimaryCoverage->plan_type === 'COMMERCIAL'){
  532. return view('app.patient.primary-coverage-manual-determination-commercial-modal', compact('patient', 'coverage'));
  533. }
  534. return "Plan Type is missing!";
  535. }
  536. public function mbClaim(Request $request, MBClaim $mbClaim) {
  537. return view('app.patient.mb-claim-single', compact('mbClaim'));
  538. }
  539. public function accounts(Request $request, Client $patient) {
  540. return view('app.patient.accounts', compact('patient'));
  541. }
  542. public function careMonthMatrix(Request $request, CareMonth $careMonth) {
  543. return view('app.patient.care-month.matrix', [
  544. 'patient' => $careMonth->patient,
  545. 'careMonth' => $careMonth,
  546. ]);
  547. }
  548. public function clientProAccess(Request $request, Client $patient) {
  549. $rows = ClientProAccess::where('client_id', $patient->id)->get();
  550. return view('app.patient.client-pro-access', compact('patient', 'rows'));
  551. }
  552. public function clientDocuments(Request $request, Client $patient){
  553. $templates = get_doc_templates();
  554. $companyProIDs = DB::select('SELECT company_pro_id FROM company_pro_document WHERE related_client_id = ?', [$patient->id]);
  555. $companyProIDInts = [];
  556. foreach($companyProIDs as $cpId){
  557. $companyProIDInts[] = $cpId->company_pro_id;
  558. }
  559. $companyPros = CompanyPro::whereIn('id', $companyProIDInts)->get();
  560. return view('app.patient.client-documents', compact('templates', 'companyPros', 'patient'));
  561. }
  562. }