Skip to main content
Version: 2.3

v2.3.2

Prod Features​

Non-outlier rate presence for 0464U​

provider_typen
Physician Group41736
Hospital16139
Laboratory6832
Code
# Non-outlier rate presence for 0464U (2025_08 only for labs)
df = pd.read_sql(f"""
SELECT provider_type, count(*)
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE billing_code = '0464U'
AND canonical_rate_score > 1
GROUP BY 1
ORDER BY 2 DESC
LIMIT 10
""", con=trino_conn)
print(df.to_markdown(index=False))

Non-outlier rate presence for other guardant codes​

'0473U',
'0487U',
'0422U',
'0486U',
'0485U',
'0464U'
provider_typebilling_coden
Laboratory0473U7218
Laboratory0464U6832
Laboratory0487U6045

0422U, 0485U, and 0486U will not be in the tool until we refresh with Q1 data due to not being on the CLFS until 2026

Code
# check other guardant lab codes
df = pd.read_sql(f"""
SELECT provider_type, billing_code, count(*) as n
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE billing_code IN (
'0473U',
'0487U',
'0422U',
'0486U',
'0485U',
'0464U'
)
AND canonical_rate_score > 1
AND provider_type = 'Laboratory'
GROUP BY 1, 2
ORDER BY 3 DESC
LIMIT 10
""", con=trino_conn)
print(df.to_markdown(index=False))

confirm Sam's lab request is present​

n
2835
Code
df = pd.read_sql(f"""
--confirmed Sam's request is in there (Agendia)
select *
from tq_production.spines.spines_provider_labs
where npi = '1821253584'
""", con=trino_conn)
print(df.to_markdown(index=False))

df = pd.read_sql(f"""
select COUNT(*)
from tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
where provider_id = '7144998591559364424'
AND canonical_rate_score > 1
""", con=trino_conn)
print(df.to_markdown(index=False))

add best payer and hospital fields​

need to add best payer/hospital contract_methodology in provider-SKU table build (i.e. prod_clickhouse_abridged)

best_payer_ratebest_hospital_ratebest_payer_method_paramsbest_hospital_method_paramsbest_payer_rate_typebest_hospital_rate_type
12.989212.9892"percentage":90.00,"ccr_adjustment":0.2238629894,"gross_charge":64.47"percentage":90.0000000000000,"ccr_adjustment":0.2238629894,"gross_charge":64.47transform: payer_gc_hosp_state_perc_to_doltransform: hospital_perc_of_total_billed_charges_gc_hosp_state_perc_to_dol
148.5148.5"percentage":100.00,"ccr_adjustment":1.0000000000,"gross_charge":148.5"percentage":100.0000000000000,"ccr_adjustment":1.0000000000,"gross_charge":148.5transform: payer_gc_komodo_cbsa_perc_to_doltransform: hospital_fee_schedule_gc_komodo_cbsa_perc_to_dol
1097.51097.5"percentage":100.00,"ccr_adjustment":1.0000000000,"gross_charge":1097.5"percentage":100.0000000000000,"ccr_adjustment":1.0000000000,"gross_charge":1097.5transform: payer_gc_komodo_cbsa_perc_to_doltransform: hospital_fee_schedule_gc_komodo_cbsa_perc_to_dol
4.614.61"percentage":57.61,"ccr_adjustment":0.4576551718,"gross_charge":17.5"percentage":57.6100000000000,"ccr_adjustment":0.4576551718,"gross_charge":17.5transform: payer_gc_hosp_state_perc_to_doltransform: hospital_perc_of_total_billed_charges_gc_hosp_state_perc_to_dol
1279.341279.18"percentage":79.01,"ccr_adjustment":0.4064288669,"gross_charge":3984.0"percentage":79.0000000000000,"ccr_adjustment":0.4064288669,"gross_charge":3984.0transform: payer_gc_hosp_state_perc_to_doltransform: hospital_perc_of_total_billed_charges_gc_hosp_state_perc_to_dol
8091.978091.97"percentage":78.69,"ccr_adjustment":0.8557342318,"gross_charge":12017.0"percentage":78.6900000000000,"ccr_adjustment":0.8557342318,"gross_charge":12017.0transform: payer_gc_hosp_state_perc_to_doltransform: hospital_perc_of_total_billed_charges_gc_hosp_state_perc_to_dol
13717.413717.4"percentage":78.69,"ccr_adjustment":0.8557342318,"gross_charge":20371.0"percentage":78.6900000000000,"ccr_adjustment":0.8557342318,"gross_charge":20371.0transform: payer_gc_hosp_state_perc_to_doltransform: hospital_perc_of_total_billed_charges_gc_hosp_state_perc_to_dol
116.488116.488"percentage":80.00,"ccr_adjustment":0.6497236487,"gross_charge":224.11111111111111"percentage":80.0000000000000,"ccr_adjustment":0.6497236487,"gross_charge":224.11111111111111transform: payer_gc_hosp_state_perc_to_doltransform: hospital_perc_of_total_billed_charges_gc_hosp_state_perc_to_dol
5332.515331.83"percentage":79.01,"ccr_adjustment":0.4064288669,"gross_charge":16606.0"percentage":79.0000000000000,"ccr_adjustment":0.4064288669,"gross_charge":16606.0transform: payer_gc_hosp_state_perc_to_doltransform: hospital_perc_of_total_billed_charges_gc_hosp_state_perc_to_dol
47524.550907.6"per_diem":2655.00,"glos":17.9000"per_diem":2844.00,"glos":17.9000transform: payer_per_diem_mult_glostransform: hosp_per_diem_mult_glos
Code
# [CLD-v2.3.2] add best payer and hospital contract methodology and params
# [CLD-v2.3.2] payer hospital best rate columns
df = pd.read_sql(f"""
SELECT
-- best_payer_contract_methodology,
-- best_hospital_contract_methodology,
best_payer_rate,
best_hospital_rate,
best_payer_method_params,
best_hospital_method_params,
best_payer_rate_type,
best_hospital_rate_type
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE best_payer_method_params IS NOT NULL
AND best_hospital_method_params IS NOT NULL
LIMIT 10
""", con=trino_conn)
df

Use "payer_hospital" for validated rates​

canonical_rate_sourcecanonical_rate_scoren
payer252344235
hospital21895781
imputation215472904
payer_hospital532964454
imputation427221378
payer494171030
02856389431
payer3217617839
imputation126614545
hospital38922889
payer160767894
hospital19334423
hospital457767469
imputation357146524
Code
# [CLD-v2.3.2] Use payer_hospital for validated rates
df = pd.read_sql(f"""
SELECT
canonical_rate_source,
canonical_rate_score,
count(*) as n
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
GROUP BY 1,2
""", con=trino_conn)
print(df.to_markdown(index=False))

df = pd.read_sql(f"""
SELECT
count(*) as n
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE canonical_rate_score = 5
AND canonical_rate_source IS NULL
""", con=trino_conn)
print(df.to_markdown(index=False))

Include all labs in core rates​

Increased to 5391 from 972

_col0
5391
Code
# [CLD-v2.3.2] Include all labs in core rates
df = pd.read_sql(f"""
SELECT COUNT(DISTINCT provider_id)
FROM tq_dev.internal_dev_csong_cld_v2_3_2.tmp_ref_provider_spine_2025_11
WHERE provider_type = 'Laboratory'
""", con=trino_conn)
print(df.to_markdown(index=False))

df = pd.read_sql(f"""
SELECT COUNT(DISTINCT provider_id)
FROM tq_dev.internal_dev_csong_cld_v2_3_2.tmp_ref_provider_spine_2025_08
WHERE provider_type = 'Laboratory'
""", con=trino_conn)
print(df.to_markdown(index=False))

df = pd.read_sql(f"""
SELECT COUNT(DISTINCT provider_id)
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE provider_type = 'Laboratory'
""", con=trino_conn)
print(df.to_markdown(index=False))

df = pd.read_sql(f"""
SELECT COUNT(DISTINCT provider_id)
FROM tq_dev.internal_dev_csong_cld_v2_3_1.tmp_int_combined_2025_10
WHERE provider_type = 'Laboratory'
""", con=trino_conn)
print(df.to_markdown(index=False))

Add new ASC codes​

billing_coden_providers
936551071
9365630
936571071
Code
# [CLD-v2.3.2] Add new ASC codes
df = pd.read_sql(f"""
SELECT billing_code, COUNT(distinct provider_id) as n_providers
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE provider_type = 'ASC'
AND billing_code IN ('93655','93656','93657')
AND canonical_rate_score > 1
GROUP BY 1
""", con=trino_conn)
print(df.to_markdown(index=False))

update OPPS codeset​

Increased to 7512 from 7084

Code
# [CLD-v2.3.2] update OPPS codeset
df = pd.read_sql(f"""
SELECT COUNT(DISTINCT billing_code)
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE bill_type = 'Outpatient'
AND provider_type = 'Hospital'
AND canonical_rate_score > 1
""", con=trino_conn)
print(df.to_markdown(index=False))

df = pd.read_sql(f"""
SELECT COUNT(DISTINCT billing_code)
FROM tq_dev.internal_dev_csong_cld_v2_3_1.tmp_int_combined_2025_10
WHERE bill_type = 'Outpatient'
AND provider_type = 'Hospital'
AND canonical_rate_score > 1
""", con=trino_conn)
print(df.to_markdown(index=False))

filter EXCHANGE in hospital plan bridge​

Sample trace_raw_id from Clear Rates and check payer_class_name in hospital_data.hospital_rates

payer_class_namen
Exchange88609

They all have "Exchange" payer class name now.

Code
# [CLD-v2.3.2] filter EXCHANGE in hospital plan bridge
df = pd.read_sql(f"""
WITH
sample AS (
SELECT hospital_rates_id
FROM tq_dev.internal_dev_csong_cld_v2_3_2.tmp_raw_mrf_hospital_rates_2025_11
WHERE network_id IN (
SELECT network_id
FROM tq_dev.internal_dev_csong_cld_v2_3_2.tmp_ref_network_spine_2025_11
WHERE network_type = 'EXCHANGE'
)
AND provider_id IN (
SELECT provider_id
FROM tq_dev.internal_dev_csong_cld_v2_3_2.tmp_ref_provider_spine_2025_11
WHERE provider_type = 'Hospital'
)
ORDER BY RANDOM()
LIMIT 100000
)
SELECT payer_class_name, count(*) as n
FROM tq_production.hospital_data.hospital_rates hr
WHERE hr.id IN (SELECT hospital_rates_id FROM sample)
GROUP BY 1
""", con=trino_conn)
df

check for RC to HCPCS imputation​

canonical_rate_sourcecanonical_rate_scorebill_typeprovider_typecanonical_rate_type_col5
imputation2OutpatientHospitalimpute: rc_hcpcs_gc_hosp_perc_to_dol212336
imputation3OutpatientHospitalimpute: rc_hcpcs_gc_komodo_perc_to_dol19761
imputation3OutpatientHospitalimpute: rc_hcpcs_gc_komodo_state_perc_to_dol1710778
imputation2OutpatientHospitalimpute: rc_hcpcs_gc_komodo_perc_to_dol32548
imputation3OutpatientHospitalimpute: rc_hcpcs_gc_komodo_cbsa_perc_to_dol210832
imputation2OutpatientHospitalimpute: rc_hcpcs_gc_hosp_cbsa_perc_to_dol208439
imputation3OutpatientHospitalimpute: rc_hcpcs_gc_hosp_cbsa_perc_to_dol404372
imputation2OutpatientHospitalimpute: rc_hcpcs_gc_komodo_state_perc_to_dol408854
imputation3OutpatientHospitalimpute: rc_hcpcs_gc_hosp_perc_to_dol804911
imputation3OutpatientHospitalimpute: rc_hcpcs_gc_hosp_state_perc_to_dol5893056
imputation2OutpatientHospitalimpute: rc_hcpcs_gc_komodo_cbsa_perc_to_dol215762
imputation2OutpatientHospitalimpute: rc_hcpcs_gc_hosp_state_perc_to_dol2614826
Code
df = pd.read_sql(f"""
SELECT canonical_rate_source, canonical_rate_score, bill_type, provider_type, canonical_rate_type, COUNT(*)
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE canonical_rate_type LIKE '%rc_hcpcs%'
AND canonical_rate_score > 1
GROUP BY 1, 2, 3, 4, 5
""", con=trino_conn)
print(df.to_markdown(index=False))

Full Code​

Code
# %%
from IPython import get_ipython
from jinja2 import Template

if get_ipython() is not None:
get_ipython().run_line_magic("load_ext", "autoreload")
get_ipython().run_line_magic("autoreload", "2")
from dotenv import load_dotenv
import pandas as pd
from tqds.sql import db, sql

import pandas as pd
import numpy as np

import seaborn as sns
import matplotlib.pyplot as plt
sns.set_theme(style='whitegrid', rc={'figure.figsize': (14, 12)})

pd.options.display.max_columns = None
pd.options.display.max_rows = 100
pd.options.display.max_colwidth = None
pd.set_option('display.float_format', lambda x: '%.3f' % x)
trino_conn = db.TrinoClient().conn
redshift_conn = db.RedshiftClient().conn
query = sql.Query()


# %% [markdown]
"""
PRs:

[CLD-v2.3.2] add best payer and hospital contract methodology and params
[CLD-v2.3.2] payer hospital best rate columns
[CLD-v2.3.2] Use payer_hospital for validated rates
[CLD-v2.3.2] Include all labs in core rates
[CLD-v2.3.2] Add new ASC codes
[CLD-v2.3.2] update OPPS codeset
[CLD-v2.3.2] filter EXCHANGE in hospital plan bridge
[CLD-v2.3.2] RC to HCPCS imputation
Double check rate presence for 0464U
"""


# %%
# Double check rate presence for 0464U (2025_08 only for labs)
df = pd.read_sql(f"""
SELECT provider_type, count(*)
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE billing_code = '0464U'
AND canonical_rate_score > 1
GROUP BY 1
ORDER BY 2 DESC
LIMIT 10
""", con=trino_conn)
df

# %%
# [CLD-v2.3.2] add best payer and hospital contract methodology and params
# [CLD-v2.3.2] payer hospital best rate columns
df = pd.read_sql(f"""
SELECT
-- best_payer_contract_methodology,
-- best_hospital_contract_methodology,
best_payer_rate,
best_hospital_rate,
best_payer_method_params,
best_hospital_method_params,
best_payer_rate_type,
best_hospital_rate_type
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE best_payer_method_params IS NOT NULL
AND best_hospital_method_params IS NOT NULL
LIMIT 10
""", con=trino_conn)
df

# %%
# [CLD-v2.3.2] Use payer_hospital for validated rates
df = pd.read_sql(f"""
SELECT
canonical_rate_source,
canonical_rate_score,
count(*) as n
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
GROUP BY 1,2
""", con=trino_conn)
df

df = pd.read_sql(f"""
SELECT
count(*) as n
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE canonical_rate_score = 5
AND canonical_rate_source IS NULL
""", con=trino_conn)
df


# %%
# [CLD-v2.3.2] Include all labs in core rates
df = pd.read_sql(f"""
SELECT COUNT(DISTINCT provider_id)
FROM tq_dev.internal_dev_csong_cld_v2_3_2.tmp_ref_provider_spine_2025_11
WHERE provider_type = 'Laboratory'
""", con=trino_conn)
print(df)

df = pd.read_sql(f"""
SELECT COUNT(DISTINCT provider_id)
FROM tq_dev.internal_dev_csong_cld_v2_3_2.tmp_ref_provider_spine_2025_08
WHERE provider_type = 'Laboratory'
""", con=trino_conn)
print(df)

df = pd.read_sql(f"""
SELECT COUNT(DISTINCT provider_id)
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE provider_type = 'Laboratory'
""", con=trino_conn)
print(df)

df = pd.read_sql(f"""
SELECT COUNT(DISTINCT provider_id)
FROM tq_dev.internal_dev_csong_cld_v2_3_1.tmp_int_combined_2025_10
WHERE provider_type = 'Laboratory'
""", con=trino_conn)
print(df)


# %%
# [CLD-v2.3.2] Add new ASC codes
df = pd.read_sql(f"""
SELECT billing_code, COUNT(distinct provider_id) as n_providers
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE provider_type = 'ASC'
AND billing_code IN ('93655','93656','93657')
GROUP BY 1
""", con=trino_conn)
print(df)

# %%
# [CLD-v2.3.2] update OPPS codeset
df = pd.read_sql(f"""
SELECT COUNT(DISTINCT billing_code)
FROM tq_dev.internal_dev_csong_cld_v2_3_2.prod_combined_abridged
WHERE bill_type = 'Outpatient'
AND provider_type = 'Hospital'
AND canonical_rate_score > 1
""", con=trino_conn)
print(df)

df = pd.read_sql(f"""
SELECT COUNT(DISTINCT billing_code)
FROM tq_dev.internal_dev_csong_cld_v2_3_1.tmp_int_combined_2025_10
WHERE bill_type = 'Outpatient'
AND provider_type = 'Hospital'
AND canonical_rate_score > 1
""", con=trino_conn)
print(df)

# %%
# [CLD-v2.3.2] filter EXCHANGE in hospital plan bridge
df = pd.read_sql(f"""
WITH
sample AS (
SELECT hospital_rates_id
FROM tq_dev.internal_dev_csong_cld_v2_3_2.tmp_raw_mrf_hospital_rates_2025_11
WHERE network_id IN (
SELECT network_id
FROM tq_dev.internal_dev_csong_cld_v2_3_2.tmp_ref_network_spine_2025_11
WHERE network_type = 'EXCHANGE'
)
AND provider_id IN (
SELECT provider_id
FROM tq_dev.internal_dev_csong_cld_v2_3_2.tmp_ref_provider_spine_2025_11
WHERE provider_type = 'Hospital'
)
ORDER BY RANDOM()
LIMIT 100000
)
SELECT payer_class_name, count(*) as n
FROM tq_production.hospital_data.hospital_rates hr
WHERE hr.id IN (SELECT hospital_rates_id FROM sample)
GROUP BY 1
""", con=trino_conn)
df


# %%