McpController.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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 = $patients->where(function ($q) {
  99. $q->whereNull('client_engagement_status_category')
  100. ->orWhere('client_engagement_status_category', '<>', 'DUMMY');
  101. });
  102. }
  103. $patients = $patients->orderBy('created_at', 'DESC')->paginate(50);
  104. return view('app.mcp.patients', compact('patients', 'filters'));
  105. }
  106. public function notes(Request $request)
  107. {
  108. $filters = $request->all();
  109. $notes = Note::query();
  110. $notes = $notes->where('hcp_pro_id', $this->performer->pro->id);
  111. $this->filterMultiQuery($request, $notes, 'effective_time', 'date_category', 'date_value_1', 'date_value_2');
  112. $this->filterSimpleQuery($request, $notes, 'new_or_fu_or_na', 'new_or_fu_or_na');
  113. $notes = $notes->orderBy('created_at', 'DESC')->paginate(20);
  114. return view('app.mcp.notes', compact('notes','filters'));
  115. }
  116. public function appointments(Request $request)
  117. {
  118. $filters = $request->all();
  119. $appointments = Appointment::where('pro_id', $this->performer->pro->id);
  120. $this->filterMultiQuery($request, $appointments, 'raw_date', 'date_category', 'date_value_1', 'date_value_2');
  121. $this->filterSimpleQuery($request, $appointments, 'status', 'status');
  122. $appointments = $appointments->orderBy('end_time', 'DESC')->paginate(20);
  123. return view('app.mcp.appointments', compact('appointments', 'filters'));
  124. }
  125. public function bills(Request $request)
  126. {
  127. $filters = $request->all();
  128. $bills = Bill::where('hcp_pro_id', $this->performer->pro->id);
  129. $this->filterMultiQuery($request, $bills, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  130. $status = $request->get('status');
  131. if($status){
  132. if($status == 'CANCELLED') $bills = $bills->where('is_cancelled', true);
  133. if($status == 'NOT_CANCELLED') $bills = $bills->where('is_cancelled', false);
  134. }
  135. $bills = $bills->orderBy('created_at', 'DESC')->paginate(20);
  136. return view('app.mcp.bills', compact('bills', 'filters'));
  137. }
  138. public function clients_bdt_devices(Request $request){
  139. $filters = $request->all();
  140. $devices = ClientBDTDevice::select('client_bdt_device.*')
  141. ->join('client', 'client.id', '=', 'client_bdt_device.client_id')
  142. ->where('client.mcp_pro_id', $this->performer->pro->id);
  143. $this->filterMultiQuery($request, $devices, 'client_bdt_device.created_at', 'date_category', 'date_value_1', 'date_value_2');
  144. $status = $request->get('status');
  145. if($status){
  146. if($status === 'ACTIVE') $devices = $devices->where('client_bdt_device.is_active', true);
  147. if($status === 'DEACTIVATED') $devices = $devices->where('client_bdt_device.is_active', false);
  148. }
  149. $devices = $devices->orderBy('created_at', 'DESC')->paginate(20);
  150. return view('app.mcp.clients_bdt_devices', compact('devices', 'filters'));
  151. }
  152. public function memos(Request $request){
  153. $filters = $request->all();
  154. $memos = ClientMemo::select('client_memo.*')
  155. ->join('client', 'client.id', '=', 'client_memo.client_id')
  156. ->where('client.mcp_pro_id', $this->performer->pro->id);
  157. $this->filterMultiQuery($request, $memos, 'client_memo.created_at', 'date_category', 'date_value_1', 'date_value_2');
  158. $this->filterSimpleQuery($request, $memos, 'category', 'category');
  159. $memos = $memos->orderBy('created_at', 'DESC')->paginate(20);
  160. return view('app.mcp.memos', compact('memos', 'filters'));
  161. }
  162. public function erx_and_orders(Request $request)
  163. {
  164. $filters = $request->all();
  165. $erxAndOrders = Erx::query();
  166. $erxAndOrders = $erxAndOrders->where('hcp_pro_id', $this->performer->pro->id);
  167. $this->filterMultiQuery($request, $erxAndOrders, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  168. $this->filterSimpleQuery($request, $erxAndOrders, 'pro_declared_status', 'status');
  169. $erxAndOrders = $erxAndOrders->orderBy('created_at', 'DESC')->paginate(20);
  170. return view('app.mcp.erx_and_orders', compact('erxAndOrders', 'filters'));
  171. }
  172. public function reports(Request $request)
  173. {
  174. $filters = $request->all();
  175. $reports = IncomingReport::where('hcp_pro_id', $this->performer->pro->id);
  176. $this->filterMultiQuery($request, $reports, 'report_date', 'date_category', 'date_value_1', 'date_value_2');
  177. $status = $request->get('status');
  178. if($status){
  179. if($status == 'SIGNED') $reports = $reports->where('has_hcp_pro_signed', true);
  180. if($status == 'NOT_SIGNED') $reports = $reports->where('has_hcp_pro_signed', false);
  181. }
  182. $reports = $reports->orderBy('created_at', 'DESC')->paginate(20);
  183. return view('app.mcp.reports', compact('reports', 'filters'));
  184. }
  185. public function supply_orders(Request $request)
  186. {
  187. $filters = $request->all();
  188. $supplyOrders = SupplyOrder::select('supply_order.*')->where('supply_order.signed_by_pro_id', $this->performer->pro->id);
  189. $this->filterMultiQuery($request, $supplyOrders, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  190. $status = $request->get('status');
  191. if($status){
  192. if($status == 'CLEARED_FOR_SHIPMENT'){
  193. $supplyOrders = $supplyOrders->where('is_cleared_for_shipment', true);
  194. }elseif($status == 'NOT_CLEARED_FOR_SHIPMENT'){
  195. $supplyOrders = $supplyOrders->where('is_cleared_for_shipment', false);
  196. }elseif($status == 'CANCELLED'){
  197. $supplyOrders = $supplyOrders->where('is_cancelled', true);
  198. }else{
  199. $supplyOrders = $supplyOrders->join('shipment', 'shipment.id', '=', 'supply_order.shipment_id')->where('shipment.status', $status);
  200. }
  201. }
  202. $supplyOrders = $supplyOrders->orderBy('created_at', 'DESC')->paginate(20);
  203. return view('app.mcp.supply_orders', compact('supplyOrders', 'filters'));
  204. }
  205. public function client_messages(Request $request)
  206. {
  207. $filters = $request->all();
  208. $clientMessages = ClientSMS::select('client_sms.*')
  209. ->join('client', 'client.id', '=', 'client_sms.client_id')
  210. ->where('client.mcp_pro_id', $this->performer->pro->id);
  211. $this->filterMultiQuery($request, $clientMessages, 'client_sms.created_at', 'date_category', 'date_value_1', 'date_value_2');
  212. $this->filterSimpleQuery($request, $clientMessages, 'sms_status', 'sms_status');
  213. $clientMessages = $clientMessages->orderBy('client_sms.created_at', 'DESC');
  214. $clientMessages = $clientMessages->paginate(20);
  215. return view('app.mcp.client_messages', compact('clientMessages', 'filters'));
  216. }
  217. public function patients_accounts_invites(Request $request){
  218. $filters = $request->all();
  219. $accountInvites = AccountInvite::select('account_invite.*')
  220. ->join('client', 'client.id', '=', 'account_invite.for_client_id');
  221. $accountInvites = $accountInvites->where('client.mcp_pro_id', $this->performer->pro->id);
  222. $this->filterMultiQuery($request, $accountInvites, 'account_invite.created_at', 'date_category', 'date_value_1', 'date_value_2');
  223. $this->filterSimpleQuery($request, $accountInvites, 'account_invite.status', 'status');
  224. $accountInvites = $accountInvites->orderBy('created_at', 'DESC')->paginate(20);
  225. return view('app.mcp.patients-accounts-invites', compact('accountInvites', 'filters'));
  226. }
  227. public function new_patients_awaiting_visit(Request $request){
  228. $data = [
  229. 'records' => Client::where('mcp_pro_id', $this->performer->pro->id)
  230. ->where('has_mcp_done_onboarding_visit', '!=', 'YES')
  231. ->orderBy('created_at')
  232. ->get()
  233. ];
  234. return view('app.mcp.new_patients_awaiting_visit', $data);
  235. }
  236. public function notes_pending_signature(Request $request){
  237. $data = [
  238. 'records' => Note::where('hcp_pro_id', $this->performer->pro->id)
  239. ->where('is_cancelled', '<>', true)
  240. ->where('is_signed_by_hcp', '<>', true)
  241. ->where('is_core_note', false)
  242. ->orderBy('created_at')
  243. ->get()
  244. ];
  245. return view('app.mcp.notes_pending_signature', $data);
  246. }
  247. public function notes_pending_billing(Request $request){
  248. $data = [
  249. 'records' => Note::where('hcp_pro_id', $this->performer->pro->id)
  250. ->where('is_cancelled', '<>', true)
  251. ->where('is_signed_by_hcp', true)
  252. ->where('is_billing_marked_done', '<>', true)
  253. ->orderBy('created_at')
  254. ->get()
  255. ];
  256. return view('app.mcp.notes_pending_billing', $data);
  257. }
  258. public function bills_pending_signature(Request $request){
  259. $data = [
  260. 'records' => Bill::where('bill_service_type', '<>', 'CARE_MONTH')->where(function ($query) {
  261. $query->where('hcp_pro_id', $this->performer->pro->id)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
  262. })
  263. ->orWhere(function ($query) {
  264. $query->where('cm_pro_id', $this->performer->pro->id)->where('is_signed_by_cm', false)->where('is_cancelled', false);
  265. })->orWhere(function ($query) {
  266. $query->where('rme_pro_id', $this->performer->pro->id)->where('is_signed_by_rme', false)->where('is_cancelled', false);
  267. })->orWhere(function ($query) {
  268. $query->where('rmm_pro_id', $this->performer->pro->id)->where('is_signed_by_rmm', false)->where('is_cancelled', false);
  269. })->orWhere(function ($query) {
  270. $query->where('generic_pro_id', $this->performer->pro->id)->where('is_signed_by_generic_pro', false)->where('is_cancelled', false);
  271. })
  272. ->orderBy('created_at', 'DESC')
  273. ->get()
  274. ];
  275. return view('app.mcp.bills_pending_signature', $data);
  276. }
  277. public function reports_pending_signature(Request $request){
  278. $data = [
  279. 'records' => IncomingReport::where('hcp_pro_id', $this->performer->pro->id)
  280. ->where('has_hcp_pro_signed', '<>', true)
  281. ->where('is_entry_error', '<>', true)
  282. ->orderBy('created_at')
  283. ->get()
  284. ];
  285. return view('app.mcp.reports_pending_signature', $data);
  286. }
  287. public function patients_without_appointments(Request $request){
  288. $patients = $this->performer->pro->get_patients_without_appointment_query()->paginate(20);
  289. return view('app.mcp.patients_without_appointments', compact('patients'));
  290. }
  291. public function patients_overdue_for_visit(Request $request){
  292. $patients = $this->performer->pro->get_patients_overdue_for_visit_query()->paginate(20);
  293. return view('app.mcp.patients_overdue_for_visit', compact('patients'));
  294. }
  295. public function cancelled_appointments_pending_review(Request $request){
  296. $data = [];
  297. return view('app.mcp.cancelled_appointments_pending_review', $data);
  298. }
  299. public function cancelled_bills_pending_review(Request $request){
  300. $data = [
  301. 'records' => Bill::where('hcp_pro_id', $this->performer->pro->id)
  302. ->where('bill_service_type', 'NOTE')
  303. ->where('is_cancelled', true)
  304. ->where('is_cancellation_acknowledged', '<>', true)
  305. ->orderBy('created_at')
  306. ->get()
  307. ];
  308. return view('app.mcp.cancelled_bills_pending_review', $data);
  309. }
  310. public function cancelled_supply_orders_pending_review(Request $request){
  311. $data = [
  312. 'records' => SupplyOrder::where('signed_by_pro_id', $this->performer->pro->id)
  313. ->where('is_cancelled', true)
  314. ->where('is_cancellation_acknowledged', '<>', true)
  315. ->orderBy('created_at')
  316. ->get()
  317. ];
  318. return view('app.mcp.cancelled_supply_orders_pending_review', $data);
  319. }
  320. public function erx_and_orders_pending_signature(Request $request){
  321. $data = [
  322. 'records' => Erx::where('hcp_pro_id', $this->performer->pro->id)
  323. ->where('pro_declared_status', '<>', 'CANCELLED')
  324. ->where('has_hcp_pro_signed', '<>', true)
  325. ->orderBy('created_at')
  326. ->get()
  327. ];
  328. return view('app.mcp.erx_and_orders_pending_signature', $data);
  329. }
  330. public function supply_orders_pending_signature(Request $request){
  331. $data = [
  332. 'records' => SupplyOrder::where('created_by_pro_id', $this->performer->pro->id)
  333. ->whereNull('signed_by_pro_id')
  334. ->where('is_cancelled', '<>', true)
  335. ->orderBy('created_at')
  336. ->get()
  337. ];
  338. return view('app.mcp.supply_orders_pending_signature', $data);
  339. }
  340. public function supply_orders_awaiting_shipment(Request $request){
  341. $data = [
  342. 'records' => SupplyOrder::where('created_by_pro_id', $this->performer->pro->id)
  343. ->where('is_signed_by_pro', true)
  344. ->where('is_cleared_for_shipment', true)
  345. ->whereNull('shipment_id')
  346. ->orderBy('created_at')
  347. ->get()
  348. ];
  349. return view('app.mcp.supply_orders_awaiting_shipment', $data);
  350. }
  351. public function measurements_pending_stamping(Request $request){
  352. $data = [
  353. 'records' => CareMonth::where('mcp_pro_id', $this->performer->pro->id)
  354. ->where('rm_num_measurements_not_stamped_by_mcp', '>', 0)
  355. ->whereNotNull('rm_num_measurements_not_stamped_by_mcp')
  356. ->orderBy('created_at', 'DESC')
  357. ->paginate(15)
  358. ];
  359. return view('app.mcp.measurements_pending_stamping', $data);
  360. }
  361. }