PatientController.php 11 KB

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