PatientController.php 15 KB

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