PatientController.php 28 KB

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