|
@@ -3656,8 +3656,12 @@ ORDER BY c.name_last, c.name_first
|
|
JOIN bill AS b ON (b.note_id = n.id AND b.is_cancelled IS NOT TRUE AND b.code ILIKE '%treatment%')
|
|
JOIN bill AS b ON (b.note_id = n.id AND b.is_cancelled IS NOT TRUE AND b.code ILIKE '%treatment%')
|
|
";
|
|
";
|
|
$where = "WHERE
|
|
$where = "WHERE
|
|
- n.is_signed_by_hcp IS TRUE AND
|
|
|
|
- -- n.is_claim_closed IS NOT TRUE AND
|
|
|
|
|
|
+
|
|
|
|
+ -- n.visit_number = 2 AND
|
|
|
|
+ n.is_signed_by_hcp IS TRUE AND
|
|
|
|
+ -- n.effective_dateest < '2022-03-01' AND
|
|
|
|
+ -- n.id IN (SELECT note_id FROM segment WHERE summary_html ILIKE '%n95%') AND
|
|
|
|
+ n.is_claim_closed IS NOT TRUE AND
|
|
n.is_cancelled IS NOT TRUE AND
|
|
n.is_cancelled IS NOT TRUE AND
|
|
n.created_at::DATE >= '2022-01-01'::DATE AND
|
|
n.created_at::DATE >= '2022-01-01'::DATE AND
|
|
c.client_engagement_status_category <> 'DUMMY' AND
|
|
c.client_engagement_status_category <> 'DUMMY' AND
|
|
@@ -3667,8 +3671,8 @@ ORDER BY c.name_last, c.name_first
|
|
-- n.id NOT IN (SELECT note_id FROM claim WHERE note_id IS NOT NULL) AND
|
|
-- n.id NOT IN (SELECT note_id FROM claim WHERE note_id IS NOT NULL) AND
|
|
c.is_part_b_primary = 'YES' AND
|
|
c.is_part_b_primary = 'YES' AND
|
|
c.latest_eligible_refresh_at::DATE >= '2022-01-01' AND
|
|
c.latest_eligible_refresh_at::DATE >= '2022-01-01' AND
|
|
- c.mpb_remaining = 0 AND
|
|
|
|
- c.created_at::DATE >= '2022-01-01'::DATE
|
|
|
|
|
|
+ c.mpb_remaining = 0 -- AND
|
|
|
|
+ -- c.created_at::DATE >= '2022-01-01'::DATE
|
|
";
|
|
";
|
|
$filters = [];
|
|
$filters = [];
|
|
if($request->input('f')) {
|
|
if($request->input('f')) {
|
|
@@ -3684,7 +3688,9 @@ ORDER BY c.name_last, c.name_first
|
|
$filters = '';
|
|
$filters = '';
|
|
}
|
|
}
|
|
// $filters = '';
|
|
// $filters = '';
|
|
- $orderBy = "ORDER BY c.id ASC, n.effective_dateest ASC";
|
|
|
|
|
|
+ $orderBy = "ORDER BY
|
|
|
|
+ c.id ASC,
|
|
|
|
+ n.id ASC, n.effective_dateest ASC";
|
|
|
|
|
|
$countQuery = "SELECT count(*) {$from} {$where} {$filters}";
|
|
$countQuery = "SELECT count(*) {$from} {$where} {$filters}";
|
|
// dd($countQuery);
|
|
// dd($countQuery);
|
|
@@ -3706,5 +3712,186 @@ ORDER BY c.name_last, c.name_first
|
|
return view('app.practice-management.notes-resolution-center-v2', compact('rows', 'paginator'));
|
|
return view('app.practice-management.notes-resolution-center-v2', compact('rows', 'paginator'));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function coverages(Request $request) {
|
|
|
|
+
|
|
|
|
+ $columns = "(c.name_first || ' ' || c.name_last) as client_name,
|
|
|
|
+ c.id,
|
|
|
|
+ c.uid,
|
|
|
|
+ c.created_at,
|
|
|
|
+ c.sex,
|
|
|
|
+ c.dob,
|
|
|
|
+ c.age_in_years,
|
|
|
|
+ row_to_json(lcpc.*)::json as latest_client_primary_coverage,
|
|
|
|
+ row_to_json(lacpc.*) as latest_auto_client_primary_coverage,
|
|
|
|
+ row_to_json(lmcpc.*) as latest_manual_client_primary_coverage,
|
|
|
|
+ row_to_json(lmcpc_payer) as latest_manual_client_primary_coverage_payer
|
|
|
|
+ ";
|
|
|
|
+ $from = "FROM client AS c
|
|
|
|
+ LEFT JOIN client_primary_coverage lcpc on c.latest_client_primary_coverage_id = lcpc.id
|
|
|
|
+ LEFT JOIN client_primary_coverage lacpc on c.latest_auto_refresh_client_primary_coverage_id = lacpc.id
|
|
|
|
+ LEFT JOIN client_primary_coverage lmcpc on c.latest_manual_client_primary_coverage_id = lmcpc.id
|
|
|
|
+ LEFT JOIN payer lmcpc_payer on lmcpc.commercial_payer_id = lmcpc_payer.id
|
|
|
|
+ ";
|
|
|
|
+ $where = "WHERE
|
|
|
|
+ c.client_engagement_status_category <> 'DUMMY' AND
|
|
|
|
+ c.name_first NOT ILIKE '%test%' AND
|
|
|
|
+ c.name_last NOT ILIKE '%test%' AND
|
|
|
|
+ c.created_at::DATE >= '2022-01-01'::DATE
|
|
|
|
+ -- lmcpc.id IS NOT NULL ANd lmcpc.plan_type != 'MEDICARE'
|
|
|
|
+ ";
|
|
|
|
+ $filters = [];
|
|
|
|
+
|
|
|
|
+ if(trim($request->input('f_name'))) {
|
|
|
|
+ $v = trim($request->input('f_name'));
|
|
|
|
+ $filters[] = "(c.name_first ILIKE '%{$v}%' OR c.name_last ILIKE '%{$v}%')";
|
|
|
|
+ }
|
|
|
|
+ if(trim($request->input('f_covered'))) {
|
|
|
|
+ $v = trim($request->input('f_covered'));
|
|
|
|
+ if($v !== 'any') {
|
|
|
|
+ switch($v) {
|
|
|
|
+ case 'covered':
|
|
|
|
+ $filters[] = "(
|
|
|
|
+ (lmcpc.id IS NOT NULL AND lmcpc.is_cancelled IS NOT TRUE AND lmcpc.manual_determination_category = 'COVERED') OR
|
|
|
|
+ ((lmcpc.id IS NULL OR lmcpc.is_cancelled IS TRUE) AND lacpc.id IS NOT NULL AND lacpc.is_cancelled IS NOT TRUE AND lacpc.auto_medicare_is_partbprimary = 'YES')
|
|
|
|
+ )";
|
|
|
|
+ break;
|
|
|
|
+ case 'not-covered':
|
|
|
|
+ $filters[] = "(
|
|
|
|
+ (lmcpc.id IS NULL OR (lmcpc.is_cancelled IS TRUE OR lmcpc.manual_determination_category = 'NOT_COVERED')) AND
|
|
|
|
+ (lacpc.id IS NULL OR (lacpc.is_cancelled IS TRUE OR lacpc.auto_medicare_is_partbprimary = 'NO')) AND
|
|
|
|
+ (lmcpc.id IS NOT NULL OR lacpc.id IS NOT NULL)
|
|
|
|
+ )";
|
|
|
|
+ break;
|
|
|
|
+ case 'unknown':
|
|
|
|
+ $filters[] = "(
|
|
|
|
+ (lmcpc.id IS NOT NULL AND lmcpc.is_cancelled IS NOT TRUE AND lmcpc.manual_determination_category = 'UNKNOWN') OR
|
|
|
|
+ ((lmcpc.id IS NULL OR lmcpc.is_cancelled IS TRUE) AND lacpc.id IS NOT NULL AND lacpc.is_cancelled IS NOT TRUE AND lacpc.auto_medicare_is_partbprimary = 'UNKNOWN')
|
|
|
|
+ )";
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(trim($request->input('f_covered'))) {
|
|
|
|
+ $v = trim($request->input('f_covered'));
|
|
|
|
+ if($v !== 'any') {
|
|
|
|
+ switch($v) {
|
|
|
|
+ case 'covered':
|
|
|
|
+ $filters[] = "(
|
|
|
|
+ (lmcpc.id IS NOT NULL AND lmcpc.is_cancelled IS NOT TRUE AND lmcpc.manual_determination_category = 'COVERED') OR
|
|
|
|
+ ((lmcpc.id IS NULL OR lmcpc.is_cancelled IS TRUE) AND lacpc.id IS NOT NULL AND lacpc.is_cancelled IS NOT TRUE AND lacpc.auto_medicare_is_partbprimary = 'YES')
|
|
|
|
+ )";
|
|
|
|
+ break;
|
|
|
|
+ case 'not-covered':
|
|
|
|
+ $filters[] = "(
|
|
|
|
+ (lmcpc.id IS NULL OR (lmcpc.is_cancelled IS TRUE OR lmcpc.manual_determination_category = 'NOT_COVERED')) AND
|
|
|
|
+ (lacpc.id IS NULL OR (lacpc.is_cancelled IS TRUE OR lacpc.auto_medicare_is_partbprimary = 'NO')) AND
|
|
|
|
+ (lmcpc.id IS NOT NULL OR lacpc.id IS NOT NULL)
|
|
|
|
+ )";
|
|
|
|
+ break;
|
|
|
|
+ case 'unknown':
|
|
|
|
+ $filters[] = "(
|
|
|
|
+ (lmcpc.id IS NOT NULL AND lmcpc.is_cancelled IS NOT TRUE AND lmcpc.manual_determination_category = 'UNKNOWN') OR
|
|
|
|
+ ((lmcpc.id IS NULL OR lmcpc.is_cancelled IS TRUE) AND lacpc.id IS NOT NULL AND lacpc.is_cancelled IS NOT TRUE AND lacpc.auto_medicare_is_partbprimary = 'UNKNOWN')
|
|
|
|
+ )";
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(trim($request->input('f_plan_type'))) {
|
|
|
|
+ $v = strtoupper(trim($request->input('f_plan_type')));
|
|
|
|
+ if($v !== 'ANY') {
|
|
|
|
+ $filters[] = "(
|
|
|
|
+ (lmcpc.id IS NOT NULL AND lmcpc.is_cancelled IS NOT TRUE AND lmcpc.plan_type = '{$v}') OR
|
|
|
|
+ ((lmcpc.id IS NULL OR lmcpc.is_cancelled IS TRUE) AND lacpc.id IS NOT NULL AND lacpc.is_cancelled IS NOT TRUE AND lacpc.plan_type = '{$v}')
|
|
|
|
+ )";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(trim($request->input('f_pb_primary'))) {
|
|
|
|
+ $v = trim($request->input('f_pb_primary'));
|
|
|
|
+ if($v !== 'any') {
|
|
|
|
+ switch($v) {
|
|
|
|
+ case 'primary':
|
|
|
|
+ $filters[] = "(
|
|
|
|
+ (lmcpc.id IS NOT NULL AND lmcpc.is_cancelled IS NOT TRUE AND lmcpc.is_partbprimary = 'YES') OR
|
|
|
|
+ ((lmcpc.id IS NULL OR lmcpc.is_cancelled IS TRUE) AND lacpc.id IS NOT NULL AND lacpc.is_cancelled IS NOT TRUE AND lacpc.auto_medicare_is_partbprimary = 'YES')
|
|
|
|
+ )";
|
|
|
|
+ break;
|
|
|
|
+ case 'not-primary':
|
|
|
|
+ $filters[] = "(
|
|
|
|
+ (lmcpc.id IS NOT NULL AND lmcpc.is_cancelled IS NOT TRUE AND lmcpc.is_partbprimary = 'NO') OR
|
|
|
|
+ ((lmcpc.id IS NULL OR lmcpc.is_cancelled IS TRUE) AND lacpc.id IS NOT NULL AND lacpc.is_cancelled IS NOT TRUE AND lacpc.auto_medicare_is_partbprimary = 'NO')
|
|
|
|
+ )";
|
|
|
|
+ break;
|
|
|
|
+ case 'unknown':
|
|
|
|
+ $filters[] = "(
|
|
|
|
+ (lmcpc.id IS NOT NULL AND lmcpc.is_cancelled IS NOT TRUE AND lmcpc.is_partbprimary = 'UNKNOWN') OR
|
|
|
|
+ ((lmcpc.id IS NULL OR lmcpc.is_cancelled IS TRUE) AND lacpc.id IS NOT NULL AND lacpc.is_cancelled IS NOT TRUE AND lacpc.auto_medicare_is_partbprimary = 'UNKNOWN')
|
|
|
|
+ )";
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(trim($request->input('f_pb_active'))) {
|
|
|
|
+ $v = trim($request->input('f_pb_active'));
|
|
|
|
+ // TODO
|
|
|
|
+ }
|
|
|
|
+ if(trim($request->input('f_pc_active'))) {
|
|
|
|
+ $v = trim($request->input('f_pc_active'));
|
|
|
|
+ // TODO
|
|
|
|
+ }
|
|
|
|
+ if(trim($request->input('f_comm_payer'))) {
|
|
|
|
+ $v = trim($request->input('f_comm_payer'));
|
|
|
|
+ $filters[] = "(lmcpc_payer.name ILIKE '%{$v}%')";
|
|
|
|
+ }
|
|
|
|
+ if(trim($request->input('f_comm_member_id'))) {
|
|
|
|
+ $v = trim($request->input('f_comm_member_id'));
|
|
|
|
+ if($v !== 'any') {
|
|
|
|
+ $filters[] = "(
|
|
|
|
+ (lmcpc.id IS NOT NULL AND lmcpc.is_cancelled IS NOT TRUE AND lmcpc.commercial_member_identifier ILIKE '%{$v}%') OR
|
|
|
|
+ ((lmcpc.id IS NULL OR lmcpc.is_cancelled IS TRUE) AND lacpc.id IS NOT NULL AND lacpc.is_cancelled IS NOT TRUE AND lacpc.commercial_member_identifier ILIKE '%{$v}%')
|
|
|
|
+ )";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(trim($request->input('f_comm_group_num'))) {
|
|
|
|
+ $v = trim($request->input('f_comm_group_num'));
|
|
|
|
+ if($v !== 'any') {
|
|
|
|
+ $filters[] = "(
|
|
|
|
+ (lmcpc.id IS NOT NULL AND lmcpc.is_cancelled IS NOT TRUE AND lmcpc.commercial_group_number ILIKE '%{$v}%') OR
|
|
|
|
+ ((lmcpc.id IS NULL OR lmcpc.is_cancelled IS TRUE) AND lacpc.id IS NOT NULL AND lacpc.is_cancelled IS NOT TRUE AND lacpc.commercial_group_number ILIKE '%{$v}%')
|
|
|
|
+ )";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(count($filters)) {
|
|
|
|
+ $filters = 'AND ' . implode(' AND ', $filters);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $filters = '';
|
|
|
|
+ }
|
|
|
|
+ // $filters = '';
|
|
|
|
+ $orderBy = "ORDER BY client_name ASC";
|
|
|
|
+
|
|
|
|
+ $countQuery = "SELECT count(*) {$from} {$where} {$filters}";
|
|
|
|
+ // dd($countQuery);
|
|
|
|
+ $countResult = DB::select($countQuery);
|
|
|
|
+ $total = $countResult[0]->count;
|
|
|
|
+
|
|
|
|
+ $defaultPageSize = 10;
|
|
|
|
+
|
|
|
|
+ $page = $request->input('page') ?: 1;
|
|
|
|
+ $perPage = $request->input('per_page') ?: $defaultPageSize;
|
|
|
|
+ $offset = ($page - 1) * $perPage;
|
|
|
|
+
|
|
|
|
+ $dataQuery = "SELECT {$columns} {$from} {$where} {$filters} {$orderBy} OFFSET {$offset} LIMIT {$perPage}";
|
|
|
|
+ $rows = DB::select($dataQuery);
|
|
|
|
+
|
|
|
|
+ $paginator = new LengthAwarePaginator($rows, $total, $request->input('per_page') ?: $defaultPageSize, $request->input('page') ?: 1);
|
|
|
|
+ $paginator->setPath(route('practice-management.coverages'));
|
|
|
|
+
|
|
|
|
+ // dd($rows);
|
|
|
|
+
|
|
|
|
+ return view('app.practice-management.coverages', compact('rows', 'paginator'));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|