Skip to content

Person

Bases: DestinationTable

CDM Person object class

Source code in docs/CaRROT-CDM/source_code/carrot/cdm/objects/versions/v5_3_1/person.py
 3
 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
58
59
60
61
62
63
class Person(DestinationTable):
    """
    CDM Person object class
    """
    name = 'person'
    def __init__(self,name=None):
        self.person_id                   = DestinationField(dtype="Integer"   , required=True , pk=True)
        self.gender_concept_id           = DestinationField(dtype="Integer"   , required=True )
        self.year_of_birth               = DestinationField(dtype="Integer"   , required=False )
        self.month_of_birth              = DestinationField(dtype="Integer"   , required=False )
        self.day_of_birth                = DestinationField(dtype="Integer"   , required=False )
        self.birth_datetime              = DestinationField(dtype="Timestamp" , required=True )
        self.race_concept_id             = DestinationField(dtype="Integer"   , required=False )
        self.ethnicity_concept_id        = DestinationField(dtype="Integer"   , required=False )
        self.location_id                 = DestinationField(dtype="Integer"   , required=False )
        self.provider_id                 = DestinationField(dtype="Integer"   , required=False )
        self.care_site_id                = DestinationField(dtype="Integer"   , required=False )
        self.person_source_value         = DestinationField(dtype="Text50"    , required=False )
        self.gender_source_value         = DestinationField(dtype="Text50"    , required=False )
        self.gender_source_concept_id    = DestinationField(dtype="Integer"   , required=False )
        self.race_source_value           = DestinationField(dtype="Text50"    , required=False )
        self.race_source_concept_id      = DestinationField(dtype="Integer"   , required=False )
        self.ethnicity_source_value      = DestinationField(dtype="Text50"    , required=False )
        self.ethnicity_source_concept_id = DestinationField(dtype="Integer"   , required=False )

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

    def finalise(self,df,**kwargs):
        """
        Overload the finalise function here for any specifics for the person table
        """
        df = super().finalise(df,**kwargs)
        return df


    def get_df(self,**kwargs):
        """
        Overload/append the creation of the dataframe, specifically for the person objects
        * year_of_birth is automatically converted to a year (int)
        * month_of_birth is automatically converted to a month (int)
        * day_of_birth is automatically converted to a day (int)
        * birth_datetime is automatically coverted to a datatime


        Returns:
           pandas.Dataframe: output dataframe
        """
        df = super().get_df(**kwargs)
        if self.automatically_fill_missing_columns == True:
            if df['year_of_birth'].isnull().all():
                df['year_of_birth'] = self.tools.get_year(df['birth_datetime'])

            if df['month_of_birth'].isnull().all():
                df['month_of_birth'] = self.tools.get_month(df['birth_datetime'])

            if df['day_of_birth'].isnull().all():
                df['day_of_birth'] = self.tools.get_day(df['birth_datetime'])

        return df

finalise(df, **kwargs)

Overload the finalise function here for any specifics for the person table

Source code in docs/CaRROT-CDM/source_code/carrot/cdm/objects/versions/v5_3_1/person.py
32
33
34
35
36
37
def finalise(self,df,**kwargs):
    """
    Overload the finalise function here for any specifics for the person table
    """
    df = super().finalise(df,**kwargs)
    return df

get_df(**kwargs)

Overload/append the creation of the dataframe, specifically for the person objects * year_of_birth is automatically converted to a year (int) * month_of_birth is automatically converted to a month (int) * day_of_birth is automatically converted to a day (int) * birth_datetime is automatically coverted to a datatime

Returns:

Type Description

pandas.Dataframe: output dataframe

Source code in docs/CaRROT-CDM/source_code/carrot/cdm/objects/versions/v5_3_1/person.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def get_df(self,**kwargs):
    """
    Overload/append the creation of the dataframe, specifically for the person objects
    * year_of_birth is automatically converted to a year (int)
    * month_of_birth is automatically converted to a month (int)
    * day_of_birth is automatically converted to a day (int)
    * birth_datetime is automatically coverted to a datatime


    Returns:
       pandas.Dataframe: output dataframe
    """
    df = super().get_df(**kwargs)
    if self.automatically_fill_missing_columns == True:
        if df['year_of_birth'].isnull().all():
            df['year_of_birth'] = self.tools.get_year(df['birth_datetime'])

        if df['month_of_birth'].isnull().all():
            df['month_of_birth'] = self.tools.get_month(df['birth_datetime'])

        if df['day_of_birth'].isnull().all():
            df['day_of_birth'] = self.tools.get_day(df['birth_datetime'])

    return df