PatientController.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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 App\Models\Point;
  37. use Illuminate\Support\Facades\Http;
  38. use PDF;
  39. class PatientController extends Controller
  40. {
  41. public function invoicingCompanies(Request $request, Client $patient) {
  42. return view('app.patient.invoicing.companies', compact('patient'));
  43. }
  44. public function invoicingInvoices(Request $request, Client $patient, Customer $customer) {
  45. return view('app.patient.invoicing.invoices', compact('patient', 'customer'));
  46. }
  47. public function invoicingCustomerTransactions(Request $request, Client $patient, Customer $customer) {
  48. return view('app.patient.invoicing.customer-transactions', compact('patient', 'customer'));
  49. }
  50. public function invoicingInvoiceTransactions(Request $request, Client $patient, Invoice $invoice) {
  51. $customer = $invoice->customer;
  52. return view('app.patient.invoicing.invoice-transactions', compact('patient', 'invoice', 'customer'));
  53. }
  54. public function invoicingInvoiceTransactionsInPopup(Request $request, Client $patient, Invoice $invoice) {
  55. $customer = $invoice->customer;
  56. return view('app.patient.invoicing.invoice-transactions-in-popup', compact('patient', 'invoice', 'customer'));
  57. }
  58. public function claimsResolver(Request $request, Client $patient)
  59. {
  60. $notes = $patient->notesAscending;
  61. $hcpSignedNotesCount = 0;
  62. foreach($notes as $note){
  63. if($note->is_signed_by_hcp){
  64. $hcpSignedNotesCount += 1;
  65. }
  66. }
  67. $data = [
  68. 'dog' => 'bark',
  69. 'patient' => $patient,
  70. 'hcpSignedNotesCount' => $hcpSignedNotesCount
  71. ];
  72. return view('app.patient.claims-resolver', $data);
  73. }
  74. public function dashboard(Request $request, Client $patient )
  75. {
  76. $mcpPros = Pro::where('is_enrolled_as_mcp', true)->get();
  77. $facilities = []; // Facility::where('is_active', true)->get();
  78. // get assigned devices
  79. $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true"));
  80. $assignedDeviceIDs = array_map(function($_x) {
  81. return $_x->device_id;
  82. }, $assignedDeviceIDs);
  83. // get all except assigned ones
  84. $devices = BDTDevice::where('is_active', true)
  85. ->whereNotIn('id', $assignedDeviceIDs)
  86. ->orderBy('imei', 'asc')
  87. ->get();
  88. $assignedDeviceIDs = null;
  89. unset($assignedDeviceIDs);
  90. $availableDevices = count($devices);
  91. $patientDeviceIDs = ClientBDTDevice::select('id')->where('client_id', $patient->id)->where('is_active', true)->get()->toArray();
  92. $patientDeviceIDs = array_map(function ($_x) {
  93. return $_x["id"];
  94. }, $patientDeviceIDs);
  95. $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
  96. ->where('category', 'dx')
  97. ->where('is_removed', false)
  98. ->orderBy('content_text', 'asc')
  99. ->get();
  100. $clientMemos = $patient->memos;
  101. $shortCutsObject = [];
  102. foreach ($this->pro->allShortcuts() as $shortcut) {
  103. // %replaceables%
  104. $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);
  105. $shortcut->text = str_replace("%GENDER%", $patient->sex, $shortcut->text);
  106. $shortcut->text = str_replace("%NAME%", $patient->displayName(), $shortcut->text);
  107. $shortCutsObject[] = [
  108. "name" => $shortcut->shortcut,
  109. "value" => $shortcut->text
  110. ];
  111. }
  112. $recentMeasurements = $patient->recentMeasurements;
  113. $latestVitals = Point::where('client_id', $patient->id)->where('category', 'VITALS')->orderBy('id', 'DESC')->first();
  114. return view('app.patient.dashboard',
  115. compact('patient', 'facilities', 'devices', 'dxInfoLines', 'clientMemos', 'shortCutsObject', 'availableDevices', 'patientDeviceIDs', 'recentMeasurements', 'latestVitals'));
  116. }
  117. public function canvasMigrate(Request $request, Client $patient )
  118. {
  119. $mcpPros = Pro::where('is_enrolled_as_mcp', true)->get();
  120. $facilities = []; // Facility::where('is_active', true)->get();
  121. // get assigned devices
  122. $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true"));
  123. $assignedDeviceIDs = array_map(function($_x) {
  124. return $_x->device_id;
  125. }, $assignedDeviceIDs);
  126. // get all except assigned ones
  127. $devices = BDTDevice::where('is_active', true)
  128. ->whereNotIn('id', $assignedDeviceIDs)
  129. ->orderBy('imei', 'asc')
  130. ->get();
  131. $assignedDeviceIDs = null;
  132. unset($assignedDeviceIDs);
  133. $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
  134. ->where('category', 'dx')
  135. ->where('is_removed', false)
  136. ->orderBy('content_text', 'asc')
  137. ->get();
  138. return view('app.patient.canvas-migrate',
  139. compact('patient', 'facilities', 'devices', 'dxInfoLines'));
  140. }
  141. public function canvas(Request $request, Client $patient){
  142. return view('app.patient.canvas_dump', compact('patient'));
  143. }
  144. public function intake(Request $request, Client $patient )
  145. {
  146. $files = File::allFiles(resource_path('views/app/intake-templates'));
  147. $templates = [];
  148. foreach ($files as $file) {
  149. $templates[] = str_replace(".blade.php", "", $file->getFilename());
  150. }
  151. return view('app.patient.intake', compact('patient', 'templates'));
  152. }
  153. public function carePlan(Request $request, Client $patient )
  154. {
  155. return view('app.patient.care-plan', compact('patient'));
  156. }
  157. public function medications(Request $request, Client $patient )
  158. {
  159. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  160. ->where('category', 'rx')
  161. ->where('is_removed', false)
  162. ->orderBy('content_text', 'asc')
  163. ->get();
  164. return view('app.patient.medications', compact('patient', 'infoLines'));
  165. }
  166. public function dxAndFocusAreas(Request $request, Client $patient )
  167. {
  168. $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
  169. ->where('category', 'dx')
  170. ->where('is_removed', false)
  171. ->orderBy('content_text', 'asc')
  172. ->get();
  173. return view('app.patient.dx-and-focus-areas', compact('patient', 'dxInfoLines'));
  174. }
  175. public function careTeam(Request $request, Client $patient )
  176. {
  177. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  178. ->where('category', 'care_team')
  179. ->where('is_removed', false)
  180. ->get();
  181. return view('app.patient.care-team', compact('patient', 'infoLines'));
  182. }
  183. public function devices(Request $request, Client $patient )
  184. {
  185. // get assigned devices
  186. $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true"));
  187. $assignedDeviceIDs = array_map(function($_x) {
  188. return $_x->device_id;
  189. }, $assignedDeviceIDs);
  190. // get all except assigned ones
  191. $devices = BDTDevice::where('is_active', true)
  192. ->whereNotIn('id', $assignedDeviceIDs)
  193. ->orderBy('imei', 'asc')
  194. ->get();
  195. $assignedDeviceIDs = null;
  196. unset($assignedDeviceIDs);
  197. return view('app.patient.devices', compact('patient', 'devices'));
  198. }
  199. public function measurements(Request $request, Client $patient )
  200. {
  201. $measurements = Measurement::where('client_id', $patient->id)->where('is_active', true)->orderByRaw('ts DESC NULLS LAST')->paginate(30);
  202. return view('app.patient.measurements', compact('patient', 'measurements'));
  203. }
  204. public function labsAndStudies(Request $request, Client $patient )
  205. {
  206. return view('app.patient.labs-and-studies', compact('patient'));
  207. }
  208. public function history(Request $request, Client $patient )
  209. {
  210. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  211. ->where('category', 'LIKE', 'history_%')
  212. ->where('is_removed', false)
  213. ->get();
  214. return view('app.patient.history', compact('patient', 'infoLines'));
  215. }
  216. public function memos(Request $request, Client $patient )
  217. {
  218. return view('app.patient.memos', compact('patient'));
  219. }
  220. public function memosThread(Request $request, Client $patient )
  221. {
  222. return view('app.patient.memos-thread', compact('patient'));
  223. }
  224. public function messagesThread(Request $request, Client $patient )
  225. {
  226. return view('app.patient.messages-thread', compact('patient'));
  227. }
  228. public function sms(Request $request, Client $patient )
  229. {
  230. return view('app.patient.sms', compact('patient'));
  231. }
  232. public function outgoingSmsLog(Request $request, Client $patient )
  233. {
  234. return view('app.patient.outgoing-sms-log', compact('patient'));
  235. }
  236. public function reviewRequests(Request $request, Client $patient){
  237. $pro = $this->performer->pro;
  238. $reviewRequests = ClientReviewRequest::where('client_id', $patient->id);
  239. if($pro->pro_type !== 'ADMIN'){
  240. $reviewRequests = $reviewRequests->where('pro_id', $pro->id)->where('is_active', true);
  241. }
  242. $reviewRequests = $reviewRequests->orderBy('created_at', 'DESC')->paginate(50);
  243. return view('app.patient.review-requests.list', compact('patient', 'reviewRequests'));
  244. }
  245. public function smsNumbers(Request $request, Client $patient )
  246. {
  247. return view('app.patient.sms-numbers', compact('patient'));
  248. }
  249. public function immunizations(Request $request, Client $patient )
  250. {
  251. return view('app.patient.immunizations', compact('patient'));
  252. }
  253. public function allergies(Request $request, Client $patient )
  254. {
  255. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  256. ->where('category', 'allergy')
  257. ->where('is_removed', false)
  258. ->get();
  259. return view('app.patient.allergies', compact('patient', 'infoLines'));
  260. }
  261. public function notes(Request $request, Client $patient, $filter = 'active')
  262. {
  263. $pros = $this->pros;
  264. return view('app.patient.notes', compact('patient','pros', 'filter'));
  265. }
  266. public function genericBills(Request $request, Client $patient)
  267. {
  268. return view('app.patient.generic-bills', compact('patient'));
  269. }
  270. public function rmSetup(Request $request, Client $patient)
  271. {
  272. // get assigned devices
  273. $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true"));
  274. $assignedDeviceIDs = array_map(function($_x) {
  275. return $_x->device_id;
  276. }, $assignedDeviceIDs);
  277. // get all except assigned ones
  278. $devices = BDTDevice::where('is_active', true)
  279. ->whereNotIn('id', $assignedDeviceIDs)
  280. ->orderBy('imei', 'asc')
  281. ->get();
  282. $assignedDeviceIDs = null;
  283. unset($assignedDeviceIDs);
  284. return view('app.patient.rm-setup', compact('patient', 'devices'));
  285. }
  286. public function handouts(Request $request, Client $patient )
  287. {
  288. $clientHandouts = HandoutClient::where('client_id', $patient->id)->get();
  289. $handouts = Handout::where('is_active', true)->orderBy('display_name', 'ASC')->get();
  290. return view('app.patient.handouts', compact('patient', 'clientHandouts', 'handouts'));
  291. }
  292. public function settings(Request $request, Client $patient )
  293. {
  294. $companies = Company::all();
  295. return view('app.patient.settings', compact('patient', 'companies'));
  296. }
  297. public function smsReminders(Request $request, Client $patient )
  298. {
  299. return view('app.patient.sms-reminders', compact('patient'));
  300. }
  301. public function measurementConfirmationNumbers(Request $request, Client $patient )
  302. {
  303. return view('app.patient.measurement-confirmation-numbers', compact('patient'));
  304. }
  305. public function pros(Request $request, Client $patient )
  306. {
  307. return view('app.patient.pros', compact('patient'));
  308. }
  309. public function proChanges(Request $request, Client $patient )
  310. {
  311. return view('app.patient.client-pro-changes', compact('patient'));
  312. }
  313. public function account(Request $request, Client $patient )
  314. {
  315. return view('app.patient.account', compact('patient'));
  316. }
  317. public function careChecklist(Request $request, Client $patient )
  318. {
  319. return view('app.patient.care-checklist', compact('patient'));
  320. }
  321. public function documents(Request $request, Client $patient )
  322. {
  323. return view('app.patient.documents', compact('patient'));
  324. }
  325. public function incomingReports(Request $request, Client $patient, IncomingReport $currentReport = null)
  326. {
  327. return view('app.patient.incoming-reports', compact('patient', 'currentReport'));
  328. }
  329. public function education(Request $request, Client $patient )
  330. {
  331. return view('app.patient.education', compact('patient'));
  332. }
  333. public function messaging(Request $request, Client $patient )
  334. {
  335. return view('app.patient.messaging', compact('patient'));
  336. }
  337. public function duplicate(Request $request, Client $patient )
  338. {
  339. return view('app.patient.duplicate', compact('patient'));
  340. }
  341. public function careMonths(Request $request, Client $patient )
  342. {
  343. $careMonths = CareMonth::where('client_id', $patient->id)->orderBy('start_date', 'desc')->get();
  344. $notes = Note::where('is_cancelled', false)->get();
  345. return view('app.patient.care-months', compact('patient', 'careMonths', 'notes'));
  346. }
  347. public function presence(Request $request, Client $patient )
  348. {
  349. return json_encode([
  350. "online" => $patient->is_online
  351. ]);
  352. }
  353. public function embedSection(Request $request, Client $patient, $section, $selectable) {
  354. return view('app.patient.partials.' . $section, compact('patient', 'selectable'));
  355. }
  356. public function calendar(Request $request, Client $patient, Appointment $currentAppointment) {
  357. $pros = [];
  358. if($this->pro && $this->pro->pro_type != 'ADMIN') {
  359. $accessiblePros = ProProAccess::where('owner_pro_id', $this->pro->id)->get();
  360. $accessibleProIds = [];
  361. foreach($accessiblePros as $accessiblePro){
  362. $accessibleProIds[] = $accessiblePro->accessible_pro_id;
  363. }
  364. $accessibleProIds[] = $this->pro->id;
  365. // for dna, add pros accessible via pro teams
  366. if($this->performer->pro->isDefaultNA()) {
  367. $teams = $this->performer->pro->teamsWhereAssistant;
  368. foreach ($teams as $team) {
  369. if(!in_array($team->mcp_pro_id, $accessibleProIds)) {
  370. $accessibleProIds[] = $team->mcp_pro_id;
  371. }
  372. }
  373. }
  374. $pros = Pro::whereIn('id', $accessibleProIds)->get();
  375. }
  376. $dateLastWeek = date_sub(date_create(), date_interval_create_from_date_string("14 days"));
  377. $dateLastWeek = date_format($dateLastWeek, "Y-m-d");
  378. $appointments = Appointment::where('client_id', $patient->id)
  379. ->orderBy('raw_date', 'desc')->orderBy('raw_start_time', 'desc')
  380. ->where('raw_date', '>=', $dateLastWeek)
  381. ->get();
  382. $appointmentProIDs = $appointments->map(function($_item) {
  383. return $_item->pro_id;
  384. });
  385. $appointmentPros = Pro::whereIn('id', $appointmentProIDs)->get();
  386. return view('app.patient.appointment-calendar',
  387. compact('pros', 'patient', 'currentAppointment', 'appointments', 'appointmentPros'));
  388. }
  389. public function flowsheets(Request $request, Client $patient, $filter = '') {
  390. $pros = $this->pros;
  391. return view('app.patient.flowsheets', compact('patient', 'pros', 'filter'));
  392. }
  393. public function vitalsSettings(Request $request, Client $patient) {
  394. return view('app.patient.vitals-settings', compact('patient'));
  395. }
  396. public function vitalsGraph(Request $request, Client $patient, $filter = '') {
  397. $pros = $this->pros;
  398. return view('app.patient.vitals-graph', compact('patient', 'pros', 'filter'));
  399. }
  400. public function sleepStudy(Request $request, Client $patient) {
  401. return view('app.patient.sleep-study', compact('patient'));
  402. }
  403. public function sleepStudyStep(Request $request, Client $patient) {
  404. return view('app.patient.sleep-study.' . $request->input('step'), compact('patient'));
  405. }
  406. public function tickets(Request $request, Client $patient, $type = '', String $currentTicket = '') {
  407. $pros = $this->pros;
  408. $allPros = Pro::all();
  409. $qlTicket = $currentTicket;
  410. if(!!$currentTicket) {
  411. $qlTicket = Ticket::where('uid', $currentTicket)->first();
  412. if($qlTicket) {
  413. $currentTicket = $qlTicket;
  414. }
  415. }
  416. return view('app.patient.tickets', compact('patient', 'pros', 'allPros', 'type', 'currentTicket'));
  417. }
  418. protected function getDefaultFacility(){
  419. $defaultFacility = Facility::where('name', 'Ultra Care Pharmacy')->where('address_city', 'Baltimore')->first();
  420. return $defaultFacility;
  421. }
  422. public function prescriptions(Request $request, Client $patient, String $type = '', String $currentErx = '') {
  423. $this->updateDefaultPatientPharmacy($patient);
  424. if(!!$currentErx) {
  425. $currentErx = Erx::where('uid', $currentErx)->first();
  426. }
  427. $note = $patient->coreNote;
  428. $defaultFacility = $this->getDefaultFacility();
  429. $patient->refresh();
  430. return view('app.patient.prescriptions.index', compact('patient', 'type', 'currentErx', 'note', 'defaultFacility'));
  431. }
  432. protected function updateDefaultPatientPharmacy(Client $patient){
  433. $prescriptions = $patient->prescriptions;
  434. if(!count($prescriptions)) return;
  435. $defaultFacility = $this->getDefaultFacility();
  436. if(!$defaultFacility) return;
  437. foreach($prescriptions as $prescription){
  438. if($prescription->logistics_detail_json) continue;
  439. $this->setPrescriptionDefaultPharmacy($prescription, $defaultFacility);
  440. }
  441. }
  442. private function setPrescriptionDefaultPharmacy(Erx $prescription, Facility $facility){
  443. $data = [
  444. 'uid' => $prescription->uid,
  445. 'logisticsDetailJson' => json_encode([
  446. 'facilityName' => $facility->name,
  447. 'facilityCity' => $facility->address_city,
  448. 'facilityState' => $facility->address_state,
  449. 'facilityAddressMemo' => '',
  450. 'facilityPhone' => $facility->phone,
  451. 'facilityFax' => $facility->fax,
  452. 'facilityZip' => $facility->address_zip,
  453. ])
  454. ];
  455. $response = $this->callJavaApi('/erx/updateLogisticsDetail', $data);
  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 companies(Request $request, Client $patient) {
  575. $companies = Company::where('is_active', true)->get();
  576. $companyClientStatusMap = [];
  577. $companyClientStatusMap['NEW'] = 'New';
  578. $companyClientStatusMap['ELIGIBILITY_VERIFIED'] = 'Eligibility Verified';
  579. $companyClientStatusMap['ELIGIBILITY_PENDING'] = 'Eligibility Pending';
  580. $companyClientStatusMap['NOT_ELIGIBLE'] = 'Not Eligible';
  581. $companyClientStatusMap['INITIAL_CONSULT'] = 'Initial Consult';
  582. $companyClientStatusMap['HST_DELIVERED'] = 'HST Delivered';
  583. $companyClientStatusMap['STUDY_PENDING'] = 'Study Pending';
  584. $companyClientStatusMap['STUDY_COMPLETED'] = 'Study Completed';
  585. $companyClientStatusMap['STUDY_INTERPRETED'] = 'Study Interpreted';
  586. $companyClientStatusMap['POST_HST_VISIT'] = 'Post HST Visit';
  587. $companyClientStatusMap['CPAP_RX'] = 'CPAP Rx';
  588. $companyClientStatusMap['ORAL_APPLIANCE_RX'] = 'Oral Appliance Rx';
  589. $companyClientStatusMap['NOT_INTERESTED'] = 'Not Interested';
  590. $companyClientStatusMap['IN_LAB_STUDY'] = 'In Lab Study';
  591. $companyClientStatusMap['UNRESPONSIVE'] = 'Unresponsive';
  592. return view('app.patient.companies', compact('patient', 'companies', 'companyClientStatusMap'));
  593. }
  594. public function rtm(Request $request, Client $patient) {
  595. return view('app.patient.rtm', compact('patient'));
  596. }
  597. public function careMonthMatrix(Request $request, CareMonth $careMonth) {
  598. return view('app.patient.care-month.matrix', [
  599. 'patient' => $careMonth->patient,
  600. 'careMonth' => $careMonth,
  601. ]);
  602. }
  603. public function clientProAccess(Request $request, Client $patient) {
  604. $rows = ClientProAccess::where('client_id', $patient->id)->get();
  605. return view('app.patient.client-pro-access', compact('patient', 'rows'));
  606. }
  607. public function clientDocuments(Request $request, Client $patient){
  608. $templates = get_doc_templates();
  609. $companyProIDs = DB::select('SELECT company_pro_id FROM company_pro_document WHERE related_client_id = ?', [$patient->id]);
  610. $companyProIDInts = [];
  611. foreach($companyProIDs as $cpId){
  612. $companyProIDInts[] = $cpId->company_pro_id;
  613. }
  614. $companyPros = CompanyPro::whereIn('id', $companyProIDInts)->get();
  615. return view('app.patient.client-documents', compact('templates', 'companyPros', 'patient'));
  616. }
  617. public function insuranceCoverageHistory(Request $request, Client $patient){
  618. $insuranceCoverageHistory = ClientPrimaryCoverage::where('client_id', $patient->id)->orderBy('created_at', 'DESC')->get();
  619. return view('app.patient.insurance-coverage-history', compact('patient', 'insuranceCoverageHistory'));
  620. }
  621. public function protocolBuilder(Request $request, Client $patient) {
  622. return view('app.patient.rtm.protocol-builder', compact('patient'));
  623. }
  624. public function checkIfCptCodeIsSubmitted(Request $request){
  625. $clientUid = $request->get('clientUid');
  626. $cptCode = $request->get('code');
  627. if(!$clientUid || !$cptCode) return $this->fail('Error');
  628. $client = Client::where('uid', $clientUid)->first();
  629. $notes = $client->notes;
  630. $isCptSubmitted = false;
  631. foreach($notes as $note){
  632. $noteClaims = $note->claims;
  633. foreach($noteClaims as $noteClaim){
  634. foreach($noteClaim->lines as $claimLine){
  635. if($claimLine->cpt == $cptCode){
  636. if($noteClaim->status == 'SUBMITTED'){
  637. $isCptSubmitted = true;
  638. }
  639. }
  640. }
  641. }
  642. }
  643. if($isCptSubmitted) return $this->pass('SUBMITTED');
  644. return $this->pass('NOT_SUBMITTED');
  645. }
  646. }