PatientController.php 15 KB

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