PatientController.php 17 KB

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