PatientController.php 29 KB

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