[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-aws-labs-quality-measures":3,"mdc--vishba-key":50,"related-repo-aws-labs-quality-measures":3321,"related-org-aws-labs-quality-measures":3418},{"slug":4,"name":4,"fn":5,"description":6,"org":7,"tags":12,"stars":26,"repoUrl":27,"updatedAt":28,"license":29,"forks":30,"topics":31,"repo":45,"sourceUrl":48,"mdContent":49},"quality-measures","compute HEDIS quality measures","Pipeline skill for computing HEDIS quality measures from claims and clinical data. Use when the user asks to calculate HEDIS measure rates, check continuous enrollment, build denominator\u002Fnumerator logic, detect care gaps, compute utilization rates, identify high-cost claimants, or score risk stratification indices. Triggers include \"calculate HEDIS\", \"measure rate\", \"continuous enrollment check\", \"care gap detection\", \"denominator query\", \"numerator logic\", \"utilization rate\", \"high-cost claimant\", \"Charlson score\", \"LACE score\", \"claims analysis\", \"quality measure SQL\".\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},"aws-labs","AWS Labs","https:\u002F\u002Fpexgzepcugksgbtrxkhf.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Forg-logos\u002Faws-labs.png","awslabs",[13,17,20,23],{"name":14,"slug":15,"type":16},"Reporting","reporting","tag",{"name":18,"slug":19,"type":16},"Healthcare","healthcare",{"name":21,"slug":22,"type":16},"Data Analysis","data-analysis",{"name":24,"slug":25,"type":16},"AWS","aws",4,"https:\u002F\u002Fgithub.com\u002Fawslabs\u002Fhcls-agent-skills","2026-07-12T08:38:33.541265",null,0,[32,33,34,35,36,37,38,39,40,41,42,43,44],"agent-skills","agentcore","ai-agents","amazon-quick-desktop","claims-processing","drug-discovery","genomics","healthcare-ai","kiro","life-sciences","medical-imaging","risk-adjustment","strands-agents",{"repoUrl":27,"stars":26,"forks":30,"topics":46,"description":47},[32,33,34,35,36,37,38,39,40,41,42,43,44],"Agent skills for healthcare and life sciences: genomics, imaging, claims, drug discovery, and more. Works with Amazon Quick, Kiro, Amazon AgentCore, AWS Strands SDK, Claude Code, Codex, and any Agent Skills-compatible platform.","https:\u002F\u002Fgithub.com\u002Fawslabs\u002Fhcls-agent-skills\u002Ftree\u002FHEAD\u002Fskills\u002Fquality-measures","---\nname: quality-measures\ndescription: >\n  Pipeline skill for computing HEDIS quality measures from claims and clinical data. Use when the\n  user asks to calculate HEDIS measure rates, check continuous enrollment, build denominator\u002Fnumerator\n  logic, detect care gaps, compute utilization rates, identify high-cost claimants, or score risk\n  stratification indices. Triggers include \"calculate HEDIS\", \"measure rate\", \"continuous enrollment\n  check\", \"care gap detection\", \"denominator query\", \"numerator logic\", \"utilization rate\",\n  \"high-cost claimant\", \"Charlson score\", \"LACE score\", \"claims analysis\", \"quality measure SQL\".\nusage: Use when building or running quality measure calculation pipelines including enrollment checks, measure rates, and care gap detection.\nversion: 1.0.0\nvalidated_against:\n  date: 2025-01-15\n  packages: {pandas: \"2.2\", sqlalchemy: \"2.0\"}\ntags: [skill, category:pipeline, quality-measures, hedis, hcls]\n---\n\n# Quality Measures Calculation Pipeline\n\n## Overview\n\nProvide deterministic Python and SQL code snippets for calculating HEDIS quality measures,\ndetecting care gaps, computing utilization rates, identifying high-cost claimants, and\nscoring risk stratification indices from claims and clinical data.\n\n## Usage\n\n- Calculate HEDIS measure rates, check continuous enrollment, detect care gaps, and score risk indices\n\n## Core Concepts\n\n## Response Format\n\n- Lead with the command or code the user needs — explain after\n- Structure as: confirm inputs → working code → key parameters explained → gotchas\n- One complete working example per task; do not show every alternative\n- Keep code comments minimal and functional (what, not why-it-exists)\n- Target: 50-100 lines of code with brief surrounding explanation\n\n## Approach Selection\n\n| Scenario | Approach | Key consideration |\n|----------|----------|-------------------|\n| Single measure, ad-hoc | Python `calculate_measure()` | Fast iteration, easy debugging |\n| Enterprise batch (all measures) | SQL CTEs per measure | Scales to millions of members |\n| Data source: claims only | Use procedure\u002Frevenue codes for numerator | No clinical data available |\n| Data source: claims + EHR | Supplement with lab values, vitals | Higher capture rate |\n| Enrollment check: single payer | `max_gap_days=45` (HEDIS default) | One enrollment table |\n| Enrollment check: multi-payer | Merge enrollment spans first, then check | Avoid double-counting gaps |\n\n## 1. Continuous Enrollment Check\n\n### 1.1 Python Implementation\n\n```python\n\"\"\"Check continuous enrollment with allowable gap.\"\"\"\nimport pandas as pd\n\n\ndef check_continuous_enrollment(\n    enrollment: pd.DataFrame, member_id: str,\n    start_date: str, end_date: str, max_gap_days: int = 45,\n) -> dict:\n    \"\"\"Check if a member is continuously enrolled with allowable gap.\n\n    Args:\n        enrollment: DataFrame [member_id, enroll_start, enroll_end].\n        member_id: Member to check.\n        start_date: Measurement period start (e.g., '2025-01-01').\n        end_date: Measurement period end \u002F anchor date (e.g., '2025-12-31').\n        max_gap_days: Maximum allowable gap in days (HEDIS default: 45).\n\n    Returns:\n        Dict with is_enrolled (bool), total_gap_days (int), gap_periods (list).\n    \"\"\"\n    start, end = pd.Timestamp(start_date), pd.Timestamp(end_date)\n    me = enrollment[enrollment[\"member_id\"] == member_id].copy()\n    me[\"enroll_start\"] = pd.to_datetime(me[\"enroll_start\"]).clip(lower=start)\n    me[\"enroll_end\"] = pd.to_datetime(me[\"enroll_end\"]).clip(upper=end)\n    me = me[me[\"enroll_start\"] \u003C= me[\"enroll_end\"]].sort_values(\"enroll_start\").reset_index(drop=True)\n    if me.empty:\n        return {\"is_enrolled\": False, \"total_gap_days\": (end - start).days, \"gap_periods\": []}\n    if not (me[\"enroll_end\"] >= end).any():\n        return {\"is_enrolled\": False, \"total_gap_days\": -1, \"gap_periods\": []}\n    gap_periods, total_gap = [], 0\n    if me.iloc[0][\"enroll_start\"] > start:\n        g = (me.iloc[0][\"enroll_start\"] - start).days\n        total_gap += g\n        gap_periods.append({\"from\": str(start.date()), \"to\": str(me.iloc[0][\"enroll_start\"].date()), \"days\": g})\n    for i in range(1, len(me)):\n        if me.iloc[i][\"enroll_start\"] > me.iloc[i-1][\"enroll_end\"] + pd.Timedelta(days=1):\n            g = (me.iloc[i][\"enroll_start\"] - me.iloc[i-1][\"enroll_end\"]).days - 1\n            total_gap += g\n            gap_periods.append({\"from\": str(me.iloc[i-1][\"enroll_end\"].date()), \"to\": str(me.iloc[i][\"enroll_start\"].date()), \"days\": g})\n    return {\"is_enrolled\": total_gap \u003C= max_gap_days, \"total_gap_days\": total_gap, \"gap_periods\": gap_periods}\n```\n\n### 1.2 SQL Implementation\n\n```sql\n-- Continuous enrollment check with allowable gap (≤45 days)\nWITH enrollment_segments AS (\n    SELECT member_id, enroll_start, enroll_end,\n           LEAD(enroll_start) OVER (PARTITION BY member_id ORDER BY enroll_start) AS next_start\n    FROM enrollment\n    WHERE enroll_end >= '2025-01-01' AND enroll_start \u003C= '2025-12-31'\n),\ngaps AS (\n    SELECT member_id,\n           DATEDIFF(day, enroll_end, next_start) - 1 AS gap_days\n    FROM enrollment_segments\n    WHERE next_start IS NOT NULL\n      AND DATEDIFF(day, enroll_end, next_start) > 1\n),\ntotal_gaps AS (\n    SELECT member_id, SUM(gap_days) AS total_gap_days\n    FROM gaps\n    GROUP BY member_id\n),\nanchor_check AS (\n    SELECT DISTINCT member_id\n    FROM enrollment\n    WHERE enroll_end >= '2025-12-31'\n)\nSELECT a.member_id,\n       COALESCE(g.total_gap_days, 0) AS total_gap_days,\n       CASE WHEN COALESCE(g.total_gap_days, 0) \u003C= 45 THEN 1 ELSE 0 END AS is_continuously_enrolled\nFROM anchor_check a\nLEFT JOIN total_gaps g ON a.member_id = g.member_id;\n```\n\n## 2. HEDIS Measure Calculation\n\n### 2.1 Generic Measure Calculator (Python)\n\n```python\n\"\"\"Generic HEDIS measure rate calculator.\"\"\"\nimport pandas as pd\nfrom dataclasses import dataclass\n\n\n@dataclass\nclass MeasureResult:\n    measure_id: str\n    denominator_count: int\n    exclusion_count: int\n    numerator_count: int\n    rate: float\n    gap_members: list[str]\n\n\ndef calculate_measure(\n    eligible: pd.DataFrame,\n    exclusions: pd.DataFrame,\n    numerator_events: pd.DataFrame,\n    measure_id: str,\n) -> MeasureResult:\n    \"\"\"Calculate a HEDIS measure rate.\n\n    Args:\n        eligible: Denominator members. Columns: [member_id].\n        exclusions: Excluded members. Columns: [member_id, exclusion_reason].\n        numerator_events: Members meeting numerator. Columns: [member_id, event_date].\n        measure_id: Measure identifier (e.g., 'CDC-HbA1c-Testing').\n\n    Returns:\n        MeasureResult with rate and gap member list.\n    \"\"\"\n    denom_ids = set(eligible[\"member_id\"])\n    excl_ids = set(exclusions[\"member_id\"])\n    eligible_denom = denom_ids - excl_ids\n    numer_ids = set(numerator_events[\"member_id\"]) & eligible_denom\n    gap_ids = eligible_denom - numer_ids\n    denom_count = len(eligible_denom)\n    rate = len(numer_ids) \u002F denom_count if denom_count > 0 else 0.0\n    return MeasureResult(\n        measure_id=measure_id,\n        denominator_count=denom_count,\n        exclusion_count=len(excl_ids & denom_ids),\n        numerator_count=len(numer_ids),\n        rate=round(rate, 4),\n        gap_members=sorted(gap_ids),\n    )\n```\n\n### 2.2 Full Measure Calculation (SQL — CDC HbA1c Testing Example)\n\n```sql\n-- CDC: Comprehensive Diabetes Care — HbA1c Testing\nWITH denominator AS (\n    SELECT DISTINCT m.member_id\n    FROM members m\n    JOIN claims c ON m.member_id = c.member_id\n    JOIN continuously_enrolled ce ON m.member_id = ce.member_id\n    WHERE DATEDIFF(year, m.date_of_birth, '2025-12-31') BETWEEN 18 AND 75\n      AND c.diagnosis_code LIKE 'E11%'\n      AND c.service_date BETWEEN '2024-01-01' AND '2025-12-31'\n      AND ce.is_continuously_enrolled = 1\n),\nexclusions AS (\n    SELECT DISTINCT member_id FROM claims\n    WHERE diagnosis_code IN ('Z51.5', 'N18.6')\n       OR revenue_code IN ('0115','0125','0135','0145','0155','0235')\n),\nnumerator AS (\n    SELECT DISTINCT member_id FROM claims\n    WHERE procedure_code IN ('83036','83037')\n      AND service_date BETWEEN '2025-01-01' AND '2025-12-31'\n)\nSELECT COUNT(*) AS denom,\n       SUM(CASE WHEN e.member_id IS NOT NULL THEN 1 ELSE 0 END) AS excluded,\n       SUM(CASE WHEN e.member_id IS NULL AND n.member_id IS NOT NULL THEN 1 ELSE 0 END) AS numer,\n       ROUND(SUM(CASE WHEN e.member_id IS NULL AND n.member_id IS NOT NULL THEN 1 ELSE 0 END)*1.0\n             \u002F NULLIF(COUNT(*) - SUM(CASE WHEN e.member_id IS NOT NULL THEN 1 ELSE 0 END), 0), 4) AS rate\nFROM denominator d\nLEFT JOIN exclusions e ON d.member_id = e.member_id\nLEFT JOIN numerator n ON d.member_id = n.member_id;\n```\n\n## 3. Care Gap Detection\n\n```python\n\"\"\"Detect and prioritize open care gaps across members.\"\"\"\nimport pandas as pd\nfrom datetime import date\n\n\ndef detect_care_gaps(\n    members: pd.DataFrame,\n    measures: list[dict],\n    claims: pd.DataFrame,\n    measurement_year: int = 2025,\n) -> pd.DataFrame:\n    \"\"\"Detect open care gaps for a population.\n\n    Args:\n        members: DataFrame [member_id, date_of_birth, gender, risk_score].\n        measures: List of dicts with keys: measure_id, age_min, age_max,\n            gender (str|None), diagnosis_codes (list), numerator_codes (list),\n            star_weight (1 or 3).\n        claims: DataFrame [member_id, service_date, diagnosis_code, procedure_code].\n        measurement_year: Calendar year for measurement.\n\n    Returns:\n        DataFrame: [member_id, measure_id, star_weight, risk_score, priority_score].\n    \"\"\"\n    anchor = date(measurement_year, 12, 31)\n    year_start = date(measurement_year, 1, 1)\n    gaps = []\n    for measure in measures:\n        eligible = members.copy()\n        eligible[\"age\"] = eligible[\"date_of_birth\"].apply(lambda d: (anchor - d).days \u002F\u002F 365)\n        eligible = eligible[eligible[\"age\"].between(measure[\"age_min\"], measure[\"age_max\"])]\n        if measure.get(\"gender\"):\n            eligible = eligible[eligible[\"gender\"] == measure[\"gender\"]]\n        if measure.get(\"diagnosis_codes\"):\n            dx_members = claims[\n                claims[\"diagnosis_code\"].str.startswith(tuple(measure[\"diagnosis_codes\"]))\n            ][\"member_id\"].unique()\n            eligible = eligible[eligible[\"member_id\"].isin(dx_members)]\n        year_claims = claims[claims[\"service_date\"].between(str(year_start), str(anchor))]\n        closed = year_claims[\n            year_claims[\"procedure_code\"].isin(measure[\"numerator_codes\"])\n        ][\"member_id\"].unique()\n        for _, row in eligible[~eligible[\"member_id\"].isin(closed)].iterrows():\n            sw = measure.get(\"star_weight\", 1)\n            gaps.append({\n                \"member_id\": row[\"member_id\"], \"measure_id\": measure[\"measure_id\"],\n                \"star_weight\": sw, \"risk_score\": row.get(\"risk_score\", 0),\n                \"priority_score\": round(sw * 30 + min(row.get(\"risk_score\", 0) * 25, 25) + 20, 1),\n            })\n    return pd.DataFrame(gaps).sort_values(\"priority_score\", ascending=False).reset_index(drop=True)\n```\n\n## 4. Utilization Rate Computation\n\n```sql\n-- Utilization rates per 1000 members: ED, inpatient, 30-day readmissions\nWITH members AS (\n    SELECT COUNT(DISTINCT member_id) AS member_count FROM continuously_enrolled WHERE is_continuously_enrolled = 1\n),\ned AS (\n    SELECT COUNT(*) AS cnt FROM claims WHERE revenue_code IN ('0450','0451','0452','0456','0459') AND service_date BETWEEN '2025-01-01' AND '2025-12-31'\n),\nip AS (\n    SELECT COUNT(DISTINCT claim_id) AS cnt FROM claims WHERE claim_type = 'inpatient' AND admit_date BETWEEN '2025-01-01' AND '2025-12-31'\n),\nreadmit AS (\n    SELECT COUNT(*) AS cnt FROM (\n        SELECT member_id, admit_date, LAG(discharge_date) OVER (PARTITION BY member_id ORDER BY admit_date) AS prev_dc\n        FROM claims WHERE claim_type = 'inpatient' AND admit_date BETWEEN '2025-01-01' AND '2025-12-31'\n    ) s WHERE DATEDIFF(day, prev_dc, admit_date) \u003C= 30 AND prev_dc IS NOT NULL\n)\nSELECT ROUND(ed.cnt*1000.0\u002Fm.member_count,1) AS ed_per_1000,\n       ROUND(ip.cnt*1000.0\u002Fm.member_count,1) AS ip_per_1000,\n       ROUND(readmit.cnt*1000.0\u002Fm.member_count,1) AS readmit_per_1000\nFROM members m, ed, ip, readmit;\n```\n\n## 5. High-Cost Claimant Identification\n\n```python\n\"\"\"Identify high-cost claimants and analyze cost drivers.\"\"\"\nimport pandas as pd\nimport numpy as np\n\n\ndef identify_high_cost_claimants(\n    claims: pd.DataFrame,\n    threshold_percentile: float = 95,\n    measurement_year: int = 2025,\n) -> dict:\n    \"\"\"Identify high-cost claimants above a percentile threshold.\n\n    Args:\n        claims: DataFrame [member_id, service_date, paid_amount, claim_type, diagnosis_code].\n        threshold_percentile: Percentile cutoff (default 95th).\n        measurement_year: Calendar year to analyze.\n\n    Returns:\n        Dict with threshold, count, pct of total spend, and member DataFrame.\n    \"\"\"\n    year_claims = claims[\n        pd.to_datetime(claims[\"service_date\"]).dt.year == measurement_year\n    ]\n    member_costs = (\n        year_claims.groupby(\"member_id\")\n        .agg(total_paid=(\"paid_amount\", \"sum\"), claim_count=(\"paid_amount\", \"count\"))\n        .reset_index()\n    )\n    threshold = np.percentile(member_costs[\"total_paid\"], threshold_percentile)\n    high_cost = member_costs[member_costs[\"total_paid\"] >= threshold].sort_values(\n        \"total_paid\", ascending=False\n    )\n    return {\n        \"threshold_amount\": round(threshold, 2),\n        \"high_cost_count\": len(high_cost),\n        \"high_cost_pct_of_total\": round(\n            high_cost[\"total_paid\"].sum() \u002F member_costs[\"total_paid\"].sum() * 100, 1\n        ),\n        \"high_cost_members\": high_cost,\n    }\n```\n\n## 6. Risk Stratification Scoring\n\n### 6.1 Charlson Comorbidity Index (Python)\n\n```python\n\"\"\"Calculate Charlson Comorbidity Index from diagnosis codes.\"\"\"\n\n# ICD-10 prefix → (condition, weight). Subset of key mappings.\nCHARLSON_MAP = {\n    \"I21\": (\"mi\", 1), \"I22\": (\"mi\", 1), \"I50\": (\"chf\", 1),\n    \"I70\": (\"pvd\", 1), \"I71\": (\"pvd\", 1), \"I6\": (\"cvd\", 1),\n    \"F01\": (\"dementia\", 1), \"F03\": (\"dementia\", 1), \"G30\": (\"dementia\", 1),\n    \"J4\": (\"copd\", 1), \"M05\": (\"ctd\", 1), \"M06\": (\"ctd\", 1),\n    \"K25\": (\"pud\", 1), \"K26\": (\"pud\", 1),\n    \"K70\": (\"mild_liver\", 1), \"K73\": (\"mild_liver\", 1), \"K74\": (\"mild_liver\", 1),\n    \"E109\": (\"dm_uncomp\", 1), \"E119\": (\"dm_uncomp\", 1),\n    \"E102\": (\"dm_comp\", 2), \"E112\": (\"dm_comp\", 2),\n    \"G81\": (\"hemiplegia\", 2), \"N18\": (\"renal\", 2),\n    \"C\": (\"cancer\", 2),\n    \"C77\": (\"metastatic\", 6), \"C78\": (\"metastatic\", 6), \"C79\": (\"metastatic\", 6),\n    \"B20\": (\"hiv\", 6),\n}\n\n\ndef charlson_score(diagnosis_codes: list[str]) -> dict:\n    \"\"\"Calculate Charlson Comorbidity Index. Returns {score, conditions}.\"\"\"\n    matched: dict[str, int] = {}\n    for code in [c.replace(\".\", \"\") for c in diagnosis_codes]:\n        for prefix, (cond, wt) in CHARLSON_MAP.items():\n            if code.startswith(prefix):\n                if cond == \"cancer\" and \"metastatic\" in matched:\n                    continue\n                if cond == \"metastatic\":\n                    matched.pop(\"cancer\", None)\n                if cond == \"dm_uncomp\" and \"dm_comp\" in matched:\n                    continue\n                if cond == \"dm_comp\":\n                    matched.pop(\"dm_uncomp\", None)\n                if cond not in matched or wt > matched[cond]:\n                    matched[cond] = wt\n                break\n    return {\"score\": sum(matched.values()), \"conditions\": matched}\n```\n\n### 6.2 LACE Readmission Risk Score\n\n```python\n\"\"\"Calculate LACE readmission risk score.\"\"\"\n\n\ndef lace_score(length_of_stay: int, acuity: str, charlson: int, ed_visits_6mo: int) -> dict:\n    \"\"\"Calculate LACE index for 30-day readmission risk.\n\n    Returns dict with total score, component scores, and risk tier.\n    \"\"\"\n    l = 7 if length_of_stay >= 14 else (5 if length_of_stay >= 7 else (4 if length_of_stay >= 4 else min(length_of_stay, 3)))\n    a = {\"emergent\": 3, \"urgent\": 2, \"elective\": 0}.get(acuity.lower(), 0)\n    c = 5 if charlson >= 4 else min(charlson, 3)\n    e = min(ed_visits_6mo, 4)\n    total = l + a + c + e\n    tier = \"high\" if total >= 10 else (\"moderate\" if total >= 5 else \"low\")\n    return {\"total\": total, \"components\": {\"L\": l, \"A\": a, \"C\": c, \"E\": e}, \"risk_tier\": tier}\n```\n\n## 7. Measure Stratification by Plan\u002FProvider\n\n```sql\n-- Measure rate stratified by health plan and provider\nSELECT health_plan, assigned_pcp_npi,\n       COUNT(*) - SUM(CASE WHEN e.member_id IS NOT NULL THEN 1 ELSE 0 END) AS eligible_denom,\n       SUM(CASE WHEN e.member_id IS NULL AND n.member_id IS NOT NULL THEN 1 ELSE 0 END) AS numerator,\n       ROUND(SUM(CASE WHEN e.member_id IS NULL AND n.member_id IS NOT NULL THEN 1 ELSE 0 END) * 100.0\n             \u002F NULLIF(COUNT(*) - SUM(CASE WHEN e.member_id IS NOT NULL THEN 1 ELSE 0 END), 0), 1) AS rate_pct\nFROM denominator_members m\nLEFT JOIN exclusion_members e ON m.member_id = e.member_id\nLEFT JOIN numerator_members n ON m.member_id = n.member_id\nGROUP BY health_plan, assigned_pcp_npi\nORDER BY rate_pct ASC;\n```\n\n## 8. Parameter Reference\n\n| Parameter | Default | Description |\n|-----------|---------|-------------|\n| `measurement_year` | Current calendar year | HEDIS reporting year |\n| `max_gap_days` | 45 | Maximum allowable enrollment gap |\n| `anchor_date` | Dec 31 of measurement year | Date member must be enrolled through |\n| `dx_lookback_years` | 2 | Years to look back for qualifying diagnoses |\n| `threshold_percentile` | 95 | Percentile cutoff for high-cost identification |\n| `readmission_window` | 30 | Days after discharge for readmission flag |\n\n## 9. Common Mistakes\n\n- **Wrong:** Including segment end dates when calculating enrollment gap days\n  **Right:** Calculate gaps as the calendar days *between* segments (day after end of segment A to day before start of segment B)\n  **Why:** Off-by-one errors in gap calculation incorrectly exclude continuously enrolled members or include ineligible ones\n\n- **Wrong:** Using enrollment segments as-is without clipping to the measurement year boundaries\n  **Right:** Clip all enrollment segments to the measurement year start and end dates before calculating gaps\n  **Why:** Segments extending beyond the year inflate coverage calculations and produce incorrect enrollment determinations\n\n- **Wrong:** Using service date for inpatient utilization metrics\n  **Right:** Use admit date and discharge date for inpatient claims — service date is for professional\u002Foutpatient claims\n  **Why:** Inpatient utilization (admissions, readmissions, length of stay) is defined by admission events, not individual service lines\n\n- **Wrong:** Counting a member multiple times in the numerator when they have multiple qualifying events\n  **Right:** Deduplicate numerator events by member ID — each member counts once regardless of how many tests or services they received\n  **Why:** Multiple events for the same member inflate the numerator and produce artificially high measure rates\n\n- **Wrong:** Calculating member age as of the run date or an arbitrary date\n  **Right:** Calculate age as of the measure-specific anchor date (typically December 31 of the measurement year)\n  **Why:** Using the wrong anchor date shifts age-based eligibility and includes or excludes members incorrectly\n\n- **Wrong:** Only looking at the measurement year for qualifying diagnoses\n  **Right:** Apply the measure-specified lookback period (typically 2 years) for identifying members with qualifying conditions\n  **Why:** Many HEDIS measures require a diagnosis in the measurement year OR the year prior; using only one year misses eligible members\n",{"data":51,"body":64},{"name":4,"description":6,"usage":52,"version":53,"validated_against":54,"tags":59},"Use when building or running quality measure calculation pipelines including enrollment checks, measure rates, and care gap detection.","1.0.0",{"date":55,"packages":56},"2025-01-15",{"pandas":57,"sqlalchemy":58},"2.2","2.0",[60,61,4,62,63],"skill","category:pipeline","hedis","hcls",{"type":65,"children":66},"root",[67,76,83,89,95,105,111,117,145,151,305,311,318,688,694,932,938,944,1324,1330,1565,1571,1973,1979,2142,2148,2462,2468,2474,2773,2779,2902,2908,3003,3009,3168,3174,3315],{"type":68,"tag":69,"props":70,"children":72},"element","h1",{"id":71},"quality-measures-calculation-pipeline",[73],{"type":74,"value":75},"text","Quality Measures Calculation Pipeline",{"type":68,"tag":77,"props":78,"children":80},"h2",{"id":79},"overview",[81],{"type":74,"value":82},"Overview",{"type":68,"tag":84,"props":85,"children":86},"p",{},[87],{"type":74,"value":88},"Provide deterministic Python and SQL code snippets for calculating HEDIS quality measures,\ndetecting care gaps, computing utilization rates, identifying high-cost claimants, and\nscoring risk stratification indices from claims and clinical data.",{"type":68,"tag":77,"props":90,"children":92},{"id":91},"usage",[93],{"type":74,"value":94},"Usage",{"type":68,"tag":96,"props":97,"children":98},"ul",{},[99],{"type":68,"tag":100,"props":101,"children":102},"li",{},[103],{"type":74,"value":104},"Calculate HEDIS measure rates, check continuous enrollment, detect care gaps, and score risk indices",{"type":68,"tag":77,"props":106,"children":108},{"id":107},"core-concepts",[109],{"type":74,"value":110},"Core Concepts",{"type":68,"tag":77,"props":112,"children":114},{"id":113},"response-format",[115],{"type":74,"value":116},"Response Format",{"type":68,"tag":96,"props":118,"children":119},{},[120,125,130,135,140],{"type":68,"tag":100,"props":121,"children":122},{},[123],{"type":74,"value":124},"Lead with the command or code the user needs — explain after",{"type":68,"tag":100,"props":126,"children":127},{},[128],{"type":74,"value":129},"Structure as: confirm inputs → working code → key parameters explained → gotchas",{"type":68,"tag":100,"props":131,"children":132},{},[133],{"type":74,"value":134},"One complete working example per task; do not show every alternative",{"type":68,"tag":100,"props":136,"children":137},{},[138],{"type":74,"value":139},"Keep code comments minimal and functional (what, not why-it-exists)",{"type":68,"tag":100,"props":141,"children":142},{},[143],{"type":74,"value":144},"Target: 50-100 lines of code with brief surrounding explanation",{"type":68,"tag":77,"props":146,"children":148},{"id":147},"approach-selection",[149],{"type":74,"value":150},"Approach Selection",{"type":68,"tag":152,"props":153,"children":154},"table",{},[155,179],{"type":68,"tag":156,"props":157,"children":158},"thead",{},[159],{"type":68,"tag":160,"props":161,"children":162},"tr",{},[163,169,174],{"type":68,"tag":164,"props":165,"children":166},"th",{},[167],{"type":74,"value":168},"Scenario",{"type":68,"tag":164,"props":170,"children":171},{},[172],{"type":74,"value":173},"Approach",{"type":68,"tag":164,"props":175,"children":176},{},[177],{"type":74,"value":178},"Key consideration",{"type":68,"tag":180,"props":181,"children":182},"tbody",{},[183,209,227,245,263,287],{"type":68,"tag":160,"props":184,"children":185},{},[186,192,204],{"type":68,"tag":187,"props":188,"children":189},"td",{},[190],{"type":74,"value":191},"Single measure, ad-hoc",{"type":68,"tag":187,"props":193,"children":194},{},[195,197],{"type":74,"value":196},"Python ",{"type":68,"tag":198,"props":199,"children":201},"code",{"className":200},[],[202],{"type":74,"value":203},"calculate_measure()",{"type":68,"tag":187,"props":205,"children":206},{},[207],{"type":74,"value":208},"Fast iteration, easy debugging",{"type":68,"tag":160,"props":210,"children":211},{},[212,217,222],{"type":68,"tag":187,"props":213,"children":214},{},[215],{"type":74,"value":216},"Enterprise batch (all measures)",{"type":68,"tag":187,"props":218,"children":219},{},[220],{"type":74,"value":221},"SQL CTEs per measure",{"type":68,"tag":187,"props":223,"children":224},{},[225],{"type":74,"value":226},"Scales to millions of members",{"type":68,"tag":160,"props":228,"children":229},{},[230,235,240],{"type":68,"tag":187,"props":231,"children":232},{},[233],{"type":74,"value":234},"Data source: claims only",{"type":68,"tag":187,"props":236,"children":237},{},[238],{"type":74,"value":239},"Use procedure\u002Frevenue codes for numerator",{"type":68,"tag":187,"props":241,"children":242},{},[243],{"type":74,"value":244},"No clinical data available",{"type":68,"tag":160,"props":246,"children":247},{},[248,253,258],{"type":68,"tag":187,"props":249,"children":250},{},[251],{"type":74,"value":252},"Data source: claims + EHR",{"type":68,"tag":187,"props":254,"children":255},{},[256],{"type":74,"value":257},"Supplement with lab values, vitals",{"type":68,"tag":187,"props":259,"children":260},{},[261],{"type":74,"value":262},"Higher capture rate",{"type":68,"tag":160,"props":264,"children":265},{},[266,271,282],{"type":68,"tag":187,"props":267,"children":268},{},[269],{"type":74,"value":270},"Enrollment check: single payer",{"type":68,"tag":187,"props":272,"children":273},{},[274,280],{"type":68,"tag":198,"props":275,"children":277},{"className":276},[],[278],{"type":74,"value":279},"max_gap_days=45",{"type":74,"value":281}," (HEDIS default)",{"type":68,"tag":187,"props":283,"children":284},{},[285],{"type":74,"value":286},"One enrollment table",{"type":68,"tag":160,"props":288,"children":289},{},[290,295,300],{"type":68,"tag":187,"props":291,"children":292},{},[293],{"type":74,"value":294},"Enrollment check: multi-payer",{"type":68,"tag":187,"props":296,"children":297},{},[298],{"type":74,"value":299},"Merge enrollment spans first, then check",{"type":68,"tag":187,"props":301,"children":302},{},[303],{"type":74,"value":304},"Avoid double-counting gaps",{"type":68,"tag":77,"props":306,"children":308},{"id":307},"_1-continuous-enrollment-check",[309],{"type":74,"value":310},"1. Continuous Enrollment Check",{"type":68,"tag":312,"props":313,"children":315},"h3",{"id":314},"_11-python-implementation",[316],{"type":74,"value":317},"1.1 Python Implementation",{"type":68,"tag":319,"props":320,"children":325},"pre",{"className":321,"code":322,"language":323,"meta":324,"style":324},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\"\"\"Check continuous enrollment with allowable gap.\"\"\"\nimport pandas as pd\n\n\ndef check_continuous_enrollment(\n    enrollment: pd.DataFrame, member_id: str,\n    start_date: str, end_date: str, max_gap_days: int = 45,\n) -> dict:\n    \"\"\"Check if a member is continuously enrolled with allowable gap.\n\n    Args:\n        enrollment: DataFrame [member_id, enroll_start, enroll_end].\n        member_id: Member to check.\n        start_date: Measurement period start (e.g., '2025-01-01').\n        end_date: Measurement period end \u002F anchor date (e.g., '2025-12-31').\n        max_gap_days: Maximum allowable gap in days (HEDIS default: 45).\n\n    Returns:\n        Dict with is_enrolled (bool), total_gap_days (int), gap_periods (list).\n    \"\"\"\n    start, end = pd.Timestamp(start_date), pd.Timestamp(end_date)\n    me = enrollment[enrollment[\"member_id\"] == member_id].copy()\n    me[\"enroll_start\"] = pd.to_datetime(me[\"enroll_start\"]).clip(lower=start)\n    me[\"enroll_end\"] = pd.to_datetime(me[\"enroll_end\"]).clip(upper=end)\n    me = me[me[\"enroll_start\"] \u003C= me[\"enroll_end\"]].sort_values(\"enroll_start\").reset_index(drop=True)\n    if me.empty:\n        return {\"is_enrolled\": False, \"total_gap_days\": (end - start).days, \"gap_periods\": []}\n    if not (me[\"enroll_end\"] >= end).any():\n        return {\"is_enrolled\": False, \"total_gap_days\": -1, \"gap_periods\": []}\n    gap_periods, total_gap = [], 0\n    if me.iloc[0][\"enroll_start\"] > start:\n        g = (me.iloc[0][\"enroll_start\"] - start).days\n        total_gap += g\n        gap_periods.append({\"from\": str(start.date()), \"to\": str(me.iloc[0][\"enroll_start\"].date()), \"days\": g})\n    for i in range(1, len(me)):\n        if me.iloc[i][\"enroll_start\"] > me.iloc[i-1][\"enroll_end\"] + pd.Timedelta(days=1):\n            g = (me.iloc[i][\"enroll_start\"] - me.iloc[i-1][\"enroll_end\"]).days - 1\n            total_gap += g\n            gap_periods.append({\"from\": str(me.iloc[i-1][\"enroll_end\"].date()), \"to\": str(me.iloc[i][\"enroll_start\"].date()), \"days\": g})\n    return {\"is_enrolled\": total_gap \u003C= max_gap_days, \"total_gap_days\": total_gap, \"gap_periods\": gap_periods}\n","python","",[326],{"type":68,"tag":198,"props":327,"children":328},{"__ignoreMap":324},[329,340,349,359,366,375,384,393,402,411,419,428,437,446,455,464,473,481,490,499,508,517,526,535,544,553,562,571,580,589,598,607,616,625,634,643,652,661,670,679],{"type":68,"tag":330,"props":331,"children":334},"span",{"class":332,"line":333},"line",1,[335],{"type":68,"tag":330,"props":336,"children":337},{},[338],{"type":74,"value":339},"\"\"\"Check continuous enrollment with allowable gap.\"\"\"\n",{"type":68,"tag":330,"props":341,"children":343},{"class":332,"line":342},2,[344],{"type":68,"tag":330,"props":345,"children":346},{},[347],{"type":74,"value":348},"import pandas as pd\n",{"type":68,"tag":330,"props":350,"children":352},{"class":332,"line":351},3,[353],{"type":68,"tag":330,"props":354,"children":356},{"emptyLinePlaceholder":355},true,[357],{"type":74,"value":358},"\n",{"type":68,"tag":330,"props":360,"children":361},{"class":332,"line":26},[362],{"type":68,"tag":330,"props":363,"children":364},{"emptyLinePlaceholder":355},[365],{"type":74,"value":358},{"type":68,"tag":330,"props":367,"children":369},{"class":332,"line":368},5,[370],{"type":68,"tag":330,"props":371,"children":372},{},[373],{"type":74,"value":374},"def check_continuous_enrollment(\n",{"type":68,"tag":330,"props":376,"children":378},{"class":332,"line":377},6,[379],{"type":68,"tag":330,"props":380,"children":381},{},[382],{"type":74,"value":383},"    enrollment: pd.DataFrame, member_id: str,\n",{"type":68,"tag":330,"props":385,"children":387},{"class":332,"line":386},7,[388],{"type":68,"tag":330,"props":389,"children":390},{},[391],{"type":74,"value":392},"    start_date: str, end_date: str, max_gap_days: int = 45,\n",{"type":68,"tag":330,"props":394,"children":396},{"class":332,"line":395},8,[397],{"type":68,"tag":330,"props":398,"children":399},{},[400],{"type":74,"value":401},") -> dict:\n",{"type":68,"tag":330,"props":403,"children":405},{"class":332,"line":404},9,[406],{"type":68,"tag":330,"props":407,"children":408},{},[409],{"type":74,"value":410},"    \"\"\"Check if a member is continuously enrolled with allowable gap.\n",{"type":68,"tag":330,"props":412,"children":414},{"class":332,"line":413},10,[415],{"type":68,"tag":330,"props":416,"children":417},{"emptyLinePlaceholder":355},[418],{"type":74,"value":358},{"type":68,"tag":330,"props":420,"children":422},{"class":332,"line":421},11,[423],{"type":68,"tag":330,"props":424,"children":425},{},[426],{"type":74,"value":427},"    Args:\n",{"type":68,"tag":330,"props":429,"children":431},{"class":332,"line":430},12,[432],{"type":68,"tag":330,"props":433,"children":434},{},[435],{"type":74,"value":436},"        enrollment: DataFrame [member_id, enroll_start, enroll_end].\n",{"type":68,"tag":330,"props":438,"children":440},{"class":332,"line":439},13,[441],{"type":68,"tag":330,"props":442,"children":443},{},[444],{"type":74,"value":445},"        member_id: Member to check.\n",{"type":68,"tag":330,"props":447,"children":449},{"class":332,"line":448},14,[450],{"type":68,"tag":330,"props":451,"children":452},{},[453],{"type":74,"value":454},"        start_date: Measurement period start (e.g., '2025-01-01').\n",{"type":68,"tag":330,"props":456,"children":458},{"class":332,"line":457},15,[459],{"type":68,"tag":330,"props":460,"children":461},{},[462],{"type":74,"value":463},"        end_date: Measurement period end \u002F anchor date (e.g., '2025-12-31').\n",{"type":68,"tag":330,"props":465,"children":467},{"class":332,"line":466},16,[468],{"type":68,"tag":330,"props":469,"children":470},{},[471],{"type":74,"value":472},"        max_gap_days: Maximum allowable gap in days (HEDIS default: 45).\n",{"type":68,"tag":330,"props":474,"children":476},{"class":332,"line":475},17,[477],{"type":68,"tag":330,"props":478,"children":479},{"emptyLinePlaceholder":355},[480],{"type":74,"value":358},{"type":68,"tag":330,"props":482,"children":484},{"class":332,"line":483},18,[485],{"type":68,"tag":330,"props":486,"children":487},{},[488],{"type":74,"value":489},"    Returns:\n",{"type":68,"tag":330,"props":491,"children":493},{"class":332,"line":492},19,[494],{"type":68,"tag":330,"props":495,"children":496},{},[497],{"type":74,"value":498},"        Dict with is_enrolled (bool), total_gap_days (int), gap_periods (list).\n",{"type":68,"tag":330,"props":500,"children":502},{"class":332,"line":501},20,[503],{"type":68,"tag":330,"props":504,"children":505},{},[506],{"type":74,"value":507},"    \"\"\"\n",{"type":68,"tag":330,"props":509,"children":511},{"class":332,"line":510},21,[512],{"type":68,"tag":330,"props":513,"children":514},{},[515],{"type":74,"value":516},"    start, end = pd.Timestamp(start_date), pd.Timestamp(end_date)\n",{"type":68,"tag":330,"props":518,"children":520},{"class":332,"line":519},22,[521],{"type":68,"tag":330,"props":522,"children":523},{},[524],{"type":74,"value":525},"    me = enrollment[enrollment[\"member_id\"] == member_id].copy()\n",{"type":68,"tag":330,"props":527,"children":529},{"class":332,"line":528},23,[530],{"type":68,"tag":330,"props":531,"children":532},{},[533],{"type":74,"value":534},"    me[\"enroll_start\"] = pd.to_datetime(me[\"enroll_start\"]).clip(lower=start)\n",{"type":68,"tag":330,"props":536,"children":538},{"class":332,"line":537},24,[539],{"type":68,"tag":330,"props":540,"children":541},{},[542],{"type":74,"value":543},"    me[\"enroll_end\"] = pd.to_datetime(me[\"enroll_end\"]).clip(upper=end)\n",{"type":68,"tag":330,"props":545,"children":547},{"class":332,"line":546},25,[548],{"type":68,"tag":330,"props":549,"children":550},{},[551],{"type":74,"value":552},"    me = me[me[\"enroll_start\"] \u003C= me[\"enroll_end\"]].sort_values(\"enroll_start\").reset_index(drop=True)\n",{"type":68,"tag":330,"props":554,"children":556},{"class":332,"line":555},26,[557],{"type":68,"tag":330,"props":558,"children":559},{},[560],{"type":74,"value":561},"    if me.empty:\n",{"type":68,"tag":330,"props":563,"children":565},{"class":332,"line":564},27,[566],{"type":68,"tag":330,"props":567,"children":568},{},[569],{"type":74,"value":570},"        return {\"is_enrolled\": False, \"total_gap_days\": (end - start).days, \"gap_periods\": []}\n",{"type":68,"tag":330,"props":572,"children":574},{"class":332,"line":573},28,[575],{"type":68,"tag":330,"props":576,"children":577},{},[578],{"type":74,"value":579},"    if not (me[\"enroll_end\"] >= end).any():\n",{"type":68,"tag":330,"props":581,"children":583},{"class":332,"line":582},29,[584],{"type":68,"tag":330,"props":585,"children":586},{},[587],{"type":74,"value":588},"        return {\"is_enrolled\": False, \"total_gap_days\": -1, \"gap_periods\": []}\n",{"type":68,"tag":330,"props":590,"children":592},{"class":332,"line":591},30,[593],{"type":68,"tag":330,"props":594,"children":595},{},[596],{"type":74,"value":597},"    gap_periods, total_gap = [], 0\n",{"type":68,"tag":330,"props":599,"children":601},{"class":332,"line":600},31,[602],{"type":68,"tag":330,"props":603,"children":604},{},[605],{"type":74,"value":606},"    if me.iloc[0][\"enroll_start\"] > start:\n",{"type":68,"tag":330,"props":608,"children":610},{"class":332,"line":609},32,[611],{"type":68,"tag":330,"props":612,"children":613},{},[614],{"type":74,"value":615},"        g = (me.iloc[0][\"enroll_start\"] - start).days\n",{"type":68,"tag":330,"props":617,"children":619},{"class":332,"line":618},33,[620],{"type":68,"tag":330,"props":621,"children":622},{},[623],{"type":74,"value":624},"        total_gap += g\n",{"type":68,"tag":330,"props":626,"children":628},{"class":332,"line":627},34,[629],{"type":68,"tag":330,"props":630,"children":631},{},[632],{"type":74,"value":633},"        gap_periods.append({\"from\": str(start.date()), \"to\": str(me.iloc[0][\"enroll_start\"].date()), \"days\": g})\n",{"type":68,"tag":330,"props":635,"children":637},{"class":332,"line":636},35,[638],{"type":68,"tag":330,"props":639,"children":640},{},[641],{"type":74,"value":642},"    for i in range(1, len(me)):\n",{"type":68,"tag":330,"props":644,"children":646},{"class":332,"line":645},36,[647],{"type":68,"tag":330,"props":648,"children":649},{},[650],{"type":74,"value":651},"        if me.iloc[i][\"enroll_start\"] > me.iloc[i-1][\"enroll_end\"] + pd.Timedelta(days=1):\n",{"type":68,"tag":330,"props":653,"children":655},{"class":332,"line":654},37,[656],{"type":68,"tag":330,"props":657,"children":658},{},[659],{"type":74,"value":660},"            g = (me.iloc[i][\"enroll_start\"] - me.iloc[i-1][\"enroll_end\"]).days - 1\n",{"type":68,"tag":330,"props":662,"children":664},{"class":332,"line":663},38,[665],{"type":68,"tag":330,"props":666,"children":667},{},[668],{"type":74,"value":669},"            total_gap += g\n",{"type":68,"tag":330,"props":671,"children":673},{"class":332,"line":672},39,[674],{"type":68,"tag":330,"props":675,"children":676},{},[677],{"type":74,"value":678},"            gap_periods.append({\"from\": str(me.iloc[i-1][\"enroll_end\"].date()), \"to\": str(me.iloc[i][\"enroll_start\"].date()), \"days\": g})\n",{"type":68,"tag":330,"props":680,"children":682},{"class":332,"line":681},40,[683],{"type":68,"tag":330,"props":684,"children":685},{},[686],{"type":74,"value":687},"    return {\"is_enrolled\": total_gap \u003C= max_gap_days, \"total_gap_days\": total_gap, \"gap_periods\": gap_periods}\n",{"type":68,"tag":312,"props":689,"children":691},{"id":690},"_12-sql-implementation",[692],{"type":74,"value":693},"1.2 SQL Implementation",{"type":68,"tag":319,"props":695,"children":699},{"className":696,"code":697,"language":698,"meta":324,"style":324},"language-sql shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","-- Continuous enrollment check with allowable gap (≤45 days)\nWITH enrollment_segments AS (\n    SELECT member_id, enroll_start, enroll_end,\n           LEAD(enroll_start) OVER (PARTITION BY member_id ORDER BY enroll_start) AS next_start\n    FROM enrollment\n    WHERE enroll_end >= '2025-01-01' AND enroll_start \u003C= '2025-12-31'\n),\ngaps AS (\n    SELECT member_id,\n           DATEDIFF(day, enroll_end, next_start) - 1 AS gap_days\n    FROM enrollment_segments\n    WHERE next_start IS NOT NULL\n      AND DATEDIFF(day, enroll_end, next_start) > 1\n),\ntotal_gaps AS (\n    SELECT member_id, SUM(gap_days) AS total_gap_days\n    FROM gaps\n    GROUP BY member_id\n),\nanchor_check AS (\n    SELECT DISTINCT member_id\n    FROM enrollment\n    WHERE enroll_end >= '2025-12-31'\n)\nSELECT a.member_id,\n       COALESCE(g.total_gap_days, 0) AS total_gap_days,\n       CASE WHEN COALESCE(g.total_gap_days, 0) \u003C= 45 THEN 1 ELSE 0 END AS is_continuously_enrolled\nFROM anchor_check a\nLEFT JOIN total_gaps g ON a.member_id = g.member_id;\n","sql",[700],{"type":68,"tag":198,"props":701,"children":702},{"__ignoreMap":324},[703,711,719,727,735,743,751,759,767,775,783,791,799,807,814,822,830,838,846,853,861,869,876,884,892,900,908,916,924],{"type":68,"tag":330,"props":704,"children":705},{"class":332,"line":333},[706],{"type":68,"tag":330,"props":707,"children":708},{},[709],{"type":74,"value":710},"-- Continuous enrollment check with allowable gap (≤45 days)\n",{"type":68,"tag":330,"props":712,"children":713},{"class":332,"line":342},[714],{"type":68,"tag":330,"props":715,"children":716},{},[717],{"type":74,"value":718},"WITH enrollment_segments AS (\n",{"type":68,"tag":330,"props":720,"children":721},{"class":332,"line":351},[722],{"type":68,"tag":330,"props":723,"children":724},{},[725],{"type":74,"value":726},"    SELECT member_id, enroll_start, enroll_end,\n",{"type":68,"tag":330,"props":728,"children":729},{"class":332,"line":26},[730],{"type":68,"tag":330,"props":731,"children":732},{},[733],{"type":74,"value":734},"           LEAD(enroll_start) OVER (PARTITION BY member_id ORDER BY enroll_start) AS next_start\n",{"type":68,"tag":330,"props":736,"children":737},{"class":332,"line":368},[738],{"type":68,"tag":330,"props":739,"children":740},{},[741],{"type":74,"value":742},"    FROM enrollment\n",{"type":68,"tag":330,"props":744,"children":745},{"class":332,"line":377},[746],{"type":68,"tag":330,"props":747,"children":748},{},[749],{"type":74,"value":750},"    WHERE enroll_end >= '2025-01-01' AND enroll_start \u003C= '2025-12-31'\n",{"type":68,"tag":330,"props":752,"children":753},{"class":332,"line":386},[754],{"type":68,"tag":330,"props":755,"children":756},{},[757],{"type":74,"value":758},"),\n",{"type":68,"tag":330,"props":760,"children":761},{"class":332,"line":395},[762],{"type":68,"tag":330,"props":763,"children":764},{},[765],{"type":74,"value":766},"gaps AS (\n",{"type":68,"tag":330,"props":768,"children":769},{"class":332,"line":404},[770],{"type":68,"tag":330,"props":771,"children":772},{},[773],{"type":74,"value":774},"    SELECT member_id,\n",{"type":68,"tag":330,"props":776,"children":777},{"class":332,"line":413},[778],{"type":68,"tag":330,"props":779,"children":780},{},[781],{"type":74,"value":782},"           DATEDIFF(day, enroll_end, next_start) - 1 AS gap_days\n",{"type":68,"tag":330,"props":784,"children":785},{"class":332,"line":421},[786],{"type":68,"tag":330,"props":787,"children":788},{},[789],{"type":74,"value":790},"    FROM enrollment_segments\n",{"type":68,"tag":330,"props":792,"children":793},{"class":332,"line":430},[794],{"type":68,"tag":330,"props":795,"children":796},{},[797],{"type":74,"value":798},"    WHERE next_start IS NOT NULL\n",{"type":68,"tag":330,"props":800,"children":801},{"class":332,"line":439},[802],{"type":68,"tag":330,"props":803,"children":804},{},[805],{"type":74,"value":806},"      AND DATEDIFF(day, enroll_end, next_start) > 1\n",{"type":68,"tag":330,"props":808,"children":809},{"class":332,"line":448},[810],{"type":68,"tag":330,"props":811,"children":812},{},[813],{"type":74,"value":758},{"type":68,"tag":330,"props":815,"children":816},{"class":332,"line":457},[817],{"type":68,"tag":330,"props":818,"children":819},{},[820],{"type":74,"value":821},"total_gaps AS (\n",{"type":68,"tag":330,"props":823,"children":824},{"class":332,"line":466},[825],{"type":68,"tag":330,"props":826,"children":827},{},[828],{"type":74,"value":829},"    SELECT member_id, SUM(gap_days) AS total_gap_days\n",{"type":68,"tag":330,"props":831,"children":832},{"class":332,"line":475},[833],{"type":68,"tag":330,"props":834,"children":835},{},[836],{"type":74,"value":837},"    FROM gaps\n",{"type":68,"tag":330,"props":839,"children":840},{"class":332,"line":483},[841],{"type":68,"tag":330,"props":842,"children":843},{},[844],{"type":74,"value":845},"    GROUP BY member_id\n",{"type":68,"tag":330,"props":847,"children":848},{"class":332,"line":492},[849],{"type":68,"tag":330,"props":850,"children":851},{},[852],{"type":74,"value":758},{"type":68,"tag":330,"props":854,"children":855},{"class":332,"line":501},[856],{"type":68,"tag":330,"props":857,"children":858},{},[859],{"type":74,"value":860},"anchor_check AS (\n",{"type":68,"tag":330,"props":862,"children":863},{"class":332,"line":510},[864],{"type":68,"tag":330,"props":865,"children":866},{},[867],{"type":74,"value":868},"    SELECT DISTINCT member_id\n",{"type":68,"tag":330,"props":870,"children":871},{"class":332,"line":519},[872],{"type":68,"tag":330,"props":873,"children":874},{},[875],{"type":74,"value":742},{"type":68,"tag":330,"props":877,"children":878},{"class":332,"line":528},[879],{"type":68,"tag":330,"props":880,"children":881},{},[882],{"type":74,"value":883},"    WHERE enroll_end >= '2025-12-31'\n",{"type":68,"tag":330,"props":885,"children":886},{"class":332,"line":537},[887],{"type":68,"tag":330,"props":888,"children":889},{},[890],{"type":74,"value":891},")\n",{"type":68,"tag":330,"props":893,"children":894},{"class":332,"line":546},[895],{"type":68,"tag":330,"props":896,"children":897},{},[898],{"type":74,"value":899},"SELECT a.member_id,\n",{"type":68,"tag":330,"props":901,"children":902},{"class":332,"line":555},[903],{"type":68,"tag":330,"props":904,"children":905},{},[906],{"type":74,"value":907},"       COALESCE(g.total_gap_days, 0) AS total_gap_days,\n",{"type":68,"tag":330,"props":909,"children":910},{"class":332,"line":564},[911],{"type":68,"tag":330,"props":912,"children":913},{},[914],{"type":74,"value":915},"       CASE WHEN COALESCE(g.total_gap_days, 0) \u003C= 45 THEN 1 ELSE 0 END AS is_continuously_enrolled\n",{"type":68,"tag":330,"props":917,"children":918},{"class":332,"line":573},[919],{"type":68,"tag":330,"props":920,"children":921},{},[922],{"type":74,"value":923},"FROM anchor_check a\n",{"type":68,"tag":330,"props":925,"children":926},{"class":332,"line":582},[927],{"type":68,"tag":330,"props":928,"children":929},{},[930],{"type":74,"value":931},"LEFT JOIN total_gaps g ON a.member_id = g.member_id;\n",{"type":68,"tag":77,"props":933,"children":935},{"id":934},"_2-hedis-measure-calculation",[936],{"type":74,"value":937},"2. HEDIS Measure Calculation",{"type":68,"tag":312,"props":939,"children":941},{"id":940},"_21-generic-measure-calculator-python",[942],{"type":74,"value":943},"2.1 Generic Measure Calculator (Python)",{"type":68,"tag":319,"props":945,"children":947},{"className":321,"code":946,"language":323,"meta":324,"style":324},"\"\"\"Generic HEDIS measure rate calculator.\"\"\"\nimport pandas as pd\nfrom dataclasses import dataclass\n\n\n@dataclass\nclass MeasureResult:\n    measure_id: str\n    denominator_count: int\n    exclusion_count: int\n    numerator_count: int\n    rate: float\n    gap_members: list[str]\n\n\ndef calculate_measure(\n    eligible: pd.DataFrame,\n    exclusions: pd.DataFrame,\n    numerator_events: pd.DataFrame,\n    measure_id: str,\n) -> MeasureResult:\n    \"\"\"Calculate a HEDIS measure rate.\n\n    Args:\n        eligible: Denominator members. Columns: [member_id].\n        exclusions: Excluded members. Columns: [member_id, exclusion_reason].\n        numerator_events: Members meeting numerator. Columns: [member_id, event_date].\n        measure_id: Measure identifier (e.g., 'CDC-HbA1c-Testing').\n\n    Returns:\n        MeasureResult with rate and gap member list.\n    \"\"\"\n    denom_ids = set(eligible[\"member_id\"])\n    excl_ids = set(exclusions[\"member_id\"])\n    eligible_denom = denom_ids - excl_ids\n    numer_ids = set(numerator_events[\"member_id\"]) & eligible_denom\n    gap_ids = eligible_denom - numer_ids\n    denom_count = len(eligible_denom)\n    rate = len(numer_ids) \u002F denom_count if denom_count > 0 else 0.0\n    return MeasureResult(\n        measure_id=measure_id,\n        denominator_count=denom_count,\n        exclusion_count=len(excl_ids & denom_ids),\n        numerator_count=len(numer_ids),\n        rate=round(rate, 4),\n        gap_members=sorted(gap_ids),\n    )\n",[948],{"type":68,"tag":198,"props":949,"children":950},{"__ignoreMap":324},[951,959,966,974,981,988,996,1004,1012,1020,1028,1036,1044,1052,1059,1066,1074,1082,1090,1098,1106,1114,1122,1129,1136,1144,1152,1160,1168,1175,1182,1190,1197,1205,1213,1221,1229,1237,1245,1253,1261,1270,1279,1288,1297,1306,1315],{"type":68,"tag":330,"props":952,"children":953},{"class":332,"line":333},[954],{"type":68,"tag":330,"props":955,"children":956},{},[957],{"type":74,"value":958},"\"\"\"Generic HEDIS measure rate calculator.\"\"\"\n",{"type":68,"tag":330,"props":960,"children":961},{"class":332,"line":342},[962],{"type":68,"tag":330,"props":963,"children":964},{},[965],{"type":74,"value":348},{"type":68,"tag":330,"props":967,"children":968},{"class":332,"line":351},[969],{"type":68,"tag":330,"props":970,"children":971},{},[972],{"type":74,"value":973},"from dataclasses import dataclass\n",{"type":68,"tag":330,"props":975,"children":976},{"class":332,"line":26},[977],{"type":68,"tag":330,"props":978,"children":979},{"emptyLinePlaceholder":355},[980],{"type":74,"value":358},{"type":68,"tag":330,"props":982,"children":983},{"class":332,"line":368},[984],{"type":68,"tag":330,"props":985,"children":986},{"emptyLinePlaceholder":355},[987],{"type":74,"value":358},{"type":68,"tag":330,"props":989,"children":990},{"class":332,"line":377},[991],{"type":68,"tag":330,"props":992,"children":993},{},[994],{"type":74,"value":995},"@dataclass\n",{"type":68,"tag":330,"props":997,"children":998},{"class":332,"line":386},[999],{"type":68,"tag":330,"props":1000,"children":1001},{},[1002],{"type":74,"value":1003},"class MeasureResult:\n",{"type":68,"tag":330,"props":1005,"children":1006},{"class":332,"line":395},[1007],{"type":68,"tag":330,"props":1008,"children":1009},{},[1010],{"type":74,"value":1011},"    measure_id: str\n",{"type":68,"tag":330,"props":1013,"children":1014},{"class":332,"line":404},[1015],{"type":68,"tag":330,"props":1016,"children":1017},{},[1018],{"type":74,"value":1019},"    denominator_count: int\n",{"type":68,"tag":330,"props":1021,"children":1022},{"class":332,"line":413},[1023],{"type":68,"tag":330,"props":1024,"children":1025},{},[1026],{"type":74,"value":1027},"    exclusion_count: int\n",{"type":68,"tag":330,"props":1029,"children":1030},{"class":332,"line":421},[1031],{"type":68,"tag":330,"props":1032,"children":1033},{},[1034],{"type":74,"value":1035},"    numerator_count: int\n",{"type":68,"tag":330,"props":1037,"children":1038},{"class":332,"line":430},[1039],{"type":68,"tag":330,"props":1040,"children":1041},{},[1042],{"type":74,"value":1043},"    rate: float\n",{"type":68,"tag":330,"props":1045,"children":1046},{"class":332,"line":439},[1047],{"type":68,"tag":330,"props":1048,"children":1049},{},[1050],{"type":74,"value":1051},"    gap_members: list[str]\n",{"type":68,"tag":330,"props":1053,"children":1054},{"class":332,"line":448},[1055],{"type":68,"tag":330,"props":1056,"children":1057},{"emptyLinePlaceholder":355},[1058],{"type":74,"value":358},{"type":68,"tag":330,"props":1060,"children":1061},{"class":332,"line":457},[1062],{"type":68,"tag":330,"props":1063,"children":1064},{"emptyLinePlaceholder":355},[1065],{"type":74,"value":358},{"type":68,"tag":330,"props":1067,"children":1068},{"class":332,"line":466},[1069],{"type":68,"tag":330,"props":1070,"children":1071},{},[1072],{"type":74,"value":1073},"def calculate_measure(\n",{"type":68,"tag":330,"props":1075,"children":1076},{"class":332,"line":475},[1077],{"type":68,"tag":330,"props":1078,"children":1079},{},[1080],{"type":74,"value":1081},"    eligible: pd.DataFrame,\n",{"type":68,"tag":330,"props":1083,"children":1084},{"class":332,"line":483},[1085],{"type":68,"tag":330,"props":1086,"children":1087},{},[1088],{"type":74,"value":1089},"    exclusions: pd.DataFrame,\n",{"type":68,"tag":330,"props":1091,"children":1092},{"class":332,"line":492},[1093],{"type":68,"tag":330,"props":1094,"children":1095},{},[1096],{"type":74,"value":1097},"    numerator_events: pd.DataFrame,\n",{"type":68,"tag":330,"props":1099,"children":1100},{"class":332,"line":501},[1101],{"type":68,"tag":330,"props":1102,"children":1103},{},[1104],{"type":74,"value":1105},"    measure_id: str,\n",{"type":68,"tag":330,"props":1107,"children":1108},{"class":332,"line":510},[1109],{"type":68,"tag":330,"props":1110,"children":1111},{},[1112],{"type":74,"value":1113},") -> MeasureResult:\n",{"type":68,"tag":330,"props":1115,"children":1116},{"class":332,"line":519},[1117],{"type":68,"tag":330,"props":1118,"children":1119},{},[1120],{"type":74,"value":1121},"    \"\"\"Calculate a HEDIS measure rate.\n",{"type":68,"tag":330,"props":1123,"children":1124},{"class":332,"line":528},[1125],{"type":68,"tag":330,"props":1126,"children":1127},{"emptyLinePlaceholder":355},[1128],{"type":74,"value":358},{"type":68,"tag":330,"props":1130,"children":1131},{"class":332,"line":537},[1132],{"type":68,"tag":330,"props":1133,"children":1134},{},[1135],{"type":74,"value":427},{"type":68,"tag":330,"props":1137,"children":1138},{"class":332,"line":546},[1139],{"type":68,"tag":330,"props":1140,"children":1141},{},[1142],{"type":74,"value":1143},"        eligible: Denominator members. Columns: [member_id].\n",{"type":68,"tag":330,"props":1145,"children":1146},{"class":332,"line":555},[1147],{"type":68,"tag":330,"props":1148,"children":1149},{},[1150],{"type":74,"value":1151},"        exclusions: Excluded members. Columns: [member_id, exclusion_reason].\n",{"type":68,"tag":330,"props":1153,"children":1154},{"class":332,"line":564},[1155],{"type":68,"tag":330,"props":1156,"children":1157},{},[1158],{"type":74,"value":1159},"        numerator_events: Members meeting numerator. Columns: [member_id, event_date].\n",{"type":68,"tag":330,"props":1161,"children":1162},{"class":332,"line":573},[1163],{"type":68,"tag":330,"props":1164,"children":1165},{},[1166],{"type":74,"value":1167},"        measure_id: Measure identifier (e.g., 'CDC-HbA1c-Testing').\n",{"type":68,"tag":330,"props":1169,"children":1170},{"class":332,"line":582},[1171],{"type":68,"tag":330,"props":1172,"children":1173},{"emptyLinePlaceholder":355},[1174],{"type":74,"value":358},{"type":68,"tag":330,"props":1176,"children":1177},{"class":332,"line":591},[1178],{"type":68,"tag":330,"props":1179,"children":1180},{},[1181],{"type":74,"value":489},{"type":68,"tag":330,"props":1183,"children":1184},{"class":332,"line":600},[1185],{"type":68,"tag":330,"props":1186,"children":1187},{},[1188],{"type":74,"value":1189},"        MeasureResult with rate and gap member list.\n",{"type":68,"tag":330,"props":1191,"children":1192},{"class":332,"line":609},[1193],{"type":68,"tag":330,"props":1194,"children":1195},{},[1196],{"type":74,"value":507},{"type":68,"tag":330,"props":1198,"children":1199},{"class":332,"line":618},[1200],{"type":68,"tag":330,"props":1201,"children":1202},{},[1203],{"type":74,"value":1204},"    denom_ids = set(eligible[\"member_id\"])\n",{"type":68,"tag":330,"props":1206,"children":1207},{"class":332,"line":627},[1208],{"type":68,"tag":330,"props":1209,"children":1210},{},[1211],{"type":74,"value":1212},"    excl_ids = set(exclusions[\"member_id\"])\n",{"type":68,"tag":330,"props":1214,"children":1215},{"class":332,"line":636},[1216],{"type":68,"tag":330,"props":1217,"children":1218},{},[1219],{"type":74,"value":1220},"    eligible_denom = denom_ids - excl_ids\n",{"type":68,"tag":330,"props":1222,"children":1223},{"class":332,"line":645},[1224],{"type":68,"tag":330,"props":1225,"children":1226},{},[1227],{"type":74,"value":1228},"    numer_ids = set(numerator_events[\"member_id\"]) & eligible_denom\n",{"type":68,"tag":330,"props":1230,"children":1231},{"class":332,"line":654},[1232],{"type":68,"tag":330,"props":1233,"children":1234},{},[1235],{"type":74,"value":1236},"    gap_ids = eligible_denom - numer_ids\n",{"type":68,"tag":330,"props":1238,"children":1239},{"class":332,"line":663},[1240],{"type":68,"tag":330,"props":1241,"children":1242},{},[1243],{"type":74,"value":1244},"    denom_count = len(eligible_denom)\n",{"type":68,"tag":330,"props":1246,"children":1247},{"class":332,"line":672},[1248],{"type":68,"tag":330,"props":1249,"children":1250},{},[1251],{"type":74,"value":1252},"    rate = len(numer_ids) \u002F denom_count if denom_count > 0 else 0.0\n",{"type":68,"tag":330,"props":1254,"children":1255},{"class":332,"line":681},[1256],{"type":68,"tag":330,"props":1257,"children":1258},{},[1259],{"type":74,"value":1260},"    return MeasureResult(\n",{"type":68,"tag":330,"props":1262,"children":1264},{"class":332,"line":1263},41,[1265],{"type":68,"tag":330,"props":1266,"children":1267},{},[1268],{"type":74,"value":1269},"        measure_id=measure_id,\n",{"type":68,"tag":330,"props":1271,"children":1273},{"class":332,"line":1272},42,[1274],{"type":68,"tag":330,"props":1275,"children":1276},{},[1277],{"type":74,"value":1278},"        denominator_count=denom_count,\n",{"type":68,"tag":330,"props":1280,"children":1282},{"class":332,"line":1281},43,[1283],{"type":68,"tag":330,"props":1284,"children":1285},{},[1286],{"type":74,"value":1287},"        exclusion_count=len(excl_ids & denom_ids),\n",{"type":68,"tag":330,"props":1289,"children":1291},{"class":332,"line":1290},44,[1292],{"type":68,"tag":330,"props":1293,"children":1294},{},[1295],{"type":74,"value":1296},"        numerator_count=len(numer_ids),\n",{"type":68,"tag":330,"props":1298,"children":1300},{"class":332,"line":1299},45,[1301],{"type":68,"tag":330,"props":1302,"children":1303},{},[1304],{"type":74,"value":1305},"        rate=round(rate, 4),\n",{"type":68,"tag":330,"props":1307,"children":1309},{"class":332,"line":1308},46,[1310],{"type":68,"tag":330,"props":1311,"children":1312},{},[1313],{"type":74,"value":1314},"        gap_members=sorted(gap_ids),\n",{"type":68,"tag":330,"props":1316,"children":1318},{"class":332,"line":1317},47,[1319],{"type":68,"tag":330,"props":1320,"children":1321},{},[1322],{"type":74,"value":1323},"    )\n",{"type":68,"tag":312,"props":1325,"children":1327},{"id":1326},"_22-full-measure-calculation-sql-cdc-hba1c-testing-example",[1328],{"type":74,"value":1329},"2.2 Full Measure Calculation (SQL — CDC HbA1c Testing Example)",{"type":68,"tag":319,"props":1331,"children":1333},{"className":696,"code":1332,"language":698,"meta":324,"style":324},"-- CDC: Comprehensive Diabetes Care — HbA1c Testing\nWITH denominator AS (\n    SELECT DISTINCT m.member_id\n    FROM members m\n    JOIN claims c ON m.member_id = c.member_id\n    JOIN continuously_enrolled ce ON m.member_id = ce.member_id\n    WHERE DATEDIFF(year, m.date_of_birth, '2025-12-31') BETWEEN 18 AND 75\n      AND c.diagnosis_code LIKE 'E11%'\n      AND c.service_date BETWEEN '2024-01-01' AND '2025-12-31'\n      AND ce.is_continuously_enrolled = 1\n),\nexclusions AS (\n    SELECT DISTINCT member_id FROM claims\n    WHERE diagnosis_code IN ('Z51.5', 'N18.6')\n       OR revenue_code IN ('0115','0125','0135','0145','0155','0235')\n),\nnumerator AS (\n    SELECT DISTINCT member_id FROM claims\n    WHERE procedure_code IN ('83036','83037')\n      AND service_date BETWEEN '2025-01-01' AND '2025-12-31'\n)\nSELECT COUNT(*) AS denom,\n       SUM(CASE WHEN e.member_id IS NOT NULL THEN 1 ELSE 0 END) AS excluded,\n       SUM(CASE WHEN e.member_id IS NULL AND n.member_id IS NOT NULL THEN 1 ELSE 0 END) AS numer,\n       ROUND(SUM(CASE WHEN e.member_id IS NULL AND n.member_id IS NOT NULL THEN 1 ELSE 0 END)*1.0\n             \u002F NULLIF(COUNT(*) - SUM(CASE WHEN e.member_id IS NOT NULL THEN 1 ELSE 0 END), 0), 4) AS rate\nFROM denominator d\nLEFT JOIN exclusions e ON d.member_id = e.member_id\nLEFT JOIN numerator n ON d.member_id = n.member_id;\n",[1334],{"type":68,"tag":198,"props":1335,"children":1336},{"__ignoreMap":324},[1337,1345,1353,1361,1369,1377,1385,1393,1401,1409,1417,1424,1432,1440,1448,1456,1463,1471,1478,1486,1494,1501,1509,1517,1525,1533,1541,1549,1557],{"type":68,"tag":330,"props":1338,"children":1339},{"class":332,"line":333},[1340],{"type":68,"tag":330,"props":1341,"children":1342},{},[1343],{"type":74,"value":1344},"-- CDC: Comprehensive Diabetes Care — HbA1c Testing\n",{"type":68,"tag":330,"props":1346,"children":1347},{"class":332,"line":342},[1348],{"type":68,"tag":330,"props":1349,"children":1350},{},[1351],{"type":74,"value":1352},"WITH denominator AS (\n",{"type":68,"tag":330,"props":1354,"children":1355},{"class":332,"line":351},[1356],{"type":68,"tag":330,"props":1357,"children":1358},{},[1359],{"type":74,"value":1360},"    SELECT DISTINCT m.member_id\n",{"type":68,"tag":330,"props":1362,"children":1363},{"class":332,"line":26},[1364],{"type":68,"tag":330,"props":1365,"children":1366},{},[1367],{"type":74,"value":1368},"    FROM members m\n",{"type":68,"tag":330,"props":1370,"children":1371},{"class":332,"line":368},[1372],{"type":68,"tag":330,"props":1373,"children":1374},{},[1375],{"type":74,"value":1376},"    JOIN claims c ON m.member_id = c.member_id\n",{"type":68,"tag":330,"props":1378,"children":1379},{"class":332,"line":377},[1380],{"type":68,"tag":330,"props":1381,"children":1382},{},[1383],{"type":74,"value":1384},"    JOIN continuously_enrolled ce ON m.member_id = ce.member_id\n",{"type":68,"tag":330,"props":1386,"children":1387},{"class":332,"line":386},[1388],{"type":68,"tag":330,"props":1389,"children":1390},{},[1391],{"type":74,"value":1392},"    WHERE DATEDIFF(year, m.date_of_birth, '2025-12-31') BETWEEN 18 AND 75\n",{"type":68,"tag":330,"props":1394,"children":1395},{"class":332,"line":395},[1396],{"type":68,"tag":330,"props":1397,"children":1398},{},[1399],{"type":74,"value":1400},"      AND c.diagnosis_code LIKE 'E11%'\n",{"type":68,"tag":330,"props":1402,"children":1403},{"class":332,"line":404},[1404],{"type":68,"tag":330,"props":1405,"children":1406},{},[1407],{"type":74,"value":1408},"      AND c.service_date BETWEEN '2024-01-01' AND '2025-12-31'\n",{"type":68,"tag":330,"props":1410,"children":1411},{"class":332,"line":413},[1412],{"type":68,"tag":330,"props":1413,"children":1414},{},[1415],{"type":74,"value":1416},"      AND ce.is_continuously_enrolled = 1\n",{"type":68,"tag":330,"props":1418,"children":1419},{"class":332,"line":421},[1420],{"type":68,"tag":330,"props":1421,"children":1422},{},[1423],{"type":74,"value":758},{"type":68,"tag":330,"props":1425,"children":1426},{"class":332,"line":430},[1427],{"type":68,"tag":330,"props":1428,"children":1429},{},[1430],{"type":74,"value":1431},"exclusions AS (\n",{"type":68,"tag":330,"props":1433,"children":1434},{"class":332,"line":439},[1435],{"type":68,"tag":330,"props":1436,"children":1437},{},[1438],{"type":74,"value":1439},"    SELECT DISTINCT member_id FROM claims\n",{"type":68,"tag":330,"props":1441,"children":1442},{"class":332,"line":448},[1443],{"type":68,"tag":330,"props":1444,"children":1445},{},[1446],{"type":74,"value":1447},"    WHERE diagnosis_code IN ('Z51.5', 'N18.6')\n",{"type":68,"tag":330,"props":1449,"children":1450},{"class":332,"line":457},[1451],{"type":68,"tag":330,"props":1452,"children":1453},{},[1454],{"type":74,"value":1455},"       OR revenue_code IN ('0115','0125','0135','0145','0155','0235')\n",{"type":68,"tag":330,"props":1457,"children":1458},{"class":332,"line":466},[1459],{"type":68,"tag":330,"props":1460,"children":1461},{},[1462],{"type":74,"value":758},{"type":68,"tag":330,"props":1464,"children":1465},{"class":332,"line":475},[1466],{"type":68,"tag":330,"props":1467,"children":1468},{},[1469],{"type":74,"value":1470},"numerator AS (\n",{"type":68,"tag":330,"props":1472,"children":1473},{"class":332,"line":483},[1474],{"type":68,"tag":330,"props":1475,"children":1476},{},[1477],{"type":74,"value":1439},{"type":68,"tag":330,"props":1479,"children":1480},{"class":332,"line":492},[1481],{"type":68,"tag":330,"props":1482,"children":1483},{},[1484],{"type":74,"value":1485},"    WHERE procedure_code IN ('83036','83037')\n",{"type":68,"tag":330,"props":1487,"children":1488},{"class":332,"line":501},[1489],{"type":68,"tag":330,"props":1490,"children":1491},{},[1492],{"type":74,"value":1493},"      AND service_date BETWEEN '2025-01-01' AND '2025-12-31'\n",{"type":68,"tag":330,"props":1495,"children":1496},{"class":332,"line":510},[1497],{"type":68,"tag":330,"props":1498,"children":1499},{},[1500],{"type":74,"value":891},{"type":68,"tag":330,"props":1502,"children":1503},{"class":332,"line":519},[1504],{"type":68,"tag":330,"props":1505,"children":1506},{},[1507],{"type":74,"value":1508},"SELECT COUNT(*) AS denom,\n",{"type":68,"tag":330,"props":1510,"children":1511},{"class":332,"line":528},[1512],{"type":68,"tag":330,"props":1513,"children":1514},{},[1515],{"type":74,"value":1516},"       SUM(CASE WHEN e.member_id IS NOT NULL THEN 1 ELSE 0 END) AS excluded,\n",{"type":68,"tag":330,"props":1518,"children":1519},{"class":332,"line":537},[1520],{"type":68,"tag":330,"props":1521,"children":1522},{},[1523],{"type":74,"value":1524},"       SUM(CASE WHEN e.member_id IS NULL AND n.member_id IS NOT NULL THEN 1 ELSE 0 END) AS numer,\n",{"type":68,"tag":330,"props":1526,"children":1527},{"class":332,"line":546},[1528],{"type":68,"tag":330,"props":1529,"children":1530},{},[1531],{"type":74,"value":1532},"       ROUND(SUM(CASE WHEN e.member_id IS NULL AND n.member_id IS NOT NULL THEN 1 ELSE 0 END)*1.0\n",{"type":68,"tag":330,"props":1534,"children":1535},{"class":332,"line":555},[1536],{"type":68,"tag":330,"props":1537,"children":1538},{},[1539],{"type":74,"value":1540},"             \u002F NULLIF(COUNT(*) - SUM(CASE WHEN e.member_id IS NOT NULL THEN 1 ELSE 0 END), 0), 4) AS rate\n",{"type":68,"tag":330,"props":1542,"children":1543},{"class":332,"line":564},[1544],{"type":68,"tag":330,"props":1545,"children":1546},{},[1547],{"type":74,"value":1548},"FROM denominator d\n",{"type":68,"tag":330,"props":1550,"children":1551},{"class":332,"line":573},[1552],{"type":68,"tag":330,"props":1553,"children":1554},{},[1555],{"type":74,"value":1556},"LEFT JOIN exclusions e ON d.member_id = e.member_id\n",{"type":68,"tag":330,"props":1558,"children":1559},{"class":332,"line":582},[1560],{"type":68,"tag":330,"props":1561,"children":1562},{},[1563],{"type":74,"value":1564},"LEFT JOIN numerator n ON d.member_id = n.member_id;\n",{"type":68,"tag":77,"props":1566,"children":1568},{"id":1567},"_3-care-gap-detection",[1569],{"type":74,"value":1570},"3. Care Gap Detection",{"type":68,"tag":319,"props":1572,"children":1574},{"className":321,"code":1573,"language":323,"meta":324,"style":324},"\"\"\"Detect and prioritize open care gaps across members.\"\"\"\nimport pandas as pd\nfrom datetime import date\n\n\ndef detect_care_gaps(\n    members: pd.DataFrame,\n    measures: list[dict],\n    claims: pd.DataFrame,\n    measurement_year: int = 2025,\n) -> pd.DataFrame:\n    \"\"\"Detect open care gaps for a population.\n\n    Args:\n        members: DataFrame [member_id, date_of_birth, gender, risk_score].\n        measures: List of dicts with keys: measure_id, age_min, age_max,\n            gender (str|None), diagnosis_codes (list), numerator_codes (list),\n            star_weight (1 or 3).\n        claims: DataFrame [member_id, service_date, diagnosis_code, procedure_code].\n        measurement_year: Calendar year for measurement.\n\n    Returns:\n        DataFrame: [member_id, measure_id, star_weight, risk_score, priority_score].\n    \"\"\"\n    anchor = date(measurement_year, 12, 31)\n    year_start = date(measurement_year, 1, 1)\n    gaps = []\n    for measure in measures:\n        eligible = members.copy()\n        eligible[\"age\"] = eligible[\"date_of_birth\"].apply(lambda d: (anchor - d).days \u002F\u002F 365)\n        eligible = eligible[eligible[\"age\"].between(measure[\"age_min\"], measure[\"age_max\"])]\n        if measure.get(\"gender\"):\n            eligible = eligible[eligible[\"gender\"] == measure[\"gender\"]]\n        if measure.get(\"diagnosis_codes\"):\n            dx_members = claims[\n                claims[\"diagnosis_code\"].str.startswith(tuple(measure[\"diagnosis_codes\"]))\n            ][\"member_id\"].unique()\n            eligible = eligible[eligible[\"member_id\"].isin(dx_members)]\n        year_claims = claims[claims[\"service_date\"].between(str(year_start), str(anchor))]\n        closed = year_claims[\n            year_claims[\"procedure_code\"].isin(measure[\"numerator_codes\"])\n        ][\"member_id\"].unique()\n        for _, row in eligible[~eligible[\"member_id\"].isin(closed)].iterrows():\n            sw = measure.get(\"star_weight\", 1)\n            gaps.append({\n                \"member_id\": row[\"member_id\"], \"measure_id\": measure[\"measure_id\"],\n                \"star_weight\": sw, \"risk_score\": row.get(\"risk_score\", 0),\n                \"priority_score\": round(sw * 30 + min(row.get(\"risk_score\", 0) * 25, 25) + 20, 1),\n            })\n    return pd.DataFrame(gaps).sort_values(\"priority_score\", ascending=False).reset_index(drop=True)\n",[1575],{"type":68,"tag":198,"props":1576,"children":1577},{"__ignoreMap":324},[1578,1586,1593,1601,1608,1615,1623,1631,1639,1647,1655,1663,1671,1678,1685,1693,1701,1709,1717,1725,1733,1740,1747,1755,1762,1770,1778,1786,1794,1802,1810,1818,1826,1834,1842,1850,1858,1866,1874,1882,1890,1898,1906,1914,1922,1930,1938,1946,1955,1964],{"type":68,"tag":330,"props":1579,"children":1580},{"class":332,"line":333},[1581],{"type":68,"tag":330,"props":1582,"children":1583},{},[1584],{"type":74,"value":1585},"\"\"\"Detect and prioritize open care gaps across members.\"\"\"\n",{"type":68,"tag":330,"props":1587,"children":1588},{"class":332,"line":342},[1589],{"type":68,"tag":330,"props":1590,"children":1591},{},[1592],{"type":74,"value":348},{"type":68,"tag":330,"props":1594,"children":1595},{"class":332,"line":351},[1596],{"type":68,"tag":330,"props":1597,"children":1598},{},[1599],{"type":74,"value":1600},"from datetime import date\n",{"type":68,"tag":330,"props":1602,"children":1603},{"class":332,"line":26},[1604],{"type":68,"tag":330,"props":1605,"children":1606},{"emptyLinePlaceholder":355},[1607],{"type":74,"value":358},{"type":68,"tag":330,"props":1609,"children":1610},{"class":332,"line":368},[1611],{"type":68,"tag":330,"props":1612,"children":1613},{"emptyLinePlaceholder":355},[1614],{"type":74,"value":358},{"type":68,"tag":330,"props":1616,"children":1617},{"class":332,"line":377},[1618],{"type":68,"tag":330,"props":1619,"children":1620},{},[1621],{"type":74,"value":1622},"def detect_care_gaps(\n",{"type":68,"tag":330,"props":1624,"children":1625},{"class":332,"line":386},[1626],{"type":68,"tag":330,"props":1627,"children":1628},{},[1629],{"type":74,"value":1630},"    members: pd.DataFrame,\n",{"type":68,"tag":330,"props":1632,"children":1633},{"class":332,"line":395},[1634],{"type":68,"tag":330,"props":1635,"children":1636},{},[1637],{"type":74,"value":1638},"    measures: list[dict],\n",{"type":68,"tag":330,"props":1640,"children":1641},{"class":332,"line":404},[1642],{"type":68,"tag":330,"props":1643,"children":1644},{},[1645],{"type":74,"value":1646},"    claims: pd.DataFrame,\n",{"type":68,"tag":330,"props":1648,"children":1649},{"class":332,"line":413},[1650],{"type":68,"tag":330,"props":1651,"children":1652},{},[1653],{"type":74,"value":1654},"    measurement_year: int = 2025,\n",{"type":68,"tag":330,"props":1656,"children":1657},{"class":332,"line":421},[1658],{"type":68,"tag":330,"props":1659,"children":1660},{},[1661],{"type":74,"value":1662},") -> pd.DataFrame:\n",{"type":68,"tag":330,"props":1664,"children":1665},{"class":332,"line":430},[1666],{"type":68,"tag":330,"props":1667,"children":1668},{},[1669],{"type":74,"value":1670},"    \"\"\"Detect open care gaps for a population.\n",{"type":68,"tag":330,"props":1672,"children":1673},{"class":332,"line":439},[1674],{"type":68,"tag":330,"props":1675,"children":1676},{"emptyLinePlaceholder":355},[1677],{"type":74,"value":358},{"type":68,"tag":330,"props":1679,"children":1680},{"class":332,"line":448},[1681],{"type":68,"tag":330,"props":1682,"children":1683},{},[1684],{"type":74,"value":427},{"type":68,"tag":330,"props":1686,"children":1687},{"class":332,"line":457},[1688],{"type":68,"tag":330,"props":1689,"children":1690},{},[1691],{"type":74,"value":1692},"        members: DataFrame [member_id, date_of_birth, gender, risk_score].\n",{"type":68,"tag":330,"props":1694,"children":1695},{"class":332,"line":466},[1696],{"type":68,"tag":330,"props":1697,"children":1698},{},[1699],{"type":74,"value":1700},"        measures: List of dicts with keys: measure_id, age_min, age_max,\n",{"type":68,"tag":330,"props":1702,"children":1703},{"class":332,"line":475},[1704],{"type":68,"tag":330,"props":1705,"children":1706},{},[1707],{"type":74,"value":1708},"            gender (str|None), diagnosis_codes (list), numerator_codes (list),\n",{"type":68,"tag":330,"props":1710,"children":1711},{"class":332,"line":483},[1712],{"type":68,"tag":330,"props":1713,"children":1714},{},[1715],{"type":74,"value":1716},"            star_weight (1 or 3).\n",{"type":68,"tag":330,"props":1718,"children":1719},{"class":332,"line":492},[1720],{"type":68,"tag":330,"props":1721,"children":1722},{},[1723],{"type":74,"value":1724},"        claims: DataFrame [member_id, service_date, diagnosis_code, procedure_code].\n",{"type":68,"tag":330,"props":1726,"children":1727},{"class":332,"line":501},[1728],{"type":68,"tag":330,"props":1729,"children":1730},{},[1731],{"type":74,"value":1732},"        measurement_year: Calendar year for measurement.\n",{"type":68,"tag":330,"props":1734,"children":1735},{"class":332,"line":510},[1736],{"type":68,"tag":330,"props":1737,"children":1738},{"emptyLinePlaceholder":355},[1739],{"type":74,"value":358},{"type":68,"tag":330,"props":1741,"children":1742},{"class":332,"line":519},[1743],{"type":68,"tag":330,"props":1744,"children":1745},{},[1746],{"type":74,"value":489},{"type":68,"tag":330,"props":1748,"children":1749},{"class":332,"line":528},[1750],{"type":68,"tag":330,"props":1751,"children":1752},{},[1753],{"type":74,"value":1754},"        DataFrame: [member_id, measure_id, star_weight, risk_score, priority_score].\n",{"type":68,"tag":330,"props":1756,"children":1757},{"class":332,"line":537},[1758],{"type":68,"tag":330,"props":1759,"children":1760},{},[1761],{"type":74,"value":507},{"type":68,"tag":330,"props":1763,"children":1764},{"class":332,"line":546},[1765],{"type":68,"tag":330,"props":1766,"children":1767},{},[1768],{"type":74,"value":1769},"    anchor = date(measurement_year, 12, 31)\n",{"type":68,"tag":330,"props":1771,"children":1772},{"class":332,"line":555},[1773],{"type":68,"tag":330,"props":1774,"children":1775},{},[1776],{"type":74,"value":1777},"    year_start = date(measurement_year, 1, 1)\n",{"type":68,"tag":330,"props":1779,"children":1780},{"class":332,"line":564},[1781],{"type":68,"tag":330,"props":1782,"children":1783},{},[1784],{"type":74,"value":1785},"    gaps = []\n",{"type":68,"tag":330,"props":1787,"children":1788},{"class":332,"line":573},[1789],{"type":68,"tag":330,"props":1790,"children":1791},{},[1792],{"type":74,"value":1793},"    for measure in measures:\n",{"type":68,"tag":330,"props":1795,"children":1796},{"class":332,"line":582},[1797],{"type":68,"tag":330,"props":1798,"children":1799},{},[1800],{"type":74,"value":1801},"        eligible = members.copy()\n",{"type":68,"tag":330,"props":1803,"children":1804},{"class":332,"line":591},[1805],{"type":68,"tag":330,"props":1806,"children":1807},{},[1808],{"type":74,"value":1809},"        eligible[\"age\"] = eligible[\"date_of_birth\"].apply(lambda d: (anchor - d).days \u002F\u002F 365)\n",{"type":68,"tag":330,"props":1811,"children":1812},{"class":332,"line":600},[1813],{"type":68,"tag":330,"props":1814,"children":1815},{},[1816],{"type":74,"value":1817},"        eligible = eligible[eligible[\"age\"].between(measure[\"age_min\"], measure[\"age_max\"])]\n",{"type":68,"tag":330,"props":1819,"children":1820},{"class":332,"line":609},[1821],{"type":68,"tag":330,"props":1822,"children":1823},{},[1824],{"type":74,"value":1825},"        if measure.get(\"gender\"):\n",{"type":68,"tag":330,"props":1827,"children":1828},{"class":332,"line":618},[1829],{"type":68,"tag":330,"props":1830,"children":1831},{},[1832],{"type":74,"value":1833},"            eligible = eligible[eligible[\"gender\"] == measure[\"gender\"]]\n",{"type":68,"tag":330,"props":1835,"children":1836},{"class":332,"line":627},[1837],{"type":68,"tag":330,"props":1838,"children":1839},{},[1840],{"type":74,"value":1841},"        if measure.get(\"diagnosis_codes\"):\n",{"type":68,"tag":330,"props":1843,"children":1844},{"class":332,"line":636},[1845],{"type":68,"tag":330,"props":1846,"children":1847},{},[1848],{"type":74,"value":1849},"            dx_members = claims[\n",{"type":68,"tag":330,"props":1851,"children":1852},{"class":332,"line":645},[1853],{"type":68,"tag":330,"props":1854,"children":1855},{},[1856],{"type":74,"value":1857},"                claims[\"diagnosis_code\"].str.startswith(tuple(measure[\"diagnosis_codes\"]))\n",{"type":68,"tag":330,"props":1859,"children":1860},{"class":332,"line":654},[1861],{"type":68,"tag":330,"props":1862,"children":1863},{},[1864],{"type":74,"value":1865},"            ][\"member_id\"].unique()\n",{"type":68,"tag":330,"props":1867,"children":1868},{"class":332,"line":663},[1869],{"type":68,"tag":330,"props":1870,"children":1871},{},[1872],{"type":74,"value":1873},"            eligible = eligible[eligible[\"member_id\"].isin(dx_members)]\n",{"type":68,"tag":330,"props":1875,"children":1876},{"class":332,"line":672},[1877],{"type":68,"tag":330,"props":1878,"children":1879},{},[1880],{"type":74,"value":1881},"        year_claims = claims[claims[\"service_date\"].between(str(year_start), str(anchor))]\n",{"type":68,"tag":330,"props":1883,"children":1884},{"class":332,"line":681},[1885],{"type":68,"tag":330,"props":1886,"children":1887},{},[1888],{"type":74,"value":1889},"        closed = year_claims[\n",{"type":68,"tag":330,"props":1891,"children":1892},{"class":332,"line":1263},[1893],{"type":68,"tag":330,"props":1894,"children":1895},{},[1896],{"type":74,"value":1897},"            year_claims[\"procedure_code\"].isin(measure[\"numerator_codes\"])\n",{"type":68,"tag":330,"props":1899,"children":1900},{"class":332,"line":1272},[1901],{"type":68,"tag":330,"props":1902,"children":1903},{},[1904],{"type":74,"value":1905},"        ][\"member_id\"].unique()\n",{"type":68,"tag":330,"props":1907,"children":1908},{"class":332,"line":1281},[1909],{"type":68,"tag":330,"props":1910,"children":1911},{},[1912],{"type":74,"value":1913},"        for _, row in eligible[~eligible[\"member_id\"].isin(closed)].iterrows():\n",{"type":68,"tag":330,"props":1915,"children":1916},{"class":332,"line":1290},[1917],{"type":68,"tag":330,"props":1918,"children":1919},{},[1920],{"type":74,"value":1921},"            sw = measure.get(\"star_weight\", 1)\n",{"type":68,"tag":330,"props":1923,"children":1924},{"class":332,"line":1299},[1925],{"type":68,"tag":330,"props":1926,"children":1927},{},[1928],{"type":74,"value":1929},"            gaps.append({\n",{"type":68,"tag":330,"props":1931,"children":1932},{"class":332,"line":1308},[1933],{"type":68,"tag":330,"props":1934,"children":1935},{},[1936],{"type":74,"value":1937},"                \"member_id\": row[\"member_id\"], \"measure_id\": measure[\"measure_id\"],\n",{"type":68,"tag":330,"props":1939,"children":1940},{"class":332,"line":1317},[1941],{"type":68,"tag":330,"props":1942,"children":1943},{},[1944],{"type":74,"value":1945},"                \"star_weight\": sw, \"risk_score\": row.get(\"risk_score\", 0),\n",{"type":68,"tag":330,"props":1947,"children":1949},{"class":332,"line":1948},48,[1950],{"type":68,"tag":330,"props":1951,"children":1952},{},[1953],{"type":74,"value":1954},"                \"priority_score\": round(sw * 30 + min(row.get(\"risk_score\", 0) * 25, 25) + 20, 1),\n",{"type":68,"tag":330,"props":1956,"children":1958},{"class":332,"line":1957},49,[1959],{"type":68,"tag":330,"props":1960,"children":1961},{},[1962],{"type":74,"value":1963},"            })\n",{"type":68,"tag":330,"props":1965,"children":1967},{"class":332,"line":1966},50,[1968],{"type":68,"tag":330,"props":1969,"children":1970},{},[1971],{"type":74,"value":1972},"    return pd.DataFrame(gaps).sort_values(\"priority_score\", ascending=False).reset_index(drop=True)\n",{"type":68,"tag":77,"props":1974,"children":1976},{"id":1975},"_4-utilization-rate-computation",[1977],{"type":74,"value":1978},"4. Utilization Rate Computation",{"type":68,"tag":319,"props":1980,"children":1982},{"className":696,"code":1981,"language":698,"meta":324,"style":324},"-- Utilization rates per 1000 members: ED, inpatient, 30-day readmissions\nWITH members AS (\n    SELECT COUNT(DISTINCT member_id) AS member_count FROM continuously_enrolled WHERE is_continuously_enrolled = 1\n),\ned AS (\n    SELECT COUNT(*) AS cnt FROM claims WHERE revenue_code IN ('0450','0451','0452','0456','0459') AND service_date BETWEEN '2025-01-01' AND '2025-12-31'\n),\nip AS (\n    SELECT COUNT(DISTINCT claim_id) AS cnt FROM claims WHERE claim_type = 'inpatient' AND admit_date BETWEEN '2025-01-01' AND '2025-12-31'\n),\nreadmit AS (\n    SELECT COUNT(*) AS cnt FROM (\n        SELECT member_id, admit_date, LAG(discharge_date) OVER (PARTITION BY member_id ORDER BY admit_date) AS prev_dc\n        FROM claims WHERE claim_type = 'inpatient' AND admit_date BETWEEN '2025-01-01' AND '2025-12-31'\n    ) s WHERE DATEDIFF(day, prev_dc, admit_date) \u003C= 30 AND prev_dc IS NOT NULL\n)\nSELECT ROUND(ed.cnt*1000.0\u002Fm.member_count,1) AS ed_per_1000,\n       ROUND(ip.cnt*1000.0\u002Fm.member_count,1) AS ip_per_1000,\n       ROUND(readmit.cnt*1000.0\u002Fm.member_count,1) AS readmit_per_1000\nFROM members m, ed, ip, readmit;\n",[1983],{"type":68,"tag":198,"props":1984,"children":1985},{"__ignoreMap":324},[1986,1994,2002,2010,2017,2025,2033,2040,2048,2056,2063,2071,2079,2087,2095,2103,2110,2118,2126,2134],{"type":68,"tag":330,"props":1987,"children":1988},{"class":332,"line":333},[1989],{"type":68,"tag":330,"props":1990,"children":1991},{},[1992],{"type":74,"value":1993},"-- Utilization rates per 1000 members: ED, inpatient, 30-day readmissions\n",{"type":68,"tag":330,"props":1995,"children":1996},{"class":332,"line":342},[1997],{"type":68,"tag":330,"props":1998,"children":1999},{},[2000],{"type":74,"value":2001},"WITH members AS (\n",{"type":68,"tag":330,"props":2003,"children":2004},{"class":332,"line":351},[2005],{"type":68,"tag":330,"props":2006,"children":2007},{},[2008],{"type":74,"value":2009},"    SELECT COUNT(DISTINCT member_id) AS member_count FROM continuously_enrolled WHERE is_continuously_enrolled = 1\n",{"type":68,"tag":330,"props":2011,"children":2012},{"class":332,"line":26},[2013],{"type":68,"tag":330,"props":2014,"children":2015},{},[2016],{"type":74,"value":758},{"type":68,"tag":330,"props":2018,"children":2019},{"class":332,"line":368},[2020],{"type":68,"tag":330,"props":2021,"children":2022},{},[2023],{"type":74,"value":2024},"ed AS (\n",{"type":68,"tag":330,"props":2026,"children":2027},{"class":332,"line":377},[2028],{"type":68,"tag":330,"props":2029,"children":2030},{},[2031],{"type":74,"value":2032},"    SELECT COUNT(*) AS cnt FROM claims WHERE revenue_code IN ('0450','0451','0452','0456','0459') AND service_date BETWEEN '2025-01-01' AND '2025-12-31'\n",{"type":68,"tag":330,"props":2034,"children":2035},{"class":332,"line":386},[2036],{"type":68,"tag":330,"props":2037,"children":2038},{},[2039],{"type":74,"value":758},{"type":68,"tag":330,"props":2041,"children":2042},{"class":332,"line":395},[2043],{"type":68,"tag":330,"props":2044,"children":2045},{},[2046],{"type":74,"value":2047},"ip AS (\n",{"type":68,"tag":330,"props":2049,"children":2050},{"class":332,"line":404},[2051],{"type":68,"tag":330,"props":2052,"children":2053},{},[2054],{"type":74,"value":2055},"    SELECT COUNT(DISTINCT claim_id) AS cnt FROM claims WHERE claim_type = 'inpatient' AND admit_date BETWEEN '2025-01-01' AND '2025-12-31'\n",{"type":68,"tag":330,"props":2057,"children":2058},{"class":332,"line":413},[2059],{"type":68,"tag":330,"props":2060,"children":2061},{},[2062],{"type":74,"value":758},{"type":68,"tag":330,"props":2064,"children":2065},{"class":332,"line":421},[2066],{"type":68,"tag":330,"props":2067,"children":2068},{},[2069],{"type":74,"value":2070},"readmit AS (\n",{"type":68,"tag":330,"props":2072,"children":2073},{"class":332,"line":430},[2074],{"type":68,"tag":330,"props":2075,"children":2076},{},[2077],{"type":74,"value":2078},"    SELECT COUNT(*) AS cnt FROM (\n",{"type":68,"tag":330,"props":2080,"children":2081},{"class":332,"line":439},[2082],{"type":68,"tag":330,"props":2083,"children":2084},{},[2085],{"type":74,"value":2086},"        SELECT member_id, admit_date, LAG(discharge_date) OVER (PARTITION BY member_id ORDER BY admit_date) AS prev_dc\n",{"type":68,"tag":330,"props":2088,"children":2089},{"class":332,"line":448},[2090],{"type":68,"tag":330,"props":2091,"children":2092},{},[2093],{"type":74,"value":2094},"        FROM claims WHERE claim_type = 'inpatient' AND admit_date BETWEEN '2025-01-01' AND '2025-12-31'\n",{"type":68,"tag":330,"props":2096,"children":2097},{"class":332,"line":457},[2098],{"type":68,"tag":330,"props":2099,"children":2100},{},[2101],{"type":74,"value":2102},"    ) s WHERE DATEDIFF(day, prev_dc, admit_date) \u003C= 30 AND prev_dc IS NOT NULL\n",{"type":68,"tag":330,"props":2104,"children":2105},{"class":332,"line":466},[2106],{"type":68,"tag":330,"props":2107,"children":2108},{},[2109],{"type":74,"value":891},{"type":68,"tag":330,"props":2111,"children":2112},{"class":332,"line":475},[2113],{"type":68,"tag":330,"props":2114,"children":2115},{},[2116],{"type":74,"value":2117},"SELECT ROUND(ed.cnt*1000.0\u002Fm.member_count,1) AS ed_per_1000,\n",{"type":68,"tag":330,"props":2119,"children":2120},{"class":332,"line":483},[2121],{"type":68,"tag":330,"props":2122,"children":2123},{},[2124],{"type":74,"value":2125},"       ROUND(ip.cnt*1000.0\u002Fm.member_count,1) AS ip_per_1000,\n",{"type":68,"tag":330,"props":2127,"children":2128},{"class":332,"line":492},[2129],{"type":68,"tag":330,"props":2130,"children":2131},{},[2132],{"type":74,"value":2133},"       ROUND(readmit.cnt*1000.0\u002Fm.member_count,1) AS readmit_per_1000\n",{"type":68,"tag":330,"props":2135,"children":2136},{"class":332,"line":501},[2137],{"type":68,"tag":330,"props":2138,"children":2139},{},[2140],{"type":74,"value":2141},"FROM members m, ed, ip, readmit;\n",{"type":68,"tag":77,"props":2143,"children":2145},{"id":2144},"_5-high-cost-claimant-identification",[2146],{"type":74,"value":2147},"5. High-Cost Claimant Identification",{"type":68,"tag":319,"props":2149,"children":2151},{"className":321,"code":2150,"language":323,"meta":324,"style":324},"\"\"\"Identify high-cost claimants and analyze cost drivers.\"\"\"\nimport pandas as pd\nimport numpy as np\n\n\ndef identify_high_cost_claimants(\n    claims: pd.DataFrame,\n    threshold_percentile: float = 95,\n    measurement_year: int = 2025,\n) -> dict:\n    \"\"\"Identify high-cost claimants above a percentile threshold.\n\n    Args:\n        claims: DataFrame [member_id, service_date, paid_amount, claim_type, diagnosis_code].\n        threshold_percentile: Percentile cutoff (default 95th).\n        measurement_year: Calendar year to analyze.\n\n    Returns:\n        Dict with threshold, count, pct of total spend, and member DataFrame.\n    \"\"\"\n    year_claims = claims[\n        pd.to_datetime(claims[\"service_date\"]).dt.year == measurement_year\n    ]\n    member_costs = (\n        year_claims.groupby(\"member_id\")\n        .agg(total_paid=(\"paid_amount\", \"sum\"), claim_count=(\"paid_amount\", \"count\"))\n        .reset_index()\n    )\n    threshold = np.percentile(member_costs[\"total_paid\"], threshold_percentile)\n    high_cost = member_costs[member_costs[\"total_paid\"] >= threshold].sort_values(\n        \"total_paid\", ascending=False\n    )\n    return {\n        \"threshold_amount\": round(threshold, 2),\n        \"high_cost_count\": len(high_cost),\n        \"high_cost_pct_of_total\": round(\n            high_cost[\"total_paid\"].sum() \u002F member_costs[\"total_paid\"].sum() * 100, 1\n        ),\n        \"high_cost_members\": high_cost,\n    }\n",[2152],{"type":68,"tag":198,"props":2153,"children":2154},{"__ignoreMap":324},[2155,2163,2170,2178,2185,2192,2200,2207,2215,2222,2229,2237,2244,2251,2259,2267,2275,2282,2289,2297,2304,2312,2320,2328,2336,2344,2352,2360,2367,2375,2383,2391,2398,2406,2414,2422,2430,2438,2446,2454],{"type":68,"tag":330,"props":2156,"children":2157},{"class":332,"line":333},[2158],{"type":68,"tag":330,"props":2159,"children":2160},{},[2161],{"type":74,"value":2162},"\"\"\"Identify high-cost claimants and analyze cost drivers.\"\"\"\n",{"type":68,"tag":330,"props":2164,"children":2165},{"class":332,"line":342},[2166],{"type":68,"tag":330,"props":2167,"children":2168},{},[2169],{"type":74,"value":348},{"type":68,"tag":330,"props":2171,"children":2172},{"class":332,"line":351},[2173],{"type":68,"tag":330,"props":2174,"children":2175},{},[2176],{"type":74,"value":2177},"import numpy as np\n",{"type":68,"tag":330,"props":2179,"children":2180},{"class":332,"line":26},[2181],{"type":68,"tag":330,"props":2182,"children":2183},{"emptyLinePlaceholder":355},[2184],{"type":74,"value":358},{"type":68,"tag":330,"props":2186,"children":2187},{"class":332,"line":368},[2188],{"type":68,"tag":330,"props":2189,"children":2190},{"emptyLinePlaceholder":355},[2191],{"type":74,"value":358},{"type":68,"tag":330,"props":2193,"children":2194},{"class":332,"line":377},[2195],{"type":68,"tag":330,"props":2196,"children":2197},{},[2198],{"type":74,"value":2199},"def identify_high_cost_claimants(\n",{"type":68,"tag":330,"props":2201,"children":2202},{"class":332,"line":386},[2203],{"type":68,"tag":330,"props":2204,"children":2205},{},[2206],{"type":74,"value":1646},{"type":68,"tag":330,"props":2208,"children":2209},{"class":332,"line":395},[2210],{"type":68,"tag":330,"props":2211,"children":2212},{},[2213],{"type":74,"value":2214},"    threshold_percentile: float = 95,\n",{"type":68,"tag":330,"props":2216,"children":2217},{"class":332,"line":404},[2218],{"type":68,"tag":330,"props":2219,"children":2220},{},[2221],{"type":74,"value":1654},{"type":68,"tag":330,"props":2223,"children":2224},{"class":332,"line":413},[2225],{"type":68,"tag":330,"props":2226,"children":2227},{},[2228],{"type":74,"value":401},{"type":68,"tag":330,"props":2230,"children":2231},{"class":332,"line":421},[2232],{"type":68,"tag":330,"props":2233,"children":2234},{},[2235],{"type":74,"value":2236},"    \"\"\"Identify high-cost claimants above a percentile threshold.\n",{"type":68,"tag":330,"props":2238,"children":2239},{"class":332,"line":430},[2240],{"type":68,"tag":330,"props":2241,"children":2242},{"emptyLinePlaceholder":355},[2243],{"type":74,"value":358},{"type":68,"tag":330,"props":2245,"children":2246},{"class":332,"line":439},[2247],{"type":68,"tag":330,"props":2248,"children":2249},{},[2250],{"type":74,"value":427},{"type":68,"tag":330,"props":2252,"children":2253},{"class":332,"line":448},[2254],{"type":68,"tag":330,"props":2255,"children":2256},{},[2257],{"type":74,"value":2258},"        claims: DataFrame [member_id, service_date, paid_amount, claim_type, diagnosis_code].\n",{"type":68,"tag":330,"props":2260,"children":2261},{"class":332,"line":457},[2262],{"type":68,"tag":330,"props":2263,"children":2264},{},[2265],{"type":74,"value":2266},"        threshold_percentile: Percentile cutoff (default 95th).\n",{"type":68,"tag":330,"props":2268,"children":2269},{"class":332,"line":466},[2270],{"type":68,"tag":330,"props":2271,"children":2272},{},[2273],{"type":74,"value":2274},"        measurement_year: Calendar year to analyze.\n",{"type":68,"tag":330,"props":2276,"children":2277},{"class":332,"line":475},[2278],{"type":68,"tag":330,"props":2279,"children":2280},{"emptyLinePlaceholder":355},[2281],{"type":74,"value":358},{"type":68,"tag":330,"props":2283,"children":2284},{"class":332,"line":483},[2285],{"type":68,"tag":330,"props":2286,"children":2287},{},[2288],{"type":74,"value":489},{"type":68,"tag":330,"props":2290,"children":2291},{"class":332,"line":492},[2292],{"type":68,"tag":330,"props":2293,"children":2294},{},[2295],{"type":74,"value":2296},"        Dict with threshold, count, pct of total spend, and member DataFrame.\n",{"type":68,"tag":330,"props":2298,"children":2299},{"class":332,"line":501},[2300],{"type":68,"tag":330,"props":2301,"children":2302},{},[2303],{"type":74,"value":507},{"type":68,"tag":330,"props":2305,"children":2306},{"class":332,"line":510},[2307],{"type":68,"tag":330,"props":2308,"children":2309},{},[2310],{"type":74,"value":2311},"    year_claims = claims[\n",{"type":68,"tag":330,"props":2313,"children":2314},{"class":332,"line":519},[2315],{"type":68,"tag":330,"props":2316,"children":2317},{},[2318],{"type":74,"value":2319},"        pd.to_datetime(claims[\"service_date\"]).dt.year == measurement_year\n",{"type":68,"tag":330,"props":2321,"children":2322},{"class":332,"line":528},[2323],{"type":68,"tag":330,"props":2324,"children":2325},{},[2326],{"type":74,"value":2327},"    ]\n",{"type":68,"tag":330,"props":2329,"children":2330},{"class":332,"line":537},[2331],{"type":68,"tag":330,"props":2332,"children":2333},{},[2334],{"type":74,"value":2335},"    member_costs = (\n",{"type":68,"tag":330,"props":2337,"children":2338},{"class":332,"line":546},[2339],{"type":68,"tag":330,"props":2340,"children":2341},{},[2342],{"type":74,"value":2343},"        year_claims.groupby(\"member_id\")\n",{"type":68,"tag":330,"props":2345,"children":2346},{"class":332,"line":555},[2347],{"type":68,"tag":330,"props":2348,"children":2349},{},[2350],{"type":74,"value":2351},"        .agg(total_paid=(\"paid_amount\", \"sum\"), claim_count=(\"paid_amount\", \"count\"))\n",{"type":68,"tag":330,"props":2353,"children":2354},{"class":332,"line":564},[2355],{"type":68,"tag":330,"props":2356,"children":2357},{},[2358],{"type":74,"value":2359},"        .reset_index()\n",{"type":68,"tag":330,"props":2361,"children":2362},{"class":332,"line":573},[2363],{"type":68,"tag":330,"props":2364,"children":2365},{},[2366],{"type":74,"value":1323},{"type":68,"tag":330,"props":2368,"children":2369},{"class":332,"line":582},[2370],{"type":68,"tag":330,"props":2371,"children":2372},{},[2373],{"type":74,"value":2374},"    threshold = np.percentile(member_costs[\"total_paid\"], threshold_percentile)\n",{"type":68,"tag":330,"props":2376,"children":2377},{"class":332,"line":591},[2378],{"type":68,"tag":330,"props":2379,"children":2380},{},[2381],{"type":74,"value":2382},"    high_cost = member_costs[member_costs[\"total_paid\"] >= threshold].sort_values(\n",{"type":68,"tag":330,"props":2384,"children":2385},{"class":332,"line":600},[2386],{"type":68,"tag":330,"props":2387,"children":2388},{},[2389],{"type":74,"value":2390},"        \"total_paid\", ascending=False\n",{"type":68,"tag":330,"props":2392,"children":2393},{"class":332,"line":609},[2394],{"type":68,"tag":330,"props":2395,"children":2396},{},[2397],{"type":74,"value":1323},{"type":68,"tag":330,"props":2399,"children":2400},{"class":332,"line":618},[2401],{"type":68,"tag":330,"props":2402,"children":2403},{},[2404],{"type":74,"value":2405},"    return {\n",{"type":68,"tag":330,"props":2407,"children":2408},{"class":332,"line":627},[2409],{"type":68,"tag":330,"props":2410,"children":2411},{},[2412],{"type":74,"value":2413},"        \"threshold_amount\": round(threshold, 2),\n",{"type":68,"tag":330,"props":2415,"children":2416},{"class":332,"line":636},[2417],{"type":68,"tag":330,"props":2418,"children":2419},{},[2420],{"type":74,"value":2421},"        \"high_cost_count\": len(high_cost),\n",{"type":68,"tag":330,"props":2423,"children":2424},{"class":332,"line":645},[2425],{"type":68,"tag":330,"props":2426,"children":2427},{},[2428],{"type":74,"value":2429},"        \"high_cost_pct_of_total\": round(\n",{"type":68,"tag":330,"props":2431,"children":2432},{"class":332,"line":654},[2433],{"type":68,"tag":330,"props":2434,"children":2435},{},[2436],{"type":74,"value":2437},"            high_cost[\"total_paid\"].sum() \u002F member_costs[\"total_paid\"].sum() * 100, 1\n",{"type":68,"tag":330,"props":2439,"children":2440},{"class":332,"line":663},[2441],{"type":68,"tag":330,"props":2442,"children":2443},{},[2444],{"type":74,"value":2445},"        ),\n",{"type":68,"tag":330,"props":2447,"children":2448},{"class":332,"line":672},[2449],{"type":68,"tag":330,"props":2450,"children":2451},{},[2452],{"type":74,"value":2453},"        \"high_cost_members\": high_cost,\n",{"type":68,"tag":330,"props":2455,"children":2456},{"class":332,"line":681},[2457],{"type":68,"tag":330,"props":2458,"children":2459},{},[2460],{"type":74,"value":2461},"    }\n",{"type":68,"tag":77,"props":2463,"children":2465},{"id":2464},"_6-risk-stratification-scoring",[2466],{"type":74,"value":2467},"6. Risk Stratification Scoring",{"type":68,"tag":312,"props":2469,"children":2471},{"id":2470},"_61-charlson-comorbidity-index-python",[2472],{"type":74,"value":2473},"6.1 Charlson Comorbidity Index (Python)",{"type":68,"tag":319,"props":2475,"children":2477},{"className":321,"code":2476,"language":323,"meta":324,"style":324},"\"\"\"Calculate Charlson Comorbidity Index from diagnosis codes.\"\"\"\n\n# ICD-10 prefix → (condition, weight). Subset of key mappings.\nCHARLSON_MAP = {\n    \"I21\": (\"mi\", 1), \"I22\": (\"mi\", 1), \"I50\": (\"chf\", 1),\n    \"I70\": (\"pvd\", 1), \"I71\": (\"pvd\", 1), \"I6\": (\"cvd\", 1),\n    \"F01\": (\"dementia\", 1), \"F03\": (\"dementia\", 1), \"G30\": (\"dementia\", 1),\n    \"J4\": (\"copd\", 1), \"M05\": (\"ctd\", 1), \"M06\": (\"ctd\", 1),\n    \"K25\": (\"pud\", 1), \"K26\": (\"pud\", 1),\n    \"K70\": (\"mild_liver\", 1), \"K73\": (\"mild_liver\", 1), \"K74\": (\"mild_liver\", 1),\n    \"E109\": (\"dm_uncomp\", 1), \"E119\": (\"dm_uncomp\", 1),\n    \"E102\": (\"dm_comp\", 2), \"E112\": (\"dm_comp\", 2),\n    \"G81\": (\"hemiplegia\", 2), \"N18\": (\"renal\", 2),\n    \"C\": (\"cancer\", 2),\n    \"C77\": (\"metastatic\", 6), \"C78\": (\"metastatic\", 6), \"C79\": (\"metastatic\", 6),\n    \"B20\": (\"hiv\", 6),\n}\n\n\ndef charlson_score(diagnosis_codes: list[str]) -> dict:\n    \"\"\"Calculate Charlson Comorbidity Index. Returns {score, conditions}.\"\"\"\n    matched: dict[str, int] = {}\n    for code in [c.replace(\".\", \"\") for c in diagnosis_codes]:\n        for prefix, (cond, wt) in CHARLSON_MAP.items():\n            if code.startswith(prefix):\n                if cond == \"cancer\" and \"metastatic\" in matched:\n                    continue\n                if cond == \"metastatic\":\n                    matched.pop(\"cancer\", None)\n                if cond == \"dm_uncomp\" and \"dm_comp\" in matched:\n                    continue\n                if cond == \"dm_comp\":\n                    matched.pop(\"dm_uncomp\", None)\n                if cond not in matched or wt > matched[cond]:\n                    matched[cond] = wt\n                break\n    return {\"score\": sum(matched.values()), \"conditions\": matched}\n",[2478],{"type":68,"tag":198,"props":2479,"children":2480},{"__ignoreMap":324},[2481,2489,2496,2504,2512,2520,2528,2536,2544,2552,2560,2568,2576,2584,2592,2600,2608,2616,2623,2630,2638,2646,2654,2662,2670,2678,2686,2694,2702,2710,2718,2725,2733,2741,2749,2757,2765],{"type":68,"tag":330,"props":2482,"children":2483},{"class":332,"line":333},[2484],{"type":68,"tag":330,"props":2485,"children":2486},{},[2487],{"type":74,"value":2488},"\"\"\"Calculate Charlson Comorbidity Index from diagnosis codes.\"\"\"\n",{"type":68,"tag":330,"props":2490,"children":2491},{"class":332,"line":342},[2492],{"type":68,"tag":330,"props":2493,"children":2494},{"emptyLinePlaceholder":355},[2495],{"type":74,"value":358},{"type":68,"tag":330,"props":2497,"children":2498},{"class":332,"line":351},[2499],{"type":68,"tag":330,"props":2500,"children":2501},{},[2502],{"type":74,"value":2503},"# ICD-10 prefix → (condition, weight). Subset of key mappings.\n",{"type":68,"tag":330,"props":2505,"children":2506},{"class":332,"line":26},[2507],{"type":68,"tag":330,"props":2508,"children":2509},{},[2510],{"type":74,"value":2511},"CHARLSON_MAP = {\n",{"type":68,"tag":330,"props":2513,"children":2514},{"class":332,"line":368},[2515],{"type":68,"tag":330,"props":2516,"children":2517},{},[2518],{"type":74,"value":2519},"    \"I21\": (\"mi\", 1), \"I22\": (\"mi\", 1), \"I50\": (\"chf\", 1),\n",{"type":68,"tag":330,"props":2521,"children":2522},{"class":332,"line":377},[2523],{"type":68,"tag":330,"props":2524,"children":2525},{},[2526],{"type":74,"value":2527},"    \"I70\": (\"pvd\", 1), \"I71\": (\"pvd\", 1), \"I6\": (\"cvd\", 1),\n",{"type":68,"tag":330,"props":2529,"children":2530},{"class":332,"line":386},[2531],{"type":68,"tag":330,"props":2532,"children":2533},{},[2534],{"type":74,"value":2535},"    \"F01\": (\"dementia\", 1), \"F03\": (\"dementia\", 1), \"G30\": (\"dementia\", 1),\n",{"type":68,"tag":330,"props":2537,"children":2538},{"class":332,"line":395},[2539],{"type":68,"tag":330,"props":2540,"children":2541},{},[2542],{"type":74,"value":2543},"    \"J4\": (\"copd\", 1), \"M05\": (\"ctd\", 1), \"M06\": (\"ctd\", 1),\n",{"type":68,"tag":330,"props":2545,"children":2546},{"class":332,"line":404},[2547],{"type":68,"tag":330,"props":2548,"children":2549},{},[2550],{"type":74,"value":2551},"    \"K25\": (\"pud\", 1), \"K26\": (\"pud\", 1),\n",{"type":68,"tag":330,"props":2553,"children":2554},{"class":332,"line":413},[2555],{"type":68,"tag":330,"props":2556,"children":2557},{},[2558],{"type":74,"value":2559},"    \"K70\": (\"mild_liver\", 1), \"K73\": (\"mild_liver\", 1), \"K74\": (\"mild_liver\", 1),\n",{"type":68,"tag":330,"props":2561,"children":2562},{"class":332,"line":421},[2563],{"type":68,"tag":330,"props":2564,"children":2565},{},[2566],{"type":74,"value":2567},"    \"E109\": (\"dm_uncomp\", 1), \"E119\": (\"dm_uncomp\", 1),\n",{"type":68,"tag":330,"props":2569,"children":2570},{"class":332,"line":430},[2571],{"type":68,"tag":330,"props":2572,"children":2573},{},[2574],{"type":74,"value":2575},"    \"E102\": (\"dm_comp\", 2), \"E112\": (\"dm_comp\", 2),\n",{"type":68,"tag":330,"props":2577,"children":2578},{"class":332,"line":439},[2579],{"type":68,"tag":330,"props":2580,"children":2581},{},[2582],{"type":74,"value":2583},"    \"G81\": (\"hemiplegia\", 2), \"N18\": (\"renal\", 2),\n",{"type":68,"tag":330,"props":2585,"children":2586},{"class":332,"line":448},[2587],{"type":68,"tag":330,"props":2588,"children":2589},{},[2590],{"type":74,"value":2591},"    \"C\": (\"cancer\", 2),\n",{"type":68,"tag":330,"props":2593,"children":2594},{"class":332,"line":457},[2595],{"type":68,"tag":330,"props":2596,"children":2597},{},[2598],{"type":74,"value":2599},"    \"C77\": (\"metastatic\", 6), \"C78\": (\"metastatic\", 6), \"C79\": (\"metastatic\", 6),\n",{"type":68,"tag":330,"props":2601,"children":2602},{"class":332,"line":466},[2603],{"type":68,"tag":330,"props":2604,"children":2605},{},[2606],{"type":74,"value":2607},"    \"B20\": (\"hiv\", 6),\n",{"type":68,"tag":330,"props":2609,"children":2610},{"class":332,"line":475},[2611],{"type":68,"tag":330,"props":2612,"children":2613},{},[2614],{"type":74,"value":2615},"}\n",{"type":68,"tag":330,"props":2617,"children":2618},{"class":332,"line":483},[2619],{"type":68,"tag":330,"props":2620,"children":2621},{"emptyLinePlaceholder":355},[2622],{"type":74,"value":358},{"type":68,"tag":330,"props":2624,"children":2625},{"class":332,"line":492},[2626],{"type":68,"tag":330,"props":2627,"children":2628},{"emptyLinePlaceholder":355},[2629],{"type":74,"value":358},{"type":68,"tag":330,"props":2631,"children":2632},{"class":332,"line":501},[2633],{"type":68,"tag":330,"props":2634,"children":2635},{},[2636],{"type":74,"value":2637},"def charlson_score(diagnosis_codes: list[str]) -> dict:\n",{"type":68,"tag":330,"props":2639,"children":2640},{"class":332,"line":510},[2641],{"type":68,"tag":330,"props":2642,"children":2643},{},[2644],{"type":74,"value":2645},"    \"\"\"Calculate Charlson Comorbidity Index. Returns {score, conditions}.\"\"\"\n",{"type":68,"tag":330,"props":2647,"children":2648},{"class":332,"line":519},[2649],{"type":68,"tag":330,"props":2650,"children":2651},{},[2652],{"type":74,"value":2653},"    matched: dict[str, int] = {}\n",{"type":68,"tag":330,"props":2655,"children":2656},{"class":332,"line":528},[2657],{"type":68,"tag":330,"props":2658,"children":2659},{},[2660],{"type":74,"value":2661},"    for code in [c.replace(\".\", \"\") for c in diagnosis_codes]:\n",{"type":68,"tag":330,"props":2663,"children":2664},{"class":332,"line":537},[2665],{"type":68,"tag":330,"props":2666,"children":2667},{},[2668],{"type":74,"value":2669},"        for prefix, (cond, wt) in CHARLSON_MAP.items():\n",{"type":68,"tag":330,"props":2671,"children":2672},{"class":332,"line":546},[2673],{"type":68,"tag":330,"props":2674,"children":2675},{},[2676],{"type":74,"value":2677},"            if code.startswith(prefix):\n",{"type":68,"tag":330,"props":2679,"children":2680},{"class":332,"line":555},[2681],{"type":68,"tag":330,"props":2682,"children":2683},{},[2684],{"type":74,"value":2685},"                if cond == \"cancer\" and \"metastatic\" in matched:\n",{"type":68,"tag":330,"props":2687,"children":2688},{"class":332,"line":564},[2689],{"type":68,"tag":330,"props":2690,"children":2691},{},[2692],{"type":74,"value":2693},"                    continue\n",{"type":68,"tag":330,"props":2695,"children":2696},{"class":332,"line":573},[2697],{"type":68,"tag":330,"props":2698,"children":2699},{},[2700],{"type":74,"value":2701},"                if cond == \"metastatic\":\n",{"type":68,"tag":330,"props":2703,"children":2704},{"class":332,"line":582},[2705],{"type":68,"tag":330,"props":2706,"children":2707},{},[2708],{"type":74,"value":2709},"                    matched.pop(\"cancer\", None)\n",{"type":68,"tag":330,"props":2711,"children":2712},{"class":332,"line":591},[2713],{"type":68,"tag":330,"props":2714,"children":2715},{},[2716],{"type":74,"value":2717},"                if cond == \"dm_uncomp\" and \"dm_comp\" in matched:\n",{"type":68,"tag":330,"props":2719,"children":2720},{"class":332,"line":600},[2721],{"type":68,"tag":330,"props":2722,"children":2723},{},[2724],{"type":74,"value":2693},{"type":68,"tag":330,"props":2726,"children":2727},{"class":332,"line":609},[2728],{"type":68,"tag":330,"props":2729,"children":2730},{},[2731],{"type":74,"value":2732},"                if cond == \"dm_comp\":\n",{"type":68,"tag":330,"props":2734,"children":2735},{"class":332,"line":618},[2736],{"type":68,"tag":330,"props":2737,"children":2738},{},[2739],{"type":74,"value":2740},"                    matched.pop(\"dm_uncomp\", None)\n",{"type":68,"tag":330,"props":2742,"children":2743},{"class":332,"line":627},[2744],{"type":68,"tag":330,"props":2745,"children":2746},{},[2747],{"type":74,"value":2748},"                if cond not in matched or wt > matched[cond]:\n",{"type":68,"tag":330,"props":2750,"children":2751},{"class":332,"line":636},[2752],{"type":68,"tag":330,"props":2753,"children":2754},{},[2755],{"type":74,"value":2756},"                    matched[cond] = wt\n",{"type":68,"tag":330,"props":2758,"children":2759},{"class":332,"line":645},[2760],{"type":68,"tag":330,"props":2761,"children":2762},{},[2763],{"type":74,"value":2764},"                break\n",{"type":68,"tag":330,"props":2766,"children":2767},{"class":332,"line":654},[2768],{"type":68,"tag":330,"props":2769,"children":2770},{},[2771],{"type":74,"value":2772},"    return {\"score\": sum(matched.values()), \"conditions\": matched}\n",{"type":68,"tag":312,"props":2774,"children":2776},{"id":2775},"_62-lace-readmission-risk-score",[2777],{"type":74,"value":2778},"6.2 LACE Readmission Risk Score",{"type":68,"tag":319,"props":2780,"children":2782},{"className":321,"code":2781,"language":323,"meta":324,"style":324},"\"\"\"Calculate LACE readmission risk score.\"\"\"\n\n\ndef lace_score(length_of_stay: int, acuity: str, charlson: int, ed_visits_6mo: int) -> dict:\n    \"\"\"Calculate LACE index for 30-day readmission risk.\n\n    Returns dict with total score, component scores, and risk tier.\n    \"\"\"\n    l = 7 if length_of_stay >= 14 else (5 if length_of_stay >= 7 else (4 if length_of_stay >= 4 else min(length_of_stay, 3)))\n    a = {\"emergent\": 3, \"urgent\": 2, \"elective\": 0}.get(acuity.lower(), 0)\n    c = 5 if charlson >= 4 else min(charlson, 3)\n    e = min(ed_visits_6mo, 4)\n    total = l + a + c + e\n    tier = \"high\" if total >= 10 else (\"moderate\" if total >= 5 else \"low\")\n    return {\"total\": total, \"components\": {\"L\": l, \"A\": a, \"C\": c, \"E\": e}, \"risk_tier\": tier}\n",[2783],{"type":68,"tag":198,"props":2784,"children":2785},{"__ignoreMap":324},[2786,2794,2801,2808,2816,2824,2831,2839,2846,2854,2862,2870,2878,2886,2894],{"type":68,"tag":330,"props":2787,"children":2788},{"class":332,"line":333},[2789],{"type":68,"tag":330,"props":2790,"children":2791},{},[2792],{"type":74,"value":2793},"\"\"\"Calculate LACE readmission risk score.\"\"\"\n",{"type":68,"tag":330,"props":2795,"children":2796},{"class":332,"line":342},[2797],{"type":68,"tag":330,"props":2798,"children":2799},{"emptyLinePlaceholder":355},[2800],{"type":74,"value":358},{"type":68,"tag":330,"props":2802,"children":2803},{"class":332,"line":351},[2804],{"type":68,"tag":330,"props":2805,"children":2806},{"emptyLinePlaceholder":355},[2807],{"type":74,"value":358},{"type":68,"tag":330,"props":2809,"children":2810},{"class":332,"line":26},[2811],{"type":68,"tag":330,"props":2812,"children":2813},{},[2814],{"type":74,"value":2815},"def lace_score(length_of_stay: int, acuity: str, charlson: int, ed_visits_6mo: int) -> dict:\n",{"type":68,"tag":330,"props":2817,"children":2818},{"class":332,"line":368},[2819],{"type":68,"tag":330,"props":2820,"children":2821},{},[2822],{"type":74,"value":2823},"    \"\"\"Calculate LACE index for 30-day readmission risk.\n",{"type":68,"tag":330,"props":2825,"children":2826},{"class":332,"line":377},[2827],{"type":68,"tag":330,"props":2828,"children":2829},{"emptyLinePlaceholder":355},[2830],{"type":74,"value":358},{"type":68,"tag":330,"props":2832,"children":2833},{"class":332,"line":386},[2834],{"type":68,"tag":330,"props":2835,"children":2836},{},[2837],{"type":74,"value":2838},"    Returns dict with total score, component scores, and risk tier.\n",{"type":68,"tag":330,"props":2840,"children":2841},{"class":332,"line":395},[2842],{"type":68,"tag":330,"props":2843,"children":2844},{},[2845],{"type":74,"value":507},{"type":68,"tag":330,"props":2847,"children":2848},{"class":332,"line":404},[2849],{"type":68,"tag":330,"props":2850,"children":2851},{},[2852],{"type":74,"value":2853},"    l = 7 if length_of_stay >= 14 else (5 if length_of_stay >= 7 else (4 if length_of_stay >= 4 else min(length_of_stay, 3)))\n",{"type":68,"tag":330,"props":2855,"children":2856},{"class":332,"line":413},[2857],{"type":68,"tag":330,"props":2858,"children":2859},{},[2860],{"type":74,"value":2861},"    a = {\"emergent\": 3, \"urgent\": 2, \"elective\": 0}.get(acuity.lower(), 0)\n",{"type":68,"tag":330,"props":2863,"children":2864},{"class":332,"line":421},[2865],{"type":68,"tag":330,"props":2866,"children":2867},{},[2868],{"type":74,"value":2869},"    c = 5 if charlson >= 4 else min(charlson, 3)\n",{"type":68,"tag":330,"props":2871,"children":2872},{"class":332,"line":430},[2873],{"type":68,"tag":330,"props":2874,"children":2875},{},[2876],{"type":74,"value":2877},"    e = min(ed_visits_6mo, 4)\n",{"type":68,"tag":330,"props":2879,"children":2880},{"class":332,"line":439},[2881],{"type":68,"tag":330,"props":2882,"children":2883},{},[2884],{"type":74,"value":2885},"    total = l + a + c + e\n",{"type":68,"tag":330,"props":2887,"children":2888},{"class":332,"line":448},[2889],{"type":68,"tag":330,"props":2890,"children":2891},{},[2892],{"type":74,"value":2893},"    tier = \"high\" if total >= 10 else (\"moderate\" if total >= 5 else \"low\")\n",{"type":68,"tag":330,"props":2895,"children":2896},{"class":332,"line":457},[2897],{"type":68,"tag":330,"props":2898,"children":2899},{},[2900],{"type":74,"value":2901},"    return {\"total\": total, \"components\": {\"L\": l, \"A\": a, \"C\": c, \"E\": e}, \"risk_tier\": tier}\n",{"type":68,"tag":77,"props":2903,"children":2905},{"id":2904},"_7-measure-stratification-by-planprovider",[2906],{"type":74,"value":2907},"7. Measure Stratification by Plan\u002FProvider",{"type":68,"tag":319,"props":2909,"children":2911},{"className":696,"code":2910,"language":698,"meta":324,"style":324},"-- Measure rate stratified by health plan and provider\nSELECT health_plan, assigned_pcp_npi,\n       COUNT(*) - SUM(CASE WHEN e.member_id IS NOT NULL THEN 1 ELSE 0 END) AS eligible_denom,\n       SUM(CASE WHEN e.member_id IS NULL AND n.member_id IS NOT NULL THEN 1 ELSE 0 END) AS numerator,\n       ROUND(SUM(CASE WHEN e.member_id IS NULL AND n.member_id IS NOT NULL THEN 1 ELSE 0 END) * 100.0\n             \u002F NULLIF(COUNT(*) - SUM(CASE WHEN e.member_id IS NOT NULL THEN 1 ELSE 0 END), 0), 1) AS rate_pct\nFROM denominator_members m\nLEFT JOIN exclusion_members e ON m.member_id = e.member_id\nLEFT JOIN numerator_members n ON m.member_id = n.member_id\nGROUP BY health_plan, assigned_pcp_npi\nORDER BY rate_pct ASC;\n",[2912],{"type":68,"tag":198,"props":2913,"children":2914},{"__ignoreMap":324},[2915,2923,2931,2939,2947,2955,2963,2971,2979,2987,2995],{"type":68,"tag":330,"props":2916,"children":2917},{"class":332,"line":333},[2918],{"type":68,"tag":330,"props":2919,"children":2920},{},[2921],{"type":74,"value":2922},"-- Measure rate stratified by health plan and provider\n",{"type":68,"tag":330,"props":2924,"children":2925},{"class":332,"line":342},[2926],{"type":68,"tag":330,"props":2927,"children":2928},{},[2929],{"type":74,"value":2930},"SELECT health_plan, assigned_pcp_npi,\n",{"type":68,"tag":330,"props":2932,"children":2933},{"class":332,"line":351},[2934],{"type":68,"tag":330,"props":2935,"children":2936},{},[2937],{"type":74,"value":2938},"       COUNT(*) - SUM(CASE WHEN e.member_id IS NOT NULL THEN 1 ELSE 0 END) AS eligible_denom,\n",{"type":68,"tag":330,"props":2940,"children":2941},{"class":332,"line":26},[2942],{"type":68,"tag":330,"props":2943,"children":2944},{},[2945],{"type":74,"value":2946},"       SUM(CASE WHEN e.member_id IS NULL AND n.member_id IS NOT NULL THEN 1 ELSE 0 END) AS numerator,\n",{"type":68,"tag":330,"props":2948,"children":2949},{"class":332,"line":368},[2950],{"type":68,"tag":330,"props":2951,"children":2952},{},[2953],{"type":74,"value":2954},"       ROUND(SUM(CASE WHEN e.member_id IS NULL AND n.member_id IS NOT NULL THEN 1 ELSE 0 END) * 100.0\n",{"type":68,"tag":330,"props":2956,"children":2957},{"class":332,"line":377},[2958],{"type":68,"tag":330,"props":2959,"children":2960},{},[2961],{"type":74,"value":2962},"             \u002F NULLIF(COUNT(*) - SUM(CASE WHEN e.member_id IS NOT NULL THEN 1 ELSE 0 END), 0), 1) AS rate_pct\n",{"type":68,"tag":330,"props":2964,"children":2965},{"class":332,"line":386},[2966],{"type":68,"tag":330,"props":2967,"children":2968},{},[2969],{"type":74,"value":2970},"FROM denominator_members m\n",{"type":68,"tag":330,"props":2972,"children":2973},{"class":332,"line":395},[2974],{"type":68,"tag":330,"props":2975,"children":2976},{},[2977],{"type":74,"value":2978},"LEFT JOIN exclusion_members e ON m.member_id = e.member_id\n",{"type":68,"tag":330,"props":2980,"children":2981},{"class":332,"line":404},[2982],{"type":68,"tag":330,"props":2983,"children":2984},{},[2985],{"type":74,"value":2986},"LEFT JOIN numerator_members n ON m.member_id = n.member_id\n",{"type":68,"tag":330,"props":2988,"children":2989},{"class":332,"line":413},[2990],{"type":68,"tag":330,"props":2991,"children":2992},{},[2993],{"type":74,"value":2994},"GROUP BY health_plan, assigned_pcp_npi\n",{"type":68,"tag":330,"props":2996,"children":2997},{"class":332,"line":421},[2998],{"type":68,"tag":330,"props":2999,"children":3000},{},[3001],{"type":74,"value":3002},"ORDER BY rate_pct ASC;\n",{"type":68,"tag":77,"props":3004,"children":3006},{"id":3005},"_8-parameter-reference",[3007],{"type":74,"value":3008},"8. Parameter Reference",{"type":68,"tag":152,"props":3010,"children":3011},{},[3012,3033],{"type":68,"tag":156,"props":3013,"children":3014},{},[3015],{"type":68,"tag":160,"props":3016,"children":3017},{},[3018,3023,3028],{"type":68,"tag":164,"props":3019,"children":3020},{},[3021],{"type":74,"value":3022},"Parameter",{"type":68,"tag":164,"props":3024,"children":3025},{},[3026],{"type":74,"value":3027},"Default",{"type":68,"tag":164,"props":3029,"children":3030},{},[3031],{"type":74,"value":3032},"Description",{"type":68,"tag":180,"props":3034,"children":3035},{},[3036,3058,3080,3102,3124,3146],{"type":68,"tag":160,"props":3037,"children":3038},{},[3039,3048,3053],{"type":68,"tag":187,"props":3040,"children":3041},{},[3042],{"type":68,"tag":198,"props":3043,"children":3045},{"className":3044},[],[3046],{"type":74,"value":3047},"measurement_year",{"type":68,"tag":187,"props":3049,"children":3050},{},[3051],{"type":74,"value":3052},"Current calendar year",{"type":68,"tag":187,"props":3054,"children":3055},{},[3056],{"type":74,"value":3057},"HEDIS reporting year",{"type":68,"tag":160,"props":3059,"children":3060},{},[3061,3070,3075],{"type":68,"tag":187,"props":3062,"children":3063},{},[3064],{"type":68,"tag":198,"props":3065,"children":3067},{"className":3066},[],[3068],{"type":74,"value":3069},"max_gap_days",{"type":68,"tag":187,"props":3071,"children":3072},{},[3073],{"type":74,"value":3074},"45",{"type":68,"tag":187,"props":3076,"children":3077},{},[3078],{"type":74,"value":3079},"Maximum allowable enrollment gap",{"type":68,"tag":160,"props":3081,"children":3082},{},[3083,3092,3097],{"type":68,"tag":187,"props":3084,"children":3085},{},[3086],{"type":68,"tag":198,"props":3087,"children":3089},{"className":3088},[],[3090],{"type":74,"value":3091},"anchor_date",{"type":68,"tag":187,"props":3093,"children":3094},{},[3095],{"type":74,"value":3096},"Dec 31 of measurement year",{"type":68,"tag":187,"props":3098,"children":3099},{},[3100],{"type":74,"value":3101},"Date member must be enrolled through",{"type":68,"tag":160,"props":3103,"children":3104},{},[3105,3114,3119],{"type":68,"tag":187,"props":3106,"children":3107},{},[3108],{"type":68,"tag":198,"props":3109,"children":3111},{"className":3110},[],[3112],{"type":74,"value":3113},"dx_lookback_years",{"type":68,"tag":187,"props":3115,"children":3116},{},[3117],{"type":74,"value":3118},"2",{"type":68,"tag":187,"props":3120,"children":3121},{},[3122],{"type":74,"value":3123},"Years to look back for qualifying diagnoses",{"type":68,"tag":160,"props":3125,"children":3126},{},[3127,3136,3141],{"type":68,"tag":187,"props":3128,"children":3129},{},[3130],{"type":68,"tag":198,"props":3131,"children":3133},{"className":3132},[],[3134],{"type":74,"value":3135},"threshold_percentile",{"type":68,"tag":187,"props":3137,"children":3138},{},[3139],{"type":74,"value":3140},"95",{"type":68,"tag":187,"props":3142,"children":3143},{},[3144],{"type":74,"value":3145},"Percentile cutoff for high-cost identification",{"type":68,"tag":160,"props":3147,"children":3148},{},[3149,3158,3163],{"type":68,"tag":187,"props":3150,"children":3151},{},[3152],{"type":68,"tag":198,"props":3153,"children":3155},{"className":3154},[],[3156],{"type":74,"value":3157},"readmission_window",{"type":68,"tag":187,"props":3159,"children":3160},{},[3161],{"type":74,"value":3162},"30",{"type":68,"tag":187,"props":3164,"children":3165},{},[3166],{"type":74,"value":3167},"Days after discharge for readmission flag",{"type":68,"tag":77,"props":3169,"children":3171},{"id":3170},"_9-common-mistakes",[3172],{"type":74,"value":3173},"9. Common Mistakes",{"type":68,"tag":96,"props":3175,"children":3176},{},[3177,3210,3231,3252,3273,3294],{"type":68,"tag":100,"props":3178,"children":3179},{},[3180,3186,3188,3193,3195,3201,3203,3208],{"type":68,"tag":3181,"props":3182,"children":3183},"strong",{},[3184],{"type":74,"value":3185},"Wrong:",{"type":74,"value":3187}," Including segment end dates when calculating enrollment gap days\n",{"type":68,"tag":3181,"props":3189,"children":3190},{},[3191],{"type":74,"value":3192},"Right:",{"type":74,"value":3194}," Calculate gaps as the calendar days ",{"type":68,"tag":3196,"props":3197,"children":3198},"em",{},[3199],{"type":74,"value":3200},"between",{"type":74,"value":3202}," segments (day after end of segment A to day before start of segment B)\n",{"type":68,"tag":3181,"props":3204,"children":3205},{},[3206],{"type":74,"value":3207},"Why:",{"type":74,"value":3209}," Off-by-one errors in gap calculation incorrectly exclude continuously enrolled members or include ineligible ones",{"type":68,"tag":100,"props":3211,"children":3212},{},[3213,3217,3219,3223,3225,3229],{"type":68,"tag":3181,"props":3214,"children":3215},{},[3216],{"type":74,"value":3185},{"type":74,"value":3218}," Using enrollment segments as-is without clipping to the measurement year boundaries\n",{"type":68,"tag":3181,"props":3220,"children":3221},{},[3222],{"type":74,"value":3192},{"type":74,"value":3224}," Clip all enrollment segments to the measurement year start and end dates before calculating gaps\n",{"type":68,"tag":3181,"props":3226,"children":3227},{},[3228],{"type":74,"value":3207},{"type":74,"value":3230}," Segments extending beyond the year inflate coverage calculations and produce incorrect enrollment determinations",{"type":68,"tag":100,"props":3232,"children":3233},{},[3234,3238,3240,3244,3246,3250],{"type":68,"tag":3181,"props":3235,"children":3236},{},[3237],{"type":74,"value":3185},{"type":74,"value":3239}," Using service date for inpatient utilization metrics\n",{"type":68,"tag":3181,"props":3241,"children":3242},{},[3243],{"type":74,"value":3192},{"type":74,"value":3245}," Use admit date and discharge date for inpatient claims — service date is for professional\u002Foutpatient claims\n",{"type":68,"tag":3181,"props":3247,"children":3248},{},[3249],{"type":74,"value":3207},{"type":74,"value":3251}," Inpatient utilization (admissions, readmissions, length of stay) is defined by admission events, not individual service lines",{"type":68,"tag":100,"props":3253,"children":3254},{},[3255,3259,3261,3265,3267,3271],{"type":68,"tag":3181,"props":3256,"children":3257},{},[3258],{"type":74,"value":3185},{"type":74,"value":3260}," Counting a member multiple times in the numerator when they have multiple qualifying events\n",{"type":68,"tag":3181,"props":3262,"children":3263},{},[3264],{"type":74,"value":3192},{"type":74,"value":3266}," Deduplicate numerator events by member ID — each member counts once regardless of how many tests or services they received\n",{"type":68,"tag":3181,"props":3268,"children":3269},{},[3270],{"type":74,"value":3207},{"type":74,"value":3272}," Multiple events for the same member inflate the numerator and produce artificially high measure rates",{"type":68,"tag":100,"props":3274,"children":3275},{},[3276,3280,3282,3286,3288,3292],{"type":68,"tag":3181,"props":3277,"children":3278},{},[3279],{"type":74,"value":3185},{"type":74,"value":3281}," Calculating member age as of the run date or an arbitrary date\n",{"type":68,"tag":3181,"props":3283,"children":3284},{},[3285],{"type":74,"value":3192},{"type":74,"value":3287}," Calculate age as of the measure-specific anchor date (typically December 31 of the measurement year)\n",{"type":68,"tag":3181,"props":3289,"children":3290},{},[3291],{"type":74,"value":3207},{"type":74,"value":3293}," Using the wrong anchor date shifts age-based eligibility and includes or excludes members incorrectly",{"type":68,"tag":100,"props":3295,"children":3296},{},[3297,3301,3303,3307,3309,3313],{"type":68,"tag":3181,"props":3298,"children":3299},{},[3300],{"type":74,"value":3185},{"type":74,"value":3302}," Only looking at the measurement year for qualifying diagnoses\n",{"type":68,"tag":3181,"props":3304,"children":3305},{},[3306],{"type":74,"value":3192},{"type":74,"value":3308}," Apply the measure-specified lookback period (typically 2 years) for identifying members with qualifying conditions\n",{"type":68,"tag":3181,"props":3310,"children":3311},{},[3312],{"type":74,"value":3207},{"type":74,"value":3314}," Many HEDIS measures require a diagnosis in the measurement year OR the year prior; using only one year misses eligible members",{"type":68,"tag":3316,"props":3317,"children":3318},"style",{},[3319],{"type":74,"value":3320},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"items":3322,"total":681},[3323,3340,3355,3369,3382,3395,3408],{"slug":3324,"name":3324,"fn":3325,"description":3326,"org":3327,"tags":3328,"stars":26,"repoUrl":27,"updatedAt":3339},"aws-genai-ml-architect","design AWS GenAI and ML architectures","Reasoning skill for designing AWS GenAI and ML architectures for healthcare and life sciences workloads. Use when the user asks to choose between SageMaker and Bedrock, design a RAG system over medical literature, architect clinical NLP or medical imaging inference, plan genomics or drug discovery pipelines on AWS, address HIPAA\u002FPHI compliance in ML systems, design MLOps for regulated clinical models, or optimize cost for HCLS ML workloads. Triggers include \"AWS architecture\", \"SageMaker vs Bedrock\", \"HIPAA ML\", \"clinical RAG\", \"medical imaging inference\", \"genomics on AWS\", \"PHI training\", \"MLOps healthcare\", \"Bedrock guardrails\", \"HealthLake\", \"HCLS cloud architecture\", \"BAA compliance\", \"SageMaker endpoint\", \"Bedrock knowledge base\", \"clinical NLP on AWS\", \"FDA SaMD on AWS\".",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3329,3332,3333,3334,3336],{"name":3330,"slug":3331,"type":16},"Architecture","architecture",{"name":24,"slug":25,"type":16},{"name":18,"slug":19,"type":16},{"name":3335,"slug":41,"type":16},"Life Sciences",{"name":3337,"slug":3338,"type":16},"LLM","llm","2026-07-12T08:38:07.975937",{"slug":3341,"name":3341,"fn":3342,"description":3343,"org":3344,"tags":3345,"stars":26,"repoUrl":27,"updatedAt":3354},"biomarker-discovery","guide biomarker discovery and validation","Reason about biomarker discovery and validation in HCLS — classifying biomarker intent, choosing feature-selection and cross-validation strategies, avoiding leakage, and planning external replication. Use when the user asks to discover, develop, or validate a biomarker; select features from high-dimensional omics or clinical data; design a validation study; choose evaluation metrics; justify sample size; combine multi-omics signals; or assess clinical utility. Triggers include \"discover a biomarker\", \"validate biomarker\", \"prognostic vs predictive\", \"feature selection\", \"LASSO vs elastic net\", \"nested cross-validation\", \"data leakage\", \"C-index\", \"time-dependent AUC\", \"decision curve analysis\", \"external validation cohort\", \"events per variable\", \"optimism-corrected\", \"multi-omics integration\", \"clinical utility of a biomarker\", \"is this biomarker ready\".",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3346,3347,3350,3351],{"name":24,"slug":25,"type":16},{"name":3348,"slug":3349,"type":16},"Bioinformatics","bioinformatics",{"name":3335,"slug":41,"type":16},{"name":3352,"slug":3353,"type":16},"Research","research","2026-07-12T08:37:49.295301",{"slug":3356,"name":3356,"fn":3357,"description":3358,"org":3359,"tags":3360,"stars":26,"repoUrl":27,"updatedAt":3368},"cdisc-compliance","reason about CDISC SDTM and ADaM implementation","Reason about CDISC SDTM and ADaM implementation for regulatory submissions. Use when the user asks about SDTM domain mapping, ADaM dataset design, controlled terminology versioning, define.xml completeness, FDA or PMDA submission requirements, query prioritization by clinical impact, SUPPQUAL usage, or CDISC compliance review. Triggers include \"SDTM mapping\", \"ADaM dataset\", \"CDISC compliance\", \"controlled terminology\", \"define.xml\", \"FDA submission data\", \"PMDA submission\", \"SDTM domain\", \"ADSL\", \"ADAE\", \"ADLB\", \"BDS structure\", \"SUPPQUAL\", \"RELREC\", \"value-level metadata\", \"CDISC CT\", \"regulatory submission data standards\", \"eCTD datasets\", \"SDTM 3.3\", \"ADaM 1.1\", \"query prioritization\", \"clinical data review\".\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3361,3364,3365],{"name":3362,"slug":3363,"type":16},"Clinical Trials","clinical-trials",{"name":3335,"slug":41,"type":16},{"name":3366,"slug":3367,"type":16},"Regulatory Compliance","regulatory-compliance","2026-07-12T08:37:33.35594",{"slug":3370,"name":3370,"fn":3371,"description":3372,"org":3373,"tags":3374,"stars":26,"repoUrl":27,"updatedAt":3381},"cell-type-annotation","annotate single-cell RNA-seq clusters","Generate code to assign cell type labels to single-cell RNA-seq clusters using CellTypist, SingleR, marker-based annotation, or reference label transfer (scANVI\u002Fingest). Triggers on requests to \"annotate cell types\", \"label clusters\", \"run CellTypist\", \"SingleR annotation\", \"marker gene dotplot\", \"transfer labels from reference atlas\", \"cell identity\", \"automated annotation\", \"reference mapping\", \"scANVI label transfer\", \"canonical markers\", \"immune cell types\", \"hierarchical annotation\", \"majority voting CellTypist\", \"over-clustering annotation\".",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3375,3376,3377,3378],{"name":3348,"slug":3349,"type":16},{"name":21,"slug":22,"type":16},{"name":3335,"slug":41,"type":16},{"name":3379,"slug":3380,"type":16},"RNA-seq","rna-seq","2026-07-12T08:38:05.443454",{"slug":3383,"name":3383,"fn":3384,"description":3385,"org":3386,"tags":3387,"stars":26,"repoUrl":27,"updatedAt":3394},"cheminformatics","calculate molecular properties with RDKit","Cheminformatics pipeline for small-molecule property calculation, filtering, and similarity analysis using RDKit. Use when the user asks to compute molecular descriptors, filter compounds by Lipinski or Veber rules, detect PAINS, calculate fingerprint similarity, run matched molecular pair analysis, generate ADMET descriptors, or process SMILES. Triggers include \"RDKit\", \"molecular descriptors\", \"Lipinski\", \"rule of five\", \"Veber\", \"PAINS\", \"pan-assay interference\", \"Morgan fingerprint\", \"Tanimoto\", \"fingerprint similarity\", \"matched molecular pair\", \"MMP\", \"mmpdb\", \"ADMET\", \"druglikeness\", \"SMILES\", \"cheminformatics\", \"compound filtering\", \"chemical similarity\".",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3388,3389,3392,3393],{"name":3348,"slug":3349,"type":16},{"name":3390,"slug":3391,"type":16},"Chemistry","chemistry",{"name":21,"slug":22,"type":16},{"name":3352,"slug":3353,"type":16},"2026-07-12T08:37:28.334619",{"slug":3396,"name":3396,"fn":3397,"description":3398,"org":3399,"tags":3400,"stars":26,"repoUrl":27,"updatedAt":3407},"claims-analytics","analyze and parse healthcare claims data","Pipeline skill for healthcare claims data parsing, analysis, and fraud detection. Use when the user asks to parse X12 837 or 835 claim files, manipulate ICD-10 CPT or HCPCS codes, detect billing pattern anomalies, profile providers against specialty peers, identify outlier billing behavior, validate NCCI edits programmatically, detect duplicate claims, run Benford's law analysis on charges, build claims data pipelines, or analyze E&M code distributions. Triggers include \"parse X12 837\", \"parse 835\", \"claims SQL\", \"ICD-10 manipulation\", \"CPT code analysis\", \"provider profiling\", \"billing outlier\", \"NCCI validation code\", \"duplicate claim detection\", \"Benford's law charges\", \"claims ETL\", \"E&M distribution analysis\", \"claims analytics pipeline\".\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3401,3402,3403,3406],{"name":21,"slug":22,"type":16},{"name":18,"slug":19,"type":16},{"name":3404,"slug":3405,"type":16},"Insurance","insurance",{"name":3335,"slug":41,"type":16},"2026-07-12T08:37:34.815088",{"slug":3409,"name":3409,"fn":3410,"description":3411,"org":3412,"tags":3413,"stars":26,"repoUrl":27,"updatedAt":3417},"claims-billing-rules","analyze healthcare claims billing rules","Reasoning skill for healthcare claims billing rules and fraud detection logic. Use when the user asks about CMS billing rules, place of service codes, global surgery periods, modifier usage (25 59 76 77), NCCI edit logic, column 1 column 2 code pairs, mutually exclusive procedures, modifier indicators, fraud waste and abuse patterns, E&M upcoding, unbundling, phantom billing, impossible day detection, coding error versus fraud distinction, FWA investigation methodology, or claims audit logic. Triggers include \"CMS billing rules\", \"NCCI edits\", \"modifier 25\", \"modifier 59\", \"global surgery period\", \"upcoding\", \"unbundling\", \"phantom billing\", \"impossible day\", \"FWA\", \"fraud waste abuse\", \"coding error vs fraud\", \"claims audit\", \"billing compliance\", \"E&M level selection\".\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3414,3415,3416],{"name":18,"slug":19,"type":16},{"name":3404,"slug":3405,"type":16},{"name":3366,"slug":3367,"type":16},"2026-07-12T08:38:28.210856",{"items":3419,"total":3592},[3420,3439,3459,3469,3482,3495,3505,3515,3536,3549,3564,3579],{"slug":3421,"name":3421,"fn":3422,"description":3423,"org":3424,"tags":3425,"stars":3436,"repoUrl":3437,"updatedAt":3438},"agentcore-investigation","investigate Bedrock AgentCore runtime sessions","Investigate Bedrock AgentCore runtime sessions via CloudWatch Logs Insights — resolve session\u002Ftrace IDs, query OTEL spans, filter noise, build timelines. Use when debugging AgentCore agent sessions, tracing tool calls, or analyzing latency.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3426,3427,3430,3433],{"name":24,"slug":25,"type":16},{"name":3428,"slug":3429,"type":16},"Debugging","debugging",{"name":3431,"slug":3432,"type":16},"Logs","logs",{"name":3434,"slug":3435,"type":16},"Observability","observability",9427,"https:\u002F\u002Fgithub.com\u002Fawslabs\u002Fmcp","2026-07-12T08:37:22.601527",{"slug":3440,"name":3441,"fn":3442,"description":3443,"org":3444,"tags":3445,"stars":3436,"repoUrl":3437,"updatedAt":3458},"amazon-aurora-dsql","amazon aurora dsql","build applications with Aurora DSQL","Build with Aurora DSQL — manage schemas, execute queries, handle migrations, diagnose query plans, load data, and develop applications with a serverless, distributed SQL database. Covers IAM auth, multi-tenant patterns, MySQL-to-DSQL and PostgreSQL-to-DSQL schema conversion, FK replacement code generation, OCC retry patterns, ORM migration (Django\u002FHibernate\u002FRails), DDL operations, query plan explainability, SQL compatibility validation, and bulk data loading. Triggers on phrases like: DSQL, Aurora DSQL, create DSQL table, DSQL schema, migrate to DSQL, distributed SQL database, serverless PostgreSQL-compatible database, DSQL query plan, DSQL EXPLAIN ANALYZE, why is my DSQL query slow, DSQL foreign key, DSQL OCC retry, DSQL multi-region, load into DSQL, load CSV into DSQL, bulk load DSQL, aurora-dsql-loader.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3446,3449,3450,3453,3456],{"name":3447,"slug":3448,"type":16},"Aurora","aurora",{"name":24,"slug":25,"type":16},{"name":3451,"slug":3452,"type":16},"Database","database",{"name":3454,"slug":3455,"type":16},"Serverless","serverless",{"name":3457,"slug":698,"type":16},"SQL","2026-07-12T08:36:45.053393",{"slug":3460,"name":3461,"fn":3442,"description":3443,"org":3462,"tags":3463,"stars":3436,"repoUrl":3437,"updatedAt":3468},"aurora-dsql","aurora dsql",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3464,3465,3466,3467],{"name":24,"slug":25,"type":16},{"name":3451,"slug":3452,"type":16},{"name":3454,"slug":3455,"type":16},{"name":3457,"slug":698,"type":16},"2026-07-12T08:36:42.694299",{"slug":3470,"name":3471,"fn":3442,"description":3443,"org":3472,"tags":3473,"stars":3436,"repoUrl":3437,"updatedAt":3481},"aws-dsql","aws dsql",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3474,3475,3476,3479,3480],{"name":24,"slug":25,"type":16},{"name":3451,"slug":3452,"type":16},{"name":3477,"slug":3478,"type":16},"Migration","migration",{"name":3454,"slug":3455,"type":16},{"name":3457,"slug":698,"type":16},"2026-07-12T08:36:38.584057",{"slug":3483,"name":3484,"fn":3442,"description":3443,"org":3485,"tags":3486,"stars":3436,"repoUrl":3437,"updatedAt":3494},"distributed-postgres","distributed postgres",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3487,3488,3489,3492,3493],{"name":24,"slug":25,"type":16},{"name":3451,"slug":3452,"type":16},{"name":3490,"slug":3491,"type":16},"PostgreSQL","postgresql",{"name":3454,"slug":3455,"type":16},{"name":3457,"slug":698,"type":16},"2026-07-12T08:36:46.530743",{"slug":3496,"name":3497,"fn":3442,"description":3443,"org":3498,"tags":3499,"stars":3436,"repoUrl":3437,"updatedAt":3504},"distributed-sql","distributed sql",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3500,3501,3502,3503],{"name":24,"slug":25,"type":16},{"name":3451,"slug":3452,"type":16},{"name":3454,"slug":3455,"type":16},{"name":3457,"slug":698,"type":16},"2026-07-12T08:36:48.104182",{"slug":3506,"name":3506,"fn":3442,"description":3443,"org":3507,"tags":3508,"stars":3436,"repoUrl":3437,"updatedAt":3514},"dsql",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3509,3510,3511,3512,3513],{"name":24,"slug":25,"type":16},{"name":3451,"slug":3452,"type":16},{"name":3477,"slug":3478,"type":16},{"name":3454,"slug":3455,"type":16},{"name":3457,"slug":698,"type":16},"2026-07-12T08:36:36.374512",{"slug":3516,"name":3516,"fn":3517,"description":3518,"org":3519,"tags":3520,"stars":3533,"repoUrl":3534,"updatedAt":3535},"cost-efficiency-analyzer","analyze cost efficiency and expenses","Analyzes cost structure, cost efficiency, and expense management from P&L data. Use when the user asks about costs, expenses, COGS, operating expenses, cost ratios, cost control, spending efficiency, margin compression from cost side, or wants to understand where money is going. Also use for \"are we spending too much\", \"cost breakdown\", \"expense analysis\", or \"how efficient are our operations\". NOT for revenue or top-line analysis.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3521,3524,3527,3530],{"name":3522,"slug":3523,"type":16},"Accounting","accounting",{"name":3525,"slug":3526,"type":16},"Analytics","analytics",{"name":3528,"slug":3529,"type":16},"Cost Optimization","cost-optimization",{"name":3531,"slug":3532,"type":16},"Finance","finance",3176,"https:\u002F\u002Fgithub.com\u002Fawslabs\u002Fagentcore-samples","2026-07-12T08:40:03.29555",{"slug":3537,"name":3537,"fn":3538,"description":3539,"org":3540,"tags":3541,"stars":3533,"repoUrl":3534,"updatedAt":3548},"executive-financial-briefing","generate executive financial briefings","Generates a concise executive-level financial briefing or summary suitable for a CEO, CFO, or board presentation. Use when the user asks for a summary, briefing, executive summary, board update, financial overview, financial health check, or \"how is the business doing\". Covers the full P&L picture in one page. Also use for \"give me the highlights\", \"what do I need to know\", or \"quick financial update\".",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3542,3543,3544,3547],{"name":24,"slug":25,"type":16},{"name":3531,"slug":3532,"type":16},{"name":3545,"slug":3546,"type":16},"Management","management",{"name":14,"slug":15,"type":16},"2026-07-12T08:40:02.066471",{"slug":3550,"name":3550,"fn":3551,"description":3552,"org":3553,"tags":3554,"stars":3533,"repoUrl":3534,"updatedAt":3563},"multi-quarter-trend-analysis","analyze multi-quarter financial trends","Analyzes financial trends across multiple quarters by comparing P&L metrics over time. Use when the user wants to see trends, patterns, trajectories, or directional movement across 3 or more quarters. Also use for \"how are we trending\", \"show me the trend\", \"track performance over time\", \"quarter over quarter comparison across all quarters\", or any multi-period longitudinal analysis.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3555,3556,3557,3560],{"name":3525,"slug":3526,"type":16},{"name":3531,"slug":3532,"type":16},{"name":3558,"slug":3559,"type":16},"Financial Statements","financial-statements",{"name":3561,"slug":3562,"type":16},"Variance Analysis","variance-analysis","2026-07-12T08:40:00.79141",{"slug":3565,"name":3565,"fn":3566,"description":3567,"org":3568,"tags":3569,"stars":3533,"repoUrl":3534,"updatedAt":3578},"pdf","process and manipulate PDF documents","Use this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text\u002Ftables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting\u002Fdecrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3570,3573,3576],{"name":3571,"slug":3572,"type":16},"Automation","automation",{"name":3574,"slug":3575,"type":16},"Documents","documents",{"name":3577,"slug":3565,"type":16},"PDF","2026-07-12T08:41:44.135656",{"slug":3580,"name":3580,"fn":3581,"description":3582,"org":3583,"tags":3584,"stars":3533,"repoUrl":3534,"updatedAt":3591},"quarterly-kpi-calculator","calculate quarterly financial KPIs","Calculates quarterly financial KPIs from P&L data. P&L figures can be provided directly by the user or fetched from the financial data MCP server. Use when the user wants KPI calculations such as Gross Margin %, EBITDA Margin %, Operating Expense Ratio, or Revenue Growth % QoQ. Also use for quarterly performance review, P&L analysis, or interpreting financial ratios against benchmarks.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":11},[3585,3586,3587,3588],{"name":3522,"slug":3523,"type":16},{"name":21,"slug":22,"type":16},{"name":3531,"slug":3532,"type":16},{"name":3589,"slug":3590,"type":16},"KPI","kpi","2026-07-12T08:39:59.54971",150]