Skip to content

eds_scikit.event.suicide_attempt

tag_suicide_attempt

tag_suicide_attempt(visit_occurrence: DataFrame, condition_occurrence: DataFrame, date_min: Optional[datetime] = None, date_max: Optional[datetime] = None, algo: str = 'X60-X84') -> DataFrame

Function to return visits that fulfill different definitions of suicide attempt by ICD10.

PARAMETER DESCRIPTION
visit_occurrence

TYPE: DataFrame

condition_occurrence

TYPE: DataFrame

date_min

Minimal starting date (on visit_start_datetime)

TYPE: Optional[datetime] DEFAULT: None

date_max

Maximal starting date (on visit_start_datetime)

TYPE: Optional[datetime] DEFAULT: None

algo

Method to use. Available values are:

  • "X60-X84": Will return a the visits that have at least one ICD code that belongs to the range X60 to X84.
  • "Haguenoer2008": Will return a the visits that follow the definiton of "Haguenoer, Ken, Agnès Caille, Marc Fillatre, Anne Isabelle Lecuyer, et Emmanuel Rusch. « Tentatives de Suicide », 2008, 4.". This rule requires at least one Main Diagnostic (DP) belonging to S00 to T98, and at least one Associated Diagnostic (DAS) that belongs to the range X60 to X84.

TYPE: str DEFAULT: 'X60-X84'

RETURNS DESCRIPTION
visit_occurrence

Tagged with an additional column SUICIDE_ATTEMPT

TYPE: DataFrame

Tip

These rules were implemented in the CSE project n°210013

Source code in eds_scikit/event/suicide_attempt.py
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 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
121
122
123
124
125
126
127
128
129
@concept_checker(concepts=["SUICIDE_ATTEMPT"])
@algo_checker(algos=ALGOS)
def tag_suicide_attempt(
    visit_occurrence: DataFrame,
    condition_occurrence: DataFrame,
    date_min: Optional[datetime] = None,
    date_max: Optional[datetime] = None,
    algo: str = "X60-X84",
) -> DataFrame:
    """
    Function to return visits that fulfill different definitions of suicide attempt by ICD10.

    Parameters
    ----------
    visit_occurrence: DataFrame
    condition_occurrence: DataFrame
    date_min: datetime
        Minimal starting date (on `visit_start_datetime`)
    date_max: datetime
        Maximal starting date (on `visit_start_datetime`)
    algo: str
        Method to use. Available values are:

        - `"X60-X84"`: Will return a the visits that have at least one ICD code that belongs to the range X60 to X84.
        - `"Haguenoer2008"`: Will return a the visits that follow the definiton of "*Haguenoer, Ken, Agnès Caille, Marc Fillatre, Anne Isabelle Lecuyer, et Emmanuel Rusch. « Tentatives de Suicide », 2008, 4.*". This rule requires at least one Main Diagnostic (DP) belonging to S00 to T98, and at least one Associated Diagnostic (DAS) that belongs to the range X60 to X84.

    Returns
    -------
    visit_occurrence: DataFrame
        Tagged with an additional column `SUICIDE_ATTEMPT`

    !!! tip
         These rules were implemented in the CSE project n°210013

    """

    events_1 = conditions_from_icd10(
        condition_occurrence,
        visit_occurrence=visit_occurrence,
        date_min=date_min,
        date_max=date_max,
        **DEFAULT_CONFIG["X60-X84"],
    )

    events_1 = events_1[
        ["visit_occurrence_id", "condition_status_source_value"]
    ].drop_duplicates(subset="visit_occurrence_id")
    events_1[CONCEPT] = True

    if algo == "X60-X84":

        visit_occurrence_tagged = visit_occurrence.merge(
            events_1[["visit_occurrence_id", CONCEPT]],
            on="visit_occurrence_id",
            how="left",
        )

        visit_occurrence_tagged[CONCEPT].fillna(False, inplace=True)

        return visit_occurrence_tagged

    if algo == "Haguenoer2008":

        events_1 = events_1[events_1.condition_status_source_value == "DAS"]

        events_2 = conditions_from_icd10(
            condition_occurrence,
            visit_occurrence=visit_occurrence,
            date_min=date_min,
            date_max=date_max,
            **DEFAULT_CONFIG[algo],
        )

        events_2 = events_2[["visit_occurrence_id"]].drop_duplicates()
        events_2[f"{CONCEPT}_BIS"] = True

        visit_occurrence_tagged = visit_occurrence.merge(
            events_1[["visit_occurrence_id", CONCEPT]],
            on="visit_occurrence_id",
            how="left",
        ).merge(
            events_2[["visit_occurrence_id", f"{CONCEPT}_BIS"]],
            on="visit_occurrence_id",
            how="left",
        )

        visit_occurrence_tagged[CONCEPT] = (
            visit_occurrence_tagged[CONCEPT] & visit_occurrence_tagged[f"{CONCEPT}_BIS"]
        )

        visit_occurrence_tagged = visit_occurrence_tagged.drop(
            columns=[f"{CONCEPT}_BIS"]
        )

        return visit_occurrence_tagged