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,188 @@
|
|
1
|
+
module HQMF
|
2
|
+
|
3
|
+
# preconditions can be in several places.
|
4
|
+
#
|
5
|
+
# precondition -> preconditions
|
6
|
+
# restriction -> preconditions
|
7
|
+
#
|
8
|
+
# also, restrictions can be on the following, which can then have preconditions
|
9
|
+
# restrictions
|
10
|
+
# comparisons
|
11
|
+
# preconditions
|
12
|
+
#
|
13
|
+
class PreconditionExtractor
|
14
|
+
|
15
|
+
|
16
|
+
def self.extract_preconditions_from_restrictions(restrictions,data_criteria_converter)
|
17
|
+
return [] unless restrictions
|
18
|
+
preconditions = []
|
19
|
+
restrictions.each do |restriction|
|
20
|
+
preconditions.concat(extract_preconditions_from_restriction(restriction,data_criteria_converter))
|
21
|
+
end
|
22
|
+
preconditions
|
23
|
+
end
|
24
|
+
|
25
|
+
# get all the preconditions for a restriction
|
26
|
+
# we need to iterate down
|
27
|
+
# restriction.preconditions
|
28
|
+
# restriction.comparison
|
29
|
+
# restriction.restriction
|
30
|
+
def self.extract_preconditions_from_restriction(restriction,data_criteria_converter)
|
31
|
+
target_id=nil
|
32
|
+
if restriction[:target_id] and data_criteria_converter.v1_data_criteria_by_id[restriction[:target_id]]
|
33
|
+
target_id = data_criteria_converter.v1_data_criteria_by_id[restriction[:target_id]].id
|
34
|
+
elsif restriction[:target_id]
|
35
|
+
puts "\tPrecondition Data Criteria MISSING: #{restriction[:target_id]}"
|
36
|
+
end
|
37
|
+
type = restriction[:type]
|
38
|
+
if (restriction[:negation])
|
39
|
+
inverted = HQMF::TemporalReference::INVERSION[type]
|
40
|
+
if (inverted)
|
41
|
+
type = inverted
|
42
|
+
else
|
43
|
+
puts "\tdon't know how to invert #{type}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# if we reference the measurement period, then we want to check if the reference is to the start or end of the measurement period
|
48
|
+
# if we SBS of the END of the measurement period, we want to convert that to SBE of the measurement period
|
49
|
+
if target_id == HQMF::Document::MEASURE_PERIOD_ID
|
50
|
+
references_start = {'SBS'=>'SBE','SAS'=>'SAE','EBS'=>'EBE','EAS'=>'EAE'}
|
51
|
+
references_end = {'EBE'=>'EBS','EAE'=>'EAS','SBE'=>'SBS','SAE'=>'SAS'}
|
52
|
+
if data_criteria_converter.measure_period_v1_keys[:measure_start] == restriction[:target_id] and references_end[type]
|
53
|
+
# before or after the END of the measurement period START. Convert to before or after the START of the measurement period.
|
54
|
+
# SAE of MPS => SAS of MP
|
55
|
+
type = references_end[type]
|
56
|
+
elsif data_criteria_converter.measure_period_v1_keys[:measure_end] == restriction[:target_id] and references_start[type]
|
57
|
+
# before or after the START of the measurement period END. Convert to before or after the END of the measurement period.
|
58
|
+
# SBS of MPE => SBE of MP
|
59
|
+
type = references_start[type]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
value = nil
|
64
|
+
if (restriction[:range])
|
65
|
+
value = HQMF::Range.from_json(JSON.parse(restriction[:range].to_json)) if (restriction[:range])
|
66
|
+
elsif(restriction[:value])
|
67
|
+
value = HQMF::Converter::SimpleOperator.parse_value(restriction[:value])
|
68
|
+
end
|
69
|
+
field = restriction[:field]
|
70
|
+
field_code = restriction[:field_code]
|
71
|
+
field_time = restriction[:field_time]
|
72
|
+
operator = HQMF::Converter::SimpleOperator.new(HQMF::Converter::SimpleOperator.find_category(type), type, value, field, field_code, field_time)
|
73
|
+
|
74
|
+
# get the precondtions off of the restriction
|
75
|
+
children = HQMF::PreconditionConverter.parse_and_merge_preconditions(restriction[:preconditions],data_criteria_converter) if restriction[:preconditions]
|
76
|
+
|
77
|
+
if restriction[:comparison]
|
78
|
+
children ||= []
|
79
|
+
# check comparison and convert it to a precondition
|
80
|
+
comparison = convert_comparison_to_precondition(restriction[:comparison], data_criteria_converter)
|
81
|
+
children << comparison
|
82
|
+
end
|
83
|
+
|
84
|
+
# check restrictions
|
85
|
+
restrictions = extract_preconditions_from_restrictions(restriction[:restrictions], data_criteria_converter) if restriction[:restrictions]
|
86
|
+
if (children)
|
87
|
+
HQMF::PreconditionConverter.apply_restrictions_to_comparisons(children, restrictions) unless restrictions.nil? or restrictions.empty?
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
container = nil
|
92
|
+
# check if there is an expression on the restriction
|
93
|
+
if (restriction[:expression])
|
94
|
+
# this is for things like TIMEDIFF
|
95
|
+
type = restriction[:expression][:type]
|
96
|
+
exp_operator = HQMF::Converter::SimpleOperator.new(HQMF::Converter::SimpleOperator.find_category(type), type, HQMF::Converter::SimpleOperator.parse_value(restriction[:expression][:value]))
|
97
|
+
preconditions = []
|
98
|
+
|
99
|
+
driv_preconditions = []
|
100
|
+
restrictions.each {|element| driv_preconditions << element if element.is_a? HQMF::Converter::SimpleRestriction and element.operator.type == 'DRIV'}
|
101
|
+
|
102
|
+
if driv_preconditions and !driv_preconditions.empty?
|
103
|
+
preconditions = driv_preconditions.map(&:preconditions).flatten
|
104
|
+
end
|
105
|
+
|
106
|
+
reference = nil
|
107
|
+
conjunction_code = nil
|
108
|
+
|
109
|
+
comparison_precondition = HQMF::Converter::SimplePrecondition.new(nil,[HQMF::Converter::SimpleRestriction.new(exp_operator, nil, preconditions)],reference,conjunction_code, false)
|
110
|
+
comparison_precondition.klass = HQMF::Converter::SimplePrecondition::COMPARISON
|
111
|
+
|
112
|
+
comparison_precondition.subset_comparison = true
|
113
|
+
container = HQMF::Converter::SimpleRestriction.new(operator, nil, [comparison_precondition])
|
114
|
+
|
115
|
+
# check if there is a subset on the restriction
|
116
|
+
elsif restriction[:subset]
|
117
|
+
# if we have a subset, we want to create a Comparison Precondition for the subset and have it be the child of the operator on the restriction.
|
118
|
+
# the reason for this is that we want the order of operations to be SBS the FIRST of a data criteria, rather than FIRST of SBS of a data criteria
|
119
|
+
|
120
|
+
subset_type = restriction[:subset]
|
121
|
+
subset_operator = HQMF::Converter::SimpleOperator.new(HQMF::Converter::SimpleOperator.find_category(subset_type), subset_type, nil)
|
122
|
+
|
123
|
+
reference = nil
|
124
|
+
conjunction_code = nil
|
125
|
+
|
126
|
+
restriction = HQMF::Converter::SimpleRestriction.new(subset_operator, target_id)
|
127
|
+
restriction.preconditions = children
|
128
|
+
|
129
|
+
comparison_precondition = HQMF::Converter::SimplePrecondition.new(nil, [restriction], reference, conjunction_code, false)
|
130
|
+
comparison_precondition.klass = HQMF::Converter::SimplePrecondition::COMPARISON
|
131
|
+
|
132
|
+
container = HQMF::Converter::SimpleRestriction.new(operator, nil, [comparison_precondition])
|
133
|
+
else
|
134
|
+
container = HQMF::Converter::SimpleRestriction.new(operator, target_id)
|
135
|
+
container.preconditions = children
|
136
|
+
end
|
137
|
+
|
138
|
+
[container]
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
# we want the comparisons to be converted to the leaf preconditions
|
143
|
+
def self.convert_comparison_to_precondition(comparison, data_criteria_converter)
|
144
|
+
|
145
|
+
data_criteria = data_criteria_converter.v1_data_criteria_by_id[comparison[:data_criteria_id]]
|
146
|
+
reference = HQMF::Reference.new(data_criteria.id)
|
147
|
+
# conjunction_code = "#{data_criteria.type.to_s.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }}Reference"
|
148
|
+
conjunction_code = nil
|
149
|
+
|
150
|
+
preconditions = []
|
151
|
+
if comparison[:restrictions]
|
152
|
+
# check for preconditions on restrictions
|
153
|
+
preconditions = extract_preconditions_from_restrictions(comparison[:restrictions], data_criteria_converter)
|
154
|
+
end
|
155
|
+
|
156
|
+
precondition = HQMF::Converter::SimplePrecondition.new(nil,preconditions,reference,conjunction_code, false)
|
157
|
+
precondition.klass = HQMF::Converter::SimplePrecondition::COMPARISON
|
158
|
+
|
159
|
+
if (comparison[:subset])
|
160
|
+
# create a restriction for a comparison subset... this is for things like first, second, etc.
|
161
|
+
type = comparison[:subset]
|
162
|
+
operator = HQMF::Converter::SimpleOperator.new(HQMF::Converter::SimpleOperator.find_category(type), type, nil)
|
163
|
+
restriction = HQMF::Converter::SimpleRestriction.new(operator, reference.id, nil)
|
164
|
+
precondition.preconditions ||= []
|
165
|
+
precondition.preconditions << restriction
|
166
|
+
end
|
167
|
+
|
168
|
+
precondition
|
169
|
+
end
|
170
|
+
|
171
|
+
# flatten a tree of preconditions into an array... if we are doing something like a count, we just want the flat list
|
172
|
+
def self.flatten_v2_preconditions(preconditions)
|
173
|
+
flattened = []
|
174
|
+
preconditions.each do |precondition|
|
175
|
+
if (precondition.reference and precondition.has_preconditions?)
|
176
|
+
raise "don't know how to handle a condition with a reference that has preconditions" if (precondition.reference and precondition.has_preconditions?)
|
177
|
+
end
|
178
|
+
if (precondition.reference)
|
179
|
+
flattened << precondition
|
180
|
+
else
|
181
|
+
flattened.concat(flatten_v2_preconditions(precondition.preconditions))
|
182
|
+
end
|
183
|
+
end
|
184
|
+
flattened
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module HQMF
|
2
|
+
|
3
|
+
module Converter
|
4
|
+
|
5
|
+
class SimpleDataCriteria < HQMF::DataCriteria
|
6
|
+
|
7
|
+
attr_accessor :precondition_id
|
8
|
+
|
9
|
+
def self.from_data_criteria(data_criteria)
|
10
|
+
HQMF::Converter::SimpleDataCriteria.new(data_criteria.id, data_criteria.title, data_criteria.display_name, data_criteria.description, data_criteria.code_list_id,
|
11
|
+
data_criteria.children_criteria, data_criteria.derivation_operator, data_criteria.definition,data_criteria.status, data_criteria.value, data_criteria.field_values,
|
12
|
+
data_criteria.effective_time, data_criteria.inline_code_list,data_criteria.negation,data_criteria.negation_code_list_id,data_criteria.temporal_references, data_criteria.subset_operators, data_criteria.specific_occurrence,data_criteria.specific_occurrence_const)
|
13
|
+
end
|
14
|
+
|
15
|
+
def assign_precondition(precondtion_id)
|
16
|
+
return if (@precondtion_id == precondtion_id)
|
17
|
+
raise "Cannot assign a second precondition to a data criteria" if @precondition_id
|
18
|
+
@precondition_id = precondtion_id
|
19
|
+
@id = "#{@id}_precondition_#{precondtion_id}"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module HQMF
|
2
|
+
|
3
|
+
module Converter
|
4
|
+
|
5
|
+
class SimpleOperator
|
6
|
+
|
7
|
+
TEMPORAL = 'TEMPORAL'
|
8
|
+
SUMMARY = 'SUMMARY'
|
9
|
+
UNKNOWN = 'UNKNOWN'
|
10
|
+
|
11
|
+
VALUE_FIELD_TIMES = {
|
12
|
+
'FACILITY_LOCATION_START' => 'FACILITY_LOCATION_ARRIVAL_DATETIME',
|
13
|
+
'FACILITY_LOCATION_END' => 'FACILITY_LOCATION_DEPARTURE_DATETIME'
|
14
|
+
}
|
15
|
+
|
16
|
+
|
17
|
+
attr_accessor :type, :value, :category, :field, :field_code, :field_time
|
18
|
+
|
19
|
+
def initialize(category, type, value, field = nil, field_code=nil, field_time=nil)
|
20
|
+
@category = category
|
21
|
+
@type = type
|
22
|
+
@value = value
|
23
|
+
@field = field
|
24
|
+
@field_code = field_code
|
25
|
+
@field_time = field_time
|
26
|
+
end
|
27
|
+
|
28
|
+
def temporal?
|
29
|
+
category == TEMPORAL
|
30
|
+
end
|
31
|
+
def summary?
|
32
|
+
category == SUMMARY
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_json
|
36
|
+
json = {}
|
37
|
+
json[:category] = @category if @category
|
38
|
+
json[:type] = @type if @type
|
39
|
+
json[:field] = @field if @field
|
40
|
+
json[:field_code] = @field_code if @field_code
|
41
|
+
json[:value] = @value.to_json if @value
|
42
|
+
json
|
43
|
+
end
|
44
|
+
|
45
|
+
def field_value_key
|
46
|
+
key = HQMF::DataCriteria::VALUE_FIELDS[field_code]
|
47
|
+
key = VALUE_FIELD_TIMES["#{key}_#{field_time.to_s.upcase}"] if (field_time)
|
48
|
+
raise "unsupported field value: #{field_code}, #{field}" unless key
|
49
|
+
key
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.parse_value(value)
|
53
|
+
return nil unless value
|
54
|
+
return value if value.is_a? String
|
55
|
+
if (value[:value])
|
56
|
+
# values should be inclusive since we will be asking if it equals the value, ranther than being part of a range
|
57
|
+
# if it's an offset we do not care that it is inclusive
|
58
|
+
val = HQMF::Value.from_json(JSON.parse(value.to_json))
|
59
|
+
val.inclusive=true
|
60
|
+
val
|
61
|
+
elsif (value[:high] or value[:low])
|
62
|
+
HQMF::Range.from_json(JSON.parse(value.to_json))
|
63
|
+
elsif (value[:type] == 'CD')
|
64
|
+
HQMF::Coded.from_json(JSON.parse(value.to_json))
|
65
|
+
elsif (value[:type] == 'ANYNonNull')
|
66
|
+
HQMF::AnyValue.from_json(JSON.parse(value.to_json))
|
67
|
+
else
|
68
|
+
raise "Unexpected value format: #{value.to_json}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.find_category(type)
|
73
|
+
return TEMPORAL if HQMF::TemporalReference::TYPES.include? type
|
74
|
+
return SUMMARY if HQMF::SubsetOperator::TYPES.include? type
|
75
|
+
return UNKNOWN
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module HQMF
|
2
|
+
|
3
|
+
module Converter
|
4
|
+
|
5
|
+
class SimplePrecondition < HQMF::Precondition
|
6
|
+
|
7
|
+
COMPARISON = "COMPARISON"
|
8
|
+
PRECONDITION = "PRECONDITION"
|
9
|
+
|
10
|
+
attr_accessor :klass, :processed, :subset_comparison, :conjunction_code
|
11
|
+
|
12
|
+
def initialize(id, preconditions,reference,conjunction_code,negation)
|
13
|
+
super(id, preconditions,reference,conjunction_code,negation)
|
14
|
+
@id = HQMF::Counter.instance.next if (@id.nil?)
|
15
|
+
@klass = PRECONDITION
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_json
|
19
|
+
json = super
|
20
|
+
# json[:klass] = @klass
|
21
|
+
json
|
22
|
+
end
|
23
|
+
|
24
|
+
def comparison?
|
25
|
+
@klass == COMPARISON
|
26
|
+
end
|
27
|
+
def restriction?
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def has_preconditions?
|
32
|
+
preconditions and !preconditions.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
def restrictions
|
36
|
+
preconditions.select {|precondition| precondition.restriction?}
|
37
|
+
end
|
38
|
+
|
39
|
+
def reference=(reference)
|
40
|
+
@reference = reference
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_converted_restrictions!
|
44
|
+
preconditions.delete_if {|precondition| precondition.restriction? and precondition.converted}
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module HQMF
|
2
|
+
|
3
|
+
module Converter
|
4
|
+
|
5
|
+
class SimpleRestriction
|
6
|
+
|
7
|
+
include HQMF::Conversion::Utilities
|
8
|
+
|
9
|
+
attr_accessor :operator, :target, :preconditions, :negation, :converted, :generated_data_criteria
|
10
|
+
def initialize(operator, target, preconditions = [])
|
11
|
+
@operator = operator
|
12
|
+
@target = target
|
13
|
+
@preconditions = preconditions
|
14
|
+
end
|
15
|
+
|
16
|
+
# Create a new population criteria from a JSON hash keyed off symbols
|
17
|
+
def self.from_json(json)
|
18
|
+
raise "not implemented"
|
19
|
+
end
|
20
|
+
|
21
|
+
def klass
|
22
|
+
"RESTRICTION"
|
23
|
+
end
|
24
|
+
|
25
|
+
def comparison?
|
26
|
+
false
|
27
|
+
end
|
28
|
+
def restriction?
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_preconditions?
|
33
|
+
preconditions and !preconditions.empty?
|
34
|
+
end
|
35
|
+
|
36
|
+
def single_target?
|
37
|
+
!target.nil?
|
38
|
+
end
|
39
|
+
def multi_target?
|
40
|
+
has_preconditions?
|
41
|
+
end
|
42
|
+
|
43
|
+
def restrictions
|
44
|
+
preconditions.select {|precondition| precondition.restriction?}
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_json
|
48
|
+
x = nil
|
49
|
+
json = {}
|
50
|
+
json[:klass] = klass
|
51
|
+
json[:operator] = @operator.to_json if @operator
|
52
|
+
json[:target] = @target if @target
|
53
|
+
json[:negation] = @negation if @negation
|
54
|
+
if (@preconditions)
|
55
|
+
json[:preconditions] = x if x = json_array(@preconditions)
|
56
|
+
end
|
57
|
+
json
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module HQMF
|
2
|
+
# Class for converting an HQMF 1.0 representation to an HQMF 2.0 representation
|
3
|
+
class ComparisonConverter
|
4
|
+
|
5
|
+
def initialize(data_criteria_converter)
|
6
|
+
@data_criteria_converter = data_criteria_converter
|
7
|
+
end
|
8
|
+
|
9
|
+
def convert_comparisons(population_criteria)
|
10
|
+
population_criteria.each do |population|
|
11
|
+
is_observation = population.type == HQMF::PopulationCriteria::OBSERV
|
12
|
+
walk_up_tree(population.preconditions)
|
13
|
+
rewrite_observation(population) if is_observation
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def walk_up_tree(preconditions)
|
18
|
+
preconditions.each do |precondition|
|
19
|
+
if (has_child_comparison(precondition))
|
20
|
+
walk_up_tree(precondition.preconditions)
|
21
|
+
end
|
22
|
+
if (precondition.comparison? && !precondition.processed)
|
23
|
+
new_data_criteria = nil
|
24
|
+
# duplicate the data criteria referenced by the comparision (unless it's the measurement period. we don't modify the measurement period)
|
25
|
+
if precondition.reference and precondition.reference.id != HQMF::Document::MEASURE_PERIOD_ID
|
26
|
+
data_criteria = @data_criteria_converter.v2_data_criteria_by_id[precondition.reference.id]
|
27
|
+
new_data_criteria = @data_criteria_converter.duplicate_data_criteria(data_criteria, precondition.id)
|
28
|
+
precondition.reference.id = new_data_criteria.id
|
29
|
+
end
|
30
|
+
# add restrictions to the duplicated data criteria
|
31
|
+
if precondition.has_preconditions?
|
32
|
+
restrictions = precondition.restrictions
|
33
|
+
# we want to process summary operators first since they can create new data criteria
|
34
|
+
restrictions.sort! {|left, right| (right.operator.summary? and !left.operator.summary?) ? 1 : 0 }
|
35
|
+
restrictions.each do |restriction|
|
36
|
+
operator = restriction.operator
|
37
|
+
# check if the data criteria has been changed by either a grouping addition or an operator
|
38
|
+
if (precondition.reference and (new_data_criteria == nil or new_data_criteria.id != precondition.reference.id))
|
39
|
+
new_data_criteria = @data_criteria_converter.v2_data_criteria_by_id[precondition.reference.id]
|
40
|
+
end
|
41
|
+
if (operator.temporal?)
|
42
|
+
HQMF::OperatorConverter.apply_temporal(new_data_criteria, precondition, restriction, @data_criteria_converter)
|
43
|
+
elsif(operator.summary?)
|
44
|
+
HQMF::OperatorConverter.apply_summary(new_data_criteria, precondition, restriction, @data_criteria_converter)
|
45
|
+
else
|
46
|
+
case operator.type
|
47
|
+
when 'REFR'
|
48
|
+
if operator.field.downcase == 'status'
|
49
|
+
# only set the status if we don't have one. We trust the template ID statuses more than the restrictions
|
50
|
+
new_data_criteria.status ||= operator.value.code
|
51
|
+
elsif operator.field.downcase == 'result value' or operator.field.downcase == 'result'
|
52
|
+
puts "\tREFR result value is nil: #{new_data_criteria.title}" if (operator.value.nil?)
|
53
|
+
new_data_criteria.value = operator.value
|
54
|
+
else
|
55
|
+
new_data_criteria.field_values ||= {}
|
56
|
+
new_data_criteria.field_values[operator.field_value_key] = operator.value
|
57
|
+
end
|
58
|
+
restriction.converted=true
|
59
|
+
when 'RSON'
|
60
|
+
new_data_criteria.negation_code_list_id = operator.value.code_list_id
|
61
|
+
new_data_criteria.negation=true
|
62
|
+
restriction.converted=true
|
63
|
+
when 'SUBJ'
|
64
|
+
new_data_criteria.field_values ||= {}
|
65
|
+
new_data_criteria.field_values[operator.field_value_key] = operator.value
|
66
|
+
restriction.converted=true
|
67
|
+
else
|
68
|
+
puts "\tOperator is unknown: #{operator.type}"
|
69
|
+
restriction.converted=true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
precondition.delete_converted_restrictions!
|
74
|
+
precondition.processed = true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def has_child_comparison(node)
|
81
|
+
get_child_comparisons(node).length > 0
|
82
|
+
end
|
83
|
+
|
84
|
+
def rewrite_observation(observation)
|
85
|
+
first_comparison = get_child_comparisons(observation).first
|
86
|
+
# clear the conjunction code since this should be a comparison
|
87
|
+
first_comparison.conjunction_code = nil
|
88
|
+
|
89
|
+
# we want to pull the aggregation function off of the top level comparison
|
90
|
+
first_criteria = @data_criteria_converter.v2_data_criteria_by_id[first_comparison.reference.id]
|
91
|
+
# pop the last subset operator which should be the closest to the root of the logic tree. Add that aggregation function to the observation as the aggregator
|
92
|
+
observation.aggregator = first_criteria.subset_operators.pop.type
|
93
|
+
|
94
|
+
# we want to get rid of any AND statements at the top level. This is calculating a numeric value, not evaluating boolean logic
|
95
|
+
observation.preconditions.clear
|
96
|
+
observation.preconditions << first_comparison
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_child_comparisons(node)
|
100
|
+
values = []
|
101
|
+
node.preconditions.each do |precondition|
|
102
|
+
if (precondition.comparison?)
|
103
|
+
values << precondition
|
104
|
+
elsif precondition.preconditions
|
105
|
+
values.concat get_child_comparisons(precondition)
|
106
|
+
end
|
107
|
+
end if node.preconditions
|
108
|
+
values
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|