Compare long-term care hospital activity and payments in Python

Add covered days, stays and Medicare payments to a facility roster, then calculate payment per covered day.

Add Medicare activity to a long-term care hospital roster

You have hospital CMS Certification Numbers (CCNs) and want to compare the scale of long-term care hospital activity. This example adds stays, covered days and Medicare payments, then calculates payment per covered day for fiscal 2024: October 2023–September 2024.

The optional input.csv contains three genuine North Carolina facility selections. The same CCNs appear in the roster list in the Python code below. No facility observations are invented.

Download facilities.csv into your working folder. It is a genuine subset of the purchased file: the three selected facilities with all 132 columns retained. The full $29 reference contains 323 hospitals, 46 separate geographic benchmarks 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 facilities.csv. It uses Python’s standard library and joins on fiscal year and CCN. The ratio is calculated only when payment and covered days are reported and the denominator is positive.

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 decimal import Decimal
from pathlib import Path

# Three real facility selections, also supplied in input.csv.
roster = [
    {'facility_ccn': '342012'},
    {'facility_ccn': '342013'},
    {'facility_ccn': '342014'},
]


def compare_facilities(roster, directory='.', fiscal_year='2024'):
    with (Path(directory) / 'facilities.csv').open(encoding='utf-8', newline='') as file:
        facilities = {}
        for row in csv.DictReader(file):
            key = (row['fiscal_year'], row['facility_ccn'])
            if row['summary_level'] != 'PROVIDER' or key in facilities:
                raise ValueError('Expected one facility row per fiscal year and CCN')
            facilities[key] = row
    results = []
    for selection in roster:
        ccn = selection['facility_ccn']
        facility = facilities.get((fiscal_year, ccn))
        result = dict(facility_ccn=ccn, facility_name='', covered_days='',
                      medicare_payment='', stays='', payment_per_covered_day='',
                      ratio_status='not_in_file')
        if facility:
            for field in ['facility_name', 'covered_days', 'medicare_payment', 'stays']:
                result[field] = facility[field]
            numerator_status = facility['medicare_payment_status']
            denominator_status = facility['covered_days_status']
            result['ratio_status'] = 'unavailable: ' + numerator_status + '/' + denominator_status
            if numerator_status == denominator_status == 'reported':
                days = Decimal(facility['covered_days'])
                result['ratio_status'] = 'zero_denominator'
                if days > 0:
                    ratio = Decimal(facility['medicare_payment']) / days
                    result.update(payment_per_covered_day=f'{ratio:.2f}', ratio_status='calculated')
            days = facility['covered_days'] if denominator_status == 'reported' else denominator_status
            stays = facility['stays'] if facility['stays_status'] == 'reported' else facility['stays_status']
            paid = f"${Decimal(facility['medicare_payment']):,.0f}" if numerator_status == 'reported' else numerator_status
            per_day = '$' + result['payment_per_covered_day'] if result['ratio_status'] == 'calculated' else result['ratio_status']
            print(f"{ccn} | {facility['facility_name']} | {days} covered days | {stays} stays | {paid} Medicare paid | {per_day} per covered day")
        else:
            print(f'{ccn} | not in this file; no zero activity inferred')
        results.append(result)
    return results


results = compare_facilities(roster)

Replace roster with your CCN selections or rows read from a CSV. Keep identifiers as strings to preserve leading zeros. Set directory when calling compare_facilities if the data are in another folder.

Analysis of the output

342012 | Kindred Hospital Greensboro | 3206 covered days | 122 stays | $6,375,570 Medicare paid | $1988.64 per covered day
342013 | Pam Specialty Hospital Of Rocky Mount | 5222 covered days | 195 stays | $8,409,031 Medicare paid | $1610.31 per covered day
342014 | Highsmith Rainey Memorial Hospital | 4019 covered days | 111 stays | $2,785,360 Medicare paid | $693.05 per covered day

Pam Specialty Hospital Of Rocky Mount reports 195 stays, 5,222 covered days and $8,409,031 in Medicare payments. Dividing the payment total by covered days gives $1,610.31 per covered day. These fields give a facility roster historical activity and payment context without requiring you to translate the original CMS variable names first.

The calculated ratio summarizes this facility’s fiscal-year activity. It is not a reimbursement schedule, current patient price or quality ranking. Patients and payment circumstances differ among facilities; these figures do not adjust for those differences. Covered days fall within the fiscal window, so dividing days by stays would not establish complete length of stay.

Reported zero remains zero. An unavailable input retains its status instead of becoming zero or a ratio. suppressed represents CMS’s asterisk. An absent CCN is labeled not_in_file, with no activity inferred.

Using the full dataset

Extract the purchased ZIP and replace the sample facilities.csv with the full file. The code runs unchanged. There is one record per fiscal_year + facility_ccn: 70 original source fields, 61 availability columns and a source-row number.

The remaining CSVs contain 45 state/jurisdiction benchmarks and one national benchmark, accounting for every source row, original field definitions and the source edition. Use published benchmarks for state or national comparisons; do not mix them into facility rows or assume summing facility beneficiaries gives unique people.

The full facility file also includes charges, allowed amounts, standardized payments, outlier payments, beneficiary characteristics, chronic-condition indicators and broad primary-diagnosis shares. Allowed amounts include beneficiary and third-party responsibility; they differ from Medicare payments. Geographic standardization is not severity adjustment. Diagnosis shares can overlap across a stay’s claims; the file does not supply individual MS-LTC-DRG or therapy-minute detail.

The hospital and care-facility selection page helps distinguish long-term care hospitals from acute inpatient hospitals, rehabilitation, skilled nursing, home health and hospice. Each product is a separate purchase with its own scope and dates; these links do not establish patient flows or shared facility identity.

Sources and versions

Source: CMS Medicare Post-Acute Care Utilization, Long-Term Care Hospital by Geography and Provider, FY2024. CMS modified the file August 11, 2026; ACD retained it October 28, 2026 UTC. The source YEAR_TYPE and methodology establish fiscal dates despite generic calendar dates in the catalog.

These are paid Medicare fee-for-service claims, excluding Medicare Advantage encounters. They are not all-payer activity, patient records or a current directory. CMS provides the original data free; ACD sells preparation, validation, documentation and delivery.

The original depression variable has conflicting descriptive prose, and the methodology’s IRF/LTCH identifier examples appear reversed. We retain the supplied records and definitions with review notes. Read the source and preparation record. Same-source processing improvements are included; genuinely new source editions may be sold separately.

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.