McpController.php 17 KB

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