RdController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Client;
  4. use App\Models\ClientProAccess;
  5. use App\Models\ClientReviewRequest;
  6. use Illuminate\Http\Request;
  7. class RdController extends Controller
  8. {
  9. public function dashboard(Request $request){
  10. $performer = $this->performer();
  11. $pro = $performer->pro;
  12. $performerProID = $performer->pro->id;
  13. $milliseconds = strtotime(date('Y-m-d')) . '000'; //required by the calendar
  14. return view('app.rd.dashboard', compact( 'milliseconds'));
  15. }
  16. public function patients(Request $request)
  17. {
  18. $filters = $request->all();
  19. $pro = $this->performer->pro;
  20. $patients = Client::where('rd_pro_id', $pro->id);
  21. $proAccessClientIDs = ClientProAccess::where('pro_id', $pro->id)->pluck('client_id')->toArray();
  22. $patients = $patients->orWhereIn('id', $proAccessClientIDs);
  23. if ($request->input('name')) {
  24. $name = trim($request->input('name'));
  25. if ($name) {
  26. $patients = $patients->where(function ($q) use ($name) {
  27. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  28. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  29. });
  30. }
  31. }
  32. if ($request->input('home_address_state')) {
  33. if($request->input('home_address_state') == 'NONE'){
  34. $patients = $patients->whereNull('mailing_address_state');
  35. }else if($request->input('home_address_state') == 'NOT_MD'){
  36. $patients = $patients->where('mailing_address_state', '<>' , 'MD');
  37. }else{
  38. $patients = $patients->where('mailing_address_state', '=' , $request->input('home_address_state'));
  39. }
  40. }
  41. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2', false);
  42. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  43. $this->filterMultiQuery($request, $patients, 'usual_bmi_max', 'bmi_category', 'bmi_value_1', 'bmi_value_2', false);
  44. $this->filterMultiQuery($request, $patients, 'most_recent_completed_mcp_note_date', 'last_visit_category', 'last_visit_value_1', 'last_visit_value_2');
  45. $this->filterMultiQuery($request, $patients, 'next_mcp_appointment_date', 'next_appointment_category', 'next_appointment_value_1', 'next_appointment_value_2');
  46. switch($request->input('status')) {
  47. case 'ACTIVE':
  48. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
  49. break;
  50. case 'AWAITING_VISIT':
  51. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
  52. break;
  53. case 'INACTIVE':
  54. $patients->where('is_active', '<>', true);
  55. break;
  56. }
  57. $sortBy = $request->input('sort_by') ?: 'name_first';
  58. $sortDir = $request->input('sort_dir') ?: 'ASC';
  59. $patients = $patients->orderByRaw("$sortBy $sortDir NULLS LAST");
  60. $patients = $patients->orderBy('created_at', 'DESC')->paginate(20);
  61. return view('app.rd.patients', compact('patients', 'filters'));
  62. }
  63. public function clientReviewRequests(Request $request){
  64. $hideTitle = $request->get('hideTitle');
  65. $performer = $this->performer();
  66. $pro = $performer->pro;
  67. $reviewRequests = ClientReviewRequest::where('pro_id', $pro->id)->where('is_active', true)->orderBy('created_at', 'DESC')->paginate(50);
  68. return view('app.rd.review-requests.list', compact('reviewRequests', 'hideTitle'));
  69. }
  70. public function patientsAwaitingMcpVisit(Request $request){
  71. $pro = $this->performer->pro;
  72. $records = $pro->patientsAwaitingMcpVisitRecordsAsRd();
  73. return view('app.rd.dashboard.patients_awaiting_mcp_visit', compact('records'));
  74. }
  75. public function patientsWithoutAppointment(Request $request){
  76. $pro = $this->performer->pro;
  77. $records = $pro->patientsWithoutAppointmentRecordsAsRd();
  78. return view('app.rd.dashboard.patients_without_appointment', compact('records'));
  79. }
  80. public function encountersPendingMyReview(Request $request){
  81. $pro = $this->performer->pro;
  82. $records = $pro->encountersPendingMyReviewRecordsAsRd();
  83. return view('app.rd.dashboard.encounters_pending_my_review', compact('records'));
  84. }
  85. public function encountersInProgress(Request $request){
  86. $pro = $this->performer->pro;
  87. $records = $pro->encountersInProgressRecordsAsRd();
  88. return view('app.rd.dashboard.encounters_in_progress', compact('records'));
  89. }
  90. public function appointmentsPendingConfirmation(Request $request){
  91. $pro = $this->performer->pro;
  92. $records = $pro->appointmentsPendingConfirmationRecordsAsRd();
  93. return view('app.rd.dashboard.appointments_pending_confirmation', compact('records'));
  94. }
  95. public function cancelledAppointmentsPendingAck(Request $request){
  96. $pro = $this->performer->pro;
  97. $records = $pro->cancelledAppointmentsPendingAckRecordsAsRd();
  98. return view('app.rd.dashboard.cancelled_appointments_pending_ack', compact('records'));
  99. }
  100. public function reportsPendingAck(Request $request){
  101. $pro = $this->performer->pro;
  102. $records = $pro->reportsPendingAckRecordsAsRd();
  103. return view('app.rd.dashboard.reports_pending_ack', compact('records'));
  104. }
  105. public function supplyOrdersPendingMyAck(Request $request){
  106. $pro = $this->performer->pro;
  107. $records = $pro->supplyOrdersPendingMyAckRecordsAsRd();
  108. return view('app.rd.dashboard.supply_orders_pending_my_ack', compact('records'));
  109. }
  110. public function supplyOrdersPendingHcpApproval(Request $request){
  111. $pro = $this->performer->pro;
  112. $records = $pro->supplyOrdersPendingHcpApprovalRecordsAsRd();
  113. return view('app.rd.dashboard.supply_orders_pending_hcp_approval', compact('records'));
  114. }
  115. }