AdminController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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 Illuminate\Support\Facades\Http;
  30. use PDF;
  31. class AdminController extends Controller
  32. {
  33. public function patients(Request $request)
  34. {
  35. $filters = $request->all();
  36. $patients = Client::whereNull('shadow_pro_id');
  37. if ($request->input('name')) {
  38. $name = trim($request->input('name'));
  39. if ($name) {
  40. $patients = $patients->where(function ($q) use ($name) {
  41. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  42. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  43. });
  44. }
  45. }
  46. if ($request->input('mcp')) {
  47. if($request->input('mcp') == 'NO_MCP'){
  48. $patients = $patients->whereNull('mcp_pro_id');
  49. }else{
  50. $mcp = Pro::where('uid', trim($request->input('mcp')))->first();
  51. if ($mcp) {
  52. $patients = $patients->where('mcp_pro_id', $mcp->id);
  53. }
  54. }
  55. }
  56. if ($request->input('na')) {
  57. if($request->input('na') == 'NO_NA'){
  58. $patients = $patients->whereNull('default_na_pro_id');
  59. }else{
  60. $na = Pro::where('uid', trim($request->input('na')))->first();
  61. if ($na) {
  62. $patients = $patients->where('default_na_pro_id', $na->id);
  63. }
  64. }
  65. }
  66. if ($request->input('next_appointment_category')) {
  67. if($request->input('next_appointment_category') == 'NONE'){
  68. $patients = $patients->whereNull('next_mcp_appointment_id');
  69. }
  70. }
  71. if ($request->input('chart_number')) {
  72. $patients = $patients->where('chart_number', 'ILIKE' , '%'.$request->input('chart_number').'%');
  73. }
  74. if ($request->input('home_address_state')) {
  75. if($request->input('home_address_state') == 'NONE'){
  76. $patients = $patients->whereRaw("mailing_address_state IS NULL OR TRIM(BOTH FROM mailing_address_state = ''");
  77. }else if($request->input('home_address_state') == 'NOT_MD'){
  78. $patients = $patients->whereRaw("(TRIM(BOTH FROM mailing_address_state) NOT ILIKE 'MD' AND TRIM(BOTH FROM mailing_address_state) NOT ILIKE 'MARYLAND')");
  79. }else{
  80. $patients = $patients->whereRaw("TRIM(BOTH FROM mailing_address_state) = '" . $request->input('home_address_state') . "'");
  81. }
  82. }
  83. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2');
  84. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  85. $this->filterMultiQuery($request, $patients, 'usual_bmi_max', 'bmi_category', 'bmi_value_1', 'bmi_value_2');
  86. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  87. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  88. $this->filterMultiQuery($request, $patients, 'created_at', 'created_at', 'created_at_value_1', 'created_at_value_2');
  89. if($request->input('number_of_measurements')){
  90. $keyName = $request->input('number_of_measurements');
  91. $measurementCountQuery = '(SELECT COUNT(*) FROM measurement WHERE measurement.client_id = client.id AND is_active IS TRUE AND is_cellular IS TRUE AND is_cellular_zero IS NOT TRUE)';
  92. switch($keyName) {
  93. case 'EXACTLY':
  94. if($request->input('number_of_measurements_value_1')) {
  95. $patients->whereRaw($measurementCountQuery . '='.$request->input('number_of_measurements_value_1'));
  96. }
  97. break;
  98. case 'LESS_THAN':
  99. if($request->input('number_of_measurements_value_1')) {
  100. $patients->whereRaw($measurementCountQuery . '<='.$request->input('number_of_measurements_value_1'));
  101. }
  102. break;
  103. case 'GREATER_THAN':
  104. if($request->input('number_of_measurements_value_1')) {
  105. $patients->whereRaw($measurementCountQuery . '>='.$request->input('number_of_measurements_value_1'));
  106. }
  107. break;
  108. case 'BETWEEN':
  109. if($request->input('number_of_measurements_value_1') && $request->input('number_of_measurements_value_2')) {
  110. $patients->whereRaw($measurementCountQuery.'>='.$request->input('number_of_measurements_value_1') .' AND '. $measurementCountQuery . '<='.$request->input('number_of_measurements_value_2'));
  111. }
  112. break;
  113. case 'NOT_BETWEEN':
  114. if($request->input('number_of_measurements_value_1') && $request->input('number_of_measurements_value_2')) {
  115. $patients->where(function ($q) use ($request, $measurementCountQuery) {
  116. $q->whereRaw($measurementCountQuery . '<'.$request->input('number_of_measurements_value_1') .' OR '. $measurementCountQuery . '>'.$request->input('number_of_measurements_value_2'));
  117. });
  118. }
  119. break;
  120. }
  121. }
  122. $status = $request->input('status');
  123. if($status){
  124. if($status == 'ACTIVE'){
  125. $patients->where('is_active', true)->where(function($q) use ($status){
  126. return $q->where('client_engagement_status_category', $status)
  127. ->orWhereNull('client_engagement_status_category');
  128. });
  129. }elseif($status = 'NONE'){
  130. $patients->whereNull('client_engagement_status_category');
  131. }else {
  132. $patients->where('client_engagement_status_category', $status);
  133. }
  134. }
  135. $initiative = $request->input('initiative');
  136. if($initiative){
  137. $wildCardedInitiative = '%'.$initiative.'%';
  138. $patients->where('initiative', 'ilike', $wildCardedInitiative);
  139. }
  140. $include_test_records = $request->input('include_test_records');
  141. if(!$include_test_records && $status != 'DUMMY'){
  142. $patients = $patients->where(function ($q) {
  143. $q->whereNull('client_engagement_status_category')
  144. ->orWhere('client_engagement_status_category', '<>', 'DUMMY');
  145. });
  146. }
  147. $zero_deductible = $request->input('zero_deductible');
  148. if($zero_deductible){
  149. $patients = $patients->where(function ($q) {
  150. $q->where('mpb_remaining', 0);
  151. });
  152. }
  153. $insurance = $request->get('insurance');
  154. if($insurance){
  155. if($insurance === 'MEDICARE'){
  156. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery) {
  157. return $cpcQuery->where('is_partbprimary', '=', 'YES');
  158. });
  159. }else{
  160. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery) use ($insurance){
  161. return $cpcQuery->where('commercial_payer_id', '=', $insurance);
  162. });
  163. }
  164. }
  165. $sortBy = $request->input('sort_by') ?: 'created_at';
  166. $sortDir = $request->input('sort_dir') ?: 'DESC';
  167. $patients = $patients->orderByRaw("$sortBy $sortDir NULLS LAST");
  168. $patients = $patients->orderBy('created_at', 'DESC')->paginate(25);
  169. $insurances = DB::select('SELECT DISTINCT commercial_payer_name, commercial_payer_id FROM client_primary_coverage WHERE commercial_payer_name IS NOT NULL ORDER BY commercial_payer_name ASC');
  170. return view('app.admin.patients', compact('patients', 'filters', 'insurances'));
  171. }
  172. public function partBPatients(Request $request){
  173. $filters = $request->all();
  174. $patients = Client::whereNull('shadow_pro_id');
  175. if ($request->input('name')) {
  176. $name = trim($request->input('name'));
  177. if ($name) {
  178. $patients = $patients->where(function ($q) use ($name) {
  179. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  180. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  181. });
  182. }
  183. }
  184. if ($request->input('mcp')) {
  185. if($request->input('mcp') == 'NO_MCP'){
  186. $patients = $patients->whereNull('mcp_pro_id');
  187. }else{
  188. $mcp = Pro::where('uid', trim($request->input('mcp')))->first();
  189. if ($mcp) {
  190. $patients = $patients->where('mcp_pro_id', $mcp->id);
  191. }
  192. }
  193. }
  194. if ($request->input('na')) {
  195. if($request->input('na') == 'NO_NA'){
  196. $patients = $patients->whereNull('default_na_pro_id');
  197. }else{
  198. $na = Pro::where('uid', trim($request->input('na')))->first();
  199. if ($na) {
  200. $patients = $patients->where('default_na_pro_id', $na->id);
  201. }
  202. }
  203. }
  204. if ($request->input('next_appointment_category')) {
  205. if($request->input('next_appointment_category') == 'NONE'){
  206. $patients = $patients->whereNull('next_mcp_appointment_id');
  207. }
  208. }
  209. if ($request->input('chart_number')) {
  210. $patients = $patients->where('chart_number', 'ILIKE' , '%'.$request->input('chart_number').'%');
  211. }
  212. if ($request->input('home_address_state')) {
  213. if($request->input('home_address_state') == 'NONE'){
  214. $patients = $patients->whereNull('mailing_address_state');
  215. }else if($request->input('home_address_state') == 'NOT_MD'){
  216. $patients = $patients->where('mailing_address_state', '<>' , 'MD');
  217. }else{
  218. $patients = $patients->where('mailing_address_state', '=' , $request->input('home_address_state'));
  219. }
  220. }
  221. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2');
  222. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  223. $this->filterMultiQuery($request, $patients, 'usual_bmi_max', 'bmi_category', 'bmi_value_1', 'bmi_value_2');
  224. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  225. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  226. if($request->input('deductible')){
  227. $keyName = $request->input('deductible');
  228. switch($keyName) {
  229. case 'EXACTLY':
  230. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  231. return $q->where('auto_medicare_mpb_deductible', '=', $request->input('deductible_value_1'));
  232. });
  233. break;
  234. case 'LESS_THAN':
  235. if($request->input('deductible_value_1')) {
  236. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  237. return $q->where('auto_medicare_mpb_deductible', '<=', $request->input('deductible_value_1'));
  238. });
  239. }
  240. break;
  241. case 'GREATER_THAN':
  242. if($request->input('deductible_value_1')) {
  243. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  244. return $q->where('auto_medicare_mpb_deductible', '>=', $request->input('deductible_value_1'));
  245. });
  246. }
  247. break;
  248. case 'BETWEEN':
  249. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  250. return $q->where('auto_medicare_mpb_deductible', '>=', $request->input('deductible_value_1'))
  251. ->where('auto_medicare_mpb_deductible', '<=', $request->input('deductible_value_2'));
  252. });
  253. break;
  254. case 'NOT_BETWEEN':
  255. if($request->input('deductible_value_1') && $request->input('deductible_value_2')) {
  256. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  257. return $q->where(function($qq) use ($request){
  258. return $qq->where('auto_medicare_mpb_deductible', '<', $request->input('deductible_value_1'))
  259. ->orWhere('auto_medicare_mpb_deductible', '>', $request->input('deductible_value_2'));
  260. });
  261. });
  262. }
  263. break;
  264. }
  265. }
  266. switch($request->input('status')) {
  267. case 'ACTIVE':
  268. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
  269. break;
  270. case 'AWAITING_VISIT':
  271. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
  272. break;
  273. case 'INACTIVE':
  274. $patients->where('is_active', '<>', true);
  275. break;
  276. }
  277. $initiative = $request->input('initiative');
  278. if($initiative){
  279. $wildCardedInitiative = '%'.$initiative.'%';
  280. $patients->where('initiative', 'ilike', $wildCardedInitiative);
  281. }
  282. $include_test_records = $request->input('include_test_records');
  283. if(!$include_test_records){
  284. $patients = $patients->where(function ($q) {
  285. return $q->whereNull('client_engagement_status_category')
  286. ->orWhere('client_engagement_status_category', '<>', 'DUMMY');
  287. });
  288. }
  289. $with_claim_not_closed = $request->input('with_claim_not_closed');
  290. if($with_claim_not_closed){
  291. $patients = $patients->whereHas('notes', function ($q) {
  292. return $q->where('is_claim_closed', false)
  293. ->where('is_signed_by_hcp', true)
  294. ->where('is_cancelled', false);
  295. });
  296. }
  297. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  298. return $cpcQuery->where('is_partbprimary', '=', 'YES');
  299. });
  300. $patients = $patients->orderBy('created_at', 'DESC')->paginate(25);
  301. return view('app.admin.part_b_patients', compact('patients', 'filters'));
  302. }
  303. public function notes(Request $request)
  304. {
  305. $notes = Note::paginate(5);
  306. // SELECT * FROM note WHERE client_id IN (SELECT id FROM client WHERE mcp_pro_id = :me.id);
  307. return view('app.mcp.notes', compact('notes'));
  308. }
  309. public function notes_pending_summary_suggestion(Request $request){
  310. $pro = $this->performer->pro;
  311. $data = [
  312. 'records' => $pro->get_notes_pending_summary_suggestion_as_admin()
  313. ];
  314. return view('app.admin.notes_pending_summary_suggestion', $data);
  315. }
  316. public function notes_rejected_summary_suggestion(Request $request){
  317. $pro = $this->performer->pro;
  318. $data = [
  319. 'records' => $pro->get_notes_rejected_summary_suggestion_as_admin()
  320. ];
  321. return view('app.admin.notes_rejected_summary_suggestion', $data);
  322. }
  323. public function appointments(Request $request)
  324. {
  325. $appointments = Appointment::paginate(5);
  326. return view('app.mcp.appointments', compact('appointments'));
  327. }
  328. public function bills(Request $request)
  329. {
  330. $bills = Bill::paginate(5);
  331. return view('app.mcp.bills', compact('bills'));
  332. }
  333. public function erx_and_orders(Request $request)
  334. {
  335. $erxAndOrders = Erx::paginate(5);
  336. return view('app.mcp.erx_and_orders', compact('erxAndOrders'));
  337. }
  338. public function reports(Request $request)
  339. {
  340. $data = [];
  341. return view('app.mcp.reports', $data);
  342. }
  343. public function supply_orders(Request $request)
  344. {
  345. $supplyOrders = SupplyOrder::paginate(5);
  346. return view('app.mcp.supply_orders', compact('supplyOrders'));
  347. }
  348. public function getCreateNewPatientScriptTemplate(Request $request){
  349. $template = $request->get('template');
  350. if(!$template) return $this->fail('No script template');
  351. $path = resource_path() . '/views/app/patient/create-patient/scripts/' . $template . '.blade.php';
  352. if(!File::exists($path)) return $this->fail('Invalid script template');
  353. $templateContent = file_get_contents($path);
  354. return $this->pass($templateContent);
  355. }
  356. public function bdtDevices(Request $request)
  357. {
  358. $filters = $request->all();
  359. $bdtDevices = BDTDevice::query();
  360. $imei = $request->input('imei');
  361. if($imei){
  362. $bdtDevices = $bdtDevices->where('imei', '=', $imei);
  363. }
  364. $client = $request->input('client');
  365. if($client){
  366. $client = '%'.$client.'%';
  367. $bdtDevices = $bdtDevices->whereHas('clientBDTDevice', function($cbdtdQuery) use ($client) {
  368. return $cbdtdQuery->whereHas('client', function($clientQuery) use ($client){
  369. return $clientQuery->where(function($q) use ($client){
  370. return $q->where('name_first', 'ilike', $client)
  371. ->orWhere('name_last', 'ilike', $client)
  372. ->orWhere('cell_number', 'ilike', $client)
  373. ->orWhereRaw("name_first||' '||name_last ILIKE "."'".$client."'");
  374. });
  375. });
  376. });
  377. }
  378. $is_issued = $request->input('is_issued');
  379. if($is_issued){
  380. if($is_issued == 'YES'){
  381. $bdtDevices = $bdtDevices->whereHas('clientBDTDevice');
  382. }
  383. if($is_issued == 'NO'){
  384. $bdtDevices = $bdtDevices->whereDoesntHave('clientBDTDevice');
  385. }
  386. }
  387. $is_issued = $request->input('is_issued');
  388. if($is_issued){
  389. if($is_issued == 'YES'){
  390. $bdtDevices = $bdtDevices->whereHas('clientBDTDevice');
  391. }
  392. if($is_issued == 'NO'){
  393. $bdtDevices = $bdtDevices->whereDoesntHave('clientBDTDevice');
  394. }
  395. }
  396. $mcp = $request->input('mcp');
  397. if($mcp){
  398. $bdtDevices = $bdtDevices->whereHas('clientBDTDevice', function($cbdtdQuery) use ($mcp) {
  399. return $cbdtdQuery->whereHas('client', function($clientQuery) use ($mcp){
  400. $mcpPro = Pro::where('uid', $mcp)->first();
  401. return $clientQuery->where('mcp_pro_id', $mcpPro->id);
  402. });
  403. });
  404. }
  405. $bdtDevices = $bdtDevices->paginate(20);
  406. return view('app.admin.bdt_devices', compact('bdtDevices', 'filters'));
  407. }
  408. public function patientsMissingDefasultSettings(Request $request){
  409. $filters = $request->all();
  410. $patients = Client::whereNull('shadow_pro_id');
  411. $patients = $patients->where(function($qry){
  412. return $qry->orWhereNull('mcp_pro_id')->orWhereNull('default_mcp_company_pro_id')->orWhereNull('default_mcp_company_pro_payer_id')->orWhereNull('default_mcp_company_location_id');
  413. });
  414. if ($request->input('name')) {
  415. $name = trim($request->input('name'));
  416. if ($name) {
  417. $patients = $patients->where(function ($q) use ($name) {
  418. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  419. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  420. });
  421. }
  422. }
  423. if ($request->input('mcp')) {
  424. if($request->input('mcp') == 'NO_MCP'){
  425. $patients = $patients->whereNull('mcp_pro_id');
  426. }else{
  427. $mcp = Pro::where('uid', trim($request->input('mcp')))->first();
  428. if ($mcp) {
  429. $patients = $patients->where('mcp_pro_id', $mcp->id);
  430. }
  431. }
  432. }
  433. if ($request->input('chart_number')) {
  434. $patients = $patients->where('chart_number', 'ILIKE' , '%'.$request->input('chart_number').'%');
  435. }
  436. $status = $request->input('status');
  437. if($status){
  438. if($status == 'ACTIVE'){
  439. $patients->where('is_active', true)->where(function($q) use ($status){
  440. return $q->where('client_engagement_status_category', $status)
  441. ->orWhereNull('client_engagement_status_category');
  442. });
  443. }else {
  444. $patients->where('client_engagement_status_category', $status);
  445. }
  446. }
  447. $insurance = $request->get('insurance');
  448. if($insurance){
  449. if($insurance === 'MEDICARE'){
  450. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  451. return $cpcQuery->where('is_partbprimary', '=', 'YES');
  452. });
  453. }elseif($insurance === 'MEDICARE_PENDING'){
  454. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  455. return $cpcQuery->where('plan_type', 'MEDICARE')->where('is_covered', '!=', 'YES');
  456. });
  457. }elseif($insurance === 'NOT_COVERED'){
  458. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  459. return $cpcQuery->where('is_covered', '!=', 'YES');
  460. });
  461. }elseif($insurance === 'PENDING'){
  462. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  463. return $cpcQuery->where('is_covered', '=', 'UNKNOWN');
  464. });
  465. }
  466. else{
  467. $patients = $patients->whereDoesntHave('effectiveClientPrimaryCoverage', function($cpcQuery){
  468. return $cpcQuery->where('is_partbprimary', '=', 'YES');
  469. });
  470. }
  471. }
  472. $missing_default_settings = $request->get('missing_default_settings');
  473. if($missing_default_settings){
  474. if($missing_default_settings === 'NO_MCP') $patients = $patients->whereNull('mcp_pro_id');
  475. if($missing_default_settings === 'NO_MCP_COMPANY_PRO') $patients = $patients->whereNull('default_mcp_company_pro_id');
  476. if($missing_default_settings === 'NO_MCP_COMPANY_PRO_PAYER') $patients = $patients->whereNull('default_mcp_company_pro_payer_id');
  477. if($missing_default_settings === 'NO_MCP_COMPANY_LOCATION') $patients = $patients->whereNull('default_mcp_company_location_id');
  478. }
  479. $care_plan = $request->get('care_plan');
  480. if($care_plan){
  481. if($care_plan === 'UNSIGNED_CARE_PLANS'){
  482. $patients = $patients->whereHas('notes', function($noteQuery){
  483. return $noteQuery->where('cm_setup_manager_signature_status', '!=', 'SIGNED');
  484. });
  485. }
  486. if($care_plan === 'UNCLEARED_CARE_PLANS'){
  487. $patients = $patients->where('has_care_plan_flag', true)->where('is_flag_cleared', false);
  488. }
  489. }
  490. $patients = $patients->orderBy('created_at', 'DESC')->paginate(50);
  491. return view('app.admin.patients_missing_default_settings', compact('patients', 'filters'));
  492. }
  493. }