PatientController.php 25 KB

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