Esempio n. 1
0
    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_maritalStatus(self, marital_status):
        """Extends superclass for convenience

        Set the marital status

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

        from server.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)
    def set_relation(self, familyHistory):
        """Extends superclass for convenience

        Keyword arguments:
        familyHistory -- the relatives
        """

        # TODO Combine multiple conditions for same person
        from server.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. 4
0
    def set_role(self, role):
        """Extends superclass for convenience

        Keyword arguments:
        role -- occupation name
        """

        if role:
            coding = supermod.Coding(display=supermod.string(value=str(role)))
            com = supermod.CodeableConcept(coding=[coding])
            super(health_Practitioner, self).set_role([com])
 def __set_gnu_gender(self):
     try:
         gender = attrgetter(self.map['gender'])(self.related_person)
         coding = supermod.Coding(
             system=supermod.uri(
                 value='http://hl7.org/fhir/v3/AdministrativeGender'),
             code=supermod.code(value=gender.upper()),
             display=supermod.string(
                 value='Male' if gender == 'm' else 'Female'))
         gender = supermod.CodeableConcept(coding=[coding])
         self.set_gender(gender)
     except:
         raise ValueError('No gender')
Esempio n. 6
0
    def set_specialty(self, specialty):
        """Extends superclass for convenience

        Keyword arguments
        specialty -- person's specialties
        """

        for spec in specialty:
            code, name = attrgetter('specialty.code', 'specialty.name')(spec)
            coding = supermod.Coding(code=supermod.string(value=code),
                                     display=supermod.string(value=name))
            com = supermod.CodeableConcept(coding=[coding])
            super(health_Practitioner, self).add_specialty(com)
Esempio n. 7
0
    def set_name(self, name):
        """Extends superclass for convenience

        Set the observation type

        Keyword arguments:
        name -- the description of the observation
        """
        #TODO Better coding

        if name:
            n = supermod.CodeableConcept()
            n.coding = [supermod.Coding()]
            n.coding[0].display = supermod.string(value=name)
            super(health_Observation, self).set_name(n)
    def set_vaccineType(self, vaccineType):
        """Extends superclass for convenience

        Keyword arguments:
        vaccineType -- the vaccine (Health model)
        """
        #TODO Need better coding, much better!

        if vaccineType:
            cc = supermod.CodeableConcept()
            c = supermod.Coding()
            c.display = cc.text = supermod.string(value=vaccineType.name.name)
            if vaccineType.name.code:
                c.code = supermod.code(value=vaccineType.name.code)
                cc.coding = [c]
            super(health_Immunization, self).set_vaccineType(cc)
Esempio n. 9
0
    def set_code(self, name, code):
        """Extends superclass for convenience

        Keyword arguments:
        code -- code value
        name -- name of the medication
        """

        #TODO Better info, use recognized codes
        if name:
            c = supermod.Coding()
            c.display = supermod.string(value=str(name))
            if code:
                c.code = supermod.code(value=code)
            cc = supermod.CodeableConcept()
            cc.coding = [c]
            super(health_Medication, self).set_code(cc)
Esempio n. 10
0
    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)
Esempio n. 11
0
    def set_gender(self, gender):
        """Extends superclass for convenience

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

        if gender:
            from server.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)
Esempio n. 12
0
    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)
Esempio n. 13
0
    def set_name(self, name):
        """Extends superclass for convenience

        Keyword arguments:
        name -- the test (Health model)
        """

        if name:
            conc = supermod.CodeableConcept()
            conc.coding = [supermod.Coding()]
            conc.coding[0].display = supermod.string(value=name.name)
            conc.coding[0].code = supermod.code(value=name.code)
            super(health_DiagnosticReport, self).set_name(conc)

        else:
            # If you don't know what is being tested,
            #   the data is useless
            raise ValueError('No test coding info')
    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_site(self, site):
        """Extends superclass for convenience

        Keyword arguments:
        site -- site code where the vaccine was administered
        """

        from server.fhir.value_sets import immunizationSite
        if site:
            m = [
                i for i in immunizationSite.contents
                if i['code'] == site.upper()
            ]
            if m:
                cc = supermod.CodeableConcept()
                c = supermod.Coding()
                c.display = cc.text = supermod.string(value=m[0]['display'])
                c.code = supermod.code(value=m[0]['code'])
                cc.coding = [c]
                super(health_Immunization, self).set_site(cc)
    def set_route(self, route):
        """Extends superclass for convenience

        Keyword argument:
        route -- how vaccine entered body
        """

        from server.fhir.value_sets import immunizationRoute
        if route:
            ir = [
                i for i in immunizationRoute.contents
                if i['code'] == route.upper()
            ]
            if ir:
                cc = supermod.CodeableConcept()
                c = supermod.Coding()
                c.display = cc.text = supermod.string(value=ir[0]['display'])
                c.code = supermod.code(value=ir[0]['code'])
                cc.coding = [c]
                super(health_Immunization, self).set_route(cc)
    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_gender(self, gender):
        """Extends superclass for convenience

        Set patient gender

        Keyword arguments:
        gender -- gender code
        """

        from server.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)
Esempio n. 19
0
    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)
Esempio n. 20
0
    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)
    def __set_gnu_dosage(self):
        """Set dosage"""
        # TODO Add better dosage info
        # FIX On hold since many changes upcoming to the dosage
        if self.medication_statement:
            d = supermod.MedicationStatement_Dosage()

            d.quantity = supermod.Quantity()
            f = safe_attrgetter(self.medication_statement,
                                self.map['dose']['quantity'])
            if f:
                d.quantity.value = supermod.decimal(value=f)
            u = safe_attrgetter(self.medication_statement,
                                self.map['dose']['units'])
            if u:
                d.quantity.units = supermod.string(value=u)

            d.route = supermod.CodeableConcept()
            r = safe_attrgetter(self.medication_statement,
                                self.map['dose']['route'])
            if r:
                d.route.coding = [supermod.Coding()]
                d.route.coding[0].code = supermod.code(value=r.code)
                d.route.coding[0].display = supermod.string(value=r.name)
                d.route.text = supermod.string(r.name)

            # PRN?
            an = safe_attrgetter(self.medication_statement,
                                 self.map['dose']['asNeededBoolean'])
            if an:
                self.set_asNeededBoolean(supermod.boolean(value=True))

            d.timing = supermod.Schedule()

            if self.medication_statement.infusion:
                d.rate