Skip to content

eds_scikit.event.ccam

procedures_from_ccam

procedures_from_ccam(procedure_occurrence: DataFrame, visit_occurrence: Optional[DataFrame] = None, codes: Optional[Dict[str, Union[str, List[str]]]] = None, date_from_visit: bool = True, additional_filtering = dict(), date_min: Optional[datetime] = None, date_max: Optional[datetime] = None) -> DataFrame

Phenotyping based on CCAM codes.

PARAMETER DESCRIPTION
procedure_occurrence

procedure_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 CCAM 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()

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 procedure_datetime, else contains visit_start_datetime
  • t_end: If date_from_visit is set to False, contains procedure_datetime, else contains visit_end_datetime
  • concept : contaning values from codes.keys()
  • value : The extracted CCAM code.
  • visit_occurrence_id : the visit_occurrence_id from the visit which contains the CCAM code.
Source code in eds_scikit/event/ccam.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
def procedures_from_ccam(
    procedure_occurrence: DataFrame,
    visit_occurrence: Optional[DataFrame] = None,
    codes: Optional[Dict[str, Union[str, List[str]]]] = None,
    date_from_visit: bool = True,
    additional_filtering=dict(),
    date_min: Optional[datetime] = None,
    date_max: Optional[datetime] = None,
) -> DataFrame:
    """

    Phenotyping based on CCAM codes.

    Parameters
    ----------
    procedure_occurrence : DataFrame
        `procedure_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 CCAM 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 `procedure_datetime`,
        else contains `visit_start_datetime`
        - `t_end`: If `date_from_visit` is set to `False`, contains `procedure_datetime`,
        else contains `visit_end_datetime`
        - `concept` : contaning values from `codes.keys()`
        - `value` : The extracted CCAM code.
        - `visit_occurrence_id` : the `visit_occurrence_id` from the visit which contains the CCAM code.
    """  # noqa: E501

    procedure_columns = dict(
        code_source_value="procedure_source_value",
        code_start_datetime="procedure_datetime",
        code_end_datetime="procedure_datetime",
    )
    events = []

    for concept, code_dict in codes.items():
        tmp_df = event_from_code(
            df=procedure_occurrence,
            columns=procedure_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(procedure_occurrence)
    return framework.concat(events)
Back to top