Skip to content

Drug Exposure

Bases: DestinationTable

CDM Drug Exposure object class

Source code in docs/CaRROT-CDM/source_code/carrot/cdm/objects/versions/v5_3_1/drug_exposure.py
 4
 5
 6
 7
 8
 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
class DrugExposure(DestinationTable):
    """
    CDM Drug Exposure object class
    """

    name = 'drug_exposure'
    def __init__(self,name=None):
        self.drug_exposure_id             = DestinationField(dtype="Integer"   , required=True , pk=True)
        self.person_id                    = DestinationField(dtype="Integer"   , required=True )
        self.drug_concept_id              = DestinationField(dtype="Integer"   , required=True )
        self.drug_exposure_start_date     = DestinationField(dtype="Date"      , required=False )
        self.drug_exposure_start_datetime = DestinationField(dtype="Timestamp" , required=True )
        self.drug_exposure_end_date       = DestinationField(dtype="Date"      , required=False )
        self.drug_exposure_end_datetime   = DestinationField(dtype="Timestamp" , required=False )
        self.verbatim_end_date            = DestinationField(dtype="Date"      , required=False )
        self.drug_type_concept_id         = DestinationField(dtype="Integer"   , required=False )
        self.stop_reason                  = DestinationField(dtype="Text20"    , required=False )
        self.refills                      = DestinationField(dtype="Integer"   , required=False )
        self.quantity                     = DestinationField(dtype="Float"     , required=False )
        self.days_supply                  = DestinationField(dtype="Integer"   , required=False )
        self.sig                          = DestinationField(dtype="Integer"   , required=False )
        self.route_concept_id             = DestinationField(dtype="Integer"   , required=False )
        self.lot_number                   = DestinationField(dtype="Text50"    , required=False )
        self.provider_id                  = DestinationField(dtype="Integer"   , required=False )
        self.visit_occurrence_id          = DestinationField(dtype="Integer"   , required=False )
        self.drug_source_value            = DestinationField(dtype="Text50"    , required=False )
        self.drug_source_concept_id       = DestinationField(dtype="Integer"   , required=False )
        self.route_source_value           = DestinationField(dtype="Text50"    , required=False )
        self.dose_unit_source_value       = DestinationField(dtype="Text50"    , required=False )

        if name is None:
            name = hex(id(self))
        super().__init__(name,self.name)


    def get_df(self,**kwargs):
        """
        Overload/append the creation of the dataframe, specifically for the drug_exposure objects
        * drug_concept_id  is required to be not null
          this can happen when spawning multiple rows from a person
          we just want to keep the ones that have actually been filled

        Returns:
           pandas.Dataframe: output dataframe
        """

        df = super().get_df(**kwargs)
        if self.automatically_fill_missing_columns == True:
            if df['drug_exposure_start_date'].isnull().all():
                df['drug_exposure_start_date'] = self.tools.get_date(df['drug_exposure_start_datetime'])

            if df['drug_exposure_end_date'].isnull().all():
                df['drug_exposure_end_date'] = self.tools.get_date(df['drug_exposure_end_datetime'])
        return df

get_df(**kwargs)

Overload/append the creation of the dataframe, specifically for the drug_exposure objects * drug_concept_id is required to be not null this can happen when spawning multiple rows from a person we just want to keep the ones that have actually been filled

Returns:

Type Description

pandas.Dataframe: output dataframe

Source code in docs/CaRROT-CDM/source_code/carrot/cdm/objects/versions/v5_3_1/drug_exposure.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def get_df(self,**kwargs):
    """
    Overload/append the creation of the dataframe, specifically for the drug_exposure objects
    * drug_concept_id  is required to be not null
      this can happen when spawning multiple rows from a person
      we just want to keep the ones that have actually been filled

    Returns:
       pandas.Dataframe: output dataframe
    """

    df = super().get_df(**kwargs)
    if self.automatically_fill_missing_columns == True:
        if df['drug_exposure_start_date'].isnull().all():
            df['drug_exposure_start_date'] = self.tools.get_date(df['drug_exposure_start_datetime'])

        if df['drug_exposure_end_date'].isnull().all():
            df['drug_exposure_end_date'] = self.tools.get_date(df['drug_exposure_end_datetime'])
    return df