PatientController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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 intake(Request $request, Client $patient )
  121. {
  122. $files = File::allFiles(resource_path('views/app/intake-templates'));
  123. $templates = [];
  124. foreach ($files as $file) {
  125. $templates[] = str_replace(".blade.php", "", $file->getFilename());
  126. }
  127. return view('app.patient.intake', compact('patient', 'templates'));
  128. }
  129. public function carePlan(Request $request, Client $patient )
  130. {
  131. return view('app.patient.care-plan', compact('patient'));
  132. }
  133. public function medications(Request $request, Client $patient )
  134. {
  135. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  136. ->where('category', 'rx')
  137. ->where('is_removed', false)
  138. ->orderBy('content_text', 'asc')
  139. ->get();
  140. return view('app.patient.medications', compact('patient', 'infoLines'));
  141. }
  142. public function dxAndFocusAreas(Request $request, Client $patient )
  143. {
  144. $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
  145. ->where('category', 'dx')
  146. ->where('is_removed', false)
  147. ->orderBy('content_text', 'asc')
  148. ->get();
  149. return view('app.patient.dx-and-focus-areas', compact('patient', 'dxInfoLines'));
  150. }
  151. public function careTeam(Request $request, Client $patient )
  152. {
  153. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  154. ->where('category', 'care_team')
  155. ->where('is_removed', false)
  156. ->get();
  157. return view('app.patient.care-team', compact('patient', 'infoLines'));
  158. }
  159. public function devices(Request $request, Client $patient )
  160. {
  161. // get assigned devices
  162. $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true"));
  163. $assignedDeviceIDs = array_map(function($_x) {
  164. return $_x->device_id;
  165. }, $assignedDeviceIDs);
  166. // get all except assigned ones
  167. $devices = BDTDevice::where('is_active', true)
  168. ->whereNotIn('id', $assignedDeviceIDs)
  169. ->orderBy('imei', 'asc')
  170. ->get();
  171. $assignedDeviceIDs = null;
  172. unset($assignedDeviceIDs);
  173. return view('app.patient.devices', compact('patient', 'devices'));
  174. }
  175. public function measurements(Request $request, Client $patient )
  176. {
  177. $measurements = Measurement::where('client_id', $patient->id)->where('is_active', true)->orderByRaw('ts DESC NULLS LAST')->paginate(30);
  178. return view('app.patient.measurements', compact('patient', 'measurements'));
  179. }
  180. public function labsAndStudies(Request $request, Client $patient )
  181. {
  182. return view('app.patient.labs-and-studies', compact('patient'));
  183. }
  184. public function history(Request $request, Client $patient )
  185. {
  186. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  187. ->where('category', 'LIKE', 'history_%')
  188. ->where('is_removed', false)
  189. ->get();
  190. return view('app.patient.history', compact('patient', 'infoLines'));
  191. }
  192. public function memos(Request $request, Client $patient )
  193. {
  194. return view('app.patient.memos', compact('patient'));
  195. }
  196. public function memosThread(Request $request, Client $patient )
  197. {
  198. return view('app.patient.memos-thread', compact('patient'));
  199. }
  200. public function messagesThread(Request $request, Client $patient )
  201. {
  202. return view('app.patient.messages-thread', compact('patient'));
  203. }
  204. public function sms(Request $request, Client $patient )
  205. {
  206. return view('app.patient.sms', compact('patient'));
  207. }
  208. public function outgoingSmsLog(Request $request, Client $patient )
  209. {
  210. return view('app.patient.outgoing-sms-log', compact('patient'));
  211. }
  212. public function reviewRequests(Request $request, Client $patient){
  213. $pro = $this->performer->pro;
  214. $reviewRequests = ClientReviewRequest::where('client_id', $patient->id);
  215. if($pro->pro_type !== 'ADMIN'){
  216. $reviewRequests = $reviewRequests->where('pro_id', $pro->id)->where('is_active', true);
  217. }
  218. $reviewRequests = $reviewRequests->orderBy('created_at', 'DESC')->paginate(50);
  219. return view('app.patient.review-requests.list', compact('patient', 'reviewRequests'));
  220. }
  221. public function smsNumbers(Request $request, Client $patient )
  222. {
  223. return view('app.patient.sms-numbers', compact('patient'));
  224. }
  225. public function immunizations(Request $request, Client $patient )
  226. {
  227. return view('app.patient.immunizations', compact('patient'));
  228. }
  229. public function allergies(Request $request, Client $patient )
  230. {
  231. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  232. ->where('category', 'allergy')
  233. ->where('is_removed', false)
  234. ->get();
  235. return view('app.patient.allergies', compact('patient', 'infoLines'));
  236. }
  237. public function notes(Request $request, Client $patient, $filter = 'active')
  238. {
  239. $pros = $this->pros;
  240. return view('app.patient.notes', compact('patient','pros', 'filter'));
  241. }
  242. public function genericBills(Request $request, Client $patient)
  243. {
  244. return view('app.patient.generic-bills', compact('patient'));
  245. }
  246. public function rmSetup(Request $request, Client $patient)
  247. {
  248. // get assigned devices
  249. $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true"));
  250. $assignedDeviceIDs = array_map(function($_x) {
  251. return $_x->device_id;
  252. }, $assignedDeviceIDs);
  253. // get all except assigned ones
  254. $devices = BDTDevice::where('is_active', true)
  255. ->whereNotIn('id', $assignedDeviceIDs)
  256. ->orderBy('imei', 'asc')
  257. ->get();
  258. $assignedDeviceIDs = null;
  259. unset($assignedDeviceIDs);
  260. return view('app.patient.rm-setup', compact('patient', 'devices'));
  261. }
  262. public function handouts(Request $request, Client $patient )
  263. {
  264. $clientHandouts = HandoutClient::where('client_id', $patient->id)->get();
  265. $handouts = Handout::where('is_active', true)->orderBy('display_name', 'ASC')->get();
  266. return view('app.patient.handouts', compact('patient', 'clientHandouts', 'handouts'));
  267. }
  268. public function settings(Request $request, Client $patient )
  269. {
  270. $companies = Company::all();
  271. return view('app.patient.settings', compact('patient', 'companies'));
  272. }
  273. public function smsReminders(Request $request, Client $patient )
  274. {
  275. return view('app.patient.sms-reminders', compact('patient'));
  276. }
  277. public function measurementConfirmationNumbers(Request $request, Client $patient )
  278. {
  279. return view('app.patient.measurement-confirmation-numbers', compact('patient'));
  280. }
  281. public function pros(Request $request, Client $patient )
  282. {
  283. return view('app.patient.pros', compact('patient'));
  284. }
  285. public function proChanges(Request $request, Client $patient )
  286. {
  287. return view('app.patient.client-pro-changes', compact('patient'));
  288. }
  289. public function account(Request $request, Client $patient )
  290. {
  291. return view('app.patient.account', compact('patient'));
  292. }
  293. public function careChecklist(Request $request, Client $patient )
  294. {
  295. return view('app.patient.care-checklist', compact('patient'));
  296. }
  297. public function documents(Request $request, Client $patient )
  298. {
  299. return view('app.patient.documents', compact('patient'));
  300. }
  301. public function incomingReports(Request $request, Client $patient, IncomingReport $currentReport = null)
  302. {
  303. return view('app.patient.incoming-reports', compact('patient', 'currentReport'));
  304. }
  305. public function education(Request $request, Client $patient )
  306. {
  307. return view('app.patient.education', compact('patient'));
  308. }
  309. public function messaging(Request $request, Client $patient )
  310. {
  311. return view('app.patient.messaging', compact('patient'));
  312. }
  313. public function duplicate(Request $request, Client $patient )
  314. {
  315. return view('app.patient.duplicate', compact('patient'));
  316. }
  317. public function careMonths(Request $request, Client $patient )
  318. {
  319. $careMonths = CareMonth::where('client_id', $patient->id)->orderBy('start_date', 'desc')->get();
  320. $notes = Note::where('is_cancelled', false)->get();
  321. return view('app.patient.care-months', compact('patient', 'careMonths', 'notes'));
  322. }
  323. public function presence(Request $request, Client $patient )
  324. {
  325. return json_encode([
  326. "online" => $patient->is_online
  327. ]);
  328. }
  329. public function embedSection(Request $request, Client $patient, $section, $selectable) {
  330. return view('app.patient.partials.' . $section, compact('patient', 'selectable'));
  331. }
  332. public function calendar(Request $request, Client $patient, Appointment $currentAppointment) {
  333. $pros = [];
  334. if($this->pro && $this->pro->pro_type != 'ADMIN') {
  335. $accessiblePros = ProProAccess::where('owner_pro_id', $this->pro->id)->get();
  336. $accessibleProIds = [];
  337. foreach($accessiblePros as $accessiblePro){
  338. $accessibleProIds[] = $accessiblePro->accessible_pro_id;
  339. }
  340. $accessibleProIds[] = $this->pro->id;
  341. // for dna, add pros accessible via pro teams
  342. if($this->performer->pro->isDefaultNA()) {
  343. $teams = $this->performer->pro->teamsWhereAssistant;
  344. foreach ($teams as $team) {
  345. if(!in_array($team->mcp_pro_id, $accessibleProIds)) {
  346. $accessibleProIds[] = $team->mcp_pro_id;
  347. }
  348. }
  349. }
  350. $pros = Pro::whereIn('id', $accessibleProIds)->get();
  351. }
  352. $dateLastWeek = date_sub(date_create(), date_interval_create_from_date_string("14 days"));
  353. $dateLastWeek = date_format($dateLastWeek, "Y-m-d");
  354. $appointments = Appointment::where('client_id', $patient->id)
  355. ->orderBy('raw_date', 'desc')->orderBy('raw_start_time', 'desc')
  356. ->where('raw_date', '>=', $dateLastWeek)
  357. ->get();
  358. $appointmentProIDs = $appointments->map(function($_item) {
  359. return $_item->pro_id;
  360. });
  361. $appointmentPros = Pro::whereIn('id', $appointmentProIDs)->get();
  362. return view('app.patient.appointment-calendar',
  363. compact('pros', 'patient', 'currentAppointment', 'appointments', 'appointmentPros'));
  364. }
  365. public function flowsheets(Request $request, Client $patient, $filter = '') {
  366. $pros = $this->pros;
  367. return view('app.patient.flowsheets', compact('patient', 'pros', 'filter'));
  368. }
  369. public function vitalsSettings(Request $request, Client $patient) {
  370. return view('app.patient.vitals-settings', compact('patient'));
  371. }
  372. public function vitalsGraph(Request $request, Client $patient, $filter = '') {
  373. $pros = $this->pros;
  374. return view('app.patient.vitals-graph', compact('patient', 'pros', 'filter'));
  375. }
  376. public function sleepStudy(Request $request, Client $patient) {
  377. return view('app.patient.sleep-study', compact('patient'));
  378. }
  379. public function sleepStudyStep(Request $request, Client $patient) {
  380. return view('app.patient.sleep-study.' . $request->input('step'), compact('patient'));
  381. }
  382. public function tickets(Request $request, Client $patient, $type = '', String $currentTicket = '') {
  383. $pros = $this->pros;
  384. $allPros = Pro::all();
  385. $qlTicket = $currentTicket;
  386. if(!!$currentTicket) {
  387. $qlTicket = Ticket::where('uid', $currentTicket)->first();
  388. if($qlTicket) {
  389. $currentTicket = $qlTicket;
  390. }
  391. }
  392. return view('app.patient.tickets', compact('patient', 'pros', 'allPros', 'type', 'currentTicket'));
  393. }
  394. protected function getDefaultFacility(){
  395. $defaultFacility = Facility::where('name', 'Ultra Care Pharmacy')->where('address_city', 'Baltimore')->first();
  396. return $defaultFacility;
  397. }
  398. public function prescriptions(Request $request, Client $patient, String $type = '', String $currentErx = '') {
  399. $this->updateDefaultPatientPharmacy($patient);
  400. if(!!$currentErx) {
  401. $currentErx = Erx::where('uid', $currentErx)->first();
  402. }
  403. $note = $patient->coreNote;
  404. $defaultFacility = $this->getDefaultFacility();
  405. $patient->refresh();
  406. return view('app.patient.prescriptions.index', compact('patient', 'type', 'currentErx', 'note', 'defaultFacility'));
  407. }
  408. protected function updateDefaultPatientPharmacy(Client $patient){
  409. $prescriptions = $patient->prescriptions;
  410. if(!count($prescriptions)) return;
  411. $defaultFacility = $this->getDefaultFacility();
  412. if(!$defaultFacility) return;
  413. foreach($prescriptions as $prescription){
  414. if($prescription->logistics_detail_json) continue;
  415. $this->setPrescriptionDefaultPharmacy($prescription, $defaultFacility);
  416. }
  417. }
  418. private function setPrescriptionDefaultPharmacy(Erx $prescription, Facility $facility){
  419. $data = [
  420. 'uid' => $prescription->uid,
  421. 'logisticsDetailJson' => json_encode([
  422. 'facilityName' => $facility->name,
  423. 'facilityCity' => $facility->address_city,
  424. 'facilityState' => $facility->address_state,
  425. 'facilityAddressMemo' => '',
  426. 'facilityPhone' => $facility->phone,
  427. 'facilityFax' => $facility->fax,
  428. 'facilityZip' => $facility->address_zip,
  429. ])
  430. ];
  431. $response = $this->callJavaApi('/erx/updateLogisticsDetail', $data);
  432. }
  433. public function prescriptionsPopup(Request $request, Client $patient, String $type = '', String $currentErx = '') {
  434. if(!!$currentErx) {
  435. $currentErx = Erx::where('uid', $currentErx)->first();
  436. }
  437. $note = null;
  438. if($request->input('noteUid')) {
  439. $note = Note::where('uid', $request->input('noteUid'))->first();
  440. }
  441. return view('app.patient.prescriptions-popup.list-popup', compact('patient', 'type', 'currentErx', 'note'));
  442. }
  443. public function prescriptionsList(Request $request, Client $patient, String $type = '', String $currentErx = '') {
  444. if(!!$currentErx) {
  445. $currentErx = Erx::where('uid', $currentErx)->first();
  446. }
  447. $note = null;
  448. if($request->input('noteUid')) {
  449. $note = Note::where('uid', $request->input('noteUid'))->first();
  450. }
  451. return view('app.patient.prescriptions.list', compact('patient', 'type', 'currentErx', 'note'));
  452. }
  453. public function downloadPrescriptionAsPdf(Request $request, Erx $prescription){
  454. if($request->input('html')) {
  455. return view('app.patient.prescriptions.pdf.pdf-preview', compact('prescription'));
  456. }
  457. else {
  458. $pdf = PDF::loadView('app.patient.prescriptions.pdf.pdf-preview', compact('prescription'));
  459. return $pdf->download($prescription->created_at .'_' . 'erx.pdf');
  460. }
  461. }
  462. public function transmitPrescription(Request $request, Erx $prescription){
  463. // re-generate pdf with cover sheet as first page and save it to FS
  464. $filePath = config('app.temp_dir') . "/{$prescription->uid}.pdf";
  465. $pdf = PDF::loadView('app.patient.prescriptions.pdf.pdf-preview-with-cover-sheet', compact('prescription'));
  466. $pdf->save($filePath);
  467. // send it along with the rest of the params to /api/erx/transmit [multi-part POST]
  468. $url = config('stag.backendUrl') . '/erx/transmit';
  469. $params = [
  470. "uid" => $request->input('uid'),
  471. "toWho" => $request->input('toWho'),
  472. "toEmail" => $request->input('toEmail'),
  473. "toFaxNumber" => $request->input('toFaxNumber'),
  474. "toFaxNumberAttentionLine" => $request->input('toFaxNumberAttentionLine'),
  475. "toFaxNumberCoverSheetMemo" => $request->input('toFaxNumberCoverSheetMemo'),
  476. ];
  477. if($request->input('copyToPatient')) {
  478. $params["copyToPatientFaxNumber"] = $request->input('copyToPatientFaxNumber');
  479. $params["copyToPatientEmail"] = $request->input('copyToPatientEmail');
  480. }
  481. $pdf = fopen($filePath, 'r');
  482. $response = Http
  483. ::attach('pdfSystemFile', $filePath, "{$prescription->uid}.pdf")
  484. ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
  485. ->post($url, $params)
  486. ->json();
  487. return $response;
  488. }
  489. public function supplyOrders(Request $request, Client $patient, SupplyOrder $supplyOrder = null)
  490. {
  491. $products = Product::where('is_active', true)->orderBy('created_at', 'desc')->get();
  492. return view('app.patient.supply-orders', compact('patient', 'supplyOrder', 'products'));
  493. }
  494. public function shipments(Request $request, Client $patient, Shipment $shipment = null)
  495. {
  496. return view('app.patient.shipments', compact('patient', 'shipment'));
  497. }
  498. public function appointments(Request $request, Client $patient, $forPro = 'all', $status = 'all') {
  499. $pros = $this->pros;
  500. $appointments = $patient->appointmentsForProByStatus($forPro, strtoupper($status));
  501. $appointmentProIDs = $appointments->map(function($_item) {
  502. return $_item->pro_id;
  503. });
  504. $appointmentPros = Pro::whereIn('id', $appointmentProIDs)->get();
  505. return view('app.patient.appointments',
  506. compact('patient', 'pros', 'appointments', 'appointmentPros', 'forPro', 'status'));
  507. }
  508. public function mcpRequests(Request $request, Client $patient) {
  509. return view('app.patient.mcp-requests', compact('patient'));
  510. }
  511. public function eligibleRefreshes(Request $request, Client $patient) {
  512. return view('app.patient.eligible-refreshes', compact('patient'));
  513. }
  514. public function insuranceCoverage(Request $request, Client $patient) {
  515. $mbPayers = MBPayer::all();
  516. return view('app.patient.insurance-coverage', compact('patient', 'mbPayers'));
  517. }
  518. public function clientPrimaryCoverages(Request $request, Client $patient) {
  519. $mbPayers = MBPayer::all();
  520. return view('app.patient.client-primary-coverages', compact('patient', 'mbPayers'));
  521. }
  522. public function primaryCoverage(Request $request, Client $patient) {
  523. $mbPayers = MBPayer::all();
  524. return view('app.patient.primary-coverage', compact('patient', 'mbPayers'));
  525. }
  526. public function primaryCoverageForm(Request $request, Client $patient) {
  527. $mbPayers = MBPayer::all();
  528. return view('app.patient.primary-coverage-form', compact('patient', 'mbPayers'));
  529. }
  530. public function primaryCoverageManualDeterminationModal(Request $request, Client $patient) {
  531. $coverageUid = $request->get('coverageUid');
  532. $coverage = ClientPrimaryCoverage::where('uid', $coverageUid)->first();
  533. if($patient->latestClientPrimaryCoverage->plan_type === 'MEDICARE'){
  534. return view('app.patient.primary-coverage-manual-determination-medicare-modal', compact('patient', 'coverage'));
  535. }
  536. if($patient->latestClientPrimaryCoverage->plan_type === 'MEDICAID'){
  537. return view('app.patient.primary-coverage-manual-determination-medicaid-modal', compact('patient', 'coverage'));
  538. }
  539. if($patient->latestClientPrimaryCoverage->plan_type === 'COMMERCIAL'){
  540. return view('app.patient.primary-coverage-manual-determination-commercial-modal', compact('patient', 'coverage'));
  541. }
  542. return "Plan Type is missing!";
  543. }
  544. public function mbClaim(Request $request, MBClaim $mbClaim) {
  545. return view('app.patient.mb-claim-single', compact('mbClaim'));
  546. }
  547. public function accounts(Request $request, Client $patient) {
  548. return view('app.patient.accounts', compact('patient'));
  549. }
  550. public function companies(Request $request, Client $patient) {
  551. $companies = Company::where('is_active', true)->get();
  552. $companyClientStatusMap = [];
  553. $companyClientStatusMap['NEW'] = 'New';
  554. $companyClientStatusMap['ELIGIBILITY_VERIFIED'] = 'Eligibility Verified';
  555. $companyClientStatusMap['ELIGIBILITY_PENDING'] = 'Eligibility Pending';
  556. $companyClientStatusMap['NOT_ELIGIBLE'] = 'Not Eligible';
  557. $companyClientStatusMap['INITIAL_CONSULT'] = 'Initial Consult';
  558. $companyClientStatusMap['HST_DELIVERED'] = 'HST Delivered';
  559. $companyClientStatusMap['STUDY_PENDING'] = 'Study Pending';
  560. $companyClientStatusMap['STUDY_COMPLETED'] = 'Study Completed';
  561. $companyClientStatusMap['STUDY_INTERPRETED'] = 'Study Interpreted';
  562. $companyClientStatusMap['POST_HST_VISIT'] = 'Post HST Visit';
  563. $companyClientStatusMap['CPAP_RX'] = 'CPAP Rx';
  564. $companyClientStatusMap['ORAL_APPLIANCE_RX'] = 'Oral Appliance Rx';
  565. $companyClientStatusMap['NOT_INTERESTED'] = 'Not Interested';
  566. $companyClientStatusMap['IN_LAB_STUDY'] = 'In Lab Study';
  567. $companyClientStatusMap['UNRESPONSIVE'] = 'Unresponsive';
  568. return view('app.patient.companies', compact('patient', 'companies', 'companyClientStatusMap'));
  569. }
  570. public function rtm(Request $request, Client $patient) {
  571. return view('app.patient.rtm', compact('patient'));
  572. }
  573. public function careMonthMatrix(Request $request, CareMonth $careMonth) {
  574. return view('app.patient.care-month.matrix', [
  575. 'patient' => $careMonth->patient,
  576. 'careMonth' => $careMonth,
  577. ]);
  578. }
  579. public function clientProAccess(Request $request, Client $patient) {
  580. $rows = ClientProAccess::where('client_id', $patient->id)->get();
  581. return view('app.patient.client-pro-access', compact('patient', 'rows'));
  582. }
  583. public function clientDocuments(Request $request, Client $patient){
  584. $templates = get_doc_templates();
  585. $companyProIDs = DB::select('SELECT company_pro_id FROM company_pro_document WHERE related_client_id = ?', [$patient->id]);
  586. $companyProIDInts = [];
  587. foreach($companyProIDs as $cpId){
  588. $companyProIDInts[] = $cpId->company_pro_id;
  589. }
  590. $companyPros = CompanyPro::whereIn('id', $companyProIDInts)->get();
  591. return view('app.patient.client-documents', compact('templates', 'companyPros', 'patient'));
  592. }
  593. public function insuranceCoverageHistory(Request $request, Client $patient){
  594. $insuranceCoverageHistory = ClientPrimaryCoverage::where('client_id', $patient->id)->orderBy('created_at', 'DESC')->get();
  595. return view('app.patient.insurance-coverage-history', compact('patient', 'insuranceCoverageHistory'));
  596. }
  597. public function protocolBuilder(Request $request, Client $patient) {
  598. return view('app.patient.rtm.protocol-builder', compact('patient'));
  599. }
  600. public function checkIfCptCodeIsSubmitted(Request $request){
  601. $clientUid = $request->get('clientUid');
  602. $cptCode = $request->get('code');
  603. if(!$clientUid || !$cptCode) return $this->fail('Error');
  604. $client = Client::where('uid', $clientUid)->first();
  605. $notes = $client->notes;
  606. $isCptSubmitted = false;
  607. foreach($notes as $note){
  608. $noteClaims = $note->claims;
  609. foreach($noteClaims as $noteClaim){
  610. foreach($noteClaim->lines as $claimLine){
  611. if($claimLine->cpt == $cptCode){
  612. if($noteClaim->status == 'SUBMITTED'){
  613. $isCptSubmitted = true;
  614. }
  615. }
  616. }
  617. }
  618. }
  619. if($isCptSubmitted) return $this->pass('SUBMITTED');
  620. return $this->pass('NOT_SUBMITTED');
  621. }
  622. }