McpController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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_max', '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 clients_bdt_devices(Request $request){
  122. $filters = $request->all();
  123. $devices = ClientBDTDevice::select('client_bdt_device.*')
  124. ->join('client', 'client.id', '=', 'client_bdt_device.client_id')
  125. ->where('client.mcp_pro_id', $this->performer->pro->id);
  126. $this->filterMultiQuery($request, $devices, 'client_bdt_device.created_at', 'date_category', 'date_value_1', 'date_value_2');
  127. $status = $request->get('status');
  128. if($status){
  129. if($status === 'ACTIVE') $devices = $devices->where('client_bdt_device.is_active', true);
  130. if($status === 'DEACTIVATED') $devices = $devices->where('client_bdt_device.is_active', false);
  131. }
  132. $devices = $devices->orderBy('created_at', 'DESC')->paginate(20);
  133. return view('app.mcp.clients_bdt_devices', compact('devices', 'filters'));
  134. }
  135. public function erx_and_orders(Request $request)
  136. {
  137. $filters = $request->all();
  138. $erxAndOrders = Erx::query();
  139. $erxAndOrders = $erxAndOrders->where('hcp_pro_id', $this->performer->pro->id);
  140. $this->filterMultiQuery($request, $erxAndOrders, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  141. $this->filterSimpleQuery($request, $erxAndOrders, 'pro_declared_status', 'status');
  142. $erxAndOrders = $erxAndOrders->orderBy('created_at', 'DESC')->paginate(20);
  143. return view('app.mcp.erx_and_orders', compact('erxAndOrders', 'filters'));
  144. }
  145. public function reports(Request $request)
  146. {
  147. $filters = $request->all();
  148. $reports = IncomingReport::where('hcp_pro_id', $this->performer->pro->id);
  149. $this->filterMultiQuery($request, $reports, 'report_date', 'date_category', 'date_value_1', 'date_value_2');
  150. $status = $request->get('status');
  151. if($status){
  152. if($status == 'SIGNED') $reports = $reports->where('has_hcp_pro_signed', true);
  153. if($status == 'NOT_SIGNED') $reports = $reports->where('has_hcp_pro_signed', false);
  154. }
  155. $reports = $reports->orderBy('created_at', 'DESC')->paginate(20);
  156. return view('app.mcp.reports', compact('reports', 'filters'));
  157. }
  158. public function supply_orders(Request $request)
  159. {
  160. $filters = $request->all();
  161. $supplyOrders = SupplyOrder::select('supply_order.*')->where('supply_order.signed_by_pro_id', $this->performer->pro->id);
  162. $this->filterMultiQuery($request, $supplyOrders, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  163. $status = $request->get('status');
  164. if($status){
  165. if($status == 'CLEARED_FOR_SHIPMENT'){
  166. $supplyOrders = $supplyOrders->where('is_cleared_for_shipment', true);
  167. }elseif($status == 'NOT_CLEARED_FOR_SHIPMENT'){
  168. $supplyOrders = $supplyOrders->where('is_cleared_for_shipment', false);
  169. }elseif($status == 'CANCELLED'){
  170. $supplyOrders = $supplyOrders->where('is_cancelled', true);
  171. }else{
  172. $supplyOrders = $supplyOrders->join('shipment', 'shipment.id', '=', 'supply_order.shipment_id')->where('shipment.status', $status);
  173. }
  174. }
  175. $supplyOrders = $supplyOrders->orderBy('created_at', 'DESC')->paginate(20);
  176. return view('app.mcp.supply_orders', compact('supplyOrders', 'filters'));
  177. }
  178. public function client_messages(Request $request)
  179. {
  180. $filters = $request->all();
  181. $clientMessages = ClientSMS::select('client_sms.*')
  182. ->join('client', 'client.id', '=', 'client_sms.client_id')
  183. ->where('client.mcp_pro_id', $this->performer->pro->id);
  184. $this->filterMultiQuery($request, $clientMessages, 'client_sms.created_at', 'date_category', 'date_value_1', 'date_value_2');
  185. $this->filterSimpleQuery($request, $clientMessages, 'sms_status', 'sms_status');
  186. $clientMessages = $clientMessages->orderBy('client_sms.created_at', 'DESC');
  187. $clientMessages = $clientMessages->paginate(20);
  188. return view('app.mcp.client_messages', compact('clientMessages', 'filters'));
  189. }
  190. public function patients_accounts_invites(Request $request){
  191. $filters = $request->all();
  192. $accountInvites = AccountInvite::select('account_invite.*')
  193. ->join('client', 'client.id', '=', 'account_invite.for_client_id');
  194. $accountInvites = $accountInvites->where('client.mcp_pro_id', $this->performer->pro->id);
  195. $this->filterMultiQuery($request, $accountInvites, 'account_invite.created_at', 'date_category', 'date_value_1', 'date_value_2');
  196. $this->filterSimpleQuery($request, $accountInvites, 'account_invite.status', 'status');
  197. $accountInvites = $accountInvites->orderBy('created_at', 'DESC')->paginate(20);
  198. return view('app.mcp.patients-accounts-invites', compact('accountInvites', 'filters'));
  199. }
  200. public function new_patients_awaiting_visit(Request $request){
  201. $data = [
  202. 'records' => Client::where('mcp_pro_id', $this->performer->pro->id)
  203. ->where('has_mcp_done_onboarding_visit', '!=', 'YES')
  204. ->orderBy('created_at')
  205. ->get()
  206. ];
  207. return view('app.mcp.new_patients_awaiting_visit', $data);
  208. }
  209. public function notes_pending_signature(Request $request){
  210. $data = [
  211. 'records' => Note::where('hcp_pro_id', $this->performer->pro->id)
  212. ->where('is_cancelled', '<>', true)
  213. ->where('is_signed_by_hcp', '<>', true)
  214. ->where('is_core_note', false)
  215. ->orderBy('created_at')
  216. ->get()
  217. ];
  218. return view('app.mcp.notes_pending_signature', $data);
  219. }
  220. public function notes_pending_billing(Request $request){
  221. $data = [
  222. 'records' => Note::where('hcp_pro_id', $this->performer->pro->id)
  223. ->where('is_cancelled', '<>', true)
  224. ->where('is_signed_by_hcp', true)
  225. ->where('is_billing_marked_done', '<>', true)
  226. ->orderBy('created_at')
  227. ->get()
  228. ];
  229. return view('app.mcp.notes_pending_billing', $data);
  230. }
  231. public function reports_pending_signature(Request $request){
  232. $data = [
  233. 'records' => IncomingReport::where('hcp_pro_id', $this->performer->pro->id)
  234. ->where('has_hcp_pro_signed', '<>', true)
  235. ->where('is_entry_error', '<>', true)
  236. ->orderBy('created_at')
  237. ->get()
  238. ];
  239. return view('app.mcp.reports_pending_signature', $data);
  240. }
  241. public function patients_without_appointments(Request $request){
  242. $patients = $this->performer->pro->get_patients_without_appointment_query()->paginate(20);
  243. return view('app.mcp.patients_without_appointments', compact('patients'));
  244. }
  245. public function patients_overdue_for_visit(Request $request){
  246. $patients = $this->performer->pro->get_patients_overdue_for_visit_query()->paginate(20);
  247. return view('app.mcp.patients_overdue_for_visit', compact('patients'));
  248. }
  249. public function cancelled_appointments_pending_review(Request $request){
  250. $data = [];
  251. return view('app.mcp.cancelled_appointments_pending_review', $data);
  252. }
  253. public function cancelled_bills_pending_review(Request $request){
  254. $data = [
  255. 'records' => Bill::where('hcp_pro_id', $this->performer->pro->id)
  256. ->where('bill_service_type', 'NOTE')
  257. ->where('is_cancelled', true)
  258. ->where('is_cancellation_acknowledged', '<>', true)
  259. ->orderBy('created_at')
  260. ->get()
  261. ];
  262. return view('app.mcp.cancelled_bills_pending_review', $data);
  263. }
  264. public function cancelled_supply_orders_pending_review(Request $request){
  265. $data = [
  266. 'records' => SupplyOrder::where('signed_by_pro_id', $this->performer->pro->id)
  267. ->where('is_cancelled', true)
  268. ->where('is_cancellation_acknowledged', '<>', true)
  269. ->orderBy('created_at')
  270. ->get()
  271. ];
  272. return view('app.mcp.cancelled_supply_orders_pending_review', $data);
  273. }
  274. public function erx_and_orders_pending_signature(Request $request){
  275. $data = [
  276. 'records' => Erx::where('hcp_pro_id', $this->performer->pro->id)
  277. ->where('pro_declared_status', '<>', 'CANCELLED')
  278. ->where('has_hcp_pro_signed', '<>', true)
  279. ->orderBy('created_at')
  280. ->get()
  281. ];
  282. return view('app.mcp.erx_and_orders_pending_signature', $data);
  283. }
  284. public function supply_orders_pending_signature(Request $request){
  285. $data = [
  286. 'records' => SupplyOrder::where('created_by_pro_id', $this->performer->pro->id)
  287. ->whereNull('signed_by_pro_id')
  288. ->where('is_cancelled', '<>', true)
  289. ->orderBy('created_at')
  290. ->get()
  291. ];
  292. return view('app.mcp.supply_orders_pending_signature', $data);
  293. }
  294. public function supply_orders_awaiting_shipment(Request $request){
  295. $data = [
  296. 'records' => SupplyOrder::where('created_by_pro_id', $this->performer->pro->id)
  297. ->where('is_signed_by_pro', true)
  298. ->where('is_cleared_for_shipment', true)
  299. ->whereNull('shipment_id')
  300. ->orderBy('created_at')
  301. ->get()
  302. ];
  303. return view('app.mcp.supply_orders_awaiting_shipment', $data);
  304. }
  305. public function measurements_pending_stamping(Request $request){
  306. $data = [
  307. 'records' => CareMonth::where('mcp_pro_id', $this->performer->pro->id)
  308. ->where('rm_num_measurements_not_stamped_by_mcp', '>', 0)
  309. ->whereNotNull('rm_num_measurements_not_stamped_by_mcp')
  310. ->orderBy('created_at', 'DESC')
  311. ->paginate(15)
  312. ];
  313. return view('app.mcp.measurements_pending_stamping', $data);
  314. }
  315. }