예제 #1
0
 def __set_rest(self):
     r = supermod.Conformance_Rest()
     r.mode = supermod.RestfulConformanceMode(value='server')
     endpoints = []
     for endpoint, mapping in [('Patient', self.patient),
                               ('DiagnosticReport', self.diagnostic_report),
                               ('Practitioner', self.practitioner),
                               ('Procedure', self.procedure),
                               ('Observation', self.observation),
                               ('Condition', self.condition),
                               ('FamilyHistory', self.family_history),
                               ('Medication', self.medication),
                               ('MedicationStatement',
                                self.medication_statement),
                               ('Immunization', self.immunization),
                               ('Organization', self.organization)]:
         e = supermod.Conformance_Resource()
         e.type_ = supermod.code(value=endpoint)
         e.operation = [
             supermod.code(value=operation)
             for operation in ['read', 'validate', 'search']
         ]
         for k, v in mapping.resource_search_params.items():
             if v is not None:  #None are non-implemented
                 s = supermod.Conformance_SearchParam()
                 s.name = supermod.string(value=str(k))
                 s.type_ = supermod.code(value=str(v))
                 e.add_searchParam(s)
         endpoints.append(e)
     r.resource = endpoints
     self.set_rest([r])
    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)
    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])
예제 #5
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)
    def set_kind(self, kind='product'):
        """Extends superclass for convenience

        Keyword arguments:
        kind - basically, product or package
        """

        if kind in ['product', 'package']:
            c = supermod.code(value=kind)
            super(health_Medication, self).set_kind(c)
예제 #7
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)
예제 #8
0
    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)
예제 #9
0
    def set_site(self, site):
        """Extends superclass for convenience

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

        from 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_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_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)
예제 #12
0
    def set_route(self, route):
        """Extends superclass for convenience

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

        from 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_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)
예제 #14
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_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)
예제 #21
0
    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
    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)
예제 #23
0
 def __set_format(self):
     f = [supermod.code(value='xml')]
     #f.append(supermod.code(value='json')) #When JSON is supported
     self.set_format(f)