AdminController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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. $sortBySQL = "$sortBy $sortDir NULLS LAST";
  168. if($sortBy !== 'client_engagement_status_category' || $request->input('status')) {
  169. $sortBySQL = "client_engagement_status_category DESC NULLS LAST";
  170. }
  171. $patients = $patients->orderByRaw($sortBySQL)->paginate(25);
  172. $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');
  173. return view('app.admin.patients', compact('patients', 'filters', 'insurances'));
  174. }
  175. public function partBPatients(Request $request){
  176. $filters = $request->all();
  177. $patients = Client::whereNull('shadow_pro_id');
  178. if ($request->input('name')) {
  179. $name = trim($request->input('name'));
  180. if ($name) {
  181. $patients = $patients->where(function ($q) use ($name) {
  182. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  183. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  184. });
  185. }
  186. }
  187. if ($request->input('mcp')) {
  188. if($request->input('mcp') == 'NO_MCP'){
  189. $patients = $patients->whereNull('mcp_pro_id');
  190. }else{
  191. $mcp = Pro::where('uid', trim($request->input('mcp')))->first();
  192. if ($mcp) {
  193. $patients = $patients->where('mcp_pro_id', $mcp->id);
  194. }
  195. }
  196. }
  197. if ($request->input('na')) {
  198. if($request->input('na') == 'NO_NA'){
  199. $patients = $patients->whereNull('default_na_pro_id');
  200. }else{
  201. $na = Pro::where('uid', trim($request->input('na')))->first();
  202. if ($na) {
  203. $patients = $patients->where('default_na_pro_id', $na->id);
  204. }
  205. }
  206. }
  207. if ($request->input('next_appointment_category')) {
  208. if($request->input('next_appointment_category') == 'NONE'){
  209. $patients = $patients->whereNull('next_mcp_appointment_id');
  210. }
  211. }
  212. if ($request->input('chart_number')) {
  213. $patients = $patients->where('chart_number', 'ILIKE' , '%'.$request->input('chart_number').'%');
  214. }
  215. if ($request->input('home_address_state')) {
  216. if($request->input('home_address_state') == 'NONE'){
  217. $patients = $patients->whereNull('mailing_address_state');
  218. }else if($request->input('home_address_state') == 'NOT_MD'){
  219. $patients = $patients->where('mailing_address_state', '<>' , 'MD');
  220. }else{
  221. $patients = $patients->where('mailing_address_state', '=' , $request->input('home_address_state'));
  222. }
  223. }
  224. $this->filterMultiQuery($request, $patients, 'age_in_years', 'age_category', 'age_value_1', 'age_value_2');
  225. $this->filterSimpleQuery($request, $patients, 'sex', 'sex');
  226. $this->filterMultiQuery($request, $patients, 'usual_bmi_max', 'bmi_category', 'bmi_value_1', 'bmi_value_2');
  227. $this->filterMultiQuery($request, $patients, 'most_recent_weight_at', 'last_weighed_in_category', 'last_weighed_in_value_1', 'last_weighed_in_value_2');
  228. $this->filterMultiQuery($request, $patients, 'most_recent_bp_at', 'last_bp_category', 'last_bp_value_1', 'last_bp_value_2');
  229. if($request->input('deductible')){
  230. $keyName = $request->input('deductible');
  231. switch($keyName) {
  232. case 'EXACTLY':
  233. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  234. return $q->where('auto_medicare_mpb_deductible', '=', $request->input('deductible_value_1'));
  235. });
  236. break;
  237. case 'LESS_THAN':
  238. if($request->input('deductible_value_1')) {
  239. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  240. return $q->where('auto_medicare_mpb_deductible', '<=', $request->input('deductible_value_1'));
  241. });
  242. }
  243. break;
  244. case 'GREATER_THAN':
  245. if($request->input('deductible_value_1')) {
  246. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  247. return $q->where('auto_medicare_mpb_deductible', '>=', $request->input('deductible_value_1'));
  248. });
  249. }
  250. break;
  251. case 'BETWEEN':
  252. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  253. return $q->where('auto_medicare_mpb_deductible', '>=', $request->input('deductible_value_1'))
  254. ->where('auto_medicare_mpb_deductible', '<=', $request->input('deductible_value_2'));
  255. });
  256. break;
  257. case 'NOT_BETWEEN':
  258. if($request->input('deductible_value_1') && $request->input('deductible_value_2')) {
  259. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($q) use ($request){
  260. return $q->where(function($qq) use ($request){
  261. return $qq->where('auto_medicare_mpb_deductible', '<', $request->input('deductible_value_1'))
  262. ->orWhere('auto_medicare_mpb_deductible', '>', $request->input('deductible_value_2'));
  263. });
  264. });
  265. }
  266. break;
  267. }
  268. }
  269. switch($request->input('status')) {
  270. case 'ACTIVE':
  271. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', true);
  272. break;
  273. case 'AWAITING_VISIT':
  274. $patients->where('is_active', true)->where('has_mcp_done_onboarding_visit', false);
  275. break;
  276. case 'INACTIVE':
  277. $patients->where('is_active', '<>', true);
  278. break;
  279. }
  280. $initiative = $request->input('initiative');
  281. if($initiative){
  282. $wildCardedInitiative = '%'.$initiative.'%';
  283. $patients->where('initiative', 'ilike', $wildCardedInitiative);
  284. }
  285. $include_test_records = $request->input('include_test_records');
  286. if(!$include_test_records){
  287. $patients = $patients->where(function ($q) {
  288. return $q->whereNull('client_engagement_status_category')
  289. ->orWhere('client_engagement_status_category', '<>', 'DUMMY');
  290. });
  291. }
  292. $with_claim_not_closed = $request->input('with_claim_not_closed');
  293. if($with_claim_not_closed){
  294. $patients = $patients->whereHas('notes', function ($q) {
  295. return $q->where('is_claim_closed', false)
  296. ->where('is_signed_by_hcp', true)
  297. ->where('is_cancelled', false);
  298. });
  299. }
  300. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  301. return $cpcQuery->where('is_partbprimary', '=', 'YES');
  302. });
  303. $patients = $patients->orderBy('created_at', 'DESC')->paginate(25);
  304. return view('app.admin.part_b_patients', compact('patients', 'filters'));
  305. }
  306. public function notes(Request $request)
  307. {
  308. $notes = Note::paginate(5);
  309. // SELECT * FROM note WHERE client_id IN (SELECT id FROM client WHERE mcp_pro_id = :me.id);
  310. return view('app.mcp.notes', compact('notes'));
  311. }
  312. public function notes_pending_summary_suggestion(Request $request){
  313. $pro = $this->performer->pro;
  314. $data = [
  315. 'records' => $pro->get_notes_pending_summary_suggestion_as_admin()
  316. ];
  317. return view('app.admin.notes_pending_summary_suggestion', $data);
  318. }
  319. public function notes_rejected_summary_suggestion(Request $request){
  320. $pro = $this->performer->pro;
  321. $data = [
  322. 'records' => $pro->get_notes_rejected_summary_suggestion_as_admin()
  323. ];
  324. return view('app.admin.notes_rejected_summary_suggestion', $data);
  325. }
  326. public function appointments(Request $request)
  327. {
  328. $appointments = Appointment::paginate(5);
  329. return view('app.mcp.appointments', compact('appointments'));
  330. }
  331. public function bills(Request $request)
  332. {
  333. $bills = Bill::paginate(5);
  334. return view('app.mcp.bills', compact('bills'));
  335. }
  336. public function erx_and_orders(Request $request)
  337. {
  338. $erxAndOrders = Erx::paginate(5);
  339. return view('app.mcp.erx_and_orders', compact('erxAndOrders'));
  340. }
  341. public function reports(Request $request)
  342. {
  343. $data = [];
  344. return view('app.mcp.reports', $data);
  345. }
  346. public function supply_orders(Request $request)
  347. {
  348. $supplyOrders = SupplyOrder::paginate(5);
  349. return view('app.mcp.supply_orders', compact('supplyOrders'));
  350. }
  351. public function getCreateNewPatientScriptTemplate(Request $request){
  352. $template = $request->get('template');
  353. if(!$template) return $this->fail('No script template');
  354. $path = resource_path() . '/views/app/patient/create-patient/scripts/' . $template . '.blade.php';
  355. if(!File::exists($path)) return $this->fail('Invalid script template');
  356. $templateContent = file_get_contents($path);
  357. return $this->pass($templateContent);
  358. }
  359. public function bdtDevices(Request $request)
  360. {
  361. $filters = $request->all();
  362. $bdtDevices = BDTDevice::query();
  363. $imei = $request->input('imei');
  364. if($imei){
  365. $bdtDevices = $bdtDevices->where('imei', '=', $imei);
  366. }
  367. $client = $request->input('client');
  368. if($client){
  369. $client = '%'.$client.'%';
  370. $bdtDevices = $bdtDevices->whereHas('clientBDTDevice', function($cbdtdQuery) use ($client) {
  371. return $cbdtdQuery->whereHas('client', function($clientQuery) use ($client){
  372. return $clientQuery->where(function($q) use ($client){
  373. return $q->where('name_first', 'ilike', $client)
  374. ->orWhere('name_last', 'ilike', $client)
  375. ->orWhere('cell_number', 'ilike', $client)
  376. ->orWhereRaw("name_first||' '||name_last ILIKE "."'".$client."'");
  377. });
  378. });
  379. });
  380. }
  381. $is_issued = $request->input('is_issued');
  382. if($is_issued){
  383. if($is_issued == 'YES'){
  384. $bdtDevices = $bdtDevices->whereHas('clientBDTDevice');
  385. }
  386. if($is_issued == 'NO'){
  387. $bdtDevices = $bdtDevices->whereDoesntHave('clientBDTDevice');
  388. }
  389. }
  390. $is_issued = $request->input('is_issued');
  391. if($is_issued){
  392. if($is_issued == 'YES'){
  393. $bdtDevices = $bdtDevices->whereHas('clientBDTDevice');
  394. }
  395. if($is_issued == 'NO'){
  396. $bdtDevices = $bdtDevices->whereDoesntHave('clientBDTDevice');
  397. }
  398. }
  399. $mcp = $request->input('mcp');
  400. if($mcp){
  401. $bdtDevices = $bdtDevices->whereHas('clientBDTDevice', function($cbdtdQuery) use ($mcp) {
  402. return $cbdtdQuery->whereHas('client', function($clientQuery) use ($mcp){
  403. $mcpPro = Pro::where('uid', $mcp)->first();
  404. return $clientQuery->where('mcp_pro_id', $mcpPro->id);
  405. });
  406. });
  407. }
  408. $bdtDevices = $bdtDevices->paginate(20);
  409. return view('app.admin.bdt_devices', compact('bdtDevices', 'filters'));
  410. }
  411. public function patientsMissingDefasultSettings(Request $request){
  412. $filters = $request->all();
  413. $patients = Client::whereNull('shadow_pro_id');
  414. $patients = $patients->where(function($qry){
  415. 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');
  416. });
  417. if ($request->input('name')) {
  418. $name = trim($request->input('name'));
  419. if ($name) {
  420. $patients = $patients->where(function ($q) use ($name) {
  421. $q->where('name_first', 'ILIKE', '%' . $name . '%')
  422. ->orWhere('name_last', 'ILIKE', '%' . $name . '%');
  423. });
  424. }
  425. }
  426. if ($request->input('mcp')) {
  427. if($request->input('mcp') == 'NO_MCP'){
  428. $patients = $patients->whereNull('mcp_pro_id');
  429. }else{
  430. $mcp = Pro::where('uid', trim($request->input('mcp')))->first();
  431. if ($mcp) {
  432. $patients = $patients->where('mcp_pro_id', $mcp->id);
  433. }
  434. }
  435. }
  436. if ($request->input('chart_number')) {
  437. $patients = $patients->where('chart_number', 'ILIKE' , '%'.$request->input('chart_number').'%');
  438. }
  439. $status = $request->input('status');
  440. if($status){
  441. if($status == 'ACTIVE'){
  442. $patients->where('is_active', true)->where(function($q) use ($status){
  443. return $q->where('client_engagement_status_category', $status)
  444. ->orWhereNull('client_engagement_status_category');
  445. });
  446. }else {
  447. $patients->where('client_engagement_status_category', $status);
  448. }
  449. }
  450. $insurance = $request->get('insurance');
  451. if($insurance){
  452. if($insurance === 'MEDICARE'){
  453. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  454. return $cpcQuery->where('is_partbprimary', '=', 'YES');
  455. });
  456. }elseif($insurance === 'MEDICARE_PENDING'){
  457. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  458. return $cpcQuery->where('plan_type', 'MEDICARE')->where('is_covered', '!=', 'YES');
  459. });
  460. }elseif($insurance === 'NOT_COVERED'){
  461. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  462. return $cpcQuery->where('is_covered', '!=', 'YES');
  463. });
  464. }elseif($insurance === 'PENDING'){
  465. $patients = $patients->whereHas('effectiveClientPrimaryCoverage', function($cpcQuery){
  466. return $cpcQuery->where('is_covered', '=', 'UNKNOWN');
  467. });
  468. }
  469. else{
  470. $patients = $patients->whereDoesntHave('effectiveClientPrimaryCoverage', function($cpcQuery){
  471. return $cpcQuery->where('is_partbprimary', '=', 'YES');
  472. });
  473. }
  474. }
  475. $missing_default_settings = $request->get('missing_default_settings');
  476. if($missing_default_settings){
  477. if($missing_default_settings === 'NO_MCP') $patients = $patients->whereNull('mcp_pro_id');
  478. if($missing_default_settings === 'NO_MCP_COMPANY_PRO') $patients = $patients->whereNull('default_mcp_company_pro_id');
  479. if($missing_default_settings === 'NO_MCP_COMPANY_PRO_PAYER') $patients = $patients->whereNull('default_mcp_company_pro_payer_id');
  480. if($missing_default_settings === 'NO_MCP_COMPANY_LOCATION') $patients = $patients->whereNull('default_mcp_company_location_id');
  481. }
  482. $care_plan = $request->get('care_plan');
  483. if($care_plan){
  484. if($care_plan === 'UNSIGNED_CARE_PLANS'){
  485. $patients = $patients->whereHas('notes', function($noteQuery){
  486. return $noteQuery->where('cm_setup_manager_signature_status', '!=', 'SIGNED');
  487. });
  488. }
  489. if($care_plan === 'UNCLEARED_CARE_PLANS'){
  490. $patients = $patients->where('has_care_plan_flag', true)->where('is_flag_cleared', false);
  491. }
  492. }
  493. $patients = $patients->orderBy('created_at', 'DESC')->paginate(50);
  494. return view('app.admin.patients_missing_default_settings', compact('patients', 'filters'));
  495. }
  496. }