AdminController.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. if ($request->input('mcp')) {
  70. $mcp = Pro::where('uid', trim($request->input('mcp')))->first();
  71. if ($mcp) {
  72. $patients = $patients->where('mcp_pro_id', $mcp->id);
  73. }
  74. }
  75. if ($request->input('na')) {
  76. $na = Pro::where('uid', trim($request->input('na')))->first();
  77. if ($na) {
  78. $patients = $patients->where('default_na_pro_id', $na->id);
  79. }
  80. }
  81. if ($request->input('next_appointment_category')) {
  82. if($request->input('next_appointment_category') == 'NONE'){
  83. $patients = $patients->whereNull('next_mcp_appointment_id');
  84. }
  85. }
  86. if ($request->input('chart_number_ends_with')) {
  87. if($request->input('chart_number_ends_with') == 'ZERO'){
  88. $patients = $patients->where('chart_number', 'ILIKE' , '%0');
  89. }else{
  90. $patients = $patients->where('chart_number', 'ILIKE' , '%'.$request->input('chart_number_ends_with'));
  91. }
  92. }
  93. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2');
  94. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  95. $this->filterMultiQuery($request, $patients, 'usual_bmi_max', 'bmi_category', 'bmi_value_1', 'bmi_value_2');
  96. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  97. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  98. switch($request->input('status')) {
  99. case 'ACTIVE':
  100. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
  101. break;
  102. case 'AWAITING_VISIT':
  103. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
  104. break;
  105. case 'INACTIVE':
  106. $patients->where('is_active', '<>', true);
  107. break;
  108. }
  109. $initiative = $request->input('initiative');
  110. if($initiative){
  111. $wildCardedInitiative = '%'.$initiative.'%';
  112. $patients->where('initiative', 'ilike', $wildCardedInitiative);
  113. }
  114. $include_test_records = $request->input('include_test_records');
  115. if(!$include_test_records){
  116. $patients = $patients->where(function ($q) {
  117. $q->whereNull('client_engagement_status_category')
  118. ->orWhere('client_engagement_status_category', '<>', 'DUMMY');
  119. });
  120. }
  121. $insurance = $request->get('insurance');
  122. if($insurance){
  123. if($insurance === 'MEDICARE'){
  124. $patients = $patients->where('is_part_b_primary', 'YES');
  125. }else{
  126. $patients = $patients->where('is_part_b_primary', '!=', 'YES');
  127. }
  128. }
  129. $patients = $patients->orderBy('created_at', 'DESC')->paginate(25);
  130. return view('app.admin.patients', compact('patients', 'filters'));
  131. }
  132. public function notes(Request $request)
  133. {
  134. $notes = Note::paginate(5);
  135. // SELECT * FROM note WHERE client_id IN (SELECT id FROM client WHERE mcp_pro_id = :me.id);
  136. return view('app.mcp.notes', compact('notes'));
  137. }
  138. public function notes_pending_summary_suggestion(Request $request){
  139. $pro = $this->performer->pro;
  140. $data = [
  141. 'records' => $pro->get_notes_pending_summary_suggestion_as_admin()
  142. ];
  143. return view('app.admin.notes_pending_summary_suggestion', $data);
  144. }
  145. public function notes_rejected_summary_suggestion(Request $request){
  146. $pro = $this->performer->pro;
  147. $data = [
  148. 'records' => $pro->get_notes_rejected_summary_suggestion_as_admin()
  149. ];
  150. return view('app.admin.notes_rejected_summary_suggestion', $data);
  151. }
  152. public function appointments(Request $request)
  153. {
  154. $appointments = Appointment::paginate(5);
  155. return view('app.mcp.appointments', compact('appointments'));
  156. }
  157. public function bills(Request $request)
  158. {
  159. $bills = Bill::paginate(5);
  160. return view('app.mcp.bills', compact('bills'));
  161. }
  162. public function erx_and_orders(Request $request)
  163. {
  164. $erxAndOrders = Erx::paginate(5);
  165. return view('app.mcp.erx_and_orders', compact('erxAndOrders'));
  166. }
  167. public function reports(Request $request)
  168. {
  169. $data = [];
  170. return view('app.mcp.reports', $data);
  171. }
  172. public function supply_orders(Request $request)
  173. {
  174. $supplyOrders = SupplyOrder::paginate(5);
  175. return view('app.mcp.supply_orders', compact('supplyOrders'));
  176. }
  177. public function getCreateNewPatientScriptTemplate(Request $request){
  178. $template = $request->get('template');
  179. if(!$template) return $this->fail('No script template');
  180. $path = resource_path() . '/views/app/patient/create-patient/scripts/' . $template . '.blade.php';
  181. if(!File::exists($path)) return $this->fail('Invalid script template');
  182. $templateContent = file_get_contents($path);
  183. return $this->pass($templateContent);
  184. }
  185. }