81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@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",
    )