Compare dialysis treatment costs and finances in Python

Compare reported treatment costs and patient-service financial margins for a real facility roster.

Compare treatment costs across dialysis facilities

You have a roster of dialysis facility CMS Certification Numbers (CCNs) and want to compare operating costs and financial results. This example adds each facility’s reported adult maintenance hemodialysis cost per treatment, then calculates a separate patient-service margin from its financial statement.

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 purchased package calls this file example_input.csv. Names, treatment counts and financial values come from CMS; none are invented.

Download reports.csv into your working folder. This is a genuine subset of the paid file: every report for the three selected CCNs, with all 356 columns. The full $29 reference contains 7,305 reports for 7,293 facilities, with coverage and source documentation across five CSV tables. Review the complete product and coverage.

Code example

Run this code in a notebook cell, IPython or a script beside reports.csv. It uses Python’s standard library and retains every matching report.

Paths are relative to your working folder; use from pathlib import Path; print(Path.cwd()) to check it, or supply full paths.

Python 3.10+ · Jupyter, IPython or a script
import csv
from collections import defaultdict
from decimal import Decimal, ROUND_HALF_UP
from pathlib import Path

# These real facility CCNs also appear in example_input.csv.
roster = [{'facility_ccn': '342521'}, {'facility_ccn': '342546'}, {'facility_ccn': '342617'}]
data_directory = Path('.')

reports = defaultdict(list)
with (data_directory / 'reports.csv').open(encoding='utf-8', newline='') as source:
    for row in csv.DictReader(source):
        reports[row['facility_ccn']].append(row)

results = []
for item in roster:
    matches = reports.get(item['facility_ccn'], [])
    if not matches:
        print(item['facility_ccn'], 'has no report in this source edition')
    for report in matches:  # Keep every report; CCN alone is not unique.
        revenue = report['net_patient_revenue']
        income = report['patient_service_income']
        margin = ''
        if (report['net_patient_revenue_status'] == 'reported'
                and report['patient_service_income_status'] == 'reported'
                and Decimal(revenue) > 0):
            margin = str((Decimal(income) / Decimal(revenue) * 100).quantize(
                Decimal('0.01'), rounding=ROUND_HALF_UP))
        results.append({
            'facility_ccn': report['facility_ccn'],
            'facility_name': report['facility_name'],
            'report_id': report['report_id'],
            'period_start': report['period_start'],
            'period_end': report['period_end'],
            'adult_hemodialysis_treatments': report['maintenance_hemo_adult_activity'],
            'adult_hemodialysis_cost_per_treatment': report['maintenance_hemo_adult_cost_per_treatment'],
            'net_patient_revenue': revenue,
            'patient_service_margin_percent': margin,
        })

for row in results:
    print(f"{row['facility_ccn']} | {row['facility_name']} | report {row['report_id']}")
    print(f"  {row['period_start']} to {row['period_end']} | adult maintenance hemodialysis treatments: {row['adult_hemodialysis_treatments'] or 'not supplied'}")
    print(f"  Reported cost/treatment: ${row['adult_hemodialysis_cost_per_treatment'] or 'not supplied'} | net patient revenue: ${row['net_patient_revenue'] or 'not supplied'} | patient-service margin: {row['patient_service_margin_percent'] + '%' if row['patient_service_margin_percent'] else 'not calculated'}")

Replace roster with your own CCN selections or rows read from a CSV, preserving identifiers as strings. Change data_directory if the data are in another folder.

Analysis of the output

342521 | SEDC - WHITEVILLE #594 | report 395967
  2024-01-01 to 2024-12-31 | adult maintenance hemodialysis treatments: 7934
  Reported cost/treatment: $272.57 | net patient revenue: $2671740 | patient-service margin: 8.60%
342546 | DIALYSIS CARE OF ROWAN COUNTY #582 | report 395980
  2024-01-01 to 2024-12-31 | adult maintenance hemodialysis treatments: 12116
  Reported cost/treatment: $249.7 | net patient revenue: $5641092 | patient-service margin: 14.54%
342617 | CAROLINA DIALYSIS - PITTSBORO | report 400776
  2024-01-01 to 2024-12-31 | adult maintenance hemodialysis treatments: 4816
  Reported cost/treatment: $340.14 | net patient revenue: $1538330 | patient-service margin: -8.26%

SEDC – Whiteville reports 7,934 adult maintenance hemodialysis treatments at an allocated cost of $272.57 per treatment. Rowan County reports $249.70; Carolina Dialysis – Pittsboro reports $340.14. These are source-reported worksheet C values for one modality, preserving CMS’s rounding. They are not Medicare payment rates.

The financial comparison answers a different question. Whiteville reports $229,776 in income from patient services and $2,671,740 in net patient revenue, giving a patient-service margin of 8.60%. Rowan’s corresponding margin is 14.54%, while Pittsboro’s is −8.26%. The formula is F-1 line 18 column 2 divided by positive line 3 column 2, multiplied by 100. It excludes other income and uses the facility’s patient-service finances, not only adult hemodialysis.

All three example reports cover January–December 2024. Elsewhere in the file, fiscal periods differ. Before interpreting cost or margin differences, review the reporting period, modality mix and underlying cost allocation. These values do not measure care quality or establish why costs differ.

The broader file keeps home CAPD and CCPD activity in patient weeks, while other modalities use treatments. Their costs per unit cannot be compared as though the units were identical. Patient counts at period end and staffing FTEs also remain distinct from treatment activity.

An omitted source coordinate stays source_cell_absent; an existing empty value is source_blank. Neither becomes zero. The code calculates a margin only when the required values are supplied and revenue is positive. An unmatched input CCN gets an explicit message.

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; twelve facility_ccn values have two reports. Use facility_coverage.csv to inspect report counts and actual fiscal dates.

source_fields.csv documents the 165 selected worksheet cells and their units. All 18 original report fields remain, including CMS filing status. Other worksheet coordinates are accounted for in source_accounting.csv and retained in the original archives; they are outside the prepared field set sold here.

Connecting to facility and quality information

The separately purchased Dialysis Facility & Quality Reference uses facility_id for the same six-character CMS CCN. Match that field to facility_ccn, retaining every financial report. All three example CCNs occur in its July 2026 edition. That establishes code matches, not unchanged ownership or aligned periods: quality observations have their own measurement dates, and the financial file covers freestanding facilities with fiscal years ending in 2024.

The hospital and care-facility selection page explains the separate financial, quality and utilization products. Each is an independent purchase.

Sources and versions

CMS RNL11 all-years archive, specifically its 2024 RPT, ALPHA and NMRC files. The source selects fiscal years ending January 1–December 31, 2024; actual reporting periods extend from January 2023 through December 2024. Hospital-based dialysis uses a different reporting form.

The archive was last modified October 5, 2026 and captured October 31, 2026 UTC. The exact HCRIS extraction date is not supplied. ACD processing revision 1 joins reports to reviewed worksheet coordinates and checks them against the originals. This is a curated reference, not a complete HCRIS export or an independent audit of provider accounts.

CMS originals are free. ACD sells preparation, validation, documentation and delivery. Read the source and preparation record. Processing improvements for these retained inputs are included; genuinely new source editions may be sold separately.

Example checked October 31, 2026 against both these samples and the complete purchased files. Source and processing records, sample checksums · Expected result CSV. Independent preparation; no agency endorsement.