def get_medications(self): medications = [] entries = self._tree.get_entries_by_template(Root.MEDICATION) for entry in entries: medication = messages.Medication() medication.product = messages.Product() date_node = entry.getElementsByTagName('effectiveTime')[0] date_range = CcdaTree.get_date_range_from_node(date_node) medication.date_range = messages.DateRange(**date_range) product_node = entry.getElementsByTagName('manufacturedProduct')[0] product_code_node = product_node.getElementsByTagName('code')[0] product_code = CcdaTree.get_code_from_node(product_code_node) medication.product.code = messages.Code(**product_code) quantity_nodes = entry.getElementsByTagName('doseQuantity') if quantity_nodes: node = quantity_nodes[0] medication.dose_quantity = CcdaTree.get_quantity_message_from_node( node) rate_nodes = entry.getElementsByTagName('rateQuantity') if rate_nodes: node = rate_nodes[0] medication.rate_quantity = CcdaTree.get_quantity_message_from_node( node) # TODO: precondition, reason, route, vehicle, administration, prescriber. medications.append(medication) return medications
def get_vitals(self): vitals = [] entries = self._tree.get_entries_by_template(Root.VITAL) for entry in entries: vital = messages.Vital() vital.date = CcdaTree.get_date_from_effective_time(entry) vital.results = [] result_entries = entry.getElementsByTagName('component') for result_entry in result_entries: vital_result = messages.VitalResult() code_node = result_entry.getElementsByTagName('code')[0] value_node = result_entry.getElementsByTagName('value')[0] vital_result_code = CcdaTree.get_code_from_node(code_node) vital_result.code = messages.Code(**vital_result_code) vital_result.value = int( float(value_node.getAttribute('value'))) vital_result.unit = value_node.getAttribute('unit') vital.results.append(vital_result) vitals.append(vital) return vitals
def get_procedures(self): procedures = [] procedure_parent = self._tree.get_entries_by_template( Root.PROCEDURE)[0] entries = procedure_parent.getElementsByTagName('entry') for entry in entries: procedure = messages.Procedure() code_node = entry.getElementsByTagName('code')[0] # print(entry.getchildren()) # print(messages.Code(**CcdaTree.get_code_from_node(code_node))) procedure_code = CcdaTree.get_code_from_node(code_node) procedure.code = messages.Code(**procedure_code) procedure.date = CcdaTree.get_date_from_effective_time(entry) # TODO: Implement specimen, performer, device. procedures.append(procedure) # x = dom.createElement("foo") # txt = dom.createTextNode("hello, world!") # creates "hello, world!" # x.appendChild(txt) # results in <foo>hello, world!</foo> return procedures
def to_message(self): """Converts the CCDA document to a ProtoRPC message.""" # TODO: Remove duplicate code. doc = messages.CcdaDocument() # Demographics. doc.demographics = messages.Demographic() doc.demographics.dob = self._tree.get_dob() doc.demographics.gender = messages.Code(**self._tree.get_gender()) doc.demographics.marital_status = messages.Code( **self._tree.get_marital_status()) doc.demographics.language = self._tree.get_language() doc.demographics.race = messages.Code(**self._tree.get_race()) doc.demographics.ethnicity = messages.Code( **self._tree.get_ethnicity()) doc.demographics.religion = messages.Code(**self._tree.get_religion()) doc.demographics.birthplace = messages.Address( **self._tree.get_birthplace()) # Allergies. # TODO: Implement allergies. doc.allergies = [] entries = self._tree.get_entries_by_template(Root.ALLERGY) for entry in entries: allergy = messages.Allergy() participantVal = entry.getElementsByTagName('participant') if participantVal: participantRoleVal = participantVal[0].getElementsByTagName( 'participantRole') if participantRoleVal: playingEntityVal = participantRoleVal[ 0].getElementsByTagName('playingEntity') if playingEntityVal: codeVals = playingEntityVal[0].getElementsByTagName( 'code') if codeVals: codeVal = codeVals[0] allergy.code = messages.Code() allergy.code.code = codeVal.getAttribute('code') allergy.code.name = codeVal.getAttribute( 'displayName') allergy.code.code_system = codeVal.getAttribute( 'codeSystem') allergy.code.code_system_name = codeVal.getAttribute( 'codeSystemName') allergyReactionNode = self._tree.get_entries_by_template( Root.ALLERGY_REACTION, entry) if allergyReactionNode: allergyReactionObservationNode = allergyReactionNode[0] if allergyReactionObservationNode: valueVals = allergyReactionObservationNode.getElementsByTagName( 'value') if valueVals: valueval = valueVals[0] allergy.reaction = messages.Code() allergy.reaction.code = valueval.getAttribute('code') allergy.reaction.name = valueval.getAttribute( 'displayName') allergy.reaction.code_system = valueval.getAttribute( 'codeSystem') allergy.reaction.code_system_name = valueval.getAttribute( 'codeSystemName') allergySeverityNode = self._tree.get_entries_by_template( Root.ALLERGY_SEVERITY, entry) if allergySeverityNode: allergySeverityObservationNode = allergySeverityNode[0] if allergySeverityObservationNode: valueVals = allergySeverityObservationNode.getElementsByTagName( 'value') if valueVals: valueval = valueVals[0] allergy.severity = messages.Code() allergy.severity.code = valueval.getAttribute('code') allergy.severity.name = valueval.getAttribute( 'displayName') allergy.severity.code_system = valueval.getAttribute( 'codeSystem') allergy.severity.code_system_name = valueval.getAttribute( 'codeSystemName') doc.allergies.append(allergy) # Immunizations. doc.immunizations = [] entries = self._tree.get_entries_by_template(Root.IMMUNIZATION) for entry in entries: product_nodes = self._tree.get_entries_by_template( Root.IMMUNIZATION_PRODUCT, parent=entry) if product_nodes: product_node = product_nodes[0] immunization = messages.Immunization() immunization.date = CcdaTree.get_date_from_effective_time( entry) immunization.product = messages.Product() code_node = product_node.getElementsByTagName('code')[0] product_code = CcdaTree.get_code_from_node(code_node) immunization.product.code = messages.Code(**product_code) doc.immunizations.append(immunization) # Labs. doc.labs = [] lab_parent = self._tree.get_entries_by_template(Root.LAB) if lab_parent: entries = lab_parent[0].getElementsByTagName('entry') for entry in entries: lab = messages.Lab() code_node = entry.getElementsByTagName('code')[0] lab_code = CcdaTree.get_code_from_node(code_node) lab.code = messages.Code(**lab_code) lab.results = [] component_nodes = entry.getElementsByTagName('component') for component_node in component_nodes: result_code_nodes = component_node.getElementsByTagName( 'code') lab_result = messages.LabResult() if result_code_nodes: result_code_node = result_code_nodes[0] result_code = CcdaTree.get_code_from_node( result_code_node) lab_result.code = messages.Code(**result_code) valueVals = component_node.getElementsByTagName('value') if valueVals: lab_result.value = valueVals[0].getAttribute('value') if lab_result.value: lab_result.unit = valueVals[0].getAttribute('unit') else: if valueVals[0].firstChild: lab_result.value = valueVals[ 0].firstChild.nodeValue lab_result.date = CcdaTree.get_date_from_effective_time( component_node) lab.results.append(lab_result) doc.labs.append(lab) # Medications. doc.medications = [] entries = self._tree.get_entries_by_template(Root.MEDICATION) for entry in entries: medication = messages.Medication() medication.product = messages.Product() date_node = entry.getElementsByTagName('effectiveTime')[0] date_range = CcdaTree.get_date_range_from_node(date_node) medication.date_range = messages.DateRange(**date_range) product_node = entry.getElementsByTagName('manufacturedProduct')[0] product_code_node = product_node.getElementsByTagName('code')[0] product_code = CcdaTree.get_code_from_node(product_code_node) medication.product.code = messages.Code(**product_code) quantity_nodes = entry.getElementsByTagName('doseQuantity') if quantity_nodes: node = quantity_nodes[0] medication.dose_quantity = CcdaTree.get_quantity_message_from_node( node) rate_nodes = entry.getElementsByTagName('rateQuantity') if rate_nodes: node = rate_nodes[0] medication.rate_quantity = CcdaTree.get_quantity_message_from_node( node) # TODO: precondition, reason, route, vehicle, administration, prescriber. doc.medications.append(medication) # Problems. doc.problems = [] entries = self._tree.get_entries_by_template(Root.PROBLEM) for entry in entries: problem = messages.Problem() code_node = entry.getElementsByTagName('value') # problem_code = CcdaTree.get_code_from_node(code_node) # problem.code = messages.Code(**problem_code) if code_node: valueval = code_node[0] problem.code = messages.Code() problem.code.code = valueval.getAttribute('code') problem.code.name = valueval.getAttribute('displayName') problem.code.code_system = valueval.getAttribute('codeSystem') problem.code.code_system_name = valueval.getAttribute( 'codeSystemName') date_nodes = entry.getElementsByTagName('effectiveTime') for date_node in date_nodes: date_range = CcdaTree.get_date_range_from_node(date_node) problem.date_range = messages.DateRange(**date_range) status_nodes = self._tree.get_entries_by_template( Root.PROBLEM_STATUS, parent=entry) if status_nodes: status_node = status_nodes[0] entry_node = status_node.getElementsByTagName('value')[0] problem.status = entry_node.getAttribute('displayName') # TODO: Implement problem.age. doc.problems.append(problem) # Procedures. doc.procedures = [] procedure_parent = self._tree.get_entries_by_template(Root.PROCEDURE) if procedure_parent: entries = procedure_parent[0].getElementsByTagName('entry') for entry in entries: procedure = messages.Procedure() code_node = entry.getElementsByTagName('code')[0] procedure_code = CcdaTree.get_code_from_node(code_node) procedure.code = messages.Code(**procedure_code) procedure.date = CcdaTree.get_date_from_effective_time(entry) # TODO: Implement specimen, performer, device. doc.procedures.append(procedure) # Vitals. doc.vitals = [] vitals_parent = self._tree.get_entries_by_template(Root.VITAL) if vitals_parent: entries = vitals_parent[0].getElementsByTagName('entry') for entry in entries: vital = messages.Vital() vital.date = CcdaTree.get_date_from_effective_time(entry) vital.results = [] result_entries = entry.getElementsByTagName('component') for result_entry in result_entries: vital_result = messages.VitalResult() code_node = result_entry.getElementsByTagName('code')[0] value_node = result_entry.getElementsByTagName('value')[0] vital_result_code = CcdaTree.get_code_from_node(code_node) vital_result.code = messages.Code(**vital_result_code) value_attribute = value_node.getAttribute('value') if value_attribute: #if not value_attribute.isalnum(): try: vital_result.value = long(float(value_attribute)) except ValueError: vital_result.value = None else: vital_result.value = None vital_result.unit = value_node.getAttribute('unit') vital.results.append(vital_result) doc.vitals.append(vital) return doc
def to_message(self): """Converts the CCDA document to a ProtoRPC message.""" # TODO: Remove duplicate code. doc = messages.CcdaDocument() # Allergies. # TODO: Implement allergies. doc.allergies = [messages.Allergy()] # Demographics. doc.demographics = messages.Demographic() doc.demographics.dob = self._tree.get_dob() doc.demographics.gender = messages.Code(**self._tree.get_gender()) doc.demographics.marital_status = messages.Code( **self._tree.get_marital_status()) doc.demographics.language = self._tree.get_language() doc.demographics.race = messages.Code(**self._tree.get_race()) doc.demographics.ethnicity = messages.Code( **self._tree.get_ethnicity()) doc.demographics.religion = messages.Code(**self._tree.get_religion()) doc.demographics.birthplace = messages.Address( **self._tree.get_birthplace()) # Immunizations. doc.immunizations = [] entries = self._tree.get_entries_by_template(Root.IMMUNIZATION) for entry in entries: product_node = self._tree.get_entries_by_template( Root.IMMUNIZATION_PRODUCT, parent=entry)[0] immunization = messages.Immunization() immunization.date = CcdaTree.get_date_from_effective_time(entry) immunization.product = messages.Product() code_node = product_node.getElementsByTagName('code')[0] product_code = CcdaTree.get_code_from_node(code_node) immunization.product.code = messages.Code(**product_code) # Labs. doc.labs = [] lab_parent = self._tree.get_entries_by_template(Root.LAB)[0] entries = lab_parent.getElementsByTagName('entry') for entry in entries: lab = messages.Lab() code_node = entry.getElementsByTagName('code')[0] lab_code = CcdaTree.get_code_from_node(code_node) lab.code = messages.Code(**lab_code) lab.result = messages.LabResult() component_node = entry.getElementsByTagName('component')[0] result_code_node = component_node.getElementsByTagName('code')[0] result_code = CcdaTree.get_code_from_node(result_code_node) lab.result.code = messages.Code(**result_code) doc.labs.append(lab) # Medications. doc.medications = [] entries = self._tree.get_entries_by_template(Root.MEDICATION) for entry in entries: medication = messages.Medication() medication.product = messages.Product() date_node = entry.getElementsByTagName('effectiveTime')[0] date_range = CcdaTree.get_date_range_from_node(date_node) medication.date_range = messages.DateRange(**date_range) product_node = entry.getElementsByTagName('manufacturedProduct')[0] product_code_node = product_node.getElementsByTagName('code')[0] product_code = CcdaTree.get_code_from_node(product_code_node) medication.product.code = messages.Code(**product_code) quantity_nodes = entry.getElementsByTagName('doseQuantity') if quantity_nodes: node = quantity_nodes[0] medication.dose_quantity = CcdaTree.get_quantity_message_from_node( node) rate_nodes = entry.getElementsByTagName('rateQuantity') if rate_nodes: node = rate_nodes[0] medication.rate_quantity = CcdaTree.get_quantity_message_from_node( node) # TODO: precondition, reason, route, vehicle, administration, prescriber. doc.medications.append(medication) # Problems. doc.problems = [] entries = self._tree.get_entries_by_template(Root.PROBLEM) for entry in entries: problem = messages.Problem() code_node = entry.getElementsByTagName('code')[0] problem_code = CcdaTree.get_code_from_node(code_node) problem.code = messages.Code(**problem_code) date_node = entry.getElementsByTagName('effectiveTime')[0] date_range = CcdaTree.get_date_range_from_node(date_node) problem.date_range = messages.DateRange(**date_range) status_nodes = self._tree.get_entries_by_template( Root.PROBLEM_STATUS, parent=entry) if status_nodes: status_node = status_nodes[0] entry_node = status_node.getElementsByTagName('value')[0] problem.status = entry_node.getAttribute('displayName') # TODO: Implement problem.age. doc.problems.append(problem) # Procedures. doc.procedures = [] procedure_parent = self._tree.get_entries_by_template( Root.PROCEDURE)[0] entries = procedure_parent.getElementsByTagName('entry') for entry in entries: procedure = messages.Procedure() code_node = entry.getElementsByTagName('code')[0] procedure_code = CcdaTree.get_code_from_node(code_node) procedure.code = messages.Code(**procedure_code) procedure.date = CcdaTree.get_date_from_effective_time(entry) # TODO: Implement specimen, performer, device. doc.procedures.append(procedure) # Vitals. doc.vitals = [] entries = self._tree.get_entries_by_template(Root.VITAL) for entry in entries: vital = messages.Vital() vital.date = CcdaTree.get_date_from_effective_time(entry) vital.results = [] result_entries = entry.getElementsByTagName('component') for result_entry in result_entries: vital_result = messages.VitalResult() code_node = result_entry.getElementsByTagName('code')[0] value_node = result_entry.getElementsByTagName('value')[0] vital_result_code = CcdaTree.get_code_from_node(code_node) vital_result.code = messages.Code(**vital_result_code) vital_result.value = int( float(value_node.getAttribute('value'))) vital_result.unit = value_node.getAttribute('unit') vital.results.append(vital_result) doc.vitals.append(vital) return doc
def to_message(self): """Converts the CCDA document to a ProtoRPC message.""" # TODO: Remove duplicate code. doc = messages.CcdaDocument() ''' Not of interest # Demographics. doc.demographics = messages.Demographic() doc.demographics.dob = self._tree.get_dob() doc.demographics.gender = messages.Code(**self._tree.get_gender()) doc.demographics.marital_status = messages.Code( **self._tree.get_marital_status()) doc.demographics.language = self._tree.get_language() doc.demographics.race = messages.Code( **self._tree.get_race()) doc.demographics.ethnicity = messages.Code( **self._tree.get_ethnicity()) doc.demographics.religion = messages.Code( **self._tree.get_religion()) doc.demographics.birthplace = messages.Address( **self._tree.get_birthplace()) ''' # Labs. doc.labs = [] lab_parent = self._tree.get_entries_by_template(Root.LAB)[0] entries = lab_parent.getElementsByTagName('entry') for entry in entries: #prettyentry_string = entry.toprettyxml() lab = messages.Lab() observationEntries = entry.getElementsByTagName('observation') for observationEntry in observationEntries: observation = messages.Observation() ValueNode = observationEntry.getElementsByTagName('value') DateNode = observationEntry.getElementsByTagName( 'effectiveTime') try: observation.name = '' observation.value = ValueNode[0].attributes.getNamedItem( 'value').value observation.unit = ValueNode[0].attributes.getNamedItem( 'unit').value observation.date = datetime.datetime.strptime( DateNode[0].attributes.getNamedItem('value').value, '%Y%m%d%H%M%S-%f') lab.observations.append(observation) except: observation.name = '' observation.value = "error" observation.unit = "error" observation.date = datetime.datetime.strptime( '29000101', '%Y%m%d') doc.labs.append(lab) # Medications. doc.medications = [] entries = self._tree.get_entries_by_template(Root.MEDICATION) for entry in entries: prettyentry_string = entry.toprettyxml() medication = messages.Medication() medication.product = messages.Product() date_node = entry.getElementsByTagName('effectiveTime')[0] date_range = CcdaTree.get_date_range_from_node(date_node) medication.date_range = messages.DateRange(**date_range) product_node = entry.getElementsByTagName('manufacturedProduct')[0] product_code_node = product_node.getElementsByTagName('code')[0] product_code = CcdaTree.get_code_from_node(product_code_node) medication.product.code = messages.Code(**product_code) quantity_nodes = entry.getElementsByTagName('doseQuantity') if quantity_nodes: node = quantity_nodes[0] medication.dose_quantity = CcdaTree.get_quantity_message_from_node( node) rate_nodes = entry.getElementsByTagName('rateQuantity') if rate_nodes: node = rate_nodes[0] medication.rate_quantity = CcdaTree.get_quantity_message_from_node( node) # TODO: precondition, reason, route, vehicle, administration, prescriber. doc.medications.append(medication) # Problems. doc.problems = [] entries = self._tree.get_entries_by_template(Root.PROBLEM) for entry in entries: problem = messages.Problem() code_node = entry.getElementsByTagName('code')[0] problem_code = CcdaTree.get_code_from_node(code_node) problem.code = messages.Code(**problem_code) date_node = entry.getElementsByTagName('effectiveTime')[0] date_range = CcdaTree.get_date_range_from_node(date_node) problem.date_range = messages.DateRange(**date_range) status_nodes = self._tree.get_entries_by_template( Root.PROBLEM_STATUS, parent=entry) if status_nodes: status_node = status_nodes[0] entry_node = status_node.getElementsByTagName('value')[0] problem.status = entry_node.getAttribute('displayName') # TODO: Implement problem.age. doc.problems.append(problem) # Procedures. doc.procedures = [] procedure_parent = self._tree.get_entries_by_template( Root.PROCEDURE)[0] entries = procedure_parent.getElementsByTagName('entry') for entry in entries: procedure = messages.Procedure() code_node = entry.getElementsByTagName('code')[0] procedure_code = CcdaTree.get_code_from_node(code_node) procedure.code = messages.Code(**procedure_code) procedure.date = CcdaTree.get_date_from_effective_time(entry) # TODO: Implement specimen, performer, device. doc.procedures.append(procedure) # Vitals. doc.vitals = [] entries = self._tree.get_entries_by_template(Root.VITAL) for entry in entries: vital = messages.Vital() vital.date = CcdaTree.get_date_from_effective_time(entry) vital.results = [] result_entries = entry.getElementsByTagName('component') for result_entry in result_entries: vital_result = messages.VitalResult() code_node = result_entry.getElementsByTagName('code')[0] value_node = result_entry.getElementsByTagName('value')[0] vital_result_code = CcdaTree.get_code_from_node(code_node) vital_result.code = messages.Code(**vital_result_code) vital_result.value = long( float(value_node.getAttribute('value'))) vital_result.unit = value_node.getAttribute('unit') vital.results.append(vital_result) doc.vitals.append(vital) return doc
def to_message(self): """Converts the CCDA document to a ProtoRPC message.""" # TODO: Remove duplicate code. doc = messages.CcdaDocument() # Allergies. ''' My modification starts here ..''' doc.allergies = [ ] # Create a list to store details of allergies from given C-CDA Xml file. entries = self._tree.get_entries_by_template(Root.ALLERGY) ''' entries is a list. It holds DOMs (Document Object Model) for templates with attribute (root) value is Root.ALLERGY from a given C-CDA Xml. Regarding each DOM, we need to access tags and their attributes by using entry. ''' for entry in entries: allergy = messages.Allergy( ) # For each DOM, use messages.py to create an object of class Allergy to store # information about an allergy. ''' Enter allergy observation details ''' date_node = entry.getElementsByTagName('effectiveTime')[ 0] # date_node is first DOM for tag <effectiveTime>. date_range = CcdaTree.get_date_range_from_node(date_node) allergy.date_range = messages.DateRange(**date_range) participant = entry.getElementsByTagName('participant')[0] ''' # [0] for first participant object from a list of objects for <participant> under entry ''' if participant: participantRole = participant.getElementsByTagName( 'participantRole')[0] ''' # [0] for first participantRole object from a list of objects for <participantRole> under <participant> ''' if participantRole: playingEntity = participantRole.getElementsByTagName( 'playingEntity')[0] ''' # [0] for first playingEntity object from a list of objects for <playingEntity> under <participantRole> ''' code_node = playingEntity.getElementsByTagName('code')[0] ''' # [0] for first code object from a list of objects for <code> under <playingEntity> ''' allergy_code = CcdaTree.get_code_from_node(code_node) ''' get_code_from_node(code_node) assigns and returns values for attributes (code, codeSystem.. e.t.c) for <code> as code = '7982', displayName = 'Penicillin G benezathine, .... etc''' allergy.code = messages.Code(**allergy_code) ''' **kwargs is used to specify any number of arguments for a function and then it makes a dictionary from those arguments ''' ''' Enter allergy status details ''' allergy_status = self._tree.get_entries_by_template( Root.ALLERGY_STATUS, parent=entry)[0] allergy_status_value_node = allergy_status.getElementsByTagName( 'value')[0] allergy_status_value = CcdaTree.get_code_from_node( allergy_status_value_node) allergy.allergen = messages.Code(**allergy_status_value) ''' Enter allergy reaction details ''' allergy_reaction = self._tree.get_entries_by_template( Root.ALLERGY_RECATION, parent=entry)[0] allergy_reaction_value_node = allergy_reaction.getElementsByTagName( 'value')[0] allergy_reaction_value = CcdaTree.get_code_from_node( allergy_reaction_value_node) allergy.reaction = messages.Code(**allergy_reaction_value) ''' Enter allergy severity details ''' allergy_severity = self._tree.get_entries_by_template( Root.ALLERGY_SEVERITY, parent=entry)[0] allergy_severity_value_node = allergy_severity.getElementsByTagName( 'value')[0] allergy.severity = allergy_severity_value_node.getAttribute( 'displayName') doc.allergies.append(allergy) ''' For each entry, adds allergy object to prepare ProtoRPC message for allergies ''' ''' My modification ends here ....''' # Demographics. doc.demographics = messages.Demographic() doc.demographics.dob = self._tree.get_dob() doc.demographics.gender = messages.Code(**self._tree.get_gender()) doc.demographics.marital_status = messages.Code( **self._tree.get_marital_status()) doc.demographics.language = self._tree.get_language() doc.demographics.race = messages.Code(**self._tree.get_race()) doc.demographics.ethnicity = messages.Code( **self._tree.get_ethnicity()) doc.demographics.religion = messages.Code(**self._tree.get_religion()) doc.demographics.birthplace = messages.Address( **self._tree.get_birthplace()) # Immunizations. doc.immunizations = [] entries = self._tree.get_entries_by_template(Root.IMMUNIZATION) for entry in entries: product_node = self._tree.get_entries_by_template( Root.IMMUNIZATION_PRODUCT, parent=entry)[0] immunization = messages.Immunization() immunization.date = CcdaTree.get_date_from_effective_time(entry) immunization.product = messages.Product() code_node = product_node.getElementsByTagName('code')[0] product_code = CcdaTree.get_code_from_node(code_node) immunization.product.code = messages.Code(**product_code) doc.immunizations.append(immunization) # Labs. doc.labs = [] lab_parent = self._tree.get_entries_by_template(Root.LAB)[0] entries = lab_parent.getElementsByTagName('entry') for entry in entries: lab = messages.Lab() code_node = entry.getElementsByTagName('code')[0] lab_code = CcdaTree.get_code_from_node(code_node) lab.code = messages.Code(**lab_code) lab.result = messages.LabResult() component_node = entry.getElementsByTagName('component')[0] result_code_node = component_node.getElementsByTagName('code')[0] result_code = CcdaTree.get_code_from_node(result_code_node) lab.result.code = messages.Code(**result_code) doc.labs.append(lab) # Medications. doc.medications = [] entries = self._tree.get_entries_by_template(Root.MEDICATION) for entry in entries: medication = messages.Medication() medication.product = messages.Product() date_node = entry.getElementsByTagName('effectiveTime')[0] date_range = CcdaTree.get_date_range_from_node(date_node) medication.date_range = messages.DateRange(**date_range) product_node = entry.getElementsByTagName('manufacturedProduct')[0] product_code_node = product_node.getElementsByTagName('code')[0] product_code = CcdaTree.get_code_from_node(product_code_node) medication.product.code = messages.Code(**product_code) quantity_nodes = entry.getElementsByTagName('doseQuantity') if quantity_nodes: node = quantity_nodes[0] medication.dose_quantity = CcdaTree.get_quantity_message_from_node( node) rate_nodes = entry.getElementsByTagName('rateQuantity') if rate_nodes: node = rate_nodes[0] medication.rate_quantity = CcdaTree.get_quantity_message_from_node( node) # TODO: precondition, reason, route, vehicle, administration, prescriber. doc.medications.append(medication) # Problems. doc.problems = [] entries = self._tree.get_entries_by_template(Root.PROBLEM) for entry in entries: problem = messages.Problem() code_node = entry.getElementsByTagName('code')[0] problem_code = CcdaTree.get_code_from_node(code_node) problem.code = messages.Code(**problem_code) date_node = entry.getElementsByTagName('effectiveTime')[0] date_range = CcdaTree.get_date_range_from_node(date_node) problem.date_range = messages.DateRange(**date_range) status_nodes = self._tree.get_entries_by_template( Root.PROBLEM_STATUS, parent=entry) if status_nodes: status_node = status_nodes[0] entry_node = status_node.getElementsByTagName('value')[0] problem.status = entry_node.getAttribute('displayName') # TODO: Implement problem.age. doc.problems.append(problem) # Procedures. doc.procedures = [] procedure_parent = self._tree.get_entries_by_template( Root.PROCEDURE)[0] entries = procedure_parent.getElementsByTagName('entry') for entry in entries: procedure = messages.Procedure() code_node = entry.getElementsByTagName('code')[0] procedure_code = CcdaTree.get_code_from_node(code_node) procedure.code = messages.Code(**procedure_code) procedure.date = CcdaTree.get_date_from_effective_time(entry) # TODO: Implement specimen, performer, device. doc.procedures.append(procedure) # Vitals. doc.vitals = [] entries = self._tree.get_entries_by_template(Root.VITAL) for entry in entries: vital = messages.Vital() vital.date = CcdaTree.get_date_from_effective_time(entry) vital.results = [] result_entries = entry.getElementsByTagName('component') for result_entry in result_entries: vital_result = messages.VitalResult() code_node = result_entry.getElementsByTagName('code')[0] value_node = result_entry.getElementsByTagName('value')[0] vital_result_code = CcdaTree.get_code_from_node(code_node) vital_result.code = messages.Code(**vital_result_code) vital_result.value = long( float(value_node.getAttribute('value'))) vital_result.unit = value_node.getAttribute('unit') vital.results.append(vital_result) doc.vitals.append(vital) return doc