Skip to content

NHSN hospital admissions

Data access

get_nhsn_hrd

get_nhsn_hrd(disease: str | Iterable[str] | None = None, state_abb: str | Iterable[str] | None = None, prelim: bool = ..., as_of: date | None = ..., start_date: date | None = ..., end_date: date | None = ..., lazy: Literal[True] = ...) -> LazyFrame
get_nhsn_hrd(disease: str | Iterable[str] | None = None, state_abb: str | Iterable[str] | None = None, prelim: bool = ..., as_of: date | None = ..., start_date: date | None = ..., end_date: date | None = ..., lazy: Literal[False] = ...) -> DataFrame
get_nhsn_hrd(disease: str | Iterable[str] | None = None, state_abb: str | Iterable[str] | None = None, prelim: bool = True, as_of: date | None = None, start_date: date | None = None, end_date: date | None = None, lazy: bool = True) -> DataFrame | LazyFrame

Retrieve and filter NHSN hospital respiratory data based on specified criteria.

This function retrieves vintages of NHSN hrd data specified by the as_of date from the datacat.public.stf catalog, applies filters for a specific disease, location, and dates if provided.

Parameters:

Name Type Description Default
disease str | Iterable[str] | None

The canonical disease name to filter for ("covid", "flu", or "rsv"). If None, all diseases are included.

None
state_abb str | Iterable[str] | None

The location abbreviation to filter for. If None, all locations are included.

None
prelim bool

Whether to retrieve "nhsn_hrd_prelim" data as opposed to "nhsn_hrd" data (defaults to True).

True
as_of date | None

The reference date for filtering. If None, the most recent 'as_of' date is used.

None
start_date date | None

The start date for the time period to include. If None, no lower bound is applied.

None
end_date date | None

The end date for the time period to include. If None, no upper bound is applied.

None
lazy bool

Whether to return a lazy frame (defaults to True). If True, returns a pl.LazyFrame; if False, returns a pl.DataFrame.

True

Returns:

Type Description
DataFrame | LazyFrame

Filtered data in long format with columns: date, state_abb, disease, target_type, and value. target_type is always "wk inc hosp", and value is the corresponding weekly incident hospital-admissions count.

Version resolution

resolve_nhsn_hrd_version

resolve_nhsn_hrd_version(prelim: bool = True, as_of: date | None = None) -> datetime | str | None

Resolve the catalog version that get_nhsn_hrd would load.

Parameters:

Name Type Description Default
prelim bool

Whether to resolve the nhsn_hrd_prelim dataset rather than nhsn_hrd.

True
as_of date | None

The latest catalog version date to consider. If None, resolves the most recent available version.

None

Returns:

Type Description
datetime | str | None

The selected catalog version converted to a datetime when possible, or None if no version matches.