PatientController.php 14 KB

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