PatientController.php 27 KB

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