PatientController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. $programs = Program::where('is_active', true)->orderBy('title', 'asc')->get();
  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', 'programs'));
  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 intake(Request $request, Client $patient )
  43. {
  44. $files = File::allFiles(resource_path('views/app/intake-templates'));
  45. $templates = [];
  46. foreach ($files as $file) {
  47. $templates[] = str_replace(".blade.php", "", $file->getFilename());
  48. }
  49. return view('app.patient.intake', compact('patient', 'templates'));
  50. }
  51. public function carePlan(Request $request, Client $patient )
  52. {
  53. return view('app.patient.care-plan', compact('patient'));
  54. }
  55. public function medications(Request $request, Client $patient )
  56. {
  57. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  58. ->where('category', 'rx')
  59. ->where('is_removed', false)
  60. ->orderBy('content_text', 'asc')
  61. ->get();
  62. return view('app.patient.medications', compact('patient', 'infoLines'));
  63. }
  64. public function dxAndFocusAreas(Request $request, Client $patient )
  65. {
  66. $dxInfoLines = ClientInfoLine::where('client_id', $patient->id)
  67. ->where('category', 'dx')
  68. ->where('is_removed', false)
  69. ->orderBy('content_text', 'asc')
  70. ->get();
  71. return view('app.patient.dx-and-focus-areas', compact('patient', 'dxInfoLines'));
  72. }
  73. public function careTeam(Request $request, Client $patient )
  74. {
  75. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  76. ->where('category', 'care_team')
  77. ->where('is_removed', false)
  78. ->get();
  79. return view('app.patient.care-team', compact('patient', 'infoLines'));
  80. }
  81. public function devices(Request $request, Client $patient )
  82. {
  83. $devices = BDTDevice::where('is_active', true)->get();
  84. $devices = $devices->filter(function ($record) {
  85. $matching = ClientBDTDevice::where('device_id', $record->id)->get();
  86. return count($matching) === 0;
  87. });
  88. return view('app.patient.devices', compact('patient', 'devices'));
  89. }
  90. public function measurements(Request $request, Client $patient )
  91. {
  92. return view('app.patient.measurements', compact('patient'));
  93. }
  94. public function labsAndStudies(Request $request, Client $patient )
  95. {
  96. return view('app.patient.labs-and-studies', compact('patient'));
  97. }
  98. public function history(Request $request, Client $patient )
  99. {
  100. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  101. ->where('category', 'LIKE', 'history_%')
  102. ->where('is_removed', false)
  103. ->get();
  104. return view('app.patient.history', compact('patient', 'infoLines'));
  105. }
  106. public function memos(Request $request, Client $patient )
  107. {
  108. return view('app.patient.memos', compact('patient'));
  109. }
  110. public function sms(Request $request, Client $patient )
  111. {
  112. return view('app.patient.sms', compact('patient'));
  113. }
  114. public function smsNumbers(Request $request, Client $patient )
  115. {
  116. return view('app.patient.sms-numbers', compact('patient'));
  117. }
  118. public function immunizations(Request $request, Client $patient )
  119. {
  120. return view('app.patient.immunizations', compact('patient'));
  121. }
  122. public function allergies(Request $request, Client $patient )
  123. {
  124. $infoLines = ClientInfoLine::where('client_id', $patient->id)
  125. ->where('category', 'allergy')
  126. ->where('is_removed', false)
  127. ->get();
  128. return view('app.patient.allergies', compact('patient', 'infoLines'));
  129. }
  130. public function notes(Request $request, Client $patient, $filter = 'active')
  131. {
  132. $pros = $this->pros;
  133. return view('app.patient.notes', compact('patient','pros', 'filter'));
  134. }
  135. public function sections(Request $request, Client $patient )
  136. {
  137. $pros = $this->pros;
  138. $sections = $patient->sections;
  139. $allSections = SectionTemplate::where('is_active', true)->get();
  140. foreach ($allSections as $section) {
  141. $section->used = false;
  142. foreach ($sections as $section) {
  143. if ($section->sectionTemplate->id === $section->id) {
  144. $section->used = true;
  145. $section->section_uid = $section->uid;
  146. break;
  147. }
  148. }
  149. }
  150. return view('app.patient.sections', compact('patient', 'pros', 'allSections'));
  151. }
  152. public function handouts(Request $request, Client $patient )
  153. {
  154. $handouts = Handout::where('is_active', true)->get();
  155. return view('app.patient.handouts', compact('patient', 'handouts'));
  156. }
  157. public function flowSheets(Request $request, Client $patient )
  158. {
  159. return view('app.patient.flowsheets', compact('patient'));
  160. }
  161. public function settings(Request $request, Client $patient )
  162. {
  163. return view('app.patient.settings', compact('patient'));
  164. }
  165. public function account(Request $request, Client $patient )
  166. {
  167. return view('app.patient.account', compact('patient'));
  168. }
  169. public function careChecklist(Request $request, Client $patient )
  170. {
  171. return view('app.patient.care-checklist', compact('patient'));
  172. }
  173. public function documents(Request $request, Client $patient )
  174. {
  175. return view('app.patient.documents', compact('patient'));
  176. }
  177. public function education(Request $request, Client $patient )
  178. {
  179. return view('app.patient.education', compact('patient'));
  180. }
  181. public function messaging(Request $request, Client $patient )
  182. {
  183. return view('app.patient.messaging', compact('patient'));
  184. }
  185. public function duplicate(Request $request, Client $patient )
  186. {
  187. return view('app.patient.duplicate', compact('patient'));
  188. }
  189. public function careMonths(Request $request, Client $patient )
  190. {
  191. $careMonths = CareMonth::where('client_id', $patient->id)->orderBy('start_date', 'desc')->get();
  192. return view('app.patient.care-months', compact('patient', 'careMonths'));
  193. }
  194. public function presence(Request $request, Client $patient )
  195. {
  196. return json_encode([
  197. "online" => $patient->is_online
  198. ]);
  199. }
  200. public function embedSection(Request $request, Client $patient, $section, $selectable) {
  201. return view('app.patient.partials.' . $section, compact('patient', 'selectable'));
  202. }
  203. public function calendar(Request $request, Client $patient, Appointment $currentAppointment) {
  204. return view('app.patient.appointment-calendar', compact('patient', 'currentAppointment'));
  205. }
  206. }