McpController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 App\Models\AccountInvite;
  30. use Illuminate\Support\Facades\Http;
  31. use PDF;
  32. class McpController extends Controller
  33. {
  34. public function patients(Request $request)
  35. {
  36. $filters = $request->all();
  37. $patients = Client::whereNull('shadow_pro_id')->where('mcp_pro_id', $this->performer->pro->id);
  38. // filters
  39. /*
  40. array:18 [▼
  41. "age_category" => "LESS_THAN"
  42. "age_value_1" => "34"
  43. "age_value_2" => null
  44. "sex" => "M"
  45. "bmi_category" => "BETWEEN"
  46. "bmi_value_1" => "20"
  47. "bmi_value_2" => "25"
  48. "last_visit_category" => "LESS_THAN"
  49. "last_visit_value_1" => "2021-10-14"
  50. "last_visit_value_2" => null
  51. "next_appointment_category" => "LESS_THAN"
  52. "next_appointment_value_1" => "2021-10-15"
  53. "status" => "ACTIVE"
  54. "last_weighed_in_category" => "EXACTLY"
  55. "last_weighed_in_value_1" => "2021-10-07"
  56. "last_bp_category" => "BETWEEN"
  57. "last_bp_value_1" => "2021-10-01"
  58. "last_bp_value_2" => "2021-10-31"
  59. ]
  60. */
  61. if ($request->input('name')) {
  62. $name = trim($request->input('name'));
  63. if ($name) {
  64. $patients = $patients->where(function ($q) use ($name) {
  65. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  66. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  67. });
  68. }
  69. }
  70. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2');
  71. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  72. $this->filterMultiQuery($request, $patients, 'usual_bmi', 'bmi_category', 'bmi_value_1', 'bmi_value_2');
  73. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  74. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  75. switch($request->input('status')) {
  76. case 'ACTIVE':
  77. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
  78. break;
  79. case 'AWAITING_VISIT':
  80. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
  81. break;
  82. case 'INACTIVE':
  83. $patients->where('is_active', '<>', true);
  84. break;
  85. }
  86. $patients = $patients->orderBy('created_at', 'DESC')->paginate(20);
  87. return view('app.mcp.patients', compact('patients', 'filters'));
  88. }
  89. public function notes(Request $request)
  90. {
  91. $filters = $request->all();
  92. $notes = Note::query();
  93. $notes = $notes->where('hcp_pro_id', $this->performer->pro->id);
  94. $this->filterMultiQuery($request, $notes, 'effective_time', 'date_category', 'date_value_1', 'date_value_2');
  95. $this->filterSimpleQuery($request, $notes, 'new_or_fu_or_na', 'new_or_fu_or_na');
  96. $notes = $notes->orderBy('created_at', 'DESC')->paginate(20);
  97. return view('app.mcp.notes', compact('notes','filters'));
  98. }
  99. public function appointments(Request $request)
  100. {
  101. $filters = $request->all();
  102. $appointments = Appointment::where('pro_id', $this->performer->pro->id);
  103. $this->filterMultiQuery($request, $appointments, 'raw_date', 'date_category', 'date_value_1', 'date_value_2');
  104. $this->filterSimpleQuery($request, $appointments, 'status', 'status');
  105. $appointments = $appointments->orderBy('end_time', 'DESC')->paginate(20);
  106. return view('app.mcp.appointments', compact('appointments', 'filters'));
  107. }
  108. public function bills(Request $request)
  109. {
  110. $filters = $request->all();
  111. $bills = Bill::where('hcp_pro_id', $this->performer->pro->id);
  112. $this->filterMultiQuery($request, $bills, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  113. $status = $request->get('status');
  114. if($status){
  115. if($status == 'CANCELLED') $bills = $bills->where('is_cancelled', true);
  116. if($status == 'NOT_CANCELLED') $bills = $bills->where('is_cancelled', false);
  117. }
  118. $bills = $bills->orderBy('created_at', 'DESC')->paginate(20);
  119. return view('app.mcp.bills', compact('bills', 'filters'));
  120. }
  121. public function erx_and_orders(Request $request)
  122. {
  123. $filters = $request->all();
  124. $erxAndOrders = Erx::query();
  125. $erxAndOrders = $erxAndOrders->where('hcp_pro_id', $this->performer->pro->id);
  126. $this->filterMultiQuery($request, $erxAndOrders, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  127. $this->filterSimpleQuery($request, $erxAndOrders, 'pro_declared_status', 'status');
  128. $erxAndOrders = $erxAndOrders->orderBy('created_at', 'DESC')->paginate(20);
  129. return view('app.mcp.erx_and_orders', compact('erxAndOrders', 'filters'));
  130. }
  131. public function reports(Request $request)
  132. {
  133. $filters = $request->all();
  134. $reports = IncomingReport::where('hcp_pro_id', $this->performer->pro->id);
  135. $this->filterMultiQuery($request, $reports, 'report_date', 'date_category', 'date_value_1', 'date_value_2');
  136. $status = $request->get('status');
  137. if($status){
  138. if($status == 'SIGNED') $reports = $reports->where('has_hcp_pro_signed', true);
  139. if($status == 'NOT_SIGNED') $reports = $reports->where('has_hcp_pro_signed', false);
  140. }
  141. $reports = $reports->orderBy('created_at', 'DESC')->paginate(20);
  142. return view('app.mcp.reports', compact('reports', 'filters'));
  143. }
  144. public function supply_orders(Request $request)
  145. {
  146. $filters = $request->all();
  147. $supplyOrders = SupplyOrder::select('supply_order.*')->where('supply_order.signed_by_pro_id', $this->performer->pro->id);
  148. $this->filterMultiQuery($request, $supplyOrders, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  149. $status = $request->get('status');
  150. if($status){
  151. if($status == 'CLEARED_FOR_SHIPMENT'){
  152. $supplyOrders = $supplyOrders->where('is_cleared_for_shipment', true);
  153. }elseif($status == 'NOT_CLEARED_FOR_SHIPMENT'){
  154. $supplyOrders = $supplyOrders->where('is_cleared_for_shipment', false);
  155. }elseif($status == 'CANCELLED'){
  156. $supplyOrders = $supplyOrders->where('is_cancelled', true);
  157. }else{
  158. $supplyOrders = $supplyOrders->join('shipment', 'shipment.id', '=', 'supply_order.shipment_id')->where('shipment.status', $status);
  159. }
  160. }
  161. $supplyOrders = $supplyOrders->orderBy('created_at', 'DESC')->paginate(20);
  162. return view('app.mcp.supply_orders', compact('supplyOrders', 'filters'));
  163. }
  164. public function client_messages(Request $request)
  165. {
  166. $filters = $request->all();
  167. $clientMessages = ClientSMS::select('client_sms.*')
  168. ->join('client', 'client.id', '=', 'client_sms.client_id')
  169. ->where('client.mcp_pro_id', $this->performer->pro->id);
  170. $this->filterMultiQuery($request, $clientMessages, 'client_sms.created_at', 'date_category', 'date_value_1', 'date_value_2');
  171. $this->filterSimpleQuery($request, $clientMessages, 'sms_status', 'sms_status');
  172. $clientMessages = $clientMessages->orderBy('client_sms.created_at', 'DESC');
  173. $clientMessages = $clientMessages->paginate(20);
  174. return view('app.mcp.client_messages', compact('clientMessages', 'filters'));
  175. }
  176. public function patients_accounts_invites(Request $request){
  177. $filters = $request->all();
  178. $accountInvites = AccountInvite::select('account_invite.*')
  179. ->join('client', 'client.id', '=', 'account_invite.for_client_id');
  180. $accountInvites = $accountInvites->where('client.mcp_pro_id', $this->performer->pro->id);
  181. $this->filterMultiQuery($request, $accountInvites, 'account_invite.created_at', 'date_category', 'date_value_1', 'date_value_2');
  182. $this->filterSimpleQuery($request, $accountInvites, 'account_invite.status', 'status');
  183. $accountInvites = $accountInvites->orderBy('created_at', 'DESC')->paginate(20);
  184. return view('app.mcp.patients-accounts-invites', compact('accountInvites', 'filters'));
  185. }
  186. public function new_patients_awaiting_visit(Request $request){
  187. $data = [
  188. 'records' => Client::where('mcp_pro_id', $this->performer->pro->id)
  189. ->where('has_mcp_done_onboarding_visit', '!=', 'YES')
  190. ->orderBy('created_at')
  191. ->get()
  192. ];
  193. return view('app.mcp.new_patients_awaiting_visit', $data);
  194. }
  195. public function notes_pending_signature(Request $request){
  196. $data = [
  197. 'records' => Note::where('hcp_pro_id', $this->performer->pro->id)
  198. ->where('is_cancelled', '<>', true)
  199. ->where('is_signed_by_hcp', '<>', true)
  200. ->where('is_core_note', false)
  201. ->orderBy('created_at')
  202. ->get()
  203. ];
  204. return view('app.mcp.notes_pending_signature', $data);
  205. }
  206. public function notes_pending_billing(Request $request){
  207. $data = [
  208. 'records' => Note::where('hcp_pro_id', $this->performer->pro->id)
  209. ->where('is_cancelled', '<>', true)
  210. ->where('is_signed_by_hcp', true)
  211. ->where('is_billing_marked_done', '<>', true)
  212. ->orderBy('created_at')
  213. ->get()
  214. ];
  215. return view('app.mcp.notes_pending_billing', $data);
  216. }
  217. public function reports_pending_signature(Request $request){
  218. $data = [
  219. 'records' => IncomingReport::where('hcp_pro_id', $this->performer->pro->id)
  220. ->where('has_hcp_pro_signed', '<>', true)
  221. ->where('is_entry_error', '<>', true)
  222. ->orderBy('created_at')
  223. ->get()
  224. ];
  225. return view('app.mcp.reports_pending_signature', $data);
  226. }
  227. public function patients_without_appointments(Request $request){
  228. $patients = $this->performer->pro->get_patients_without_appointment_query()->paginate(20);
  229. return view('app.mcp.patients_without_appointments', compact('patients'));
  230. }
  231. public function patients_overdue_for_visit(Request $request){
  232. $patients = $this->performer->pro->get_patients_overdue_for_visit_query()->paginate(20);
  233. return view('app.mcp.patients_overdue_for_visit', compact('patients'));
  234. }
  235. public function cancelled_appointments_pending_review(Request $request){
  236. $data = [];
  237. return view('app.mcp.cancelled_appointments_pending_review', $data);
  238. }
  239. public function cancelled_bills_pending_review(Request $request){
  240. $data = [
  241. 'records' => Bill::where('hcp_pro_id', $this->performer->pro->id)
  242. ->where('bill_service_type', 'NOTE')
  243. ->where('is_cancelled', true)
  244. ->where('is_cancellation_acknowledged', '<>', true)
  245. ->orderBy('created_at')
  246. ->get()
  247. ];
  248. return view('app.mcp.cancelled_bills_pending_review', $data);
  249. }
  250. public function cancelled_supply_orders_pending_review(Request $request){
  251. $data = [
  252. 'records' => SupplyOrder::where('signed_by_pro_id', $this->performer->pro->id)
  253. ->where('is_cancelled', true)
  254. ->where('is_cancellation_acknowledged', '<>', true)
  255. ->orderBy('created_at')
  256. ->get()
  257. ];
  258. return view('app.mcp.cancelled_supply_orders_pending_review', $data);
  259. }
  260. public function erx_and_orders_pending_signature(Request $request){
  261. $data = [
  262. 'records' => Erx::where('hcp_pro_id', $this->performer->pro->id)
  263. ->where('pro_declared_status', '<>', 'CANCELLED')
  264. ->where('has_hcp_pro_signed', '<>', true)
  265. ->orderBy('created_at')
  266. ->get()
  267. ];
  268. return view('app.mcp.erx_and_orders_pending_signature', $data);
  269. }
  270. public function supply_orders_pending_signature(Request $request){
  271. $data = [
  272. 'records' => SupplyOrder::where('created_by_pro_id', $this->performer->pro->id)
  273. ->whereNull('signed_by_pro_id')
  274. ->where('is_cancelled', '<>', true)
  275. ->orderBy('created_at')
  276. ->get()
  277. ];
  278. return view('app.mcp.supply_orders_pending_signature', $data);
  279. }
  280. public function supply_orders_awaiting_shipment(Request $request){
  281. $data = [
  282. 'records' => SupplyOrder::where('created_by_pro_id', $this->performer->pro->id)
  283. ->where('is_signed_by_pro', true)
  284. ->where('is_cleared_for_shipment', true)
  285. ->whereNull('shipment_id')
  286. ->orderBy('created_at')
  287. ->get()
  288. ];
  289. return view('app.mcp.supply_orders_awaiting_shipment', $data);
  290. }
  291. public function measurements_pending_stamping(Request $request){
  292. $data = [
  293. 'records' => CareMonth::where('mcp_pro_id', $this->performer->pro->id)
  294. ->where('rm_num_measurements_not_stamped_by_mcp', '>', 0)
  295. ->whereNotNull('rm_num_measurements_not_stamped_by_mcp')
  296. ->orderBy('created_at', 'DESC')
  297. ->paginate(15)
  298. ];
  299. return view('app.mcp.measurements_pending_stamping', $data);
  300. }
  301. }