cqm-parsers 0.2.2 → 3.0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +7 -3
  3. data/README.md +57 -5
  4. data/Rakefile +1 -0
  5. data/lib/{hqmf-parser.rb → cqm-parsers.rb} +13 -45
  6. data/lib/ext/data_element.rb +1 -1
  7. data/lib/hqmf-parser/2.0/document.rb +1 -1
  8. data/lib/hqmf-parser/2.0/population_criteria.rb +1 -1
  9. data/lib/hqmf-parser/cql/document_helpers/doc_population_helper.rb +11 -6
  10. data/lib/measure-loader/cql_loader.rb +165 -0
  11. data/lib/measure-loader/elm_dependency_finder.rb +72 -0
  12. data/lib/measure-loader/elm_parser.rb +67 -0
  13. data/lib/measure-loader/exceptions.rb +10 -0
  14. data/lib/measure-loader/helpers.rb +11 -0
  15. data/lib/measure-loader/hqmf_measure_loader.rb +170 -0
  16. data/lib/measure-loader/mat_measure_files.rb +138 -0
  17. data/lib/measure-loader/source_data_criteria_loader.rb +75 -0
  18. data/lib/measure-loader/value_set_helpers.rb +68 -0
  19. data/lib/measure-loader/vsac_value_set_loader.rb +97 -0
  20. data/lib/tasks/hqmf.rake +1 -1
  21. data/lib/util/util.rb +23 -0
  22. data/lib/util/vsac_api.rb +166 -103
  23. metadata +49 -116
  24. data/lib/ext/code.rb +0 -10
  25. data/lib/qrda-export/catI-r5/_code.mustache +0 -1
  26. data/lib/qrda-export/catI-r5/_codes.mustache +0 -10
  27. data/lib/qrda-export/catI-r5/_header.mustache +0 -28
  28. data/lib/qrda-export/catI-r5/_measure_section.mustache +0 -59
  29. data/lib/qrda-export/catI-r5/_reporting_period.mustache +0 -23
  30. data/lib/qrda-export/catI-r5/_values.mustache +0 -10
  31. data/lib/qrda-export/catI-r5/qrda1_r5.mustache +0 -137
  32. data/lib/qrda-export/catI-r5/qrda1_r5.rb +0 -125
  33. data/lib/qrda-export/catI-r5/qrda_header/_author.mustache +0 -24
  34. data/lib/qrda-export/catI-r5/qrda_header/_custodian.mustache +0 -43
  35. data/lib/qrda-export/catI-r5/qrda_header/_documentation_of_service_event.mustache +0 -82
  36. data/lib/qrda-export/catI-r5/qrda_header/_information_recipient.mustache +0 -7
  37. data/lib/qrda-export/catI-r5/qrda_header/_legal_authenticator.mustache +0 -25
  38. data/lib/qrda-export/catI-r5/qrda_header/_participant.mustache +0 -7
  39. data/lib/qrda-export/catI-r5/qrda_header/_record_target.mustache +0 -28
  40. data/lib/qrda-export/catI-r5/qrda_templates/adverse_event.mustache +0 -28
  41. data/lib/qrda-export/catI-r5/qrda_templates/allergy_intolerance.mustache +0 -28
  42. data/lib/qrda-export/catI-r5/qrda_templates/assessment_performed.mustache +0 -25
  43. data/lib/qrda-export/catI-r5/qrda_templates/communication_from_patient_to_provider.mustache +0 -29
  44. data/lib/qrda-export/catI-r5/qrda_templates/communication_from_provider_to_patient.mustache +0 -24
  45. data/lib/qrda-export/catI-r5/qrda_templates/communication_from_provider_to_provider.mustache +0 -31
  46. data/lib/qrda-export/catI-r5/qrda_templates/device_applied.mustache +0 -32
  47. data/lib/qrda-export/catI-r5/qrda_templates/device_ordered.mustache +0 -31
  48. data/lib/qrda-export/catI-r5/qrda_templates/diagnosis.mustache +0 -38
  49. data/lib/qrda-export/catI-r5/qrda_templates/diagnostic_study_ordered.mustache +0 -19
  50. data/lib/qrda-export/catI-r5/qrda_templates/diagnostic_study_performed.mustache +0 -29
  51. data/lib/qrda-export/catI-r5/qrda_templates/encounter_ordered.mustache +0 -24
  52. data/lib/qrda-export/catI-r5/qrda_templates/encounter_performed.mustache +0 -40
  53. data/lib/qrda-export/catI-r5/qrda_templates/immunization_administered.mustache +0 -29
  54. data/lib/qrda-export/catI-r5/qrda_templates/insurance_provider.mustache +0 -11
  55. data/lib/qrda-export/catI-r5/qrda_templates/intervention_ordered.mustache +0 -18
  56. data/lib/qrda-export/catI-r5/qrda_templates/intervention_performed.mustache +0 -25
  57. data/lib/qrda-export/catI-r5/qrda_templates/lab_test_ordered.mustache +0 -18
  58. data/lib/qrda-export/catI-r5/qrda_templates/lab_test_performed.mustache +0 -22
  59. data/lib/qrda-export/catI-r5/qrda_templates/medication_active.mustache +0 -35
  60. data/lib/qrda-export/catI-r5/qrda_templates/medication_administered.mustache +0 -31
  61. data/lib/qrda-export/catI-r5/qrda_templates/medication_discharge.mustache +0 -55
  62. data/lib/qrda-export/catI-r5/qrda_templates/medication_dispensed.mustache +0 -39
  63. data/lib/qrda-export/catI-r5/qrda_templates/medication_ordered.mustache +0 -38
  64. data/lib/qrda-export/catI-r5/qrda_templates/patient_characteristic_expired.mustache +0 -16
  65. data/lib/qrda-export/catI-r5/qrda_templates/physical_exam_performed.mustache +0 -25
  66. data/lib/qrda-export/catI-r5/qrda_templates/procedure_ordered.mustache +0 -19
  67. data/lib/qrda-export/catI-r5/qrda_templates/procedure_performed.mustache +0 -44
  68. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_admission_source.mustache +0 -6
  69. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_anatomical_location_site.mustache +0 -1
  70. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_author.mustache +0 -7
  71. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_author_participation.mustache +0 -7
  72. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_component.mustache +0 -11
  73. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_encounter_diagnosis.mustache +0 -19
  74. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_encounter_facility_location.mustache +0 -16
  75. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_mediation_frequency.mustache +0 -3
  76. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_medication_details.mustache +0 -11
  77. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_ordinality.mustache +0 -1
  78. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_principal_diagnosis.mustache +0 -8
  79. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_reason.mustache +0 -12
  80. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_related_to.mustache +0 -6
  81. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_results.mustache +0 -21
  82. data/lib/qrda-export/catI-r5/qrda_templates/template_partials/_severity.mustache +0 -8
  83. data/lib/qrda-export/helper/cat_1_view_helper.rb +0 -142
  84. data/lib/qrda-export/helper/code_system_helper.rb +0 -77
  85. data/lib/qrda-export/helper/date_helper.rb +0 -85
  86. data/lib/qrda-import/base-importers/demographics_importer.rb +0 -43
  87. data/lib/qrda-import/base-importers/medication_importer.rb +0 -23
  88. data/lib/qrda-import/base-importers/section_importer.rb +0 -196
  89. data/lib/qrda-import/cda_identifier.rb +0 -19
  90. data/lib/qrda-import/data-element-importers/adverse_event_importer.rb +0 -24
  91. data/lib/qrda-import/data-element-importers/allergy_intolerance_importer.rb +0 -22
  92. data/lib/qrda-import/data-element-importers/assessment_performed_importer.rb +0 -24
  93. data/lib/qrda-import/data-element-importers/communication_from_patient_to_provider_importer.rb +0 -19
  94. data/lib/qrda-import/data-element-importers/communication_from_provider_to_patient_importer.rb +0 -19
  95. data/lib/qrda-import/data-element-importers/communication_from_provider_to_provider_importer.rb +0 -21
  96. data/lib/qrda-import/data-element-importers/device_applied_importer.rb +0 -24
  97. data/lib/qrda-import/data-element-importers/device_order_importer.rb +0 -19
  98. data/lib/qrda-import/data-element-importers/diagnosis_importer.rb +0 -24
  99. data/lib/qrda-import/data-element-importers/diagnostic_study_order_importer.rb +0 -21
  100. data/lib/qrda-import/data-element-importers/diagnostic_study_performed_importer.rb +0 -31
  101. data/lib/qrda-import/data-element-importers/encounter_order_importer.rb +0 -21
  102. data/lib/qrda-import/data-element-importers/encounter_performed_importer.rb +0 -42
  103. data/lib/qrda-import/data-element-importers/immunization_administered_importer.rb +0 -18
  104. data/lib/qrda-import/data-element-importers/intervention_order_importer.rb +0 -19
  105. data/lib/qrda-import/data-element-importers/intervention_performed_importer.rb +0 -23
  106. data/lib/qrda-import/data-element-importers/laboratory_test_order_importer.rb +0 -21
  107. data/lib/qrda-import/data-element-importers/laboratory_test_performed_importer.rb +0 -29
  108. data/lib/qrda-import/data-element-importers/medication_active_importer.rb +0 -17
  109. data/lib/qrda-import/data-element-importers/medication_administered_importer.rb +0 -17
  110. data/lib/qrda-import/data-element-importers/medication_discharge_importer.rb +0 -19
  111. data/lib/qrda-import/data-element-importers/medication_dispensed_importer.rb +0 -19
  112. data/lib/qrda-import/data-element-importers/medication_order_importer.rb +0 -16
  113. data/lib/qrda-import/data-element-importers/patient_characteristic_expired.rb +0 -22
  114. data/lib/qrda-import/data-element-importers/physical_exam_performed_importer.rb +0 -27
  115. data/lib/qrda-import/data-element-importers/procedure_order_importer.rb +0 -27
  116. data/lib/qrda-import/data-element-importers/procedure_performed_importer.rb +0 -35
  117. data/lib/qrda-import/data-element-importers/substance_administered_importer.rb +0 -16
  118. data/lib/qrda-import/entry_finder.rb +0 -20
  119. data/lib/qrda-import/entry_package.rb +0 -16
  120. data/lib/qrda-import/narrative_reference_handler.rb +0 -33
  121. data/lib/qrda-import/patient_importer.rb +0 -111
@@ -1,17 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class MedicationActiveImporter < MedicationImporter
4
- def initialize(entry_finder = QRDA::Cat1::EntryFinder.new("./cda:entry/cda:substanceAdministration[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.41']"))
5
- super(entry_finder)
6
- @author_datetime_xpath = nil
7
- @entry_class = QDM::MedicationActive
8
- end
9
-
10
- def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
11
- medication_active = super
12
- medication_active
13
- end
14
-
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class MedicationAdministeredImporter < MedicationImporter
4
- def initialize(entry_finder = QRDA::Cat1::EntryFinder.new("./cda:entry/cda:substanceAdministration[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.42']"))
5
- super(entry_finder)
6
- @route_xpath = "./cda:routeCode"
7
- @entry_class = QDM::MedicationAdministered
8
- end
9
-
10
- def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
11
- medication_administered = super
12
- medication_administered
13
- end
14
-
15
- end
16
- end
17
- end
@@ -1,19 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class MedicationDischargeImporter < MedicationImporter
4
- def initialize(entry_finder = QRDA::Cat1::EntryFinder.new("./cda:entry/cda:act[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.105']"))
5
- super(entry_finder)
6
- @code_xpath = "./cda:entryRelationship/cda:substanceAdministration[cda:templateId/@root = '2.16.840.1.113883.10.20.22.4.16']/cda:consumable/cda:manufacturedProduct/cda:manufacturedMaterial/cda:code"
7
- @relevant_period_xpath = nil
8
- @author_datetime_xpath = "./cda:entryRelationship/cda:substanceAdministration[cda:templateId/@root = '2.16.840.1.113883.10.20.22.4.16']/cda:author/cda:time"
9
- @entry_class = QDM::MedicationDischarge
10
- end
11
-
12
- def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
13
- medication_discharge = super
14
- medication_discharge
15
- end
16
-
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class MedicationDispensedImporter < MedicationImporter
4
- def initialize(entry_finder = QRDA::Cat1::EntryFinder.new("./cda:entry/cda:act[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.139']"))
5
- super(entry_finder)
6
- @relevant_period_xpath = "./cda:entryRelationship/cda:supply[cda:templateId/@root = '2.16.840.1.113883.10.20.22.4.18']/cda:effectiveTime"
7
- @author_datetime_xpath = "./cda:entryRelationship/cda:supply[cda:templateId/@root = '2.16.840.1.113883.10.20.22.4.18']/cda:author/cda:time"
8
- @code_xpath = "./cda:entryRelationship/cda:supply[cda:templateId/@root = '2.16.840.1.113883.10.20.22.4.18']/cda:product/cda:manufacturedProduct/cda:manufacturedMaterial/cda:code"
9
- @entry_class = QDM::MedicationDispensed
10
- end
11
-
12
- def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
13
- medication_dispensed = super
14
- medication_dispensed
15
- end
16
-
17
- end
18
- end
19
- end
@@ -1,16 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class MedicationOrderImporter < MedicationImporter
4
- def initialize(entry_finder = QRDA::Cat1::EntryFinder.new("./cda:entry/cda:substanceAdministration[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.47']"))
5
- super(entry_finder)
6
- @entry_class = QDM::MedicationOrder
7
- end
8
-
9
- def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
10
- medication_order = super
11
- medication_order
12
- end
13
-
14
- end
15
- end
16
- end
@@ -1,22 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class PatientCharacteristicExpired < SectionImporter
4
- def initialize(entry_finder = QRDA::Cat1::EntryFinder.new("./cda:entry/cda:observation[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.54']"))
5
- super(entry_finder)
6
- @id_xpath = './cda:id'
7
- @code_xpath = './cda:value'
8
- @expired_datetime_xpath = './cda:effectiveTime/cda:low'
9
- @cause = "./cda:entryRelationship/cda:observation[cda:templateId/@root = '2.16.840.1.113883.10.20.22.4.4']/cda:value"
10
- @entry_class = QDM::PatientCharacteristicExpired
11
- end
12
-
13
- def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
14
- patient_characteristic_expired = super
15
- patient_characteristic_expired.expiredDatetime = extract_time(entry_element, @expired_datetime_xpath)
16
- patient_characteristic_expired.cause = code_if_present(entry_element.at_xpath(@cause))
17
- patient_characteristic_expired
18
- end
19
-
20
- end
21
- end
22
- end
@@ -1,27 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class PhysicalExamPerformedImporter < SectionImporter
4
- def initialize(entry_finder = QRDA::Cat1::EntryFinder.new("./cda:entry/cda:observation[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.59']"))
5
- super(entry_finder)
6
- @id_xpath = './cda:id'
7
- @code_xpath = "./cda:code"
8
- @relevant_period_xpath = "./cda:effectiveTime"
9
- @author_datetime_xpath = "./cda:author/cda:time"
10
- @method_xpath = './cda:methodCode'
11
- @result_xpath = "./cda:value"
12
- @anatomical_location_site_xpath = "./cda:targetSiteCode"
13
- @components_xpath = "./cda:entryRelationship/cda:observation[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.149']"
14
- @entry_class = QDM::PhysicalExamPerformed
15
- end
16
-
17
- def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
18
- physical_exam_performed = super
19
- physical_exam_performed.method = code_if_present(entry_element.at_xpath(@method_xpath))
20
- physical_exam_performed.anatomicalLocationSite = code_if_present(entry_element.at_xpath(@anatomical_location_site_xpath))
21
- physical_exam_performed.components = extract_components(entry_element)
22
- physical_exam_performed
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class ProcedureOrderImporter < SectionImporter
4
- def initialize(entry_finder = QRDA::Cat1::EntryFinder.new("./cda:entry/cda:procedure[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.63']"))
5
- super(entry_finder)
6
- @id_xpath = './cda:id'
7
- @code_xpath = './cda:code'
8
- @author_datetime_xpath = "./cda:author/cda:time"
9
- @method_xpath = './cda:methodCode'
10
- @anatomical_approach_site_xpath = "./cda:approachSiteCode"
11
- @anatomical_location_site_xpath = "./cda:targetSiteCode"
12
- @ordinality_xpath = "./cda:priorityCode"
13
- @entry_class = QDM::ProcedureOrder
14
- end
15
-
16
- def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
17
- procedure_order = super
18
- procedure_order.method = code_if_present(entry_element.at_xpath(@method_xpath))
19
- procedure_order.anatomicalApproachSite = code_if_present(entry_element.at_xpath(@anatomical_approach_site_xpath))
20
- procedure_order.anatomicalLocationSite = code_if_present(entry_element.at_xpath(@anatomical_location_site_xpath))
21
- procedure_order.ordinality = code_if_present(entry_element.at_xpath(@ordinality_xpath))
22
- procedure_order
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,35 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class ProcedurePerformedImporter < SectionImporter
4
- def initialize(entry_finder = QRDA::Cat1::EntryFinder.new("./cda:entry/cda:procedure[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.64']"))
5
- super(entry_finder)
6
- @id_xpath = './cda:id'
7
- @code_xpath = "./cda:code"
8
- @relevant_period_xpath = "./cda:effectiveTime"
9
- @author_datetime_xpath = "./cda:author/cda:time"
10
- @method_xpath = './cda:methodCode'
11
- @result_xpath = "./cda:entryRelationship[@typeCode='REFR']/cda:observation/cda:value"
12
- @status_xpath = "./cda:entryRelationship/cda:observation[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.93']/cda:value"
13
- @anatomical_approach_site_xpath = "./cda:approachSiteCode"
14
- @anatomical_location_site_xpath = "./cda:targetSiteCode"
15
- @ordinality_xpath = "./cda:priorityCode"
16
- @incision_datetime_xpath = "./cda:entryRelationship/cda:procedure[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.89']/cda:effectiveTime"
17
- @components_xpath = "./cda:entryRelationship/cda:observation[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.149']"
18
- @entry_class = QDM::ProcedurePerformed
19
- end
20
-
21
- def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
22
- procedure_performed = super
23
- procedure_performed.method = code_if_present(entry_element.at_xpath(@method_xpath))
24
- procedure_performed.status = code_if_present(entry_element.at_xpath(@status_xpath))
25
- procedure_performed.anatomicalApproachSite = code_if_present(entry_element.at_xpath(@anatomical_approach_site_xpath))
26
- procedure_performed.anatomicalLocationSite = code_if_present(entry_element.at_xpath(@anatomical_location_site_xpath))
27
- procedure_performed.ordinality = code_if_present(entry_element.at_xpath(@ordinality_xpath))
28
- procedure_performed.incisionDatetime = extract_time(entry_element, @incision_datetime_xpath)
29
- procedure_performed.components = extract_components(entry_element)
30
- procedure_performed
31
- end
32
-
33
- end
34
- end
35
- end
@@ -1,16 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class SubstanceAdministeredImporter < MedicationAdministeredImporter
4
- def initialize(entry_finder = QRDA::Cat1::EntryFinder.new("./cda:entry/cda:substanceAdministration[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.42']"))
5
- super(entry_finder)
6
- @entry_class = QDM::SubstanceAdministered
7
- end
8
-
9
- def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
10
- substance_administered = super
11
- substance_administered
12
- end
13
-
14
- end
15
- end
16
- end
@@ -1,20 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class EntryFinder
4
- def initialize(entry_xpath)
5
- @entry_xpath = entry_xpath
6
- end
7
-
8
- def entries(doc)
9
- entry_elements = doc.xpath(@entry_xpath)
10
- if block_given?
11
- entry_elements.each do |entry_element|
12
- yield entry_element
13
- end
14
- else
15
- entry_elements
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,16 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class EntryPackage
4
-
5
- attr_accessor :importer_type
6
-
7
- def initialize(type)
8
- self.importer_type = type
9
- end
10
-
11
- def package_entries(doc, nrh)
12
- importer_type.create_entries(doc, nrh)
13
- end
14
- end
15
- end
16
- end
@@ -1,33 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- class NarrativeReferenceHandler
4
- def initialize
5
- @id_map = {}
6
- end
7
-
8
- def build_id_map(doc)
9
- path = "//*[@ID]"
10
- ids = doc.xpath(path)
11
- ids.each do |id|
12
- tag = id['ID']
13
- value = id.content
14
- @id_map[tag] = value
15
- end
16
- end
17
-
18
- # @param [String] tag
19
- # @return [String] text description of tag
20
- def lookup_tag(tag)
21
- value = @id_map[tag]
22
- # Not sure why, but sometimes the reference is #<Reference> and the ID value is <Reference>, and
23
- # sometimes it is #<Reference>. We look for both.
24
- if !value and tag[0] == '#'
25
- tag = tag[1,tag.length]
26
- value = @id_map[tag]
27
- end
28
-
29
- value
30
- end
31
- end
32
- end
33
- end
@@ -1,111 +0,0 @@
1
- module QRDA
2
- module Cat1
3
- # This class is the central location for taking a QRDA Cat 1 XML document and converting it
4
- # into the processed form we store in MongoDB. The class does this by running each measure
5
- # independently on the XML document
6
- #
7
- # This class is a Singleton. It should be accessed by calling PatientImporter.instance
8
- class PatientImporter
9
- include Singleton
10
- include DemographicsImporter
11
-
12
- def initialize
13
- # This differs from other HDS patient importers in that sections can have multiple importers
14
- @data_element_importers = []
15
-
16
- @data_element_importers << generate_importer(EncounterPerformedImporter)
17
- @data_element_importers << generate_importer(PhysicalExamPerformedImporter)
18
- @data_element_importers << generate_importer(LaboratoryTestPerformedImporter)
19
- @data_element_importers << generate_importer(DiagnosisImporter)
20
- @data_element_importers << generate_importer(InterventionOrderImporter)
21
- @data_element_importers << generate_importer(ProcedurePerformedImporter)
22
- @data_element_importers << generate_importer(MedicationActiveImporter)
23
- @data_element_importers << generate_importer(AllergyIntoleranceImporter)
24
- @data_element_importers << generate_importer(MedicationOrderImporter)
25
- @data_element_importers << generate_importer(DiagnosticStudyOrderImporter)
26
-
27
- @data_element_importers << generate_importer(AdverseEventImporter)
28
- @data_element_importers << generate_importer(AssessmentPerformedImporter)
29
- @data_element_importers << generate_importer(CommunicationFromPatientToProviderImporter)
30
- @data_element_importers << generate_importer(CommunicationFromProviderToPatientImporter)
31
- @data_element_importers << generate_importer(CommunicationFromProviderToProviderImporter)
32
- @data_element_importers << generate_importer(DeviceAppliedImporter)
33
- @data_element_importers << generate_importer(DeviceOrderImporter)
34
- @data_element_importers << generate_importer(DiagnosticStudyPerformedImporter)
35
- @data_element_importers << generate_importer(EncounterOrderImporter)
36
- @data_element_importers << generate_importer(ImmunizationAdministeredImporter)
37
- @data_element_importers << generate_importer(InterventionPerformedImporter)
38
- @data_element_importers << generate_importer(LaboratoryTestOrderImporter)
39
- @data_element_importers << generate_importer(MedicationAdministeredImporter)
40
- @data_element_importers << generate_importer(MedicationDischargeImporter)
41
- @data_element_importers << generate_importer(MedicationDispensedImporter)
42
- @data_element_importers << generate_importer(PatientCharacteristicExpired)
43
- @data_element_importers << generate_importer(ProcedureOrderImporter)
44
- @data_element_importers << generate_importer(SubstanceAdministeredImporter)
45
-
46
- end
47
-
48
- def parse_cat1(doc)
49
- patient = QDM::Patient.new
50
- entry_id_map = {}
51
- import_data_elements(patient, doc, entry_id_map)
52
- normalize_references(patient, entry_id_map)
53
- get_demographics(patient, doc)
54
- patient
55
- end
56
-
57
- def import_data_elements(patient, doc, entry_id_map)
58
- context = doc.xpath("/cda:ClinicalDocument/cda:component/cda:structuredBody/cda:component/cda:section[cda:templateId/@root = '2.16.840.1.113883.10.20.24.2.1']")
59
- nrh = NarrativeReferenceHandler.new
60
- nrh.build_id_map(doc)
61
- @data_element_importers.each do |entry_package|
62
- data_elements, id_map = entry_package.package_entries(context, nrh)
63
- new_data_elements = []
64
-
65
- id_map.each_value do |elem_ids|
66
-
67
- elem_id = elem_ids.first
68
- data_element = data_elements.find { |de| de.id == elem_id }
69
-
70
- elem_ids[1,elem_ids.length].each do |merge_id|
71
- merge_element = data_elements.find { |de| de.id == merge_id }
72
- data_element.merge!(merge_element)
73
- end
74
-
75
- new_data_elements << data_element
76
- end
77
-
78
- patient.dataElements << new_data_elements
79
- entry_id_map.merge!(id_map)
80
- end
81
- end
82
-
83
- def get_patient_expired(record, doc)
84
- entry_elements = doc.xpath("/cda:ClinicalDocument/cda:component/cda:structuredBody/cda:component/cda:section[cda:templateId/@root = '2.16.840.1.113883.10.20.24.2.1']/cda:entry/cda:observation[cda:templateId/@root = '2.16.840.1.113883.10.20.24.3.54']")
85
- return unless entry_elements.empty?
86
- record.expired = true
87
- record.deathdate = HealthDataStandards::Util::HL7Helper.timestamp_to_integer(entry_elements.at_xpath("./cda:effectiveTime/cda:low")['value'])
88
- end
89
-
90
- def normalize_references(patient, entry_id_map)
91
- patient.dataElements.each do |data_element|
92
- next unless data_element.respond_to?(:relatedTo) && data_element.relatedTo
93
- relations_to_add = []
94
- data_element.relatedTo.each do |related_to|
95
- relations_to_add << entry_id_map[related_to.value]
96
- end
97
- data_element.relatedTo.destroy
98
- relations_to_add.each do |relation_to_add|
99
- data_element.relatedTo << relation_to_add
100
- end
101
- end
102
- end
103
-
104
- private
105
-
106
- def generate_importer(importer_class)
107
- EntryPackage.new(importer_class.new)
108
- end
109
- end
110
- end
111
- end