AdminController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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');
  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. if ($request->input('name')) {
  61. $name = trim($request->input('name'));
  62. if ($name) {
  63. $patients = $patients->where(function ($q) use ($name) {
  64. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  65. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  66. });
  67. }
  68. }
  69. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2');
  70. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  71. $this->filterMultiQuery($request, $patients, 'usual_bmi_max', 'bmi_category', 'bmi_value_1', 'bmi_value_2');
  72. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  73. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  74. switch($request->input('status')) {
  75. case 'ACTIVE':
  76. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
  77. break;
  78. case 'AWAITING_VISIT':
  79. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
  80. break;
  81. case 'INACTIVE':
  82. $patients->where('is_active', '<>', true);
  83. break;
  84. }
  85. $initiative = $request->input('initiative');
  86. if($initiative){
  87. $wildCardedInitiative = '%'.$initiative.'%';
  88. $patients->where('initiative', 'ilike', $wildCardedInitiative);
  89. }
  90. $include_test_records = $request->input('include_test_records');
  91. if(!$include_test_records){
  92. $patients = $patients->where(function ($q) {
  93. $q->whereNull('client_engagement_status_category')
  94. ->orWhere('client_engagement_status_category', '<>', 'DUMMY');
  95. });
  96. }
  97. $patients = $patients->orderBy('created_at', 'DESC')->paginate(50);
  98. return view('app.admin.patients', compact('patients', 'filters'));
  99. }
  100. public function notes(Request $request)
  101. {
  102. $notes = Note::paginate(5);
  103. // SELECT * FROM note WHERE client_id IN (SELECT id FROM client WHERE mcp_pro_id = :me.id);
  104. return view('app.mcp.notes', compact('notes'));
  105. }
  106. public function appointments(Request $request)
  107. {
  108. $appointments = Appointment::paginate(5);
  109. return view('app.mcp.appointments', compact('appointments'));
  110. }
  111. public function bills(Request $request)
  112. {
  113. $bills = Bill::paginate(5);
  114. return view('app.mcp.bills', compact('bills'));
  115. }
  116. public function erx_and_orders(Request $request)
  117. {
  118. $erxAndOrders = Erx::paginate(5);
  119. return view('app.mcp.erx_and_orders', compact('erxAndOrders'));
  120. }
  121. public function reports(Request $request)
  122. {
  123. $data = [];
  124. return view('app.mcp.reports', $data);
  125. }
  126. public function supply_orders(Request $request)
  127. {
  128. $supplyOrders = SupplyOrder::paginate(5);
  129. return view('app.mcp.supply_orders', compact('supplyOrders'));
  130. }
  131. }