62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 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
116
117
118
119
120
@concept_checker(concepts=["IS_EMERGENCY", "EMERGENCY_TYPE"])
def from_mapping(
    care_site: DataFrame,
    version: Optional[str] = None,
) -> DataFrame:
    """This algo uses a labelled list of 201 emergency care sites.

    Those care sites were extracted and verified by Ariel COHEN,
    Judith LEBLANC, and an ER doctor validated them.

    Those emergency care sites are further divised into different categories,
    as defined in the concept 'EMERGENCY_TYPE'.
    The different categories are:

    - Urgences spécialisées
    - UHCD + Post-urgences
    - Urgences pédiatriques
    - Urgences générales adulte
    - Consultation urgences
    - SAMU / SMUR

    See the dataset [here](/datasets/care-site-emergency)

    Parameters
    ----------
    care_site: DataFrame
        Should at least contains the `care_site_source_value` column
    version: Optional[str]
        Optional version string for the mapping

    Returns
    -------
    care_site: DataFrame
        Dataframe with 2 added columns corresponding to the following concepts:

        - `"IS_EMERGENCY"`
        - `"EMERGENCY_TYPE"`

    """

    function_name = "get_care_site_emergency_mapping"
    if version is not None:
        function_name += f".{version}"

    mapping = registry.get("data", function_name=function_name)()

    # Getting the right framework
    fw = framework.get_framework(care_site)
    mapping = framework.to(fw, mapping)

    care_site = care_site.merge(
        mapping,
        how="left",
        on="care_site_source_value",
    )

    care_site["IS_EMERGENCY"] = care_site["EMERGENCY_TYPE"].notna()

    return care_site