PatientController.php 15 KB

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