Skip to content

eds_scikit.event.icd10

conditions_from_icd10

conditions_from_icd10(condition_occurrence: DataFrame, visit_occurrence: Optional[DataFrame] = None, codes: Optional[Dict[str, Union[str, List[str]]]] = None, date_from_visit: bool = True, additional_filtering: Dict[str, Any] = dict(condition_status_source_value={'DP', 'DAS'}), date_min: Optional[datetime] = None, date_max: Optional[datetime] = None) -> DataFrame

Phenotyping based on ICD-10 codes.

PARAMETER DESCRIPTION
condition_occurrence

condition_occurrence OMOP DataFrame.

TYPE: DataFrame

visit_occurrence

visit_occurrence OMOP DataFrame, only necessary if date_from_visit is set to True.

TYPE: Optional[DataFrame] DEFAULT: None

codes

Dictionary which values are ICD-10 codes (as a unique string or as a list) and which keys are at least one of the following:

  • exact: To match the codes in codes["exact"] exactly
  • prefix: To match the codes in codes["prefix"] as prefixes
  • regex: To match the codes in codes["regex"] as regexes You can combine any of those keys.

TYPE: Dict[str, Union[str, List[str]]] DEFAULT: None

date_from_visit

If set to True, uses visit_start_datetime as the code datetime

TYPE: bool DEFAULT: True

additional_filtering

An optional dictionary to filter the resulting DataFrame.

Keys should be column names on which to filter, and values should be either

  • A single value
  • A list or set of values.

TYPE: Dict[str, Any] DEFAULT: dict(condition_status_source_value={'DP', 'DAS'})

date_min

The minimum code datetime to keep. Depends on the date_from_visit flag

TYPE: Optional[datetime] DEFAULT: None

date_max

The minimum code datetime to keep. Depends on the date_from_visit flag

TYPE: Optional[datetime] DEFAULT: None

RETURNS DESCRIPTION
DataFrame

"event" DataFrame including the following columns:

  • t_start: If date_from_visit is set to False, contains condition_start_datetime, else contains visit_start_datetime
  • t_end: If date_from_visit is set to False, contains condition_start_datetime, else contains visit_end_datetime
  • concept : contaning values from codes.keys()
  • value : The extracted ICD-10 code.
  • visit_occurrence_id : the visit_occurrence_id from the visit which contains the ICD-10 code.
Source code in eds_scikit/event/icd10.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
def conditions_from_icd10(
    condition_occurrence: DataFrame,
    visit_occurrence: Optional[DataFrame] = None,
    codes: Optional[Dict[str, Union[str, List[str]]]] = None,
    date_from_visit: bool = True,
    additional_filtering: Dict[str, Any] = dict(
        condition_status_source_value={"DP", "DAS"}
    ),
    date_min: Optional[datetime] = None,
    date_max: Optional[datetime] = None,
) -> DataFrame:
    """

    Phenotyping based on ICD-10 codes.

    Parameters
    ----------
    condition_occurrence : DataFrame
        `condition_occurrence` OMOP DataFrame.
    visit_occurrence : Optional[DataFrame]
        `visit_occurrence` OMOP DataFrame, only necessary if `date_from_visit` is set to `True`.
    codes : Dict[str, Union[str, List[str]]]
        Dictionary which values are ICD-10 codes (as a unique string or as a list) and which keys are
        at least one of the following:

        - `exact`: To match the codes in `codes["exact"]` **exactly**
        - `prefix`: To match the codes in `codes["prefix"]` **as prefixes**
        - `regex`: To match the codes in `codes["regex"]` **as regexes**
        You can combine any of those keys.
    date_from_visit : bool
        If set to `True`, uses `visit_start_datetime` as the code datetime
    additional_filtering : Dict[str, Any]
        An optional dictionary to filter the resulting DataFrame.

        Keys should be column names on which to filter, and values should be either

        - A single value
        - A list or set of values.
    date_min : Optional[datetime]
        The minimum code datetime to keep. **Depends on the `date_from_visit` flag**
    date_max : Optional[datetime]
        The minimum code datetime to keep. **Depends on the `date_from_visit` flag**

    Returns
    -------
    DataFrame
        "event" DataFrame including the following columns:

        - `t_start`: If `date_from_visit` is set to `False`, contains `condition_start_datetime`,
        else contains `visit_start_datetime`
        - `t_end`: If `date_from_visit` is set to `False`, contains `condition_start_datetime`,
        else contains `visit_end_datetime`
        - `concept` : contaning values from `codes.keys()`
        - `value` : The extracted ICD-10 code.
        - `visit_occurrence_id` : the `visit_occurrence_id` from the visit which contains the ICD-10 code.
    """  # noqa: E501

    condition_columns = dict(
        code_source_value="condition_source_value",
        code_start_datetime="condition_start_datetime",
        code_end_datetime="condition_start_datetime",
    )
    events = []

    for concept, code_dict in codes.items():
        tmp_df = event_from_code(
            df=condition_occurrence,
            columns=condition_columns,
            visit_occurrence=visit_occurrence,
            concept=concept,
            codes=code_dict,
            date_from_visit=date_from_visit,
            additional_filtering=additional_filtering,
            date_min=date_min,
            date_max=date_max,
        )

        events.append(tmp_df)

    framework = get_framework(condition_occurrence)
    return framework.concat(events)