lib/health-data-standards/export/ccr.rb in health-data-standards-0.5.0 vs lib/health-data-standards/export/ccr.rb in health-data-standards-0.7.0

- old
+ new

@@ -25,33 +25,34 @@ xml.ActorLink do xml.ActorID("AA0002") end end to_ccr_purpose(xml) - xml.body do + xml.Body do to_ccr_problems(xml, patient) - to_ccr_vitals(xml, patient) - to_ccr_results(xml, patient) - to_ccr_encounters(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_allergies(xml, patient) + to_ccr_encounters(xml, patient) + end to_ccr_actors(xml, patient) end end extend self private def code_section(xml, codes) - xml.Code do - if codes.present? - codes.each_pair do |code_set, coded_values| - coded_values.each do |coded_value| + if codes.present? + codes.each_pair do |code_set, coded_values| + coded_values.each do |coded_value| + xml.Code do xml.Value(coded_value) xml.CodingSystem(code_set) #TODO: Need to fix this and not be a hard-coded value xml.Version("2005") end @@ -69,10 +70,11 @@ xml.ActorID(patient.id) end end end + # Builds the XML snippet for the problems section inside the CCR standard # # @return [Builder::XmlMarkup] CCR XML representation of patient data def to_ccr_problems(xml, patient) if patient.conditions.present? @@ -134,29 +136,61 @@ # @return [Builder::XmlMarkup] CCR XML representation of patient data def to_ccr_vitals(xml, patient) if patient.vital_signs.present? xml.VitalSigns do patient.vital_signs.each_with_index do |vital_sign, index| - xml.Result do - xml.CCRDataObjectID("VT000#{index + 1}") - xml.DateTime do - xml.Type do - xml.Text("Start date") - end - #time - xml.ExactDateTime(convert_to_ccr_time_string(vital_sign.time)) - end - xml.Description do - xml.Text(vital_sign.description) - code_section(xml, vital_sign.codes) - end - end + to_result(xml,vital_sign,"VT000#{index + 1}") end end end end + + # Builds the XML snippet for the lab section inside the CCR standard + # + # @return [Builder::XmlMarkup] CCR XML representation of patient data + def to_ccr_results(xml, patient) + if patient.results.present? + xml.Results do + patient.results.each_with_index do |lab_result, index| + to_result(xml,lab_result,"LB000#{index + 1}") + end + end + end + end + + + 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 + xml.Description do + xml.Text(res.description) + code_section(xml, res.codes) + end + + xml.Source + xml.Test do + xml.CCRDataObjectID("#{ccr_id}TestResult") + xml.Source + xml.TestResult do + xml.Value(res.value["scalar"]) + xml.Units do + xml.Unit(res.value["units"]) + end + end + end + end + + end + # Builds the XML snippet for the medications section inside the CCR standard # # @return [Builder::XmlMarkup] CCR XML representation of patient data def to_ccr_medications(xml, patient) if patient.medications.present? @@ -223,35 +257,11 @@ end end end end - # Builds the XML snippet for the lab section inside the CCR standard - # - # @return [Builder::XmlMarkup] CCR XML representation of patient data - def to_ccr_results(xml, patient) - if patient.results.present? - xml.Results do - patient.results.each_with_index do |lab_result, index| - xml.Result do - xml.CCRDataObjectID("LB000#{index + 1}") - xml.DateTime do - xml.Type do - xml.Text("Start date") - end - #time - xml.ExactDateTime(convert_to_ccr_time_string(lab_result.time)) - end - xml.Description do - xml.Text(lab_result.description) - code_section(xml, lab_result.codes) - end - end - end - end - end - end + # Builds the XML snippet for the procedures section inside the CCR standard # # @return [Builder::XmlMarkup] CCR XML representation of patient data def to_ccr_procedures(xml, patient) @@ -272,10 +282,11 @@ code_section(xml, procedure.codes) end xml.Status do xml.Text("Active") end + xml.Source end end end end end @@ -301,10 +312,11 @@ code_section(xml, allergy.codes) end xml.Status do xml.Text("Current") end + xml.Source end end end end end @@ -313,22 +325,22 @@ # # @return [Builder::XmlMarkup] CCR XML representation of patient data def to_ccr_actors(xml, patient) xml.Actors do xml.Actor do - xml.ActorObjectID("AA0001") + xml.ActorObjectID(patient.id) xml.Person do xml.Name do xml.CurrentName do xml.Given(patient.first) xml.Family(patient.last) end end - end - xml.DateOfBirth do - xml.ExactDateTime(convert_to_ccr_time_string(patient.birthdate)) - if (patient.gender) + xml.DateOfBirth do + xml.ExactDateTime(convert_to_ccr_time_string(patient.birthdate)) + end + if (patient.gender) xml.Gender do if (patient.gender.upcase == "M") xml.Text("Male") elsif (patient.gender.upcase == "F") xml.Text("Female") @@ -336,9 +348,10 @@ xml.Text("Undifferentiated") end end end end + xml.Source end end end # Builds the XML snippet for a purpose section inside the CCR standard \ No newline at end of file