PatientController.php 15 KB

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