|
@@ -1861,7 +1861,7 @@ WHERE
|
|
$rc = $request->input('rc') ?: 1;
|
|
$rc = $request->input('rc') ?: 1;
|
|
$rc2 = $request->input('rc2') ?: 2;
|
|
$rc2 = $request->input('rc2') ?: 2;
|
|
|
|
|
|
- $conditions = [];// $this->rpmConditions($performer, $rc, $rc2);
|
|
|
|
|
|
+ $conditions = []; // ["(care_month.start_date >= '2022-01-01')"];
|
|
|
|
|
|
$sortBy = $request->input('sort_by') ?: 'name_first';
|
|
$sortBy = $request->input('sort_by') ?: 'name_first';
|
|
$sortDir = $request->input('sort_dir') ?: 'ASC';
|
|
$sortDir = $request->input('sort_dir') ?: 'ASC';
|
|
@@ -1879,7 +1879,7 @@ WHERE
|
|
|
|
|
|
// default sort
|
|
// default sort
|
|
if(!$request->input('sort_by')) {
|
|
if(!$request->input('sort_by')) {
|
|
- $orderBy = "ORDER BY care_month.number_of_days_with_remote_measurements DESC NULLS LAST, care_month.rm_total_time_in_seconds_by_mcp DESC NULLS LAST, care_month.rm_total_time_in_seconds_by_rmm_pro DESC NULLS LAST";
|
|
|
|
|
|
+ $orderBy = "ORDER BY care_month.start_date DESC, care_month.number_of_days_with_remote_measurements DESC NULLS LAST, care_month.rm_total_time_in_seconds_by_mcp DESC NULLS LAST, care_month.rm_total_time_in_seconds_by_rmm_pro DESC NULLS LAST";
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
$sortBy = json_decode($request->input('sort_by'));
|
|
$sortBy = json_decode($request->input('sort_by'));
|
|
@@ -1900,6 +1900,15 @@ WHERE
|
|
}
|
|
}
|
|
|
|
|
|
// filters from the UI
|
|
// filters from the UI
|
|
|
|
+ if(trim($request->input('m'))) {
|
|
|
|
+ $v = trim($request->input('m'));
|
|
|
|
+ $conditions[] = "(EXTRACT(MONTH from care_month.start_date) = $v)";
|
|
|
|
+ }
|
|
|
|
+ if(trim($request->input('y'))) {
|
|
|
|
+ $v = trim($request->input('y'));
|
|
|
|
+ $conditions[] = "(EXTRACT(YEAR from care_month.start_date) = $v)";
|
|
|
|
+ }
|
|
|
|
+
|
|
if(trim($request->input('f_ces'))) {
|
|
if(trim($request->input('f_ces'))) {
|
|
$v = trim($request->input('f_ces'));
|
|
$v = trim($request->input('f_ces'));
|
|
if($v === 'ACTIVE') {
|
|
if($v === 'ACTIVE') {
|
|
@@ -2061,6 +2070,12 @@ WHERE
|
|
$conditions[] = "(DATE_PART('day', NOW() - client.most_recent_cellular_measurement_at) {$o} {$v})";
|
|
$conditions[] = "(DATE_PART('day', NOW() - client.most_recent_cellular_measurement_at) {$o} {$v})";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if(trim($request->input('f_dslv_op')) && trim($request->input('f_dslv')) !== '') {
|
|
|
|
+ $o = trim($request->input('f_dslv_op'));
|
|
|
|
+ $v = trim($request->input('f_dslv'));
|
|
|
|
+ $conditions[] = "(care_month.days_between_most_recent_mcp_note_date_and_end_of_care_month {$o} {$v})";
|
|
|
|
+ }
|
|
|
|
+
|
|
if($request->input('not-enrolled')) {
|
|
if($request->input('not-enrolled')) {
|
|
$conditions[] = "(care_month.is_client_enrolled_in_rm IS NOT TRUE)";
|
|
$conditions[] = "(care_month.is_client_enrolled_in_rm IS NOT TRUE)";
|
|
}
|
|
}
|
|
@@ -2077,6 +2092,96 @@ WHERE
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if($request->input('f_mcp_billable')) {
|
|
|
|
+ if($request->input('f_mcp_billable') === 'no') {
|
|
|
|
+ $conditions[] = "(care_month.is_billable_by_mcp IS NULL OR care_month.is_billable_by_mcp IS FALSE)";
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $conditions[] = "(care_month.is_billable_by_mcp IS TRUE)";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if($request->input('f_rmm_billable')) {
|
|
|
|
+ if($request->input('f_rmm_billable') === 'no') {
|
|
|
|
+ $conditions[] = "(care_month.is_billable_by_rmm IS NULL OR care_month.is_billable_by_rmm IS FALSE)";
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $conditions[] = "(care_month.is_billable_by_rmm IS TRUE)";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ switch($request->input('f_454')) {
|
|
|
|
+ case 'Claimable':
|
|
|
|
+ $conditions[] = "(care_month.is_99454_claimable IS TRUE)";
|
|
|
|
+ break;
|
|
|
|
+ case 'Not Claimable':
|
|
|
|
+ $conditions[] = "(care_month.is_99454_claimable IS NULL OR care_month.is_99454_claimable IS FALSE)";
|
|
|
|
+ break;
|
|
|
|
+ case 'Claimed':
|
|
|
|
+ $conditions[] = "(care_month.is_99454_claimable IS TRUE AND care_month.is_99454_claimed IS TRUE)";
|
|
|
|
+ break;
|
|
|
|
+ case 'Not Claimed':
|
|
|
|
+ $conditions[] = "(care_month.is_99454_claimable IS TRUE AND (care_month.is_99454_claimed IS NULL OR care_month.is_99454_claimed IS FALSE))";
|
|
|
|
+ break;
|
|
|
|
+ case 'Waived':
|
|
|
|
+ $conditions[] = "(care_month.is_99454_claimable IS TRUE AND care_month.is_99454_claiming_waived IS TRUE)";
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ switch($request->input('f_454')) {
|
|
|
|
+ case 'Claimable':
|
|
|
|
+ $conditions[] = "(care_month.is_99454_claimable IS TRUE)";
|
|
|
|
+ break;
|
|
|
|
+ case 'Not Claimable':
|
|
|
|
+ $conditions[] = "(care_month.is_99454_claimable IS NULL OR care_month.is_99454_claimable IS FALSE)";
|
|
|
|
+ break;
|
|
|
|
+ case 'Claimed':
|
|
|
|
+ $conditions[] = "(care_month.is_99454_claimable IS TRUE AND care_month.is_99454_claimed IS TRUE)";
|
|
|
|
+ break;
|
|
|
|
+ case 'Not Claimed':
|
|
|
|
+ $conditions[] = "(care_month.is_99454_claimable IS TRUE AND (care_month.is_99454_claimed IS NULL OR care_month.is_99454_claimed IS FALSE))";
|
|
|
|
+ break;
|
|
|
|
+ case 'Waived':
|
|
|
|
+ $conditions[] = "(care_month.is_99454_claimable IS TRUE AND care_month.is_99454_claiming_waived IS TRUE)";
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ switch($request->input('f_457')) {
|
|
|
|
+ case 'Claimable':
|
|
|
|
+ $conditions[] = "(care_month.is_99457_claimable IS TRUE)";
|
|
|
|
+ break;
|
|
|
|
+ case 'Not Claimable':
|
|
|
|
+ $conditions[] = "(care_month.is_99457_claimable IS NULL OR care_month.is_99457_claimable IS FALSE)";
|
|
|
|
+ break;
|
|
|
|
+ case 'Claimed':
|
|
|
|
+ $conditions[] = "(care_month.is_99457_claimable IS TRUE AND care_month.is_99457_claimed IS TRUE)";
|
|
|
|
+ break;
|
|
|
|
+ case 'Not Claimed':
|
|
|
|
+ $conditions[] = "(care_month.is_99457_claimable IS TRUE AND (care_month.is_99457_claimed IS NULL OR care_month.is_99457_claimed IS FALSE))";
|
|
|
|
+ break;
|
|
|
|
+ case 'Waived':
|
|
|
|
+ $conditions[] = "(care_month.is_99457_claimable IS TRUE AND care_month.is_99457_claiming_waived IS TRUE)";
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ switch($request->input('f_458')) {
|
|
|
|
+ case 'Claimable':
|
|
|
|
+ $conditions[] = "(care_month.is_99458_claimable IS TRUE)";
|
|
|
|
+ break;
|
|
|
|
+ case 'Not Claimable':
|
|
|
|
+ $conditions[] = "(care_month.is_99458_claimable IS NULL OR care_month.is_99458_claimable IS FALSE)";
|
|
|
|
+ break;
|
|
|
|
+ case 'Claimed':
|
|
|
|
+ $conditions[] = "(care_month.is_99458_claimable IS TRUE AND care_month.is_99458_claimed IS TRUE)";
|
|
|
|
+ break;
|
|
|
|
+ case 'Not Claimed':
|
|
|
|
+ $conditions[] = "(care_month.is_99458_claimable IS TRUE AND (care_month.is_99458_claimed IS NULL OR care_month.is_99458_claimed IS FALSE))";
|
|
|
|
+ break;
|
|
|
|
+ case 'Waived':
|
|
|
|
+ $conditions[] = "(care_month.is_99458_claimable IS TRUE AND care_month.is_99458_claiming_waived IS TRUE)";
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
if($request->input('f_visit_90_days')) {
|
|
if($request->input('f_visit_90_days')) {
|
|
/*if($request->input('f_visit_90_days') === 'yes') {
|
|
/*if($request->input('f_visit_90_days') === 'yes') {
|
|
$conditions[] = "(care_month.is_claim_closed IS " . ($request->input('f_claim_closed') === 'yes' ? 'TRUE' : 'FALSE') . ")";
|
|
$conditions[] = "(care_month.is_claim_closed IS " . ($request->input('f_claim_closed') === 'yes' ? 'TRUE' : 'FALSE') . ")";
|
|
@@ -2115,9 +2220,7 @@ FROM care_month join client on care_month.client_id = client.id
|
|
left join payer on cpc.commercial_payer_id = payer.id
|
|
left join payer on cpc.commercial_payer_id = payer.id
|
|
{$genericBillJoinClause}
|
|
{$genericBillJoinClause}
|
|
WHERE
|
|
WHERE
|
|
- EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
|
|
|
|
- AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
|
|
|
|
- " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '') . "
|
|
|
|
|
|
+ " . (count($conditions) > 0 ? implode(" AND ", $conditions) : '') . "
|
|
";
|
|
";
|
|
|
|
|
|
$countResult = DB::select($countQuery);
|
|
$countResult = DB::select($countQuery);
|
|
@@ -2141,6 +2244,7 @@ SELECT client.name_first, client.name_last,
|
|
care_month.id as care_month_id,
|
|
care_month.id as care_month_id,
|
|
care_month.is_claim_closed,
|
|
care_month.is_claim_closed,
|
|
care_month.start_date,
|
|
care_month.start_date,
|
|
|
|
+ care_month.rm_total_time_in_seconds,
|
|
care_month.rm_total_time_in_seconds_by_mcp,
|
|
care_month.rm_total_time_in_seconds_by_mcp,
|
|
care_month.rm_total_time_in_seconds_by_rmm_pro,
|
|
care_month.rm_total_time_in_seconds_by_rmm_pro,
|
|
care_month.number_of_days_with_remote_measurements,
|
|
care_month.number_of_days_with_remote_measurements,
|
|
@@ -2150,6 +2254,23 @@ SELECT client.name_first, client.name_last,
|
|
care_month.rm_num_measurements_not_stamped_by_non_hcp,
|
|
care_month.rm_num_measurements_not_stamped_by_non_hcp,
|
|
care_month.rm_num_measurements_not_stamped_by_rmm,
|
|
care_month.rm_num_measurements_not_stamped_by_rmm,
|
|
care_month.rm_num_measurements_not_stamped_by_rme,
|
|
care_month.rm_num_measurements_not_stamped_by_rme,
|
|
|
|
+ care_month.is_99454_claimable,
|
|
|
|
+ care_month.is_99454_claimed,
|
|
|
|
+ care_month.is_99454_claiming_waived,
|
|
|
|
+ care_month.is_99457_claimable,
|
|
|
|
+ care_month.is_99457_claimed,
|
|
|
|
+ care_month.is_99457_claiming_waived,
|
|
|
|
+ care_month.is_99458_claimable,
|
|
|
|
+ care_month.is_99458_claimed,
|
|
|
|
+ care_month.is_99458_claiming_waived,
|
|
|
|
+ care_month.is_billable_by_mcp,
|
|
|
|
+ care_month.is_billable_by_rmm,
|
|
|
|
+ care_month.why_99454_not_claimable_reason,
|
|
|
|
+ care_month.why_99457_not_claimable_reason,
|
|
|
|
+ care_month.why_99458_not_claimable_reason,
|
|
|
|
+ care_month.why_claiming_99454_waived,
|
|
|
|
+ care_month.why_claiming_99457_waived,
|
|
|
|
+ care_month.why_claiming_99458_waived,
|
|
care_month.mcp_pro_id as care_month_mcp_pro_id,
|
|
care_month.mcp_pro_id as care_month_mcp_pro_id,
|
|
care_month.rmm_pro_id as care_month_rmm_pro_id,
|
|
care_month.rmm_pro_id as care_month_rmm_pro_id,
|
|
client.mcp_pro_id,
|
|
client.mcp_pro_id,
|
|
@@ -2169,6 +2290,7 @@ SELECT client.name_first, client.name_last,
|
|
rmmPro.rmm_payment_amount,
|
|
rmmPro.rmm_payment_amount,
|
|
client.mailing_address_state,
|
|
client.mailing_address_state,
|
|
care_month.most_recent_cellular_weight_measurement_at,
|
|
care_month.most_recent_cellular_weight_measurement_at,
|
|
|
|
+ care_month.days_between_most_recent_mcp_note_date_and_end_of_care_month,
|
|
cpc.plan_type,
|
|
cpc.plan_type,
|
|
cpc.auto_medicare_is_partbprimary,
|
|
cpc.auto_medicare_is_partbprimary,
|
|
(CASE
|
|
(CASE
|
|
@@ -2177,6 +2299,7 @@ SELECT client.name_first, client.name_last,
|
|
END) as payer_name,
|
|
END) as payer_name,
|
|
(SELECT COUNT(*) FROM claim_line where claim_line.cpt = '99454' AND claim_line.claim_id IN (SELECT claim.id FROM claim WHERE claim.care_month_id = care_month.id AND claim.status != 'CANCELLED')) as claim_454,
|
|
(SELECT COUNT(*) FROM claim_line where claim_line.cpt = '99454' AND claim_line.claim_id IN (SELECT claim.id FROM claim WHERE claim.care_month_id = care_month.id AND claim.status != 'CANCELLED')) as claim_454,
|
|
(SELECT COUNT(*) FROM claim_line where claim_line.cpt = '99457' AND claim_line.claim_id IN (SELECT claim.id FROM claim WHERE claim.care_month_id = care_month.id AND claim.status != 'CANCELLED')) as claim_457,
|
|
(SELECT COUNT(*) FROM claim_line where claim_line.cpt = '99457' AND claim_line.claim_id IN (SELECT claim.id FROM claim WHERE claim.care_month_id = care_month.id AND claim.status != 'CANCELLED')) as claim_457,
|
|
|
|
+ (SELECT COUNT(*) FROM claim_line where claim_line.cpt = '99458' AND claim_line.claim_id IN (SELECT claim.id FROM claim WHERE claim.care_month_id = care_month.id AND claim.status != 'CANCELLED')) as claim_458,
|
|
{$genericBillIdColumns}
|
|
{$genericBillIdColumns}
|
|
FROM care_month join client on care_month.client_id = client.id
|
|
FROM care_month join client on care_month.client_id = client.id
|
|
left join note mrnote on client.most_recent_completed_mcp_note_id = mrnote.id
|
|
left join note mrnote on client.most_recent_completed_mcp_note_id = mrnote.id
|
|
@@ -2187,9 +2310,7 @@ FROM care_month join client on care_month.client_id = client.id
|
|
left join appointment nv on nv.id = mrnote.follow_up_appointment_id
|
|
left join appointment nv on nv.id = mrnote.follow_up_appointment_id
|
|
{$genericBillJoinClause}
|
|
{$genericBillJoinClause}
|
|
WHERE
|
|
WHERE
|
|
- EXTRACT(MONTH from care_month.start_date) = " . ($request->input('m') ?: 'EXTRACT(MONTH from now())') . "
|
|
|
|
- AND EXTRACT(YEAR from care_month.start_date) = " . ($request->input('y') ?: 'EXTRACT(YEAR from now())') . "
|
|
|
|
- " . (count($conditions) > 0 ? 'AND ' . implode(" AND ", $conditions) : '') . "
|
|
|
|
|
|
+ " . (count($conditions) > 0 ? implode(" AND ", $conditions) : '') . "
|
|
{$orderBy} OFFSET {$offset} LIMIT {$perPage}
|
|
{$orderBy} OFFSET {$offset} LIMIT {$perPage}
|
|
|
|
|
|
";
|
|
";
|