@concept_checker(concepts=["IS_EMERGENCY"])
def from_vo_visit_source_value(
visit_detail: DataFrame,
visit_occurrence: DataFrame,
) -> DataFrame:
"""
This algo uses the *"Type de dossier"* of each visit detail's parent visit occurrence.
Thus, a visit_detail will be tagged with `IS_EMERGENCY=True` iff the visit occurrence it belongs to
is an emergency-type visit (meaning that `visit_occurrence.visit_source_value=='urgence'`)
!!! aphp "Admission through ICU"
At AP-HP, when a patient is hospitalized after coming to the ICU, its `visit_source_value`
is set from `"urgence"` to `"hospitalisation complète"`. So you should keep in mind
that this method doesn't tag those visits as ICU.
Parameters
----------
visit_detail: DataFrame
visit_occurrence: DataFrame
Returns
-------
visit_detail: DataFrame
Dataframe with added columns corresponding to the following conceps:
- `"IS_EMERGENCY"`
"""
vo_emergency = visit_occurrence[["visit_occurrence_id", "visit_source_value"]]
vo_emergency["IS_EMERGENCY"] = visit_occurrence.visit_source_value == "urgence"
return visit_detail.merge(
vo_emergency[["visit_occurrence_id", "IS_EMERGENCY"]],
on="visit_occurrence_id",
how="left",
)