McpController.php 17 KB

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