PatientController.php 14 KB

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