Compare nursing-facility capacity and patient-service margins in Python
Add report dates, SNF beds and net patient revenue to a facility roster, then calculate patient-service margins.
Add financial context to a nursing-facility roster
You have nursing-facility CMS Certification Numbers (CCNs) and want to compare financial scale and capacity. This example adds SNF beds, 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 facility 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 239 columns retained. The full $29 reference contains 14,587 reports for 13,988 CCNs, facility 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 facility selections, also supplied in input.csv.
roster = [
{'facility_ccn': '345180'},
{'facility_ccn': '345363'},
{'facility_ccn': '345542'},
]
def compare_facilities(roster, directory='.'):
selected = {row['facility_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['facility_ccn'] in selected:
reports.append(row)
results = []
for row in sorted(reports, key=lambda r: (r['facility_ccn'], r['period_start'], r['report_id'])):
result = {key: row[key] for key in [
'facility_ccn', 'report_id', 'facility_name', 'period_start', 'period_end',
'period_days', 'period_status', 'ccn_report_count', 'snf_beds', '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']
beds = row['snf_beds'] if row['snf_beds_status'] == 'reported' else row['snf_beds_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['facility_ccn']} | {row['facility_name']} | report {row['report_id']} | {period_text} | {beds} SNF beds | {revenue_text} net patient revenue | {margin_text} patient-service margin")
results.append(result)
for ccn in sorted(selected - {row['facility_ccn'] for row in reports}):
print(f'{ccn} | not in this file; no activity inferred')
return results
results = compare_facilities(roster)
Replace roster with your CCN selections or rows read from a CSV. Preserve identifiers as strings. Set directory when calling compare_facilities if the data are in another folder.
Analysis of the output
345180 | WESLEY PINES RETIREMENT HOME | report 1403224 | 2023-10-01 to 2024-09-30 (366 days) | 62 SNF beds | $10,696,635 net patient revenue | 2.01% patient-service margin
345363 | COMPASS HEALTHCARE & REHAB HAWFIELDS | report 1403226 | 2023-10-01 to 2024-09-30 (366 days) | 117 SNF beds | $10,672,702 net patient revenue | 4.48% patient-service margin
345542 | THE FOREST AT DUKE INC. | report 1402410 | 2023-10-01 to 2024-09-30 (366 days) | 58 SNF beds | $28,545,510 net patient revenue | -16.74% patient-service margin
Wesley Pines reports 62 SNF beds and $10,696,635 in net patient revenue for October 2023–September 2024. Its supplied patient-service income is $215,095. Dividing income by revenue gives 2.01%. The Forest at Duke 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, making the date comparison straightforward. Other reports in the full file cover different periods or lack dates. 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 excludes other income and expenses, so it is not a total net margin, reimbursement rate or care-quality ranking. The financial statements can cover a healthcare complex with services beyond its skilled nursing facility. snf_beds describes one component; it is shown as capacity context and is not used as the denominator for the financial ratio. Review service mix and reporting scope before drawing conclusions from differences between facilities.
The file also supplies operating expenses, net income, assets and liabilities. Total-complex, SNF and nursing-facility (NF) beds and days remain separate. 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. facility_ccn links to a roster but is not unique: 565 CCNs have multiple reports, all retained.
Use facility_coverage.csv to identify repeated CCNs, differing names, report lengths and missing periods. There are 226 reports with both fiscal dates missing; their period_status is missing_both and their dates and duration remain blank. No overlapping pairs were found among complete known intervals. That check says nothing about reports with unknown dates. 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 122 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 nursing-home quality, Medicare skilled-nursing utilization and hospital 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 Skilled Nursing Facility Cost Report, CostReportsnf_Final_24.csv. CMS’s methodology identifies a September 18, 2026 HCRIS extract; the distribution was modified October 5. ACD retained the source October 29, 2026 UTC and prepared the package October 30 UTC. Each report’s fiscal dates remain separate.
This public-use file is a subset of CMS-2540-2010 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.
The PDF’s net-patient-revenue prose reverses subtraction and swaps line descriptions. We retain the original definitions and supplied values with a review note. The example uses the supplied revenue and patient-service income without recalculating either from that prose. The legacy Total RUG Days field is retained without assuming it is a current payment-group classification.
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.