def set_name(self, name): """Extends superclass for convenience Set patient's name and nickname Keyword arguments: name -- patient party model """ if name: names = [] family = [] full_given_name = name.name full_family_name = name.lastname '''nickname = name.alias''' given = [supermod.string(value=x) for x in full_given_name.split()] after_names = [ supermod.string(value=x) for x in full_family_name.split() ] if len(after_names) > 1: family = after_names[-1:] given.extend(after_names[:-1]) else: family = after_names names.append( supermod.HumanName(use=supermod.NameUse(value='usual'), family=family, given=given)) ''' DEVICEAPI - DISABLED! ''' '''if nickname: names.append(supermod.HumanName( use=supermod.NameUse(value='nickname'), given=[supermod.string(value=nickname)]))''' super(health_Patient, self).set_name(names)
def set_result(self, result): """Extends superclass for convenience Keyword arguments: result -- the results """ if result: for test in result: if RUN_FLASK: uri = url_for('obs_record', log_id=test.id) else: uri = dumb_url_generate(['Observation', test.id]) display = test.rec_name ref=supermod.ResourceReference() ref.display = supermod.string(value=display) ref.reference = supermod.string(value=uri) super(health_DiagnosticReport, self).add_result(ref) # No data = useless if len(self.get_result()) == 0: raise ValueError('No data') else: # No data = useless raise ValueError('No data')
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_identifier(self, observation, patient, date): """Extends superclass for convenience Set the identifier from the data model Keyword arguments: observation -- the observation (Health model) patient -- patient (Health model) date -- date of observation (datetime object) """ if observation and patient: if date is not None: label = '{0} value for {1} on {2}'.format( observation.name, patient.name.rec_name, date.strftime('%Y/%m/%d')) else: label = '{0} value for {1} on unknown'.format( observation.name, patient.name.rec_name) if RUN_FLASK: value = url_for('obs_record', log_id=observation.id) else: value = dumb_url_generate(['Observation', observation.id]) ident = supermod.Identifier(label=supermod.string(value=label), value=supermod.string(value=value)) super(health_Observation, self).set_identifier(ident)
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_identifier(self, puid, alternative): """Extends superclass for convenience Set patient identifiers Keyword arguments: puid -- the puid/mrn alternate -- alternate ids (SSN, etc) """ idents = [] if puid: idents.append( supermod.Identifier(use=supermod.IdentifierUse(value='usual'), label=supermod.string(value='PUID'), value=supermod.string(value=puid))) for alt in alternative: idents.append( supermod.Identifier( use=supermod.IdentifierUse(value='official'), label=supermod.string(value=alt.alternative_id_type), value=supermod.string(value=alt.code))) if idents: super(health_Patient, self).set_identifier(idents)
def __set_gnu_medication(self): if self.medication_statement: med = attrgetter(self.map['medication'])(self.medication_statement) if RUN_FLASK: uri = url_for('med_record', log_id=med.id) else: uri = dumb_url_generate(['Medication', med.id]) display = med.active_component ref = supermod.ResourceReference() ref.display = supermod.string(value=display) ref.reference = supermod.string(value=uri) self.set_medication(ref)
def set_identifier(self, identifier): """Extends superclass for convenience Keyword arguments: identifier -- puid """ if identifier: ident = supermod.Identifier( use=supermod.IdentifierUse(value='usual'), label=supermod.string(value='PUID'), value=supermod.string(value=identifier)) super(health_Practitioner, self).add_identifier(ident)
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)
def __set_gnu_patient(self): """Set the patient info""" if self.medication_statement: patient = attrgetter(self.map['patient'])( self.medication_statement) if RUN_FLASK: uri = url_for('pat_record', log_id=patient.id) else: uri = dumb_url_generate(['Patient', patient.id]) display = patient.rec_name ref = supermod.ResourceReference() ref.display = supermod.string(value=display) ref.reference = supermod.string(value=uri) self.set_patient(ref)
def set_identifier(self, identifier): """Extend superclass Set the institution's identifier Keyword arguments: identifier - institution code """ if identifier is not None: ident = supermod.Identifier( use=supermod.IdentifierUse(value='official'), label=supermod.string(value='Institution code'), value=supermod.string(value=str(identifier))) super(health_Organization, self).set_identifier([ident])
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_telecom(self, contacts): """Extends superclass for convenience Set telecom information Keyword arguments: contacts -- contacts info (Party model) """ telecom = [] for contact in contacts: c = supermod.Contact() c.value = supermod.string(value=contact.value) if contact.type == 'phone': system = 'phone' use = 'home' elif contact.type == 'mobile': system = 'phone' use = 'mobile' else: use = system = contact.type c.system = supermod.ContactSystem(value=system) c.use = supermod.ContactUse(value=use) telecom.append(c) if telecom: super(health_Patient, self).set_telecom(telecom)
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_name(self, name): """Set medication name""" #TODO Need common/commercial names if name: n = supermod.string(value=str(name)) super(health_Medication, self).set_name(n)
def set_asserter(self, asserter): """Extends superclass for convenience Keyword arguments: asserter -- the practitioner (Health model) """ if asserter: if RUN_FLASK: uri = url_for('hp_record', log_id=asserter.id) else: uri = dumb_url_generate(['Practitioner', asserter.id]) display = asserter.rec_name ref = supermod.ResourceReference() ref.display = supermod.string(value=display) ref.reference = supermod.string(value=uri) super(health_Condition, self).set_asserter(ref)
def set_subject(self, subject): """Extends superclass for convenience Keyword arguments: subject -- patient (Health model) """ if subject: if RUN_FLASK: uri = url_for('pat_record', log_id=subject.id) else: uri = dumb_url_generate(['Patient', subject.id]) display = subject.rec_name ref = supermod.ResourceReference() ref.display = supermod.string(value=display) ref.reference = supermod.string(value=uri) super(health_Condition, self).set_subject(ref)
def set_performer(self, performer): """Extends superclass for convenience Keyword arguments: performer -- the lab performer (Health model) """ if performer: if RUN_FLASK: uri = url_for('hp_record', log_id=performer.id) else: uri = dumb_url_generate(['Practitioner', performer.id]) display = performer.name.rec_name ref=supermod.ResourceReference() ref.display = supermod.string(value=display) ref.reference = supermod.string(value=uri) super(health_DiagnosticReport, self).set_performer(ref)
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_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_identifier(self, report, patient, date): """Extends superclass for convenience Keyword arguments: report -- the report (Health model) patient -- patient name date -- the date (datetime object) """ if report and patient and date: label = '{0} for {1} on {2}'.format(report.name, patient, date.strftime('%Y/%m/%d')) if RUN_FLASK: value = url_for('dr_record', log_id=report.id) else: value = dumb_url_generate(['DiagnosticReport', report.id]) ident = supermod.Identifier( label=supermod.string(value=label), value=supermod.string(value=value)) super(health_DiagnosticReport, self).set_identifier(ident)
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_notes(self, notes): """Extends superclass for convenience Keyword arguments: notes -- notes to add """ if notes: n = supermod.string(value=str(s)) super(health_Condition, self).set_notes(n)
def set_lotNumber(self, lotNumber): """Extends superclass for convenience Keyword arguments: lotNumber -- lot id (string, number, etc.) """ if lotNumber is not None: s = supermod.string(value=str(lotNumber)) super(health_Immunization, self).set_lotNumber(s)
def set_conclusion(self, conclusion): """Extends superclass for convenience Keyword arguments: conclusion -- the report's conclusion """ if conclusion: c = supermod.string(value=conclusion) super(health_DiagnosticReport, self).set_conclusion(c)
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_careProvider(self, care_provider): """Extends superclass for convienience Set patient's care provider Keyword arguments: care_provider -- health professional model """ if care_provider: if RUN_FLASK: uri = url_for('hp_record', log_id=care_provider.id) else: uri = dumb_url_generate(['Practitioner', care_provider.id]) display = care_provider.rec_name ref = supermod.ResourceReference() ref.display = supermod.string(value=display) ref.reference = supermod.string(value=uri) super(health_Patient, self).set_careProvider([ref])
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_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_comments(self, comments): """Extends superclass for convenience Set comments Keyword arguments: comments -- the comments """ if comments: m = supermod.string(value=str(comments)) super(health_Observation, self).set_comments(m)