McpController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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\Measurement;
  16. use App\Models\Note;
  17. use App\Models\NoteTemplate;
  18. use App\Models\Pro;
  19. use App\Models\Product;
  20. use App\Models\ProProAccess;
  21. use App\Models\SectionTemplate;
  22. use App\Models\Shipment;
  23. use App\Models\SupplyOrder;
  24. use App\Models\Ticket;
  25. use Illuminate\Http\Request;
  26. use Illuminate\Support\Facades\DB;
  27. use Illuminate\Support\Facades\File;
  28. use App\Models\Bill;
  29. use App\Models\ClientSMS;
  30. use App\Models\AccountInvite;
  31. use App\Models\ClientMemo;
  32. use App\Models\ClientProAccess;
  33. use Illuminate\Support\Facades\Http;
  34. use PDF;
  35. class McpController extends Controller
  36. {
  37. public function patients(Request $request)
  38. {
  39. $pro = $this->performer->pro;
  40. $filters = $request->all();
  41. $patients = Client::whereNull('shadow_pro_id');
  42. //TODO: implement in admin controller
  43. if($pro->pro_type != 'ADMIN'){
  44. $patients->where('mcp_pro_id', $pro->id);
  45. }
  46. //Also include the ones given access to:
  47. $proAccessClientIDs = ClientProAccess::where('pro_id', $pro->id)->pluck('client_id')->toArray();
  48. $patients = $patients->orWhereIn('id', $proAccessClientIDs);
  49. // filters
  50. /*
  51. array:18 [▼
  52. "age_category" => "LESS_THAN"
  53. "age_value_1" => "34"
  54. "age_value_2" => null
  55. "sex" => "M"
  56. "bmi_category" => "BETWEEN"
  57. "bmi_value_1" => "20"
  58. "bmi_value_2" => "25"
  59. "last_visit_category" => "LESS_THAN"
  60. "last_visit_value_1" => "2021-10-14"
  61. "last_visit_value_2" => null
  62. "next_appointment_category" => "LESS_THAN"
  63. "next_appointment_value_1" => "2021-10-15"
  64. "status" => "ACTIVE"
  65. "last_weighed_in_category" => "EXACTLY"
  66. "last_weighed_in_value_1" => "2021-10-07"
  67. "last_bp_category" => "BETWEEN"
  68. "last_bp_value_1" => "2021-10-01"
  69. "last_bp_value_2" => "2021-10-31"
  70. ]
  71. */
  72. if ($request->input('name')) {
  73. $name = trim($request->input('name'));
  74. if ($name) {
  75. $patients = $patients->where(function ($q) use ($name) {
  76. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  77. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  78. });
  79. }
  80. }
  81. if ($request->input('home_address_state')) {
  82. if($request->input('home_address_state') == 'NONE'){
  83. $patients = $patients->whereNull('mailing_address_state');
  84. }else if($request->input('home_address_state') == 'NOT_MD'){
  85. $patients = $patients->where('mailing_address_state', '<>' , 'MD');
  86. }else{
  87. $patients = $patients->where('mailing_address_state', '=' , $request->input('home_address_state'));
  88. }
  89. }
  90. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2', false);
  91. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  92. $this->filterMultiQuery($request, $patients, 'usual_bmi_max', 'bmi_category', 'bmi_value_1', 'bmi_value_2', false);
  93. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  94. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  95. $this->filterMultiQuery($request, $patients, 'most_recent_completed_mcp_note_date', 'last_visit_category', 'last_visit_value_1', 'last_visit_value_2');
  96. $status = $request->input('status');
  97. if($status){
  98. if($status === 'ACTIVE'){
  99. $patients->where('is_active', true)->where(function($q) use ($status){
  100. return $q->where('client_engagement_status_category', $status)
  101. ->orWhereNull('client_engagement_status_category');
  102. });
  103. }elseif($status === 'NONE'){
  104. $patients->whereNull('client_engagement_status_category');
  105. }else {
  106. $patients->where('client_engagement_status_category', $status);
  107. }
  108. }
  109. $initiative = $request->input('initiative');
  110. if($initiative){
  111. $wildCardedInitiative = '%'.$initiative.'%';
  112. $patients->where('initiative', 'ilike', $wildCardedInitiative);
  113. }
  114. $include_test_records = $request->input('include_test_records');
  115. if(!$include_test_records){
  116. $patients = $patients->where(function ($q) {
  117. $q->whereNull('client_engagement_status_category')
  118. ->orWhere('client_engagement_status_category', '<>', 'DUMMY');
  119. });
  120. }
  121. if ($request->input('next_appointment_category')) {
  122. if($request->input('next_appointment_category') == 'NONE'){
  123. $patients = $patients->whereNull('next_mcp_appointment_id');
  124. }else{
  125. $self = $this;
  126. $patients = $patients->whereHas('nextMcpAppointment', function($pQry) use ($request, $self){
  127. return $self->filterMultiQuery($request, $pQry, 'raw_date', 'next_appointment_category', 'next_appointment_value_1', 'next_appointment_value_2');
  128. });
  129. }
  130. }
  131. if ($request->input('chart_number')) {
  132. $patients = $patients->where('chart_number', 'ILIKE' , '%'.$request->input('chart_number').'%');
  133. }
  134. $sortBy = $request->input('sort_by') ?: 'name_first';
  135. $sortDir = $request->input('sort_dir') ?: 'ASC';
  136. $patients = $patients->orderByRaw("$sortBy $sortDir NULLS LAST");
  137. $patients = $patients->orderBy('created_at', 'DESC')->paginate(50);
  138. return view('app.mcp.patients', compact('patients', 'filters'));
  139. }
  140. public function notes(Request $request)
  141. {
  142. $filters = $request->all();
  143. $notes = Note::query();
  144. $notes = $notes->where('hcp_pro_id', $this->performer->pro->id);
  145. $this->filterMultiQuery($request, $notes, 'effective_time', 'date_category', 'date_value_1', 'date_value_2');
  146. $this->filterSimpleQuery($request, $notes, 'new_or_fu_or_na', 'new_or_fu_or_na');
  147. $notes = $notes->orderBy('created_at', 'DESC')->paginate(20);
  148. return view('app.mcp.notes', compact('notes','filters'));
  149. }
  150. public function appointments(Request $request)
  151. {
  152. $filters = $request->all();
  153. $appointments = Appointment::where('pro_id', $this->performer->pro->id);
  154. $this->filterMultiQuery($request, $appointments, 'raw_date', 'date_category', 'date_value_1', 'date_value_2');
  155. $this->filterSimpleQuery($request, $appointments, 'status', 'status');
  156. $appointments = $appointments->orderBy('end_time', 'DESC')->paginate(20);
  157. return view('app.mcp.appointments', compact('appointments', 'filters'));
  158. }
  159. public function bills(Request $request)
  160. {
  161. $filters = $request->all();
  162. $bills = Bill::where('hcp_pro_id', $this->performer->pro->id);
  163. $this->filterMultiQuery($request, $bills, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  164. $status = $request->get('status');
  165. if($status){
  166. if($status == 'CANCELLED') $bills = $bills->where('is_cancelled', true);
  167. if($status == 'NOT_CANCELLED') $bills = $bills->where('is_cancelled', false);
  168. }
  169. $bills = $bills->orderBy('created_at', 'DESC')->paginate(20);
  170. return view('app.mcp.bills', compact('bills', 'filters'));
  171. }
  172. public function clients_bdt_devices(Request $request){
  173. $filters = $request->all();
  174. $devices = ClientBDTDevice::select('client_bdt_device.*')
  175. ->join('client', 'client.id', '=', 'client_bdt_device.client_id')
  176. ->where('client.mcp_pro_id', $this->performer->pro->id);
  177. $this->filterMultiQuery($request, $devices, 'client_bdt_device.created_at', 'date_category', 'date_value_1', 'date_value_2');
  178. $status = $request->get('status');
  179. if($status){
  180. if($status === 'ACTIVE') $devices = $devices->where('client_bdt_device.is_active', true);
  181. if($status === 'DEACTIVATED') $devices = $devices->where('client_bdt_device.is_active', false);
  182. }
  183. $devices = $devices->orderBy('created_at', 'DESC')->paginate(20);
  184. return view('app.mcp.clients_bdt_devices', compact('devices', 'filters'));
  185. }
  186. public function memos(Request $request){
  187. $filters = $request->all();
  188. $memos = ClientMemo::select('client_memo.*')
  189. ->join('client', 'client.id', '=', 'client_memo.client_id')
  190. ->where('client.mcp_pro_id', $this->performer->pro->id);
  191. $this->filterMultiQuery($request, $memos, 'client_memo.created_at', 'date_category', 'date_value_1', 'date_value_2');
  192. $this->filterSimpleQuery($request, $memos, 'category', 'category');
  193. $memos = $memos->orderBy('created_at', 'DESC')->paginate(20);
  194. return view('app.mcp.memos', compact('memos', 'filters'));
  195. }
  196. public function erx_and_orders(Request $request)
  197. {
  198. $filters = $request->all();
  199. $erxAndOrders = Erx::query();
  200. $erxAndOrders = $erxAndOrders->where('hcp_pro_id', $this->performer->pro->id);
  201. $this->filterMultiQuery($request, $erxAndOrders, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  202. $this->filterSimpleQuery($request, $erxAndOrders, 'pro_declared_status', 'status');
  203. $erxAndOrders = $erxAndOrders->orderBy('created_at', 'DESC')->paginate(20);
  204. return view('app.mcp.erx_and_orders', compact('erxAndOrders', 'filters'));
  205. }
  206. public function reports(Request $request)
  207. {
  208. $filters = $request->all();
  209. $reports = IncomingReport::where('hcp_pro_id', $this->performer->pro->id);
  210. $this->filterMultiQuery($request, $reports, 'report_date', 'date_category', 'date_value_1', 'date_value_2');
  211. $status = $request->get('status');
  212. if($status){
  213. if($status == 'SIGNED') $reports = $reports->where('has_hcp_pro_signed', true);
  214. if($status == 'NOT_SIGNED') $reports = $reports->where('has_hcp_pro_signed', false);
  215. }
  216. $reports = $reports->orderBy('created_at', 'DESC')->paginate(20);
  217. return view('app.mcp.reports', compact('reports', 'filters'));
  218. }
  219. public function supply_orders(Request $request)
  220. {
  221. $filters = $request->all();
  222. $supplyOrders = SupplyOrder::select('supply_order.*')->where('supply_order.signed_by_pro_id', $this->performer->pro->id);
  223. $this->filterMultiQuery($request, $supplyOrders, 'created_at', 'date_category', 'date_value_1', 'date_value_2');
  224. $status = $request->get('status');
  225. if($status){
  226. if($status == 'CLEARED_FOR_SHIPMENT'){
  227. $supplyOrders = $supplyOrders->where('is_cleared_for_shipment', true);
  228. }elseif($status == 'NOT_CLEARED_FOR_SHIPMENT'){
  229. $supplyOrders = $supplyOrders->where('is_cleared_for_shipment', false);
  230. }elseif($status == 'CANCELLED'){
  231. $supplyOrders = $supplyOrders->where('is_cancelled', true);
  232. }else{
  233. $supplyOrders = $supplyOrders->join('shipment', 'shipment.id', '=', 'supply_order.shipment_id')->where('shipment.status', $status);
  234. }
  235. }
  236. $supplyOrders = $supplyOrders->orderBy('created_at', 'DESC')->paginate(20);
  237. return view('app.mcp.supply_orders', compact('supplyOrders', 'filters'));
  238. }
  239. public function client_messages(Request $request)
  240. {
  241. $filters = $request->all();
  242. $clientMessages = ClientSMS::select('client_sms.*')
  243. ->join('client', 'client.id', '=', 'client_sms.client_id')
  244. ->where('client.mcp_pro_id', $this->performer->pro->id);
  245. $this->filterMultiQuery($request, $clientMessages, 'client_sms.created_at', 'date_category', 'date_value_1', 'date_value_2');
  246. $this->filterSimpleQuery($request, $clientMessages, 'sms_status', 'sms_status');
  247. $clientMessages = $clientMessages->orderBy('client_sms.created_at', 'DESC');
  248. $clientMessages = $clientMessages->paginate(20);
  249. return view('app.mcp.client_messages', compact('clientMessages', 'filters'));
  250. }
  251. public function patients_accounts_invites(Request $request){
  252. $filters = $request->all();
  253. $accountInvites = AccountInvite::select('account_invite.*')
  254. ->join('client', 'client.id', '=', 'account_invite.for_client_id');
  255. $accountInvites = $accountInvites->where('client.mcp_pro_id', $this->performer->pro->id);
  256. $this->filterMultiQuery($request, $accountInvites, 'account_invite.created_at', 'date_category', 'date_value_1', 'date_value_2');
  257. $this->filterSimpleQuery($request, $accountInvites, 'account_invite.status', 'status');
  258. $accountInvites = $accountInvites->orderBy('created_at', 'DESC')->paginate(20);
  259. return view('app.mcp.patients-accounts-invites', compact('accountInvites', 'filters'));
  260. }
  261. public function new_patients_awaiting_visit(Request $request){
  262. $data = [
  263. 'records' => Client::where('mcp_pro_id', $this->performer->pro->id)
  264. ->where('has_mcp_done_onboarding_visit', '!=', 'YES')
  265. ->orderBy('created_at')
  266. ->get()
  267. ];
  268. return view('app.mcp.new_patients_awaiting_visit', $data);
  269. }
  270. public function notes_pending_signature(Request $request){
  271. $data = [
  272. 'records' => Note::where('hcp_pro_id', $this->performer->pro->id)
  273. ->where('is_cancelled', '<>', true)
  274. ->where('is_signed_by_hcp', '<>', true)
  275. ->where('is_core_note', false)
  276. ->orderBy('created_at')
  277. ->get()
  278. ];
  279. return view('app.mcp.notes_pending_signature', $data);
  280. }
  281. public function notes_pending_summary_suggestion(Request $request){
  282. $pro = $this->performer->pro;
  283. $data = [
  284. 'records' => $pro->get_notes_pending_summary_suggestion_as_mcp()
  285. ];
  286. return view('app.mcp.notes_pending_summary_suggestion', $data);
  287. }
  288. public function notes_rejected_summary_suggestion(Request $request){
  289. $pro = $this->performer->pro;
  290. $data = [
  291. 'records' => $pro->get_notes_rejected_summary_suggestion_as_mcp()
  292. ];
  293. return view('app.mcp.notes_rejected_summary_suggestion', $data);
  294. }
  295. public function notes_pending_billing(Request $request){
  296. $data = [
  297. 'records' => Note::where('hcp_pro_id', $this->performer->pro->id)
  298. ->where('is_cancelled', '<>', true)
  299. ->where('is_signed_by_hcp', true)
  300. ->where('is_billing_marked_done', '<>', true)
  301. ->orderBy('created_at')
  302. ->get()
  303. ];
  304. return view('app.mcp.notes_pending_billing', $data);
  305. }
  306. public function bills_pending_signature(Request $request){
  307. $data = [
  308. 'records' => Bill::where('bill_service_type', '<>', 'CARE_MONTH')->where(function ($query) {
  309. $query->where('hcp_pro_id', $this->performer->pro->id)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
  310. })
  311. ->orWhere(function ($query) {
  312. $query->where('cm_pro_id', $this->performer->pro->id)->where('is_signed_by_cm', false)->where('is_cancelled', false);
  313. })->orWhere(function ($query) {
  314. $query->where('rme_pro_id', $this->performer->pro->id)->where('is_signed_by_rme', false)->where('is_cancelled', false);
  315. })->orWhere(function ($query) {
  316. $query->where('rmm_pro_id', $this->performer->pro->id)->where('is_signed_by_rmm', false)->where('is_cancelled', false);
  317. })->orWhere(function ($query) {
  318. $query->where('generic_pro_id', $this->performer->pro->id)->where('is_signed_by_generic_pro', false)->where('is_cancelled', false);
  319. })
  320. ->orderBy('created_at', 'DESC')
  321. ->get()
  322. ];
  323. return view('app.mcp.bills_pending_signature', $data);
  324. }
  325. public function reports_pending_signature(Request $request){
  326. $data = [
  327. 'records' => IncomingReport::where('hcp_pro_id', $this->performer->pro->id)
  328. ->where('has_hcp_pro_signed', '<>', true)
  329. ->where('is_entry_error', '<>', true)
  330. ->orderBy('created_at')
  331. ->get()
  332. ];
  333. return view('app.mcp.reports_pending_signature', $data);
  334. }
  335. public function patients_without_appointments(Request $request){
  336. $patients = $this->performer->pro->get_patients_without_appointment_query()->paginate(20);
  337. return view('app.mcp.patients_without_appointments', compact('patients'));
  338. }
  339. public function patients_overdue_for_visit(Request $request){
  340. $patients = $this->performer->pro->get_patients_overdue_for_visit_query()->paginate(20);
  341. return view('app.mcp.patients_overdue_for_visit', compact('patients'));
  342. }
  343. public function cancelled_appointments_pending_review(Request $request){
  344. $data = [];
  345. return view('app.mcp.cancelled_appointments_pending_review', $data);
  346. }
  347. public function cancelled_bills_pending_review(Request $request){
  348. $data = [
  349. 'records' => Bill::where('hcp_pro_id', $this->performer->pro->id)
  350. ->where('bill_service_type', 'NOTE')
  351. ->where('is_cancelled', true)
  352. ->where('is_cancellation_acknowledged', '<>', true)
  353. ->orderBy('created_at')
  354. ->get()
  355. ];
  356. return view('app.mcp.cancelled_bills_pending_review', $data);
  357. }
  358. public function cancelled_supply_orders_pending_review(Request $request){
  359. $data = [
  360. 'records' => SupplyOrder::where('signed_by_pro_id', $this->performer->pro->id)
  361. ->where('is_cancelled', true)
  362. ->where('is_cancellation_acknowledged', '<>', true)
  363. ->orderBy('created_at')
  364. ->get()
  365. ];
  366. return view('app.mcp.cancelled_supply_orders_pending_review', $data);
  367. }
  368. public function erx_and_orders_pending_signature(Request $request){
  369. $data = [
  370. 'records' => Erx::where('hcp_pro_id', $this->performer->pro->id)
  371. ->where('pro_declared_status', '<>', 'CANCELLED')
  372. ->where('has_hcp_pro_signed', '<>', true)
  373. ->orderBy('created_at')
  374. ->get()
  375. ];
  376. return view('app.mcp.erx_and_orders_pending_signature', $data);
  377. }
  378. public function supply_orders_pending_signature(Request $request){
  379. $data = [
  380. 'records' => SupplyOrder::where('created_by_pro_id', $this->performer->pro->id)
  381. ->whereNull('signed_by_pro_id')
  382. ->where('is_cancelled', '<>', true)
  383. ->orderBy('created_at')
  384. ->get()
  385. ];
  386. return view('app.mcp.supply_orders_pending_signature', $data);
  387. }
  388. public function supply_orders_awaiting_shipment(Request $request){
  389. $data = [
  390. 'records' => SupplyOrder::where('created_by_pro_id', $this->performer->pro->id)
  391. ->where('is_signed_by_pro', true)
  392. ->where('is_cleared_for_shipment', true)
  393. ->whereNull('shipment_id')
  394. ->orderBy('created_at')
  395. ->get()
  396. ];
  397. return view('app.mcp.supply_orders_awaiting_shipment', $data);
  398. }
  399. public function unsigned_incoming_reports(Request $request){
  400. $data = [
  401. 'records' => IncomingReport::where('hcp_pro_id', $this->performer->pro->id)
  402. ->whereRaw('(has_hcp_pro_signed IS NULL OR has_hcp_pro_signed = FALSE)')
  403. ->orderBy('created_at', 'desc')
  404. ->get()
  405. ];
  406. return view('app.mcp.unsigned_incoming_reports', $data);
  407. }
  408. public function patients_awaiting_rpm_interaction(Request $request) {
  409. $cmStartDate = date('Y-m-01');
  410. $query = "
  411. SELECT
  412. client.uid as client_uid,
  413. care_month.uid as care_month_uid,
  414. (client.name_first || ' ' || client.name_last) as client_name,
  415. client.age_in_years,
  416. client.sex,
  417. care_month.start_date,
  418. care_month.number_of_days_with_remote_measurements
  419. FROM
  420. client join care_month on client.id = care_month.client_id
  421. WHERE
  422. care_month.start_date = '{$cmStartDate}'
  423. AND care_month.is_client_enrolled_in_rm
  424. AND care_month.has_mcp_interacted_with_client_about_rm IS NOT TRUE
  425. AND care_month.mcp_pro_id = {$this->performer->pro->id}
  426. AND (client.client_engagement_status_category IS NULL OR client.client_engagement_status_category != 'DUMMY')
  427. AND client.name_first NOT ILIKE '%test%'
  428. AND client.name_last NOT ILIKE '%test%'
  429. ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST
  430. ";
  431. $data = [
  432. 'records' => DB::select($query)
  433. ];
  434. return view('app.mcp.patients_awaiting_rpm_interaction', $data);
  435. }
  436. public function measurements_pending_stamping(Request $request){
  437. $data = [
  438. 'records' => CareMonth::where('mcp_pro_id', $this->performer->pro->id)
  439. ->where('rm_num_measurements_not_stamped_by_mcp', '>', 0)
  440. ->whereNotNull('rm_num_measurements_not_stamped_by_mcp')
  441. ->orderBy('created_at', 'DESC')
  442. ->paginate(15)
  443. ];
  444. return view('app.mcp.measurements_pending_stamping', $data);
  445. }
  446. public function measurements_pending_stamping_in_care_month(Request $request) {
  447. $patient = Client::where('uid', $request->input('patientUid'))->first();
  448. $careMonth = CareMonth::where('uid', $request->input('careMonthUid'))->first();
  449. return view('app.mcp.measurements_pending_stamping_in_care_month', compact('patient', 'careMonth'));
  450. }
  451. public function measurements_mass_stamping(Request $request){
  452. $careMonthsWithMeasurementsPendingStamping = CareMonth::select('id')
  453. ->where('mcp_pro_id', $this->performer->pro->id)
  454. ->where('rm_num_measurements_not_stamped_by_mcp', '>', 0)
  455. ->whereNotNull('rm_num_measurements_not_stamped_by_mcp')
  456. ->orderBy('created_at', 'DESC')
  457. ->get()
  458. ->map(function($_x) {
  459. return $_x->id;
  460. })
  461. ->toArray();
  462. $measurementsPendingStamping = Measurement::whereIn('care_month_id', $careMonthsWithMeasurementsPendingStamping)
  463. ->orderBy('created_at', 'DESC')
  464. ->whereNotNull('ts')
  465. ->whereNotIn('label', ['SBP', 'DBP'])
  466. ->where('is_cellular_zero', '<>', true)
  467. ->where('is_active', true)
  468. ->where('has_been_stamped_by_mcp', false)
  469. ->whereNotNull('client_bdt_measurement_id')
  470. ->paginate(500);
  471. return view('app.mcp.measurements_mass_stamping', compact('measurementsPendingStamping'));
  472. }
  473. }