health-data-standards 2.2.1 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/lib/health-data-standards.rb +55 -12
- data/lib/health-data-standards/export/c32.rb +7 -6
- data/lib/health-data-standards/export/cat_1.rb +18 -0
- data/lib/health-data-standards/export/ccda.rb +8 -8
- data/lib/health-data-standards/export/green_c32/entry.rb +8 -5
- data/lib/health-data-standards/export/green_c32/export_generator.rb +1 -1
- data/lib/health-data-standards/export/green_c32/record.rb +10 -7
- data/lib/health-data-standards/export/hdata/metadata.rb +7 -6
- data/lib/health-data-standards/export/helper/cat1_view_helper.rb +133 -0
- data/lib/health-data-standards/export/helper/gc32_view_helper.rb +39 -0
- data/lib/health-data-standards/export/helper/html_view_helper.rb +23 -0
- data/lib/health-data-standards/export/html.rb +22 -10
- data/lib/health-data-standards/export/qrda/entry_template_resolver.rb +31 -0
- data/lib/health-data-standards/export/qrda/hqmf-qrda-oids.json +638 -0
- data/lib/health-data-standards/export/rendering_context.rb +37 -3
- data/lib/health-data-standards/export/template_helper.rb +20 -23
- data/lib/health-data-standards/export/view_helper.rb +8 -42
- data/lib/health-data-standards/import/bundle/importer.rb +148 -0
- data/lib/health-data-standards/import/c32/care_goal_importer.rb +14 -26
- data/lib/health-data-standards/import/c32/condition_importer.rb +12 -51
- data/lib/health-data-standards/import/c32/immunization_importer.rb +9 -27
- data/lib/health-data-standards/import/c32/insurance_provider_importer.rb +24 -21
- data/lib/health-data-standards/import/c32/patient_importer.rb +27 -34
- data/lib/health-data-standards/import/cat1/diagnosis_active_importer.rb +19 -0
- data/lib/health-data-standards/import/cat1/diagnosis_inactive_importer.rb +19 -0
- data/lib/health-data-standards/import/cat1/diagnostic_study_order_importer.rb +24 -0
- data/lib/health-data-standards/import/cat1/encounter_order_importer.rb +24 -0
- data/lib/health-data-standards/import/cat1/entry_package.rb +25 -0
- data/lib/health-data-standards/import/cat1/gestational_age_importer.rb +42 -0
- data/lib/health-data-standards/import/cat1/lab_order_importer.rb +24 -0
- data/lib/health-data-standards/import/cat1/medication_dispensed_importer.rb +13 -0
- data/lib/health-data-standards/import/cat1/patient_importer.rb +104 -0
- data/lib/health-data-standards/import/cat1/procedure_intolerance_importer.rb +13 -0
- data/lib/health-data-standards/import/cat1/procedure_order_importer.rb +38 -0
- data/lib/health-data-standards/import/cat1/tobacco_use_importer.rb +19 -0
- data/lib/health-data-standards/import/ccda/allergy_importer.rb +2 -8
- data/lib/health-data-standards/import/ccda/care_goal_importer.rb +1 -1
- data/lib/health-data-standards/import/ccda/condition_importer.rb +2 -3
- data/lib/health-data-standards/import/ccda/encounter_importer.rb +2 -5
- data/lib/health-data-standards/import/ccda/immunization_importer.rb +1 -3
- data/lib/health-data-standards/import/ccda/insurance_provider_importer.rb +1 -1
- data/lib/health-data-standards/import/ccda/medical_equipment_importer.rb +2 -4
- data/lib/health-data-standards/import/ccda/medication_importer.rb +2 -4
- data/lib/health-data-standards/import/ccda/patient_importer.rb +1 -1
- data/lib/health-data-standards/import/ccda/procedure_importer.rb +2 -6
- data/lib/health-data-standards/import/ccda/result_importer.rb +2 -5
- data/lib/health-data-standards/import/ccda/vital_sign_importer.rb +2 -3
- data/lib/health-data-standards/import/cda/allergy_importer.rb +32 -0
- data/lib/health-data-standards/import/cda/condition_importer.rb +51 -0
- data/lib/health-data-standards/import/{c32 → cda}/encounter_importer.rb +9 -35
- data/lib/health-data-standards/import/cda/entry_finder.rb +22 -0
- data/lib/health-data-standards/import/{c32 → cda}/locatable_import_utils.rb +2 -3
- data/lib/health-data-standards/import/cda/medical_equipment_importer.rb +24 -0
- data/lib/health-data-standards/import/{c32 → cda}/medication_importer.rb +13 -15
- data/lib/health-data-standards/import/cda/narrative_reference_handler.rb +35 -0
- data/lib/health-data-standards/import/{c32 → cda}/organization_importer.rb +1 -1
- data/lib/health-data-standards/import/cda/procedure_importer.rb +35 -0
- data/lib/health-data-standards/import/{c32 → cda}/provider_importer.rb +4 -8
- data/lib/health-data-standards/import/cda/result_importer.rb +31 -0
- data/lib/health-data-standards/import/{c32 → cda}/section_importer.rb +26 -48
- data/lib/health-data-standards/import/{c32 → cda}/vital_sign_importer.rb +2 -3
- data/lib/health-data-standards/import/green_c32/section_importer.rb +8 -6
- data/lib/health-data-standards/import/provider_import_utils.rb +2 -2
- data/lib/health-data-standards/models/address.rb +1 -1
- data/lib/health-data-standards/models/condition.rb +7 -6
- data/lib/health-data-standards/models/cqm/bundle.rb +45 -0
- data/lib/health-data-standards/models/cqm/measure.rb +36 -0
- data/lib/health-data-standards/models/guarantor.rb +1 -0
- data/lib/health-data-standards/models/insurance_provider.rb +2 -0
- data/lib/health-data-standards/models/order_information.rb +2 -0
- data/lib/health-data-standards/models/record.rb +6 -5
- data/lib/health-data-standards/models/svs/value_set.rb +1 -1
- data/lib/health-data-standards/railtie.rb +11 -0
- data/lib/health-data-standards/tasks/bundle.rake +107 -0
- data/lib/health-data-standards/util/code_system_helper.rb +9 -1
- data/lib/hqmf-generator/attribute.xml.erb +11 -0
- data/lib/hqmf-generator/characteristic_criteria.xml.erb +21 -0
- data/lib/hqmf-generator/code.xml.erb +13 -0
- data/lib/hqmf-generator/condition_criteria.xml.erb +22 -0
- data/lib/hqmf-generator/derivation.xml.erb +6 -0
- data/lib/hqmf-generator/description.xml.erb +1 -0
- data/lib/hqmf-generator/document.xml.erb +63 -0
- data/lib/hqmf-generator/effective_time.xml.erb +4 -0
- data/lib/hqmf-generator/encounter_criteria.xml.erb +21 -0
- data/lib/hqmf-generator/field.xml.erb +28 -0
- data/lib/hqmf-generator/hqmf-generator.rb +292 -0
- data/lib/hqmf-generator/observation_criteria.xml.erb +25 -0
- data/lib/hqmf-generator/population_criteria.xml.erb +23 -0
- data/lib/hqmf-generator/precondition.xml.erb +14 -0
- data/lib/hqmf-generator/procedure_criteria.xml.erb +22 -0
- data/lib/hqmf-generator/reason.xml.erb +3 -0
- data/lib/hqmf-generator/reference.xml.erb +3 -0
- data/lib/hqmf-generator/source.xml.erb +6 -0
- data/lib/hqmf-generator/specific_occurrence.xml.erb +7 -0
- data/lib/hqmf-generator/subset.xml.erb +8 -0
- data/lib/hqmf-generator/substance_criteria.xml.erb +26 -0
- data/lib/hqmf-generator/supply_criteria.xml.erb +26 -0
- data/lib/hqmf-generator/template_id.xml.erb +5 -0
- data/lib/hqmf-generator/temporal_relationship.xml.erb +6 -0
- data/lib/hqmf-generator/value.xml.erb +24 -0
- data/lib/hqmf-generator/variable_criteria.xml.erb +12 -0
- data/lib/hqmf-model/attribute.rb +35 -0
- data/lib/hqmf-model/data_criteria.json +1123 -0
- data/lib/hqmf-model/data_criteria.rb +344 -0
- data/lib/hqmf-model/document.rb +178 -0
- data/lib/hqmf-model/population_criteria.rb +96 -0
- data/lib/hqmf-model/precondition.rb +91 -0
- data/lib/hqmf-model/types.rb +319 -0
- data/lib/hqmf-model/utilities.rb +52 -0
- data/lib/hqmf-parser.rb +56 -0
- data/lib/hqmf-parser/1.0/attribute.rb +68 -0
- data/lib/hqmf-parser/1.0/comparison.rb +34 -0
- data/lib/hqmf-parser/1.0/data_criteria.rb +92 -0
- data/lib/hqmf-parser/1.0/data_criteria_oid_xpath.json +91 -0
- data/lib/hqmf-parser/1.0/document.rb +203 -0
- data/lib/hqmf-parser/1.0/expression.rb +58 -0
- data/lib/hqmf-parser/1.0/observation.rb +61 -0
- data/lib/hqmf-parser/1.0/population_criteria.rb +75 -0
- data/lib/hqmf-parser/1.0/precondition.rb +89 -0
- data/lib/hqmf-parser/1.0/range.rb +65 -0
- data/lib/hqmf-parser/1.0/restriction.rb +160 -0
- data/lib/hqmf-parser/1.0/utilities.rb +41 -0
- data/lib/hqmf-parser/2.0/data_criteria.rb +319 -0
- data/lib/hqmf-parser/2.0/document.rb +165 -0
- data/lib/hqmf-parser/2.0/population_criteria.rb +53 -0
- data/lib/hqmf-parser/2.0/precondition.rb +44 -0
- data/lib/hqmf-parser/2.0/types.rb +223 -0
- data/lib/hqmf-parser/2.0/utilities.rb +30 -0
- data/lib/hqmf-parser/converter/pass1/data_criteria_converter.rb +252 -0
- data/lib/hqmf-parser/converter/pass1/document_converter.rb +185 -0
- data/lib/hqmf-parser/converter/pass1/population_criteria_converter.rb +165 -0
- data/lib/hqmf-parser/converter/pass1/precondition_converter.rb +173 -0
- data/lib/hqmf-parser/converter/pass1/precondition_extractor.rb +188 -0
- data/lib/hqmf-parser/converter/pass1/simple_data_criteria.rb +26 -0
- data/lib/hqmf-parser/converter/pass1/simple_operator.rb +89 -0
- data/lib/hqmf-parser/converter/pass1/simple_population_criteria.rb +10 -0
- data/lib/hqmf-parser/converter/pass1/simple_precondition.rb +51 -0
- data/lib/hqmf-parser/converter/pass1/simple_restriction.rb +64 -0
- data/lib/hqmf-parser/converter/pass2/comparison_converter.rb +112 -0
- data/lib/hqmf-parser/converter/pass2/operator_converter.rb +102 -0
- data/lib/hqmf-parser/parser.rb +54 -0
- data/lib/hqmf-parser/value_sets/value_set_parser.rb +241 -0
- data/lib/util/counter.rb +20 -0
- data/templates/{_allergies.c32.erb → c32/_allergies.c32.erb} +0 -0
- data/templates/{_allergies_no_current.c32.erb → c32/_allergies_no_current.c32.erb} +0 -0
- data/templates/{_care_goals.c32.erb → c32/_care_goals.c32.erb} +0 -0
- data/templates/{_code_with_reference.c32.erb → c32/_code_with_reference.c32.erb} +0 -0
- data/templates/{_conditions.c32.erb → c32/_conditions.c32.erb} +0 -0
- data/templates/{_conditions_no_current.c32.erb → c32/_conditions_no_current.c32.erb} +0 -0
- data/templates/{_encounters.c32.erb → c32/_encounters.c32.erb} +0 -0
- data/templates/{_immunizations.c32.erb → c32/_immunizations.c32.erb} +0 -0
- data/templates/{_medical_equipment.c32.erb → c32/_medical_equipment.c32.erb} +0 -0
- data/templates/{_medications.c32.erb → c32/_medications.c32.erb} +0 -0
- data/templates/{_medications_no_current.c32.erb → c32/_medications_no_current.c32.erb} +0 -0
- data/templates/{_narrative_block.c32.erb → c32/_narrative_block.c32.erb} +0 -0
- data/templates/{_procedures.c32.erb → c32/_procedures.c32.erb} +0 -0
- data/templates/{_results.c32.erb → c32/_results.c32.erb} +0 -0
- data/templates/{_social_history.c32.erb → c32/_social_history.c32.erb} +0 -0
- data/templates/{_vital_signs.c32.erb → c32/_vital_signs.c32.erb} +0 -0
- data/templates/{show.c32.erb → c32/show.c32.erb} +0 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.22.4.85.cat1.erb +18 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.1.cat1.erb +14 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.101.cat1.erb +25 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.103.cat1.erb +12 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.105.cat1.erb +60 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.11.cat1.erb +41 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.12.cat1.erb +50 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.13.cat1.erb +37 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.14.cat1.erb +35 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.17.cat1.erb +22 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.18.cat1.erb +21 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.2.cat1.erb +28 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.20.cat1.erb +20 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.22.cat1.erb +21 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.23.cat1.erb +71 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.28.cat1.erb +20 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.3.cat1.erb +24 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.31.cat1.erb +20 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.32.cat1.erb +15 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.34.cat1.erb +58 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.37.cat1.erb +20 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.38.cat1.erb +16 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.4.cat1.erb +27 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.40.cat1.erb +17 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.41.cat1.erb +38 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.42.cat1.erb +38 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.43.cat1.erb +24 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.44.cat1.erb +24 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.45.cat1.erb +26 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.46.cat1.erb +30 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.47.cat1.erb +26 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.51.cat1.erb +13 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.54.cat1.erb +16 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.55.cat1.erb +10 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.57.cat1.erb +19 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.59.cat1.erb +17 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.62.cat1.erb +36 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.63.cat1.erb +23 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.64.cat1.erb +29 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.66.cat1.erb +34 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.69.cat1.erb +23 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.7.cat1.erb +30 -0
- data/templates/cat1/_2.16.840.1.113883.10.20.24.3.76.cat1.erb +32 -0
- data/templates/cat1/_measures.cat1.erb +66 -0
- data/templates/cat1/_medication_details.cat1.erb +9 -0
- data/templates/cat1/_ordinality.cat1.erb +4 -0
- data/templates/cat1/_patient_data.cat1.erb +14 -0
- data/templates/cat1/_reason.cat1.erb +16 -0
- data/templates/cat1/_record_target.cat1.erb +39 -0
- data/templates/cat1/_reporting_parameters.cat1.erb +24 -0
- data/templates/cat1/_result_value.cat1.erb +16 -0
- data/templates/cat1/show.cat1.erb +125 -0
- data/templates/{_address.gc32.erb → gc32/_address.gc32.erb} +1 -1
- data/templates/gc32/_advance_directive.gc32.erb +5 -0
- data/templates/gc32/_allergy.gc32.erb +12 -0
- data/templates/{_care_goal.gc32.erb → gc32/_care_goal.gc32.erb} +1 -1
- data/templates/gc32/_condition.gc32.erb +10 -0
- data/templates/gc32/_encounter.gc32.erb +28 -0
- data/templates/gc32/_entry.gc32.erb +3 -0
- data/templates/gc32/_entry_attributes.gc32.erb +10 -0
- data/templates/gc32/_immunization.gc32.erb +9 -0
- data/templates/gc32/_insurance_provider.gc32.erb +28 -0
- data/templates/gc32/_medical_equipment.gc32.erb +6 -0
- data/templates/gc32/_medication.gc32.erb +91 -0
- data/templates/{_name.gc32.erb → gc32/_name.gc32.erb} +0 -0
- data/templates/gc32/_organization.gc32.erb +10 -0
- data/templates/gc32/_person_attributes.gc32.erb +7 -0
- data/templates/gc32/_procedure.gc32.erb +9 -0
- data/templates/gc32/_provider.gc32.erb +9 -0
- data/templates/gc32/_result.gc32.erb +12 -0
- data/templates/gc32/_social_history.gc32.erb +6 -0
- data/templates/{_support.gc32.erb → gc32/_support.gc32.erb} +4 -3
- data/templates/gc32/_telecom.gc32.erb +1 -0
- data/templates/gc32/_vital_sign.gc32.erb +4 -0
- data/templates/{record.gc32.erb → gc32/record.gc32.erb} +26 -10
- data/templates/html/_entries_by_encounter.html.erb +2 -2
- data/templates/html/_entries_by_section.html.erb +1 -1
- data/templates/html/_entry.html.erb +16 -21
- data/templates/html/_header.html.erb +1 -1
- data/templates/html/_section.html.erb +1 -1
- data/templates/html/show.html.erb +23 -2
- data/templates/metadata.hdata.erb +3 -3
- metadata +282 -54
- data/lib/health-data-standards/import/c32/allergy_importer.rb +0 -47
- data/lib/health-data-standards/import/c32/medical_equipment_importer.rb +0 -45
- data/lib/health-data-standards/import/c32/procedure_importer.rb +0 -62
- data/lib/health-data-standards/import/c32/result_importer.rb +0 -56
- data/templates/_advance_directive.gc32.erb +0 -8
- data/templates/_allergy.gc32.erb +0 -23
- data/templates/_condition.gc32.erb +0 -9
- data/templates/_encounter.gc32.erb +0 -26
- data/templates/_entry.gc32.erb +0 -14
- data/templates/_immunization.gc32.erb +0 -11
- data/templates/_insurance_provider.gc32.erb +0 -0
- data/templates/_medical_equipment.gc32.erb +0 -7
- data/templates/_medication.gc32.erb +0 -72
- data/templates/_organization.gc32.erb +0 -10
- data/templates/_procedure.gc32.erb +0 -10
- data/templates/_provider.gc32.erb +0 -19
- data/templates/_result.gc32.erb +0 -16
- data/templates/_social_history.gc32.erb +0 -8
- data/templates/_telecom.gc32.erb +0 -1
- data/templates/_vital_sign.gc32.erb +0 -7
@@ -0,0 +1,102 @@
|
|
1
|
+
module HQMF
|
2
|
+
# Class for converting an HQMF 1.0 representation to an HQMF 2.0 representation
|
3
|
+
class OperatorConverter
|
4
|
+
|
5
|
+
def self.apply_temporal(data_criteria, precondition, restriction, data_criteria_converter)
|
6
|
+
data_criteria.temporal_references ||= []
|
7
|
+
value = restriction.operator.value
|
8
|
+
type = restriction.operator.type
|
9
|
+
temporal_reference = nil
|
10
|
+
if (restriction.single_target?)
|
11
|
+
# multiple targets appears to be the result of restrictions with restrictions
|
12
|
+
target = restriction.target
|
13
|
+
if (restriction.multi_target?)
|
14
|
+
found = false
|
15
|
+
# restrictions with restrictions can have a target that is modified by the child restrcitons
|
16
|
+
restriction.preconditions.each do |precondition|
|
17
|
+
if precondition.reference.id.start_with? target
|
18
|
+
found = true
|
19
|
+
target = precondition.reference.id
|
20
|
+
end
|
21
|
+
end
|
22
|
+
unless found
|
23
|
+
puts "\tmultiple targets... need to check this" if restriction.multi_target?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
temporal_reference = HQMF::TemporalReference.new(type, HQMF::Reference.new(target),value)
|
27
|
+
data_criteria_converter.validate_not_deleted(target)
|
28
|
+
elsif (restriction.multi_target?)
|
29
|
+
|
30
|
+
children_criteria = HQMF::DataCriteriaConverter.extract_data_criteria(restriction.preconditions, data_criteria_converter)
|
31
|
+
|
32
|
+
if (children_criteria.length == 1)
|
33
|
+
target = children_criteria[0].id
|
34
|
+
temporal_reference = HQMF::TemporalReference.new(type, HQMF::Reference.new(target),value)
|
35
|
+
data_criteria_converter.validate_not_deleted(target)
|
36
|
+
else
|
37
|
+
parent_id = "GROUP"
|
38
|
+
if restriction.generated_data_criteria.nil?
|
39
|
+
# we pass in restriction.preconditions here rather than children_criteria because we need to be able to create grouping data criteria for and and or preconditions in a tree
|
40
|
+
group_criteria = data_criteria_converter.create_group_data_criteria(restriction.preconditions, "#{type}_CHILDREN", value, parent_id, HQMF::Counter.instance.next, "grouping", "temporal")
|
41
|
+
# save the generated grouping criteria so that we can reference it from other locations
|
42
|
+
restriction.generated_data_criteria = group_criteria
|
43
|
+
else
|
44
|
+
# we have already processed this restriction and have a grouping criteria for it. Take the one we have previously generated
|
45
|
+
group_criteria = restriction.generated_data_criteria
|
46
|
+
end
|
47
|
+
temporal_reference = HQMF::TemporalReference.new(type, HQMF::Reference.new(group_criteria.id), value)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
raise "no target for temporal restriction"
|
51
|
+
end
|
52
|
+
restriction.converted=true
|
53
|
+
|
54
|
+
# add temporal reference to data criteria
|
55
|
+
data_criteria.temporal_references << temporal_reference unless data_criteria.has_temporal(temporal_reference)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def self.apply_summary(data_criteria, precondition, restriction, data_criteria_converter)
|
60
|
+
value = restriction.operator.value
|
61
|
+
type = restriction.operator.type
|
62
|
+
subset_operator = HQMF::SubsetOperator.new(type, value)
|
63
|
+
|
64
|
+
if (restriction.multi_target?)
|
65
|
+
children_criteria = HQMF::DataCriteriaConverter.extract_data_criteria(restriction.preconditions, data_criteria_converter)
|
66
|
+
|
67
|
+
data_criteria = nil
|
68
|
+
if (children_criteria.length == 1)
|
69
|
+
data_criteria = children_criteria[0]
|
70
|
+
data_criteria.subset_operators ||= []
|
71
|
+
# add subset operator to data criteria
|
72
|
+
data_criteria.subset_operators << subset_operator unless data_criteria.has_subset(subset_operator)
|
73
|
+
else
|
74
|
+
parent_id = "GROUP"
|
75
|
+
|
76
|
+
if restriction.generated_data_criteria.nil?
|
77
|
+
# we pass in restriction.preconditions here rather than children_criteria because we need to be able to create grouping data criteria for and and or preconditions in a tree
|
78
|
+
data_criteria = data_criteria_converter.create_group_data_criteria(restriction.preconditions, type, value, parent_id, HQMF::Counter.instance.next, "grouping", "summary")
|
79
|
+
# save the generated grouping criteria so that we can reference it from other locations
|
80
|
+
restriction.generated_data_criteria = data_criteria
|
81
|
+
else
|
82
|
+
# we have already processed this restriction and have a grouping criteria for it. Take the one we have previously generated
|
83
|
+
data_criteria = restriction.generated_data_criteria
|
84
|
+
end
|
85
|
+
|
86
|
+
data_criteria.subset_operators ||= []
|
87
|
+
# add subset operator to data criteria
|
88
|
+
data_criteria.subset_operators << subset_operator unless data_criteria.has_subset(subset_operator)
|
89
|
+
end
|
90
|
+
precondition.reference = HQMF::Reference.new(data_criteria.id)
|
91
|
+
elsif (restriction.single_target?)
|
92
|
+
subset_operator = HQMF::SubsetOperator.new(type, value)
|
93
|
+
data_criteria.subset_operators ||= []
|
94
|
+
# add subset operator to data criteria
|
95
|
+
data_criteria.subset_operators << subset_operator unless data_criteria.has_subset(subset_operator)
|
96
|
+
end
|
97
|
+
|
98
|
+
restriction.converted=true
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module HQMF
|
2
|
+
class Parser
|
3
|
+
|
4
|
+
HQMF_VERSION_1 = "1.0"
|
5
|
+
HQMF_VERSION_2 = "2.0"
|
6
|
+
|
7
|
+
def self.parse(hqmf_contents, version, codes = nil)
|
8
|
+
|
9
|
+
HQMF::Counter.instance.reset()
|
10
|
+
case version
|
11
|
+
when HQMF_VERSION_1
|
12
|
+
puts("\tCodes not passed in, cannot backfill properties like gender") unless codes
|
13
|
+
HQMF::DocumentConverter.convert(HQMF1::Document.new(hqmf_contents).to_json, codes)
|
14
|
+
when HQMF_VERSION_2
|
15
|
+
HQMF2::Document.new(hqmf_contents).to_model
|
16
|
+
else
|
17
|
+
raise "Unsupported HQMF version specified: #{version}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.parse_fields(hqmf_contents, version)
|
22
|
+
result = {}
|
23
|
+
case version
|
24
|
+
when HQMF_VERSION_1
|
25
|
+
doc = HQMF1::Document.parse(hqmf_contents)
|
26
|
+
type = doc.at_xpath('//cda:code/@code').value
|
27
|
+
if type == '57024-2'
|
28
|
+
id = doc.at_xpath('//cda:id/@root').value.upcase
|
29
|
+
set_id = doc.at_xpath('//cda:setId/@root').value.upcase
|
30
|
+
version_number = doc.at_xpath('//cda:versionNumber/@value').value.to_i
|
31
|
+
title = doc.at_xpath('cda:QualityMeasureDocument/cda:title').inner_text
|
32
|
+
description = doc.at_xpath('cda:QualityMeasureDocument/cda:text').inner_text
|
33
|
+
result = {'id' => id, 'set_id' => set_id, 'version' => version_number, 'title' => title, 'description' => description}
|
34
|
+
end
|
35
|
+
when HQMF_VERSION_2
|
36
|
+
doc = HQMF2::Document.parse(hqmf_contents)
|
37
|
+
type = doc.at_xpath('cda:QualityMeasureDocument/cda:code/@code').value
|
38
|
+
if type == '57024-2'
|
39
|
+
id = doc.at_xpath('cda:QualityMeasureDocument/cda:id/@extension', HQMF2::Document::NAMESPACES).value.upcase
|
40
|
+
set_id = doc.at_xpath('cda:QualityMeasureDocument/cda:setId/@extension').value.upcase
|
41
|
+
version_number = doc.at_xpath('cda:QualityMeasureDocument/cda:versionNumber/@value').value.to_i
|
42
|
+
title = doc.at_xpath('cda:QualityMeasureDocument/cda:title/@value').inner_text
|
43
|
+
description = doc.at_xpath('cda:QualityMeasureDocument/cda:text/@value').inner_text
|
44
|
+
result = {'id' => id, 'set_id' => set_id, 'version' => version_number, 'title' => title, 'description' => description}
|
45
|
+
end
|
46
|
+
else
|
47
|
+
raise "Unsupported HQMF version specified: #{version}"
|
48
|
+
end
|
49
|
+
result
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,241 @@
|
|
1
|
+
require 'zip/zipfilesystem'
|
2
|
+
require 'spreadsheet'
|
3
|
+
require 'google_spreadsheet'
|
4
|
+
require 'roo'
|
5
|
+
require 'iconv'
|
6
|
+
|
7
|
+
module HQMF
|
8
|
+
module ValueSet
|
9
|
+
class Parser
|
10
|
+
|
11
|
+
attr_accessor :child_oids
|
12
|
+
|
13
|
+
GROUP_CODE_SET = "GROUPING"
|
14
|
+
|
15
|
+
ORGANIZATION_TITLE = "Value Set Developer"
|
16
|
+
OID_TITLE = "Value Set OID"
|
17
|
+
CONCEPT_TITLE = "Value Set Name"
|
18
|
+
CATEGORY_TITLE = "QDM Category"
|
19
|
+
CODE_SET_TITLE ="Code System"
|
20
|
+
VERSION_TITLE = "Code System Version"
|
21
|
+
CODE_TITLE = "Code"
|
22
|
+
DESCRIPTION_TITLE = "Descriptor"
|
23
|
+
|
24
|
+
CODE_SYSTEM_NORMALIZER = {
|
25
|
+
'ICD-9'=>'ICD-9-CM',
|
26
|
+
'ICD-10'=>'ICD-10-CM',
|
27
|
+
'HL7 (2.16.840.1.113883.5.1)'=>'HL7'
|
28
|
+
}
|
29
|
+
IGNORED_CODE_SYSTEM_NAMES = ['Grouping', 'GROUPING' ,'HL7', "Administrative Sex"]
|
30
|
+
|
31
|
+
def initialize()
|
32
|
+
@child_oids = []
|
33
|
+
end
|
34
|
+
|
35
|
+
# import an excel matrix array into mongo
|
36
|
+
def parse(file, options={})
|
37
|
+
sheet_array = file_to_array(file, options)
|
38
|
+
by_oid_ungrouped = cells_to_hashs_by_oid(sheet_array)
|
39
|
+
value_sets = collapse_groups(by_oid_ungrouped)
|
40
|
+
translate_json(value_sets)
|
41
|
+
end
|
42
|
+
|
43
|
+
def collapse_groups(by_oid_ungrouped)
|
44
|
+
|
45
|
+
final = []
|
46
|
+
|
47
|
+
# select the grouped code sets and fill in the children... also remove the children that are a
|
48
|
+
# member of a group. We remove the children so that we can create parent groups for the orphans
|
49
|
+
(by_oid_ungrouped.select {|key,value| value["code_set"].upcase == GROUP_CODE_SET}).each do |key, value|
|
50
|
+
# remove the group so that it is not in the orphan list
|
51
|
+
by_oid_ungrouped.delete(value["oid"])
|
52
|
+
codes = []
|
53
|
+
value["codes"].each do |child_oid|
|
54
|
+
# codes << by_oid_ungrouped.delete(child_oid)
|
55
|
+
# do not delete the children of a group. These may be referenced by other groups or directly by the measure
|
56
|
+
code = by_oid_ungrouped[child_oid]
|
57
|
+
@child_oids << child_oid
|
58
|
+
puts "\tcode could not be found: #{child_oid}" unless code
|
59
|
+
codes << code if code
|
60
|
+
# for hierarchies we need to probably have codes be a hash that we select from if we don't find the
|
61
|
+
# element in by_oid_ungrouped we may need to look for it in final
|
62
|
+
end
|
63
|
+
value["code_sets"] = codes
|
64
|
+
value.delete("codes")
|
65
|
+
value.delete("code_set")
|
66
|
+
final << value
|
67
|
+
end
|
68
|
+
|
69
|
+
# fill out the orphans
|
70
|
+
by_oid_ungrouped.each do |key, orphan|
|
71
|
+
final << adopt_orphan(orphan)
|
72
|
+
end
|
73
|
+
|
74
|
+
deleted = []
|
75
|
+
final.delete_if {|x| to_delete = x['code_sets'].nil? || x['code_sets'].empty?; deleted << x if to_delete; to_delete }
|
76
|
+
deleted.each do |value|
|
77
|
+
puts "\tDeleted value set with no code sets: #{value['oid']}"
|
78
|
+
end
|
79
|
+
final
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
def adopt_orphan(orphan)
|
84
|
+
parent = orphan.dup
|
85
|
+
parent["code_sets"] = [orphan]
|
86
|
+
parent.delete("codes")
|
87
|
+
parent.delete("code_set")
|
88
|
+
parent
|
89
|
+
end
|
90
|
+
|
91
|
+
# take an excel matrix array and turn it into an array of db models
|
92
|
+
def cells_to_hashs_by_oid(array)
|
93
|
+
a = Array.new(array) # new variable for reentrant
|
94
|
+
headers = a.shift.map {|i| i.to_s } # because of this shift
|
95
|
+
string_data = a.map {|row| row.map {|cell| cell.to_s } }
|
96
|
+
array_of_hashes = string_data.map {|row| Hash[*headers.zip(row).flatten] }
|
97
|
+
|
98
|
+
by_oid = {}
|
99
|
+
array_of_hashes.each do |row|
|
100
|
+
entry = convert_row(row)
|
101
|
+
|
102
|
+
existing = by_oid[entry["oid"]]
|
103
|
+
if (existing)
|
104
|
+
existing["codes"].concat(entry["codes"])
|
105
|
+
else
|
106
|
+
by_oid[entry["oid"]] = entry
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
by_oid
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.get_format(file_path)
|
114
|
+
if file_path =~ /xls$/
|
115
|
+
:xls
|
116
|
+
elsif file_path =~ /xlsx$/
|
117
|
+
:xlsx
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def convert_row(row)
|
124
|
+
# Value Set Developer
|
125
|
+
# Value Set OID
|
126
|
+
# Value Set Name
|
127
|
+
# QDM Category
|
128
|
+
# Code System
|
129
|
+
# Code System Version
|
130
|
+
# Code
|
131
|
+
# Descriptor
|
132
|
+
value = {
|
133
|
+
"key" => normalize_names(row[CATEGORY_TITLE],row[CONCEPT_TITLE]),
|
134
|
+
"organization" => row[ORGANIZATION_TITLE],
|
135
|
+
"oid" => row[OID_TITLE].strip.gsub(/[^0-9\.]/i, ''),
|
136
|
+
"concept" => normalize_names(row[CONCEPT_TITLE]),
|
137
|
+
"category" => normalize_names(row[CATEGORY_TITLE]),
|
138
|
+
"code_set" => normalize_code_system(row[CODE_SET_TITLE]),
|
139
|
+
"version" => row[VERSION_TITLE],
|
140
|
+
"codes" => extract_code(row[CODE_TITLE], row[CODE_SET_TITLE]),
|
141
|
+
"description" => row[DESCRIPTION_TITLE]
|
142
|
+
}
|
143
|
+
value['codes'].map! {|code| code.strip.gsub(/[^0-9\.]/i, '')} if (value['code_set'].upcase == GROUP_CODE_SET)
|
144
|
+
value
|
145
|
+
end
|
146
|
+
|
147
|
+
# Break all the supplied strings into separate words and return the resulting list as a
|
148
|
+
# new string with each word separated with '_'
|
149
|
+
def normalize_names(*components)
|
150
|
+
name = []
|
151
|
+
components.each do |component|
|
152
|
+
name.concat component.gsub(/\W/,' ').split.collect { |word| word.strip.downcase }
|
153
|
+
end
|
154
|
+
name.join '_'
|
155
|
+
end
|
156
|
+
|
157
|
+
def normalize_code_system(code_system_name)
|
158
|
+
code_system_name = CODE_SYSTEM_NORMALIZER[code_system_name] if CODE_SYSTEM_NORMALIZER[code_system_name]
|
159
|
+
return code_system_name if IGNORED_CODE_SYSTEM_NAMES.include? code_system_name
|
160
|
+
oid = HealthDataStandards::Util::CodeSystemHelper.oid_for_code_system(code_system_name)
|
161
|
+
puts "\tbad code system name: #{code_system_name}" unless oid
|
162
|
+
code_system_name
|
163
|
+
end
|
164
|
+
|
165
|
+
def extract_code(code, set)
|
166
|
+
|
167
|
+
code.strip!
|
168
|
+
if set=='CPT' && code.include?('-')
|
169
|
+
eval(code.strip.gsub('-','..')).to_a.collect { |i| i.to_s }
|
170
|
+
else
|
171
|
+
[code]
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
def file_to_array(file_path, options)
|
177
|
+
defaults = {
|
178
|
+
:columns => 2, # range of import
|
179
|
+
:sheet => 1 # only one sheet at a time can be worked on
|
180
|
+
}
|
181
|
+
options = defaults.merge(options)
|
182
|
+
|
183
|
+
book = book_by_format(file_path, options[:format])
|
184
|
+
book.default_sheet=book.sheets[options[:sheet]]
|
185
|
+
|
186
|
+
# catch double byte encoding problems in spreadsheet files
|
187
|
+
# Encoding::InvalidByteSequenceError: "\x9E\xDE" on UTF-16LE
|
188
|
+
begin
|
189
|
+
book.to_matrix.to_a
|
190
|
+
rescue Encoding::InvalidByteSequenceError => e
|
191
|
+
raise "Spreadsheet encoding problem: #{e}"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def book_by_format(file_path, format)
|
196
|
+
format = HQMF::ValueSet::Parser.get_format(file_path) unless format
|
197
|
+
|
198
|
+
if format == :xls
|
199
|
+
book = Excel.new(file_path, nil, :ignore)
|
200
|
+
elsif format == :xlsx
|
201
|
+
book = Excelx.new(file_path, nil, :ignore)
|
202
|
+
else
|
203
|
+
raise "File does not end in .xls or .xlsx"
|
204
|
+
end
|
205
|
+
book
|
206
|
+
end
|
207
|
+
|
208
|
+
def translate_json(value_sets)
|
209
|
+
value_set_models = []
|
210
|
+
|
211
|
+
value_sets.each do |value_set|
|
212
|
+
hds_value_set = HealthDataStandards::SVS::ValueSet.new()
|
213
|
+
hds_value_set['oid'] = value_set['oid']
|
214
|
+
hds_value_set['display_name'] = value_set['key']
|
215
|
+
hds_value_set['version'] = value_set['version']
|
216
|
+
hds_value_set['concepts'] = []
|
217
|
+
|
218
|
+
value_set['code_sets'].each do |code_set|
|
219
|
+
code_set['codes'].map{ |code|
|
220
|
+
concept = HealthDataStandards::SVS::Concept.new()
|
221
|
+
concept['code'] = code
|
222
|
+
concept['code_system'] = nil
|
223
|
+
concept['code_system_name'] = code_set['code_set']
|
224
|
+
concept['code_system_version'] = code_set['version']
|
225
|
+
concept['display_name'] = nil
|
226
|
+
hds_value_set['concepts'].concat([concept])
|
227
|
+
}
|
228
|
+
end
|
229
|
+
if hds_value_set['concepts'].include? nil
|
230
|
+
puts "Value Set has a bad code set (code set is null)"
|
231
|
+
hds_value_set['concepts'].compact!
|
232
|
+
end
|
233
|
+
value_set_models << hds_value_set
|
234
|
+
end
|
235
|
+
value_set_models
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
data/lib/util/counter.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module HQMF
|
2
|
+
# Simple class to issue monotonically increasing integer identifiers
|
3
|
+
class InstanceCounter
|
4
|
+
def initialize
|
5
|
+
@count=0
|
6
|
+
end
|
7
|
+
|
8
|
+
def reset
|
9
|
+
@count=0
|
10
|
+
end
|
11
|
+
|
12
|
+
def next
|
13
|
+
@count+=1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Counter < InstanceCounter
|
18
|
+
include Singleton
|
19
|
+
end
|
20
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|