AdminController.php 25 KB

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