PatientController.php 15 KB

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