AdminController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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\Erx;
  10. use App\Models\Facility;
  11. use App\Models\Handout;
  12. use App\Models\IncomingReport;
  13. use App\Models\MBClaim;
  14. use App\Models\MBPayer;
  15. use App\Models\Note;
  16. use App\Models\NoteTemplate;
  17. use App\Models\Pro;
  18. use App\Models\Product;
  19. use App\Models\ProProAccess;
  20. use App\Models\SectionTemplate;
  21. use App\Models\Shipment;
  22. use App\Models\SupplyOrder;
  23. use App\Models\Ticket;
  24. use Illuminate\Http\Request;
  25. use Illuminate\Support\Facades\DB;
  26. use Illuminate\Support\Facades\File;
  27. use App\Models\Bill;
  28. use App\Models\ClientSMS;
  29. use Illuminate\Support\Facades\Http;
  30. use PDF;
  31. class AdminController extends Controller
  32. {
  33. public function patients(Request $request)
  34. {
  35. $filters = $request->all();
  36. $patients = Client::whereNull('shadow_pro_id')->where('client_engagement_status_category', '!=', 'NO_LONGER_INTERESTED');
  37. // filters
  38. /*
  39. array:18 [▼
  40. "age_category" => "LESS_THAN"
  41. "age_value_1" => "34"
  42. "age_value_2" => null
  43. "sex" => "M"
  44. "bmi_category" => "BETWEEN"
  45. "bmi_value_1" => "20"
  46. "bmi_value_2" => "25"
  47. "last_visit_category" => "LESS_THAN"
  48. "last_visit_value_1" => "2021-10-14"
  49. "last_visit_value_2" => null
  50. "next_appointment_category" => "LESS_THAN"
  51. "next_appointment_value_1" => "2021-10-15"
  52. "status" => "ACTIVE"
  53. "last_weighed_in_category" => "EXACTLY"
  54. "last_weighed_in_value_1" => "2021-10-07"
  55. "last_bp_category" => "BETWEEN"
  56. "last_bp_value_1" => "2021-10-01"
  57. "last_bp_value_2" => "2021-10-31"
  58. ]
  59. */
  60. $insurance = $request->get('insurance');
  61. if($insurance){
  62. // $patients = $patients->where(function ($query) use ($insurance) {
  63. // return $query
  64. // ->whereRaw('client_id IN (SELECT client_id FROM client_primary_coverage WHERE (plan_type ILIKE %'.$insurance.'%)');
  65. // });
  66. }
  67. if ($request->input('name')) {
  68. $name = trim($request->input('name'));
  69. if ($name) {
  70. $patients = $patients->where(function ($q) use ($name) {
  71. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  72. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  73. });
  74. }
  75. }
  76. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2');
  77. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  78. $this->filterMultiQuery($request, $patients, 'usual_bmi_max', 'bmi_category', 'bmi_value_1', 'bmi_value_2');
  79. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  80. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  81. switch($request->input('status')) {
  82. case 'ACTIVE':
  83. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
  84. break;
  85. case 'AWAITING_VISIT':
  86. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
  87. break;
  88. case 'INACTIVE':
  89. $patients->where('is_active', '<>', true);
  90. break;
  91. }
  92. $initiative = $request->input('initiative');
  93. if($initiative){
  94. $wildCardedInitiative = '%'.$initiative.'%';
  95. $patients->where('initiative', 'ilike', $wildCardedInitiative);
  96. }
  97. $include_test_records = $request->input('include_test_records');
  98. if(!$include_test_records){
  99. $patients = $patients->where(function ($q) {
  100. $q->whereNull('client_engagement_status_category')
  101. ->orWhere('client_engagement_status_category', '<>', 'DUMMY');
  102. });
  103. }
  104. $patients = $patients->orderBy('created_at', 'DESC')->paginate(25);
  105. return view('app.admin.patients', compact('patients', 'filters'));
  106. }
  107. public function notes(Request $request)
  108. {
  109. $notes = Note::paginate(5);
  110. // SELECT * FROM note WHERE client_id IN (SELECT id FROM client WHERE mcp_pro_id = :me.id);
  111. return view('app.mcp.notes', compact('notes'));
  112. }
  113. public function appointments(Request $request)
  114. {
  115. $appointments = Appointment::paginate(5);
  116. return view('app.mcp.appointments', compact('appointments'));
  117. }
  118. public function bills(Request $request)
  119. {
  120. $bills = Bill::paginate(5);
  121. return view('app.mcp.bills', compact('bills'));
  122. }
  123. public function erx_and_orders(Request $request)
  124. {
  125. $erxAndOrders = Erx::paginate(5);
  126. return view('app.mcp.erx_and_orders', compact('erxAndOrders'));
  127. }
  128. public function reports(Request $request)
  129. {
  130. $data = [];
  131. return view('app.mcp.reports', $data);
  132. }
  133. public function supply_orders(Request $request)
  134. {
  135. $supplyOrders = SupplyOrder::paginate(5);
  136. return view('app.mcp.supply_orders', compact('supplyOrders'));
  137. }
  138. public function getCreateNewPatientScriptTemplate(Request $request){
  139. $template = $request->get('template');
  140. if(!$template) return $this->fail('No script template');
  141. $path = resource_path() . '/views/app/patient/create-patient/scripts/' . $template . '.blade.php';
  142. if(!File::exists($path)) return $this->fail('Invalid script template');
  143. $templateContent = file_get_contents($path);
  144. return $this->pass($templateContent);
  145. }
  146. }