PatientController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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\NoteTemplate;
  12. use App\Models\Pro;
  13. use App\Models\Program;
  14. use App\Models\SectionTemplate;
  15. use App\Models\Ticket;
  16. use Illuminate\Http\Request;
  17. use Illuminate\Support\Facades\File;
  18. class PatientController extends Controller
  19. {
  20. public function dashboard(Request $request, Client $patient )
  21. {
  22. $mcpPros = Pro::where('is_enrolled_as_mcp', true)->get();
  23. $facilities = Facility::where('is_active', true)->get();
  24. $devices = BDTDevice::where('is_active', true)->orderBy('imei', 'asc')->get();
  25. $devices = $devices->filter(function ($record) {
  26. $matching = ClientBDTDevice::where('device_id', $record->id)->get();
  27. return count($matching) === 0;
  28. });
  29. $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
  30. ->where('category', 'dx')
  31. ->where('is_removed', false)
  32. ->orderBy('content_text', 'asc')
  33. ->get();
  34. return view('app.patient.dashboard',
  35. compact('patient', 'facilities', 'devices', 'dxInfoLines'));
  36. }
  37. public function actionItems(Request $request, Client $patient )
  38. {
  39. $facilities = Facility::where('is_active', true)->get();
  40. return view('app.patient.action-items', compact('patient', 'facilities'));
  41. }
  42. public function actionItemsErx(Request $request, Client $patient, $filter = 'open')
  43. {
  44. $allPros = Pro::all();
  45. $facilities = Facility::where('is_active', true)->get();
  46. return view('app.patient.action-items-erx', compact('patient', 'facilities', 'filter', 'allPros'));
  47. }
  48. public function actionItemsLab(Request $request, Client $patient, $filter = 'open')
  49. {
  50. $allPros = Pro::all();
  51. $facilities = Facility::where('is_active', true)->get();
  52. return view('app.patient.action-items-lab', compact('patient', 'facilities', 'filter', 'allPros'));
  53. }
  54. public function actionItemsImaging(Request $request, Client $patient, $filter = 'open')
  55. {
  56. $allPros = Pro::all();
  57. $facilities = Facility::where('is_active', true)->get();
  58. return view('app.patient.action-items-imaging', compact('patient', 'facilities', 'filter', 'allPros'));
  59. }
  60. public function actionItemsEquipment(Request $request, Client $patient, $filter = 'open')
  61. {
  62. $allPros = Pro::all();
  63. $facilities = Facility::where('is_active', true)->get();
  64. return view('app.patient.action-items-equipment', compact('patient', 'facilities', 'filter', 'allPros'));
  65. }
  66. public function actionItemsOther(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-other', compact('patient', 'facilities', 'filter', 'allPros'));
  71. }
  72. public function actionItemsErxSingle(Request $request, Client $patient, Ticket $ticket) {
  73. $allPros = Pro::all();
  74. $facilities = Facility::where('is_active', true)->get();
  75. return view('app.patient.action-items-erx-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  76. }
  77. public function actionItemsLabSingle(Request $request, Client $patient, Ticket $ticket) {
  78. $allPros = Pro::all();
  79. $facilities = Facility::where('is_active', true)->get();
  80. return view('app.patient.action-items-lab-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  81. }
  82. public function actionItemsImagingSingle(Request $request, Client $patient, Ticket $ticket) {
  83. $allPros = Pro::all();
  84. $facilities = Facility::where('is_active', true)->get();
  85. return view('app.patient.action-items-imaging-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  86. }
  87. public function actionItemsEquipmentSingle(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-equipment-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  91. }
  92. public function actionItemsOtherSingle(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-other-single', compact('patient', 'facilities', 'allPros', 'ticket'));
  96. }
  97. public function intake(Request $request, Client $patient )
  98. {
  99. $files = File::allFiles(resource_path('views/app/intake-templates'));
  100. $templates = [];
  101. foreach ($files as $file) {
  102. $templates[] = str_replace(".blade.php", "", $file->getFilename());
  103. }
  104. return view('app.patient.intake', compact('patient', 'templates'));
  105. }
  106. public function carePlan(Request $request, Client $patient )
  107. {
  108. return view('app.patient.care-plan', compact('patient'));
  109. }
  110. public function medications(Request $request, Client $patient )
  111. {
  112. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  113. ->where('category', 'rx')
  114. ->where('is_removed', false)
  115. ->orderBy('content_text', 'asc')
  116. ->get();
  117. return view('app.patient.medications', compact('patient', 'infoLines'));
  118. }
  119. public function dxAndFocusAreas(Request $request, Client $patient )
  120. {
  121. $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
  122. ->where('category', 'dx')
  123. ->where('is_removed', false)
  124. ->orderBy('content_text', 'asc')
  125. ->get();
  126. return view('app.patient.dx-and-focus-areas', compact('patient', 'dxInfoLines'));
  127. }
  128. public function careTeam(Request $request, Client $patient )
  129. {
  130. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  131. ->where('category', 'care_team')
  132. ->where('is_removed', false)
  133. ->get();
  134. return view('app.patient.care-team', compact('patient', 'infoLines'));
  135. }
  136. public function devices(Request $request, Client $patient )
  137. {
  138. $devices = BDTDevice::where('is_active', true)->get();
  139. $devices = $devices->filter(function ($record) {
  140. $matching = ClientBDTDevice::where('device_id', $record->id)->get();
  141. return count($matching) === 0;
  142. });
  143. return view('app.patient.devices', compact('patient', 'devices'));
  144. }
  145. public function measurements(Request $request, Client $patient )
  146. {
  147. return view('app.patient.measurements', compact('patient'));
  148. }
  149. public function labsAndStudies(Request $request, Client $patient )
  150. {
  151. return view('app.patient.labs-and-studies', compact('patient'));
  152. }
  153. public function history(Request $request, Client $patient )
  154. {
  155. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  156. ->where('category', 'LIKE', 'history_%')
  157. ->where('is_removed', false)
  158. ->get();
  159. return view('app.patient.history', compact('patient', 'infoLines'));
  160. }
  161. public function memos(Request $request, Client $patient )
  162. {
  163. return view('app.patient.memos', compact('patient'));
  164. }
  165. public function sms(Request $request, Client $patient )
  166. {
  167. return view('app.patient.sms', compact('patient'));
  168. }
  169. public function smsNumbers(Request $request, Client $patient )
  170. {
  171. return view('app.patient.sms-numbers', compact('patient'));
  172. }
  173. public function immunizations(Request $request, Client $patient )
  174. {
  175. return view('app.patient.immunizations', compact('patient'));
  176. }
  177. public function allergies(Request $request, Client $patient )
  178. {
  179. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  180. ->where('category', 'allergy')
  181. ->where('is_removed', false)
  182. ->get();
  183. return view('app.patient.allergies', compact('patient', 'infoLines'));
  184. }
  185. public function notes(Request $request, Client $patient, $filter = 'active')
  186. {
  187. $pros = $this->pros;
  188. return view('app.patient.notes', compact('patient','pros', 'filter'));
  189. }
  190. public function sections(Request $request, Client $patient )
  191. {
  192. $pros = $this->pros;
  193. $sections = $patient->sections;
  194. $allSections = SectionTemplate::where('is_active', true)->get();
  195. foreach ($allSections as $section) {
  196. $section->used = false;
  197. foreach ($sections as $section) {
  198. if ($section->sectionTemplate->id === $section->id) {
  199. $section->used = true;
  200. $section->section_uid = $section->uid;
  201. break;
  202. }
  203. }
  204. }
  205. return view('app.patient.sections', compact('patient', 'pros', 'allSections'));
  206. }
  207. public function handouts(Request $request, Client $patient )
  208. {
  209. $handouts = Handout::where('is_active', true)->get();
  210. return view('app.patient.handouts', compact('patient', 'handouts'));
  211. }
  212. public function flowSheets(Request $request, Client $patient )
  213. {
  214. return view('app.patient.flowsheets', compact('patient'));
  215. }
  216. public function settings(Request $request, Client $patient )
  217. {
  218. return view('app.patient.settings', compact('patient'));
  219. }
  220. public function pros(Request $request, Client $patient )
  221. {
  222. return view('app.patient.pros', compact('patient'));
  223. }
  224. public function account(Request $request, Client $patient )
  225. {
  226. return view('app.patient.account', compact('patient'));
  227. }
  228. public function careChecklist(Request $request, Client $patient )
  229. {
  230. return view('app.patient.care-checklist', compact('patient'));
  231. }
  232. public function documents(Request $request, Client $patient )
  233. {
  234. return view('app.patient.documents', compact('patient'));
  235. }
  236. public function education(Request $request, Client $patient )
  237. {
  238. return view('app.patient.education', compact('patient'));
  239. }
  240. public function messaging(Request $request, Client $patient )
  241. {
  242. return view('app.patient.messaging', compact('patient'));
  243. }
  244. public function duplicate(Request $request, Client $patient )
  245. {
  246. return view('app.patient.duplicate', compact('patient'));
  247. }
  248. public function careMonths(Request $request, Client $patient )
  249. {
  250. $careMonths = CareMonth::where('client_id', $patient->id)->orderBy('start_date', 'desc')->get();
  251. return view('app.patient.care-months', compact('patient', 'careMonths'));
  252. }
  253. public function presence(Request $request, Client $patient )
  254. {
  255. return json_encode([
  256. "online" => $patient->is_online
  257. ]);
  258. }
  259. public function embedSection(Request $request, Client $patient, $section, $selectable) {
  260. return view('app.patient.partials.' . $section, compact('patient', 'selectable'));
  261. }
  262. public function calendar(Request $request, Client $patient, Appointment $currentAppointment) {
  263. return view('app.patient.appointment-calendar', compact('patient', 'currentAppointment'));
  264. }
  265. public function programs(Request $request, Client $patient, $filter = '') {
  266. $pros = $this->pros;
  267. return view('app.patient.programs', compact('patient', 'pros', 'filter'));
  268. }
  269. }