PatientController.php 31 KB

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