lib/health-data-standards/export/ccr.rb in health-data-standards-0.7.1 vs lib/health-data-standards/export/ccr.rb in health-data-standards-0.8.0

- old
+ new

@@ -26,20 +26,21 @@ xml.ActorID("AA0002") end end to_ccr_purpose(xml) xml.Body do + to_ccr_problems(xml, patient) + to_ccr_socialhistory(xml, patient) to_ccr_allergies(xml, patient) + to_ccr_medications(xml, patient) to_ccr_immunizations(xml, patient) to_ccr_vitals(xml, patient) to_ccr_results(xml, patient) to_ccr_procedures(xml, patient) - to_ccr_encounters(xml, patient) - to_ccr_socialhistory(xml, patient) - + to_ccr_encounters(xml, patient) end to_ccr_actors(xml, patient) end end @@ -81,17 +82,11 @@ if patient.conditions.present? xml.Problems do patient.conditions.each_with_index do |condition, index| xml.Problem do xml.CCRDataObjectID("PR000#{index + 1}") - xml.DateTime do - xml.Type do - xml.Text("Start date") - end - #time - xml.ExactDateTime(convert_to_ccr_time_string(condition.time)) - end + to_ccr_date(xml, condition.as_point_in_time, "Start date") xml.Type do #TODO: Need to fix this and not be a hard-coded value xml.Text("Diagnosis") end xml.Description do @@ -112,17 +107,11 @@ if patient.encounters.present? xml.Encounters do patient.encounters.each_with_index do |encounter, index| xml.Encounter do xml.CCRDataObjectID("EN000#{index + 1}") - xml.DateTime do - xml.Type do - xml.Text("Encounter Date") - end - #time - xml.ExactDateTime(convert_to_ccr_time_string(encounter.time)) - end + to_ccr_date(xml, encounter.as_point_in_time, "Encounter Date") xml.Description do xml.Text(encounter.description) code_section(xml, encounter.codes) end active_status_and_source(xml, patient) @@ -161,18 +150,11 @@ def to_result(xml, res, ccr_id ) xml.Result do xml.CCRDataObjectID(ccr_id) - xml.DateTime do - xml.Type do - xml.Text("Start date") - end - #time - xml.ExactDateTime(convert_to_ccr_time_string(res.time)) - end - + to_ccr_date(xml, res.as_point_in_time, "Start date") xml.Source xml.Test do xml.CCRDataObjectID("#{ccr_id}TestResult") xml.Description do xml.Text(res.description) @@ -198,17 +180,11 @@ if patient.medications.present? xml.Medications do patient.medications.each_with_index do |medication, index| xml.Medication do xml.CCRDataObjectID("MD000#{index + 1}") - xml.DateTime do - xml.Type do - xml.Text("Prescription Date") - end - #time - xml.ExactDateTime(convert_to_ccr_time_string(medication.time)) - end + to_ccr_date(xml, medication.as_point_in_time, "Prescription Date") xml.Type do xml.Text("Medication") end active_status_and_source(xml, patient) xml.Product do @@ -233,17 +209,11 @@ if patient.immunizations.present? xml.Immunizations do patient.immunizations.each_with_index do |immunization, index| xml.Immunization do xml.CCRDataObjectID("IM000#{index + 1}") - xml.DateTime do - xml.Type do - xml.Text("Prescription Date") - end - #time - xml.ExactDateTime(convert_to_ccr_time_string(immunization.time)) - end + to_ccr_date(xml, immunization.as_point_in_time, "Prescription Date") xml.Type do xml.Text("Immunization") end active_status_and_source(xml, patient) xml.Product do @@ -270,17 +240,11 @@ if patient.procedures.present? xml.Procedures do patient.procedures.each_with_index do |procedure, index| xml.Procedure do xml.CCRDataObjectID("PR000#{index + 1}") - xml.DateTime do - xml.Type do - xml.Text("Service date") - end - #time - xml.ExactDateTime(convert_to_ccr_time_string(procedure.time)) - end + to_ccr_date(xml, procedure.as_point_in_time, "Service date") xml.Description do xml.Text(procedure.description) code_section(xml, procedure.codes) end xml.Status do @@ -297,17 +261,11 @@ if patient.allergies.present? xml.Alerts do patient.allergies.each_with_index do |allergy, index| xml.Alert do xml.CCRDataObjectID("AL000#{index + 1}") - xml.DateTime do - xml.Type do - xml.Text("Initial Occurrence") - end - #time - xml.ExactDateTime(convert_to_ccr_time_string(allergy.time)) - end + to_ccr_date(xml, allergy.as_point_in_time, "Initial Occurrence") xml.Type do xml.Text("Allergy") end xml.Description do xml.Text(allergy.description) @@ -337,13 +295,42 @@ xml.Description do xml.Text(history.description) code_section(xml, history.codes) end - + xml.Source end end + + if patient.race + xml.SocialHistoryElement do + xml.CCRDataObjectID("SH000RACE") + xml.Type do + xml.Text("Race") + end + xml.Description do + + code_section(xml, {"2.16.840.1.113883.6.238"=>[patient.race["code"]]}) + end + xml.Source + end + end + + if patient.ethnicity + xml.SocialHistoryElement do + xml.CCRDataObjectID("SH000ETHICITY") + xml.Type do + xml.Text("Ethnicity") + end + xml.Description do + + code_section(xml, {"2.16.840.1.113883.6.238" => [patient.ethnicity["code"]]}) + end + xml.Source + end + end + end end end # Builds the XML snippet for a actors section inside the CCR standard @@ -402,11 +389,23 @@ end end end def convert_to_ccr_time_string(time) - converted_time = Time.at(time) - converted_time.strftime("%Y-%m-%dT%H:%M:%SZ") + converted_time = Time.at(time) + converted_time.strftime("%Y-%m-%dT%H:%M:%SZ") + end + + def to_ccr_date(xml, time, type) + if time + xml.DateTime do + xml.Type do + xml.Text(type) + end + #time + xml.ExactDateTime(convert_to_ccr_time_string(time)) + end + end end end end end \ No newline at end of file