Join home health agency visits and payment groups in Python
Connect calendar-2024 agency nursing visits with a selected payment group’s periods and average Medicare payment.
Connect agency visits with payment-group activity
You have a home health agency roster and want to examine historical Medicare activity for the same payment group. This example adds agency nursing visits, group payment periods and average Medicare payment per period for three North Carolina agencies in calendar 2024.
The optional input.csv contains three genuine agency CMS Certification Numbers (CCNs), each paired with HIPPS code 3EC21. The same selections appear in the roster list in the Python code below. No agency observations are invented. This code represents a late, community-admitted period in the musculoskeletal rehabilitation group, with high functional impairment and a low comorbidity adjustment.
Download agencies.csv, agency_groups.csv and agency_coverage.csv into your working folder. These genuine subsets contain the three selected agencies, their three selected group records and their coverage records, retaining all 148, 55 and 10 columns respectively. The full $29 reference covers 8,609 agencies and 106,381 published agency/group records, with separate benchmarks. Review the complete product and coverage.
Code example
Run this standard-library Python code in a notebook cell, IPython or a script beside the three CSV files. Agency totals and coverage use year and CCN; group detail adds the HIPPS code.
Paths are relative to your working folder; use from pathlib import Path; print(Path.cwd()) to check it, or supply full paths.
import csv
from decimal import Decimal
from pathlib import Path
# These real agency/group selections also appear in example_input.csv.
roster = [
{"agency_ccn": "347001", "hipps_code": "3EC21"},
{"agency_ccn": "347002", "hipps_code": "3EC21"},
{"agency_ccn": "347005", "hipps_code": "3EC21"},
]
def compare_agencies(roster, directory=".", year="2024"):
directory = Path(directory)
def index(filename, keys):
result = {}
with (directory / filename).open(encoding="utf-8", newline="") as f:
for row in csv.DictReader(f):
if row["year"] != year:
continue
key = tuple(row[k] for k in keys)
if key in result:
raise ValueError(f"Duplicate key in {filename}: {key}")
result[key] = row
return result
agencies = index("agencies.csv", ["agency_ccn"])
groups = index("agency_groups.csv", ["agency_ccn", "hipps_code"])
coverage = index("agency_coverage.csv", ["agency_ccn"])
results = []
for item in roster:
ccn, code = item["agency_ccn"], item["hipps_code"]
agency, group = agencies.get((ccn,)), groups.get((ccn, code))
detail = coverage.get((ccn,), {})
results.append({
"agency_ccn": ccn, "hipps_code": code,
"agency_name": agency["agency_name"] if agency else "Not in agency file",
"agency_nursing_visits": agency["nursing_visits"] if agency else "",
"nursing_status": agency["nursing_visits_status"] if agency else "not_in_file",
"group_periods": group["payment_periods"] if group else "",
"group_average_payment": group["average_payment_per_period"] if group else "",
"group_status": group["average_payment_per_period_status"] if group else "not_in_public_group_file",
"published_group_rows": detail.get("published_group_rows", ""),
})
return results
results = compare_agencies(roster)
for row in results:
payment = (f"${Decimal(row['group_average_payment']):,.0f}"
if row["group_status"] == "reported" else row["group_status"])
visits = row["agency_nursing_visits"] if row["nursing_status"] == "reported" else row["nursing_status"]
print(f"{row['agency_ccn']} | {row['agency_name']} | agency nursing visits: {visits} | "
f"{row['hipps_code']} periods: {row['group_periods'] or 'unavailable'} | "
f"average Medicare payment/period: {payment}")
Replace roster with your own agency/group selections or rows read from a CSV. Keep identifiers as strings, including leading zeros. Set directory to the folder holding the files when calling compare_agencies.
Analysis of the output
347001 | Liberty Home Care, Llc | agency nursing visits: 2313 | 3EC21 periods: 21 | average Medicare payment/period: $1,737
347002 | Well Care Home Health | agency nursing visits: 35527 | 3EC21 periods: 333 | average Medicare payment/period: $1,546
347005 | Adoration Home Health | agency nursing visits: 3700 | 3EC21 periods: 30 | average Medicare payment/period: $1,686
For Well Care Home Health, the selected group has 333 payment periods and an average Medicare payment of $1,546 per period. The 35,527 nursing visits describe the whole agency’s published activity, not those 333 periods alone. That gives you agency context alongside a defined group comparison without confusing the two levels.
Do not sum agency nursing visits after joining an agency to several groups. The group file also repeats three agency therapy-visit totals; admission and comorbidity percentages repeat within their respective categories. The coverage file supplies the checked therapy-visit totals once per agency.
A reported zero is retained. A blank with suppressed preserves CMS’s asterisk, and source_limitation preserves its Puerto Rico dual-eligibility plus marker. A missing group is labeled not_in_public_group_file; it does not establish zero activity. The full coverage file distinguishes 5,738 agencies with published group detail from 2,871 without it.
These are 30-day payment periods, distinct from 60-day care certification or actual days of care. CMS excludes low-utilization payment adjustment (LUPA) periods from payment variables and group detail. Agency payment totals are not complete revenue, and group averages are not current patient prices or measures of care quality.
Using the full dataset
Extract the purchased ZIP and replace all three sample CSVs with their full counterparts. The code runs unchanged. The main agency table has one row per year + agency_ccn; group detail adds hipps_code. Both cover calendar 2024.
Eight CSVs supply agency summaries, group detail, agency coverage, two benchmark tables, complete source-row accounting, source-field mappings and source editions. Dictionaries document each measure’s scope; checksums and independent source reconciliation accompany them.
The original group file contains 22 allowed/paid average pairs across 20 rows that differ by $1, despite CMS’s statement that those amounts should agree. Both values remain intact. payment_average_consistency flags those rows, and source_discrepancies.json identifies every pair. The retained sources do not establish the cause.
Use the published state or national benchmark appropriate to your question. Do not append benchmark rows to agencies or expect sums to reproduce them: distinct beneficiaries overlap and suppression varies. Standardized payments adjust geography, not patient severity or quality.
The Home Health Agency & Quality Reference adds separately dated agency attributes and quality measures. Check historical CCN identity, names and measure reporting periods before joining. The hospital and care-facility selection page explains the other settings. These products are separate purchases.
Sources and versions
Source: CMS Medicare Post-Acute Care Utilization, Home Health Agency summary and group files, calendar 2024. Both distributions were modified August 11, 2026 and captured by ACD October 28, 2026 UTC. Both official dictionaries and the August 2026 methodology are retained with reviewed notes on repeated measures and inconsistent dictionary labels.
This is Original Medicare fee-for-service home health activity, not all payers, Medicare Advantage or patient-level claims. Names and locations are historical. The original government sources are free; ACD sells preparation, validation, documentation and delivery.
Same-source processing improvements are included; genuinely new source editions may be sold separately. No automatic refresh is promised. Read the source and preparation record.
Example checked October 28, 2026 against both these samples and the complete purchased files. Source and processing records, sample checksums · Expected result CSV. Independent preparation; no agency endorsement.