PatientController.php 16 KB

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