PatientController.php 16 KB

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