Feature: Support YTA arrival observation modes in get_prob_dist_by_service
Summary
Extend get_prob_dist_by_service so yet-to-arrive bed-demand PMFs can be built with observation_mode="arrived_in_window" (and optionally arrived_and_admitted_in_window) using an inpatient_arrivals frame — the same helper already used for ED-current and departures.
Simplify notebook 4d by replacing its hand-rolled YTA PMF loop with this API.
Problem
The evaluate layer supports arrived_in_window with inpatient_arrivals, but get_prob_dist_by_service does not:
validate_observation_mode_for_component only allows admitted_at_some_point and admitted_in_window for component="arrivals".
- Those modes require
ed_visits, which is wrong for YTA and direct-admission flows.
Notebook 4d works around this with nested loops calling yta_model.predict and count_observed per specialty and date, while ED-current PMFs in the same section already use get_prob_dist_by_service.
Proposed changes
aggregate.py — add inpatient_arrivals parameter and extend frame requirements:
component |
observation_mode |
Required frame |
arrivals |
admitted_at_some_point, admitted_in_window |
ed_visits |
arrivals |
arrived_in_window, arrived_and_admitted_in_window |
inpatient_arrivals |
departures |
departed_in_window |
inpatient_visits |
Update validate_observation_mode_for_component in observations.py accordingly. Pass inpatient_arrivals through to count_observed for observed counts in returned leaves.
For YTA-only FlowSelection (include_ed_yta=True, include_ed_current=False):
- Do not require
ed_visits.
- Do not require curve parameters
x1–y2 unless parametric in-window weighting is active.
- Keep using
build_service_data / DemandPredictor so predicted PMFs match production.
Notebook 4d — replace the hand-rolled YTA block in section 2b with:
flow_sel_ed_yta = FlowSelection.custom(
include_ed_current=False,
include_ed_yta=True,
include_non_ed_yta=False,
include_elective_yta=False,
include_transfers_in=False,
include_departures=False,
)
ed_yta_by_specialty = get_prob_dist_by_service(
ed_visits=None,
snapshot_dates=eval_snapshot_dates,
prediction_time=prediction_time,
models=service_models,
specialties=specialties,
prediction_window=prediction_window,
flow_selection=flow_sel_ed_yta,
component="arrivals",
observation_mode="arrived_in_window",
inpatient_arrivals=eval_inpatient_arrivals_df,
x1=x1, y1=y1, x2=x2, y2=y2,
verbose=False,
)
Acceptance criteria
Feature: Support YTA arrival observation modes in
get_prob_dist_by_serviceSummary
Extend
get_prob_dist_by_serviceso yet-to-arrive bed-demand PMFs can be built withobservation_mode="arrived_in_window"(and optionallyarrived_and_admitted_in_window) using aninpatient_arrivalsframe — the same helper already used for ED-current and departures.Simplify notebook 4d by replacing its hand-rolled YTA PMF loop with this API.
Problem
The evaluate layer supports
arrived_in_windowwithinpatient_arrivals, butget_prob_dist_by_servicedoes not:validate_observation_mode_for_componentonly allowsadmitted_at_some_pointandadmitted_in_windowforcomponent="arrivals".ed_visits, which is wrong for YTA and direct-admission flows.Notebook 4d works around this with nested loops calling
yta_model.predictandcount_observedper specialty and date, while ED-current PMFs in the same section already useget_prob_dist_by_service.Proposed changes
aggregate.py— addinpatient_arrivalsparameter and extend frame requirements:componentobservation_modearrivalsadmitted_at_some_point,admitted_in_windowed_visitsarrivalsarrived_in_window,arrived_and_admitted_in_windowinpatient_arrivalsdeparturesdeparted_in_windowinpatient_visitsUpdate
validate_observation_mode_for_componentinobservations.pyaccordingly. Passinpatient_arrivalsthrough tocount_observedfor observed counts in returned leaves.For YTA-only
FlowSelection(include_ed_yta=True,include_ed_current=False):ed_visits.x1–y2unless parametric in-window weighting is active.build_service_data/DemandPredictorso predicted PMFs match production.Notebook 4d — replace the hand-rolled YTA block in section 2b with:
Acceptance criteria
arrived_in_windowworks onget_prob_dist_by_servicewithinpatient_arrivalsand withouted_visits.admitted_in_windowstill requiresed_visits(regression).agg_predictedandagg_observedfor a minimal YTA fixture.tests/test_aggregate.py; CI green.