PatientController.php 15 KB

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