Compare home-health agency revenue, visits and patient-service margins in Python
Add report dates, service visits and net patient revenue to an agency roster, then calculate patient-service margins.
Add financial context to a home-health agency roster
You have home-health agency CMS Certification Numbers (CCNs) and want to compare financial scale and service activity. This example adds total visits, net patient revenue and report dates, then calculates patient-service income as a percentage of net patient revenue.
The optional input.csv contains three real North Carolina agency selections. The same CCNs appear in the roster list in the Python code below. The names and financial observations come from CMS; none are invented.
Download reports.csv into your working folder. It is a genuine subset of the purchased file: every report for these three CCNs, with all 399 columns retained. The full $29 reference contains 10,970 reports for 10,794 CCNs, agency report coverage and source documentation across five CSV tables. Review the complete product and coverage.
Code example
Run the code in a notebook cell, IPython or a script beside reports.csv. It uses Python’s standard library. All matching reports are printed with their dates; it does not pick a preferred filing or drop repeated CCNs.
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
# Real agency selections, also supplied in input.csv.
roster = [
{'agency_ccn': '347011'},
{'agency_ccn': '347031'},
{'agency_ccn': '347191'},
]
def compare_agencies(roster, directory='.'):
selected = {row['agency_ccn'] for row in roster}
reports = []
seen = set()
with (Path(directory) / 'reports.csv').open(encoding='utf-8', newline='') as file:
for row in csv.DictReader(file):
if row['report_id'] in seen:
raise ValueError('Duplicate report ID')
seen.add(row['report_id'])
if row['agency_ccn'] in selected:
reports.append(row)
results = []
for row in sorted(reports, key=lambda r: (r['agency_ccn'], r['period_start'], r['report_id'])):
result = {key: row[key] for key in [
'agency_ccn', 'report_id', 'agency_name', 'period_start', 'period_end',
'period_days', 'period_status', 'ccn_report_count', 'total_visits', 'net_patient_revenue',
'operating_expense', 'patient_service_income']}
result.update(patient_service_margin_pct='', margin_status='unavailable')
if row['net_patient_revenue_status'] == row['patient_service_income_status'] == 'reported':
revenue = Decimal(row['net_patient_revenue'])
result['margin_status'] = 'nonpositive_revenue'
if revenue > 0:
margin = Decimal(row['patient_service_income']) / revenue * 100
result.update(patient_service_margin_pct=f'{margin:.2f}', margin_status='calculated')
margin_text = result['patient_service_margin_pct'] + '%' if result['margin_status'] == 'calculated' else result['margin_status']
visits = row['total_visits'] if row['total_visits_status'] == 'reported' else row['total_visits_status']
revenue_text = f"${Decimal(row['net_patient_revenue']):,.0f}" if row['net_patient_revenue_status'] == 'reported' else row['net_patient_revenue_status']
period_text = f"{row['period_start']} to {row['period_end']} ({row['period_days']} days)" if row['period_status'] == 'reported' else row['period_status']
print(f"{row['agency_ccn']} | {row['agency_name']} | report {row['report_id']} | {period_text} | {visits} total visits | {revenue_text} net patient revenue | {margin_text} patient-service margin")
results.append(result)
for ccn in sorted(selected - {row['agency_ccn'] for row in reports}):
print(f'{ccn} | not in this file; no activity inferred')
return results
results = compare_agencies(roster)
Replace roster with your CCN selections or rows read from a CSV. Preserve identifiers as strings. Set directory when calling compare_agencies if the data are in another folder.
Analysis of the output
347011 | BROOKDALE HOME HEALTH RALEIGH | report 573038 | 2024-01-01 to 2024-12-31 (366 days) | 19704 total visits | $4,569,098 net patient revenue | 9.43% patient-service margin
347031 | CENTERWELL HOME HEALTH | report 591919 | 2024-01-01 to 2024-12-31 (366 days) | 51022 total visits | $11,236,243 net patient revenue | 44.03% patient-service margin
347191 | ATRIUM HEALTH AT HOME LINCOLN | report 596971 | 2024-01-01 to 2024-12-31 (366 days) | 12330 total visits | $2,282,315 net patient revenue | -35.67% patient-service margin
Brookdale Home Health Raleigh reports 19,704 visits and $4,569,098 in net patient revenue for calendar 2024. Its supplied patient-service income is $430,762. Dividing income by revenue gives 9.43%. Atrium Health at Home Lincoln reports negative patient-service income, so its calculated margin remains negative rather than being replaced with zero.
These three reports share a 366-day period. Other reports in the full file cover different fiscal periods. The 2024 CMS file edition is not a guarantee of a common calendar year; use the actual dates to choose a comparison group.
The ratio describes income from patient services relative to net patient revenue. It uses the supplied worksheet F-1 line 18 income and line 3 column 4 revenue. It excludes other income, so it is not a total net margin, reimbursement rate or care-quality ranking. Review service mix and reporting scope before drawing conclusions from differences between agencies.
Visits describe service activity, not unique patients or Medicare payment periods. A patient can receive several visits and appear in more than one discipline’s patient census. The total-visits field is displayed as context; it is not the denominator of the financial ratio. The file also supplies discipline and payer detail, operating expenses, assets, liabilities and affiliated HHA-based hospice fields.
A numeric blank stays unavailable, reported zero stays zero, and the example calculates a margin only when both inputs are reported and revenue is positive. An absent CCN is printed as not in this file, without inferring zero activity.
Using the full dataset
Extract the purchased ZIP and replace the sample reports.csv with the full file. The code runs unchanged. Its unique key is report_id, the CMS report record number. agency_ccn links to a roster but is not unique: 174 CCNs have multiple reports, all retained.
Use agency_coverage.csv to identify repeated CCNs, differing names and report lengths. All fiscal dates are present in this edition, and no overlapping report pairs were found within a CCN. The source does not supply filing status or acceptance timestamps, so the highest report number is not a documented rule for choosing a preferred filing.
Every original source field is retained under a documented name. Additional CSVs account for every source row, map all 201 fields to original CMS worksheet definitions, and record the edition and source dates. The original CMS dictionary and methodology PDFs, full dictionaries, validation results and this example are included.
The hospital and care-facility selection page links to home-health quality, Medicare home-health utilization and other care-setting finances. These are separate purchases with their own dates and scope. Review historical CCN identity and periods before joining; financial reports, quality measures and Medicare claims answer different questions.
Sources and versions
Source: CMS Home Health Agency Cost Report, CostReport_HHA_2024.csv. CMS’s methodology identifies a September 18, 2026 HCRIS extract; the distribution was modified September 30. ACD retained the source and prepared this package October 30, 2026 UTC. Each report’s fiscal dates remain separate.
This public-use file is a subset of CMS-1728-2020 cost-report information. It is not a complete HCRIS export, current directory or collection of independently audited statements. Original government data are free; ACD sells preparation, validation, documentation and delivery.
Read the source and preparation record. Same-source processing improvements are included; genuinely new source editions may be sold separately.
Example checked October 30, 2026 against both these samples and the complete purchased files. Source and processing records, sample checksums · Expected result CSV. Independent preparation; no agency endorsement.