PatientController.php 27 KB

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