PatientController.php 16 KB

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