PatientController.php 28 KB

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