def set_interpretation(self, value, lower_limit, upper_limit):
        """Extends superclass for convenience

        Set the interpretation

        Keyword arguments:
        value -- observation value
        lower_limit -- the lower normal
        upper_limit -- the upper normal
        """
        # TODO: Interpretation is complicated

        if value and lower_limit and upper_limit:
            interp = supermod.CodeableConcept()
            interp.coding = [supermod.Coding()]
            if value < lower_limit:
                v = 'L'
                d = 'Low'
            elif value > upper_limit:
                v = 'H'
                d = 'High'
            else:
                v = 'N'
                d = 'Normal'
            interp.coding[0].system = supermod.uri(
                value='http://hl7.org/fhir/v2/0078')
            interp.coding[0].code = supermod.code(value=v)
            interp.coding[0].display = supermod.string(value=d)
            super(health_Observation, self).set_interpretation(interp)
    def set_referenceRange(self, units, lower_limit, upper_limit):
        """Extends superclass for convenience

        Set reference range from data model

        Keyword arguments:
        units -- units name
        lower_limit -- lower limit
        upper_limit -- upper limit
        """

        if units is not None \
                and lower_limit is not None \
                and upper_limit is not None:
            ref = supermod.Observation_ReferenceRange()
            #ref.age = supermod.Range() #Not relevant, usually
            ref.low = supermod.Quantity()
            ref.high = supermod.Quantity()
            ref.low.units = ref.high.units = supermod.string(value=units)
            ref.low.value = supermod.decimal(value=lower_limit)
            ref.high.value = supermod.decimal(value=upper_limit)
            ref.meaning = supermod.Coding()
            ref.meaning.system = supermod.uri(
                value='http://hl7.org/fhir/referencerange-meaning')
            ref.meaning.code = supermod.code(value='normal')
            ref.meaning.display = supermod.string(value='Normal range')
            super(health_Observation, self).set_referenceRange([ref])
    def set_maritalStatus(self, marital_status):
        """Extends superclass for convenience

        Set the marital status

        Keyword arguments:
        marital_status --  marital status code
        """

        from fhir.value_sets import maritalStatus as ms
        #Health has concubinage and separated, which aren't truly
        # matching to the FHIR defined statuses
        if marital_status:
            us = marital_status.upper()  #Codes are uppercase
            fhir_status = [x for x in ms.contents\
                                    if x['code'] == us]
            if fhir_status:
                code = supermod.code(value=fhir_status[0]['code'])
                display = supermod.string(value=fhir_status[0]['display'])
            else:
                code = supermod.code(value='OTH')
                display = supermod.string(value='other')
            coding = supermod.Coding(system=supermod.uri(
                value='http://hl7.org/fhir/v3/MaritalStatus'),
                                     code=code,
                                     display=display)
            ms = supermod.CodeableConcept(coding=[coding])
            super(health_Patient, self).set_maritalStatus(ms)
Esempio n. 4
0
    def set_relation(self, familyHistory):
        """Extends superclass for convenience

        Keyword arguments:
        familyHistory -- the relatives
        """

        # TODO Combine multiple conditions for same person
        from fhir.value_sets import familyMember
        for member in familyHistory:
            rel = supermod.FamilyHistory_Relation()
            rel.relationship = supermod.CodeableConcept()

            # Add relationship
            t = {'s': 'sibling', 'm': 'maternal', 'f': 'paternal'}
            k = ' '.join((t.get(member.xory, ''), member.relative))
            info = [d for d in familyMember.contents if d['display'] == k]

            c = supermod.Coding()
            if info:
                c.code = supermod.code(value=info[0]['code'])
                c.system = supermod.uri(value=info[0]['system'])
            rel.relationship.text = supermod.string(value=k)
            c.display = supermod.string(value=k)
            rel.relationship.text = supermod.string(value=k)
            rel.relationship.coding = [c]

            # Add the condition
            s = attrgetter(self.map_['condition'])(member)
            if s:
                con = supermod.FamilyHistory_Condition()
                t = supermod.CodeableConcept()
                t.coding = [supermod.Coding()]
                t.coding[0].display = supermod.string(value=s.name)
                t.coding[0].code = supermod.code(value=s.code)
                #ICD-10-CM
                t.coding[0].system = supermod.uri(
                    value='urn:oid:2.16.840.1.113883.6.90')
                t.text = supermod.string(value=s.name)
                con.set_type(t)
                rel.add_condition(con)

            super(health_FamilyHistory, self).add_relation(rel)
Esempio n. 5
0
    def set_doseQuantity(self, doseQuantity):
        """Extends superclass for convenience

        Keyword arguments:
        doseQuantity -- amount in mL
        """

        if doseQuantity is not None:
            v = supermod.decimal(value=str(float(doseQuantity)))
            u = supermod.string(value='mL')
            s = supermod.uri(value='http://snomed.info/sct')
            c = supermod.code(value='258773002')
            dq = supermod.Quantity(value=v, units=u, system=s, code=c)
            super(health_Immunization, self).set_doseQuantity(dq)
    def set_code(self, code):
        """Extends superclass for convenience

        Keyword arguments:
        code -- the pathology info (Health model)
        """

        if code:
            c = supermod.CodeableConcept()
            c.coding = [supermod.Coding()]
            c.coding[0].display = supermod.string(value=code.name)
            c.coding[0].code = supermod.code(value=code.code)
            #ICD-10-CM
            c.coding[0].system = supermod.uri(
                value='urn:oid:2.16.840.1.113883.6.90')
            c.text = supermod.string(value=code.name)
            super(health_Condition, self).set_code(c)
    def set_gender(self, gender):
        """Extends superclass for convenience

        Keyword arguments:
        gender -- practitioner's gender
        """

        if gender:
            from fhir.value_sets import administrativeGender as codes
            us = gender.upper()
            sd = [x for x in codes.contents if x['code'] == us][0]
            coding = supermod.Coding(
                        system=supermod.uri(value=sd['system']),
                        code=supermod.code(value=sd['code']),
                        display=supermod.string(value=sd['display'])
                        )
            g=supermod.CodeableConcept(coding=[coding])
            super(health_Practitioner, self).set_gender(g)
    def set_communication(self, communication):
        """Extends superclass for convenience

        Keyword arguments:
        communication -- language
        """

        if communication:
            from re import sub
            code=sub('_','-', communication.code)
            name=communication.name
            coding = supermod.Coding(
                        system=supermod.uri(value='urn:ietf:bcp:47'),
                        code=supermod.code(value=code),
                        display=supermod.string(value=name)
                        )
            com=supermod.CodeableConcept(coding=[coding],
                                    text=supermod.string(value=name))
            super(health_Practitioner, self).add_communication(com)
    def set_type(self, type_):
        """Extend superclass

        Set the institution's type

        Keyword arguments:
        type_ - type description
        """

        # TODO Use FHIR codes
        g = supermod.CodeableConcept()
        coding = supermod.Coding(
            system=supermod.uri(value='http://hl7.org/fhir/organization-type'),
            code=supermod.code(value='prov'),
            display=supermod.string(value='Healthcare Provider'))
        if type_:
            g.text = supermod.string(value=str(type_))
        g.coding = [coding]
        super(health_Organization, self).set_type(g)
    def set_communication(self, communication):
        """Extends superclass for convenience

        Set patient language

        Keyword arguments:
        communication -- the language model
        """

        if communication:
            from re import sub
            code = sub('_', '-', communication.code)  #Standard requires dashes
            name = communication.name
            coding = supermod.Coding(
                system=supermod.uri(value='urn:ietf:bcp:47'),
                code=supermod.code(value=code),
                display=supermod.string(value=name))
            com = supermod.CodeableConcept(coding=[coding],
                                           text=supermod.string(value=name))
            super(health_Patient, self).set_communication([com])
    def set_type(self, type_):
        """Extends superclass for convenience

        Keyword arguments:
        type_ -- procedure (Health model)
        """

        if type_:
            concept = supermod.CodeableConcept()
            des = type_.description
            if des:
                concept.text = supermod.string(value=des)
            concept.coding = [supermod.Coding()]
            name = type_.rec_name
            if name:
                concept.coding[0].display = supermod.string(value=name)
                concept.text = supermod.string(value=name)
            concept.coding[0].code = supermod.code(value=type_.name)
            #ICD-10-PCS
            concept.coding[0].system = supermod.uri(
                value='urn:oid:2.16.840.1.113883.6.4')
            super(health_Procedure, self).set_type(concept)
    def set_gender(self, gender):
        """Extends superclass for convenience

        Set patient gender

        Keyword arguments:
        gender -- gender code
        """

        from fhir.value_sets import administrativeGender as gender_codes
        if gender:
            us = gender.upper()  #Standard requires uppercase
            try:
                sd = [x for x in gender_codes.contents if x['code'] == us][0]
            except:
                return None
            coding = supermod.Coding(
                system=supermod.uri(value=sd['system']),
                code=supermod.code(value=sd['code']),
                display=supermod.string(value=sd['display']))
            g = supermod.CodeableConcept(coding=[coding])
            super(health_Patient, self).set_gender(g)
    def set_valueQuantity(self, value, units=None, code=None, system=None):
        """Extends superclass for convenience

        Set actual value of observation

        Keyword arguments:
        value -- the actual value
        units -- units (e.g., g/dL)
        code -- the code (e.g., 'XHEHA1')
        system -- the code system (e.g., 'http://code.system')
        """

        if value:

            # This is to handle multi-field
            #if self.field == 'temp':
            #units = "degrees C"
            #code = "258710007"
            #system = "http://snomed.info/sct"
            #elif self.field == 'press_d':
            #units = "mm[Hg]"
            #elif self.field == 'press_s':
            #units = "mm[Hg]"
            #elif self.field == 'pulse':
            #units = "beats/min"
            #elif self.field == 'rate':
            #units= "breaths/min"

            q = supermod.Quantity()
            q.value = supermod.decimal(value=value)

            if units:
                q.units = supermod.string(value=str(units))
            if code:
                q.code = supermod.code(value=str(code))
            if system:
                q.system = supermod.uri(value=str(system))
            super(health_Observation, self).set_valueQuantity(q)
    def set_severity(self, severity):
        """Extends superclass for convenience

        Keyword arguments:
        severity -- the disease severity
        """

        if severity:
            # These are the snomed codes
            sev = {
                '1_mi': ('Mild', '255604002'),
                '2_mo': ('Moderate', '6736007'),
                '3_sv': ('Severe', '24484000')
            }
            t = sev.get(severity)
            if t:
                c = supermod.CodeableConcept()
                c.coding = [supermod.Coding()]
                c.coding[0].display = supermod.string(value=t[0])
                c.coding[0].code = supermod.code(value=t[1])
                c.coding[0].system = supermod.uri(
                    value='http://snomed.info/sct')
                c.text = supermod.string(value=t[0])
                super(health_Condition, self).set_severity(c)
Esempio n. 15
0
 def __set_implementation(self):
     i = supermod.Conformance_Implementation()
     i.url = supermod.uri(value='/')
     i.description = supermod.string(value='FHIR installation')
     self.set_implementation(i)