PatientController.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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\Erx;
  10. use App\Models\Facility;
  11. use App\Models\Handout;
  12. use App\Models\IncomingReport;
  13. use App\Models\MBClaim;
  14. use App\Models\MBPayer;
  15. use App\Models\Note;
  16. use App\Models\NoteTemplate;
  17. use App\Models\Pro;
  18. use App\Models\Product;
  19. use App\Models\ProProAccess;
  20. use App\Models\SectionTemplate;
  21. use App\Models\Shipment;
  22. use App\Models\SupplyOrder;
  23. use App\Models\Ticket;
  24. use Illuminate\Http\Request;
  25. use Illuminate\Support\Facades\DB;
  26. use Illuminate\Support\Facades\File;
  27. use PDF;
  28. class PatientController extends Controller
  29. {
  30. public function claimsResolver(Request $request, Client $patient)
  31. {
  32. $notes = $patient->notesAscending;
  33. $hcpSignedNotesCount = 0;
  34. foreach($notes as $note){
  35. if($note->is_signed_by_hcp){
  36. $hcpSignedNotesCount += 1;
  37. }
  38. }
  39. $data = [
  40. 'dog' => 'bark',
  41. 'patient' => $patient,
  42. 'hcpSignedNotesCount' => $hcpSignedNotesCount
  43. ];
  44. return view('app.patient.claims-resolver', $data);
  45. }
  46. public function dashboard(Request $request, Client $patient )
  47. {
  48. $mcpPros = Pro::where('is_enrolled_as_mcp', true)->get();
  49. $facilities = []; // Facility::where('is_active', true)->get();
  50. // get assigned devices
  51. $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true"));
  52. $assignedDeviceIDs = array_map(function($_x) {
  53. return $_x->device_id;
  54. }, $assignedDeviceIDs);
  55. // get all except assigned ones
  56. $devices = BDTDevice::where('is_active', true)
  57. ->whereNotIn('id', $assignedDeviceIDs)
  58. ->orderBy('imei', 'asc')
  59. ->get();
  60. $assignedDeviceIDs = null;
  61. unset($assignedDeviceIDs);
  62. $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
  63. ->where('category', 'dx')
  64. ->where('is_removed', false)
  65. ->orderBy('content_text', 'asc')
  66. ->get();
  67. return view('app.patient.dashboard',
  68. compact('patient', 'facilities', 'devices', 'dxInfoLines'));
  69. }
  70. public function actionItems(Request $request, Client $patient )
  71. {
  72. $facilities = []; // Facility::where('is_active', true)->get();
  73. return view('app.patient.action-items', compact('patient', 'facilities'));
  74. }
  75. public function actionItemsErx(Request $request, Client $patient, $filter = 'open')
  76. {
  77. $allPros = Pro::all();
  78. $facilities = []; // Facility::where('is_active', true)->get();
  79. return view('app.patient.action-items-erx', compact('patient', 'facilities', 'filter', 'allPros'));
  80. }
  81. public function actionItemsLab(Request $request, Client $patient, $filter = 'open')
  82. {
  83. $allPros = Pro::all();
  84. $facilities = []; // Facility::where('is_active', true)->get();
  85. return view('app.patient.action-items-lab', compact('patient', 'facilities', 'filter', 'allPros'));
  86. }
  87. public function actionItemsImaging(Request $request, Client $patient, $filter = 'open')
  88. {
  89. $allPros = Pro::all();
  90. $facilities = []; // Facility::where('is_active', true)->get();
  91. return view('app.patient.action-items-imaging', compact('patient', 'facilities', 'filter', 'allPros'));
  92. }
  93. public function actionItemsEquipment(Request $request, Client $patient, $filter = 'open')
  94. {
  95. $allPros = Pro::all();
  96. $facilities = []; // Facility::where('is_active', true)->get();
  97. return view('app.patient.action-items-equipment', compact('patient', 'facilities', 'filter', 'allPros'));
  98. }
  99. public function actionItemsOther(Request $request, Client $patient, $filter = 'open')
  100. {
  101. $allPros = Pro::all();
  102. $facilities = []; // Facility::where('is_active', true)->get();
  103. return view('app.patient.action-items-other', compact('patient', 'facilities', 'filter', 'allPros'));
  104. }
  105. public function actionItemsErxSingle(Request $request, Client $patient, Ticket $ticket) {
  106. $allPros = Pro::all();
  107. $facilities = []; // Facility::where('is_active', true)->get();
  108. return view('app.patient.action-items-erx-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  109. }
  110. public function actionItemsLabSingle(Request $request, Client $patient, Ticket $ticket) {
  111. $allPros = Pro::all();
  112. $facilities = []; // Facility::where('is_active', true)->get();
  113. return view('app.patient.action-items-lab-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  114. }
  115. public function actionItemsImagingSingle(Request $request, Client $patient, Ticket $ticket) {
  116. $allPros = Pro::all();
  117. $facilities = []; // Facility::where('is_active', true)->get();
  118. return view('app.patient.action-items-imaging-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  119. }
  120. public function actionItemsEquipmentSingle(Request $request, Client $patient, Ticket $ticket) {
  121. $allPros = Pro::all();
  122. $facilities = []; // Facility::where('is_active', true)->get();
  123. return view('app.patient.action-items-equipment-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  124. }
  125. public function actionItemsOtherSingle(Request $request, Client $patient, Ticket $ticket) {
  126. $allPros = Pro::all();
  127. $facilities = []; // Facility::where('is_active', true)->get();
  128. return view('app.patient.action-items-other-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  129. }
  130. public function intake(Request $request, Client $patient )
  131. {
  132. $files = File::allFiles(resource_path('views/app/intake-templates'));
  133. $templates = [];
  134. foreach ($files as $file) {
  135. $templates[] = str_replace(".blade.php", "", $file->getFilename());
  136. }
  137. return view('app.patient.intake', compact('patient', 'templates'));
  138. }
  139. public function carePlan(Request $request, Client $patient )
  140. {
  141. return view('app.patient.care-plan', compact('patient'));
  142. }
  143. public function medications(Request $request, Client $patient )
  144. {
  145. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  146. ->where('category', 'rx')
  147. ->where('is_removed', false)
  148. ->orderBy('content_text', 'asc')
  149. ->get();
  150. return view('app.patient.medications', compact('patient', 'infoLines'));
  151. }
  152. public function dxAndFocusAreas(Request $request, Client $patient )
  153. {
  154. $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
  155. ->where('category', 'dx')
  156. ->where('is_removed', false)
  157. ->orderBy('content_text', 'asc')
  158. ->get();
  159. return view('app.patient.dx-and-focus-areas', compact('patient', 'dxInfoLines'));
  160. }
  161. public function careTeam(Request $request, Client $patient )
  162. {
  163. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  164. ->where('category', 'care_team')
  165. ->where('is_removed', false)
  166. ->get();
  167. return view('app.patient.care-team', compact('patient', 'infoLines'));
  168. }
  169. public function devices(Request $request, Client $patient )
  170. {
  171. // get assigned devices
  172. $assignedDeviceIDs = DB::select(DB::raw("SELECT device_id from client_bdt_device where is_active = true"));
  173. $assignedDeviceIDs = array_map(function($_x) {
  174. return $_x->device_id;
  175. }, $assignedDeviceIDs);
  176. // get all except assigned ones
  177. $devices = BDTDevice::where('is_active', true)
  178. ->whereNotIn('id', $assignedDeviceIDs)
  179. ->orderBy('imei', 'asc')
  180. ->get();
  181. $assignedDeviceIDs = null;
  182. unset($assignedDeviceIDs);
  183. return view('app.patient.devices', compact('patient', 'devices'));
  184. }
  185. public function measurements(Request $request, Client $patient )
  186. {
  187. return view('app.patient.measurements', compact('patient'));
  188. }
  189. public function labsAndStudies(Request $request, Client $patient )
  190. {
  191. return view('app.patient.labs-and-studies', compact('patient'));
  192. }
  193. public function history(Request $request, Client $patient )
  194. {
  195. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  196. ->where('category', 'LIKE', 'history_%')
  197. ->where('is_removed', false)
  198. ->get();
  199. return view('app.patient.history', compact('patient', 'infoLines'));
  200. }
  201. public function memos(Request $request, Client $patient )
  202. {
  203. return view('app.patient.memos', compact('patient'));
  204. }
  205. public function sms(Request $request, Client $patient )
  206. {
  207. return view('app.patient.sms', compact('patient'));
  208. }
  209. public function smsNumbers(Request $request, Client $patient )
  210. {
  211. return view('app.patient.sms-numbers', compact('patient'));
  212. }
  213. public function immunizations(Request $request, Client $patient )
  214. {
  215. return view('app.patient.immunizations', compact('patient'));
  216. }
  217. public function allergies(Request $request, Client $patient )
  218. {
  219. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  220. ->where('category', 'allergy')
  221. ->where('is_removed', false)
  222. ->get();
  223. return view('app.patient.allergies', compact('patient', 'infoLines'));
  224. }
  225. public function notes(Request $request, Client $patient, $filter = 'active')
  226. {
  227. $pros = $this->pros;
  228. return view('app.patient.notes', compact('patient','pros', 'filter'));
  229. }
  230. public function genericBills(Request $request, Client $patient)
  231. {
  232. return view('app.patient.generic-bills', compact('patient'));
  233. }
  234. public function rmSetup(Request $request, Client $patient)
  235. {
  236. return view('app.patient.rm-setup', compact('patient'));
  237. }
  238. public function sections(Request $request, Client $patient )
  239. {
  240. $pros = $this->pros;
  241. $sections = $patient->sections;
  242. $allSections = SectionTemplate::where('is_active', true)->get();
  243. foreach ($allSections as $section) {
  244. $section->used = false;
  245. foreach ($sections as $section) {
  246. if ($section->sectionTemplate->id === $section->id) {
  247. $section->used = true;
  248. $section->section_uid = $section->uid;
  249. break;
  250. }
  251. }
  252. }
  253. return view('app.patient.sections', compact('patient', 'pros', 'allSections'));
  254. }
  255. public function handouts(Request $request, Client $patient )
  256. {
  257. $handouts = Handout::where('is_active', true)->get();
  258. return view('app.patient.handouts', compact('patient', 'handouts'));
  259. }
  260. public function settings(Request $request, Client $patient )
  261. {
  262. return view('app.patient.settings', compact('patient'));
  263. }
  264. public function smsReminders(Request $request, Client $patient )
  265. {
  266. return view('app.patient.sms-reminders', compact('patient'));
  267. }
  268. public function measurementConfirmationNumbers(Request $request, Client $patient )
  269. {
  270. return view('app.patient.measurement-confirmation-numbers', compact('patient'));
  271. }
  272. public function pros(Request $request, Client $patient )
  273. {
  274. return view('app.patient.pros', compact('patient'));
  275. }
  276. public function account(Request $request, Client $patient )
  277. {
  278. return view('app.patient.account', compact('patient'));
  279. }
  280. public function careChecklist(Request $request, Client $patient )
  281. {
  282. return view('app.patient.care-checklist', compact('patient'));
  283. }
  284. public function documents(Request $request, Client $patient )
  285. {
  286. return view('app.patient.documents', compact('patient'));
  287. }
  288. public function incomingReports(Request $request, Client $patient, IncomingReport $currentReport = null)
  289. {
  290. return view('app.patient.incoming-reports', compact('patient', 'currentReport'));
  291. }
  292. public function education(Request $request, Client $patient )
  293. {
  294. return view('app.patient.education', compact('patient'));
  295. }
  296. public function messaging(Request $request, Client $patient )
  297. {
  298. return view('app.patient.messaging', compact('patient'));
  299. }
  300. public function duplicate(Request $request, Client $patient )
  301. {
  302. return view('app.patient.duplicate', compact('patient'));
  303. }
  304. public function careMonths(Request $request, Client $patient )
  305. {
  306. $careMonths = CareMonth::where('client_id', $patient->id)->orderBy('start_date', 'desc')->get();
  307. $notes = Note::where('is_cancelled', false)->get();
  308. return view('app.patient.care-months', compact('patient', 'careMonths', 'notes'));
  309. }
  310. public function presence(Request $request, Client $patient )
  311. {
  312. return json_encode([
  313. "online" => $patient->is_online
  314. ]);
  315. }
  316. public function embedSection(Request $request, Client $patient, $section, $selectable) {
  317. return view('app.patient.partials.' . $section, compact('patient', 'selectable'));
  318. }
  319. public function calendar(Request $request, Client $patient, Appointment $currentAppointment) {
  320. $pros = [];
  321. if($this->pro && $this->pro->pro_type != 'ADMIN') {
  322. $accessiblePros = ProProAccess::where('owner_pro_id', $this->pro->id)->get();
  323. $accessibleProIds = [];
  324. foreach($accessiblePros as $accessiblePro){
  325. $accessibleProIds[] = $accessiblePro->id;
  326. }
  327. $accessibleProIds[] = $this->pro->id;
  328. $pros = Pro::whereIn('id', $accessibleProIds)->get();
  329. }
  330. return view('app.patient.appointment-calendar', compact('pros', 'patient', 'currentAppointment'));
  331. }
  332. public function programs(Request $request, Client $patient, $filter = '') {
  333. $pros = $this->pros;
  334. return view('app.patient.programs', compact('patient', 'pros', 'filter'));
  335. }
  336. public function flowsheets(Request $request, Client $patient, $filter = '') {
  337. $pros = $this->pros;
  338. return view('app.patient.flowsheets', compact('patient', 'pros', 'filter'));
  339. }
  340. public function vitalsGraph(Request $request, Client $patient, $filter = '') {
  341. $pros = $this->pros;
  342. return view('app.patient.vitals-graph', compact('patient', 'pros', 'filter'));
  343. }
  344. public function tickets(Request $request, Client $patient, $type = '', String $currentTicket = '') {
  345. $pros = $this->pros;
  346. $allPros = Pro::all();
  347. $qlTicket = $currentTicket;
  348. if(!!$currentTicket) {
  349. $qlTicket = Ticket::where('uid', $currentTicket)->first();
  350. if($qlTicket) {
  351. $currentTicket = $qlTicket;
  352. }
  353. }
  354. return view('app.patient.tickets', compact('patient', 'pros', 'allPros', 'type', 'currentTicket'));
  355. }
  356. public function prescriptions(Request $request, Client $patient, String $type = '', String $currentErx = '') {
  357. if(!!$currentErx) {
  358. $currentErx = Erx::where('uid', $currentErx)->first();
  359. }
  360. return view('app.patient.prescriptions.index', compact('patient', 'type', 'currentErx'));
  361. }
  362. public function downloadPrescriptionAsPdf(Request $request, Erx $prescription){
  363. if($request->input('html')) {
  364. return view('app.patient.prescriptions.pdf.pdf-preview', compact('prescription'));
  365. }
  366. else {
  367. $pdf = PDF::loadView('app.patient.prescriptions.pdf.pdf-preview', compact('prescription'));
  368. return $pdf->download($prescription->created_at .'_' . 'erx.pdf');
  369. }
  370. }
  371. public function supplyOrders(Request $request, Client $patient, SupplyOrder $supplyOrder = null)
  372. {
  373. $products = Product::where('is_active', true)->orderBy('created_at', 'desc')->get();
  374. return view('app.patient.supply-orders', compact('patient', 'supplyOrder', 'products'));
  375. }
  376. public function shipments(Request $request, Client $patient, Shipment $shipment = null)
  377. {
  378. return view('app.patient.shipments', compact('patient', 'shipment'));
  379. }
  380. public function appointments(Request $request, Client $patient, $forPro = 'all', $status = 'all') {
  381. $pros = $this->pros;
  382. $appointments = $patient->appointmentsForProByStatus('all', 'ALL');
  383. $appointmentProIDs = $appointments->map(function($_item) {
  384. return $_item->pro_id;
  385. });
  386. $appointmentPros = Pro::whereIn('id', $appointmentProIDs)->get();
  387. $appointments = $patient->appointmentsForProByStatus($forPro, strtoupper($status));
  388. return view('app.patient.appointments',
  389. compact('patient', 'pros', 'appointments', 'appointmentPros', 'forPro', 'status'));
  390. }
  391. public function mcpRequests(Request $request, Client $patient) {
  392. return view('app.patient.mcp-requests', compact('patient'));
  393. }
  394. public function eligibleRefreshes(Request $request, Client $patient) {
  395. return view('app.patient.eligible-refreshes', compact('patient'));
  396. }
  397. public function insuranceCoverage(Request $request, Client $patient) {
  398. $mbPayers = MBPayer::all();
  399. return view('app.patient.insurance-coverage', compact('patient', 'mbPayers'));
  400. }
  401. public function mbClaim(Request $request, MBClaim $mbClaim) {
  402. return view('app.patient.mb-claim-single', compact('mbClaim'));
  403. }
  404. public function accounts(Request $request, Client $patient) {
  405. return view('app.patient.accounts', compact('patient'));
  406. }
  407. public function careMonthMatrix(Request $request, CareMonth $careMonth) {
  408. return view('app.patient.care-month.matrix', [
  409. 'patient' => $careMonth->patient,
  410. 'careMonth' => $careMonth,
  411. ]);
  412. }
  413. }