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.
Files changed (264) hide show
  1. data/Gemfile +5 -0
  2. data/lib/health-data-standards.rb +55 -12
  3. data/lib/health-data-standards/export/c32.rb +7 -6
  4. data/lib/health-data-standards/export/cat_1.rb +18 -0
  5. data/lib/health-data-standards/export/ccda.rb +8 -8
  6. data/lib/health-data-standards/export/green_c32/entry.rb +8 -5
  7. data/lib/health-data-standards/export/green_c32/export_generator.rb +1 -1
  8. data/lib/health-data-standards/export/green_c32/record.rb +10 -7
  9. data/lib/health-data-standards/export/hdata/metadata.rb +7 -6
  10. data/lib/health-data-standards/export/helper/cat1_view_helper.rb +133 -0
  11. data/lib/health-data-standards/export/helper/gc32_view_helper.rb +39 -0
  12. data/lib/health-data-standards/export/helper/html_view_helper.rb +23 -0
  13. data/lib/health-data-standards/export/html.rb +22 -10
  14. data/lib/health-data-standards/export/qrda/entry_template_resolver.rb +31 -0
  15. data/lib/health-data-standards/export/qrda/hqmf-qrda-oids.json +638 -0
  16. data/lib/health-data-standards/export/rendering_context.rb +37 -3
  17. data/lib/health-data-standards/export/template_helper.rb +20 -23
  18. data/lib/health-data-standards/export/view_helper.rb +8 -42
  19. data/lib/health-data-standards/import/bundle/importer.rb +148 -0
  20. data/lib/health-data-standards/import/c32/care_goal_importer.rb +14 -26
  21. data/lib/health-data-standards/import/c32/condition_importer.rb +12 -51
  22. data/lib/health-data-standards/import/c32/immunization_importer.rb +9 -27
  23. data/lib/health-data-standards/import/c32/insurance_provider_importer.rb +24 -21
  24. data/lib/health-data-standards/import/c32/patient_importer.rb +27 -34
  25. data/lib/health-data-standards/import/cat1/diagnosis_active_importer.rb +19 -0
  26. data/lib/health-data-standards/import/cat1/diagnosis_inactive_importer.rb +19 -0
  27. data/lib/health-data-standards/import/cat1/diagnostic_study_order_importer.rb +24 -0
  28. data/lib/health-data-standards/import/cat1/encounter_order_importer.rb +24 -0
  29. data/lib/health-data-standards/import/cat1/entry_package.rb +25 -0
  30. data/lib/health-data-standards/import/cat1/gestational_age_importer.rb +42 -0
  31. data/lib/health-data-standards/import/cat1/lab_order_importer.rb +24 -0
  32. data/lib/health-data-standards/import/cat1/medication_dispensed_importer.rb +13 -0
  33. data/lib/health-data-standards/import/cat1/patient_importer.rb +104 -0
  34. data/lib/health-data-standards/import/cat1/procedure_intolerance_importer.rb +13 -0
  35. data/lib/health-data-standards/import/cat1/procedure_order_importer.rb +38 -0
  36. data/lib/health-data-standards/import/cat1/tobacco_use_importer.rb +19 -0
  37. data/lib/health-data-standards/import/ccda/allergy_importer.rb +2 -8
  38. data/lib/health-data-standards/import/ccda/care_goal_importer.rb +1 -1
  39. data/lib/health-data-standards/import/ccda/condition_importer.rb +2 -3
  40. data/lib/health-data-standards/import/ccda/encounter_importer.rb +2 -5
  41. data/lib/health-data-standards/import/ccda/immunization_importer.rb +1 -3
  42. data/lib/health-data-standards/import/ccda/insurance_provider_importer.rb +1 -1
  43. data/lib/health-data-standards/import/ccda/medical_equipment_importer.rb +2 -4
  44. data/lib/health-data-standards/import/ccda/medication_importer.rb +2 -4
  45. data/lib/health-data-standards/import/ccda/patient_importer.rb +1 -1
  46. data/lib/health-data-standards/import/ccda/procedure_importer.rb +2 -6
  47. data/lib/health-data-standards/import/ccda/result_importer.rb +2 -5
  48. data/lib/health-data-standards/import/ccda/vital_sign_importer.rb +2 -3
  49. data/lib/health-data-standards/import/cda/allergy_importer.rb +32 -0
  50. data/lib/health-data-standards/import/cda/condition_importer.rb +51 -0
  51. data/lib/health-data-standards/import/{c32 → cda}/encounter_importer.rb +9 -35
  52. data/lib/health-data-standards/import/cda/entry_finder.rb +22 -0
  53. data/lib/health-data-standards/import/{c32 → cda}/locatable_import_utils.rb +2 -3
  54. data/lib/health-data-standards/import/cda/medical_equipment_importer.rb +24 -0
  55. data/lib/health-data-standards/import/{c32 → cda}/medication_importer.rb +13 -15
  56. data/lib/health-data-standards/import/cda/narrative_reference_handler.rb +35 -0
  57. data/lib/health-data-standards/import/{c32 → cda}/organization_importer.rb +1 -1
  58. data/lib/health-data-standards/import/cda/procedure_importer.rb +35 -0
  59. data/lib/health-data-standards/import/{c32 → cda}/provider_importer.rb +4 -8
  60. data/lib/health-data-standards/import/cda/result_importer.rb +31 -0
  61. data/lib/health-data-standards/import/{c32 → cda}/section_importer.rb +26 -48
  62. data/lib/health-data-standards/import/{c32 → cda}/vital_sign_importer.rb +2 -3
  63. data/lib/health-data-standards/import/green_c32/section_importer.rb +8 -6
  64. data/lib/health-data-standards/import/provider_import_utils.rb +2 -2
  65. data/lib/health-data-standards/models/address.rb +1 -1
  66. data/lib/health-data-standards/models/condition.rb +7 -6
  67. data/lib/health-data-standards/models/cqm/bundle.rb +45 -0
  68. data/lib/health-data-standards/models/cqm/measure.rb +36 -0
  69. data/lib/health-data-standards/models/guarantor.rb +1 -0
  70. data/lib/health-data-standards/models/insurance_provider.rb +2 -0
  71. data/lib/health-data-standards/models/order_information.rb +2 -0
  72. data/lib/health-data-standards/models/record.rb +6 -5
  73. data/lib/health-data-standards/models/svs/value_set.rb +1 -1
  74. data/lib/health-data-standards/railtie.rb +11 -0
  75. data/lib/health-data-standards/tasks/bundle.rake +107 -0
  76. data/lib/health-data-standards/util/code_system_helper.rb +9 -1
  77. data/lib/hqmf-generator/attribute.xml.erb +11 -0
  78. data/lib/hqmf-generator/characteristic_criteria.xml.erb +21 -0
  79. data/lib/hqmf-generator/code.xml.erb +13 -0
  80. data/lib/hqmf-generator/condition_criteria.xml.erb +22 -0
  81. data/lib/hqmf-generator/derivation.xml.erb +6 -0
  82. data/lib/hqmf-generator/description.xml.erb +1 -0
  83. data/lib/hqmf-generator/document.xml.erb +63 -0
  84. data/lib/hqmf-generator/effective_time.xml.erb +4 -0
  85. data/lib/hqmf-generator/encounter_criteria.xml.erb +21 -0
  86. data/lib/hqmf-generator/field.xml.erb +28 -0
  87. data/lib/hqmf-generator/hqmf-generator.rb +292 -0
  88. data/lib/hqmf-generator/observation_criteria.xml.erb +25 -0
  89. data/lib/hqmf-generator/population_criteria.xml.erb +23 -0
  90. data/lib/hqmf-generator/precondition.xml.erb +14 -0
  91. data/lib/hqmf-generator/procedure_criteria.xml.erb +22 -0
  92. data/lib/hqmf-generator/reason.xml.erb +3 -0
  93. data/lib/hqmf-generator/reference.xml.erb +3 -0
  94. data/lib/hqmf-generator/source.xml.erb +6 -0
  95. data/lib/hqmf-generator/specific_occurrence.xml.erb +7 -0
  96. data/lib/hqmf-generator/subset.xml.erb +8 -0
  97. data/lib/hqmf-generator/substance_criteria.xml.erb +26 -0
  98. data/lib/hqmf-generator/supply_criteria.xml.erb +26 -0
  99. data/lib/hqmf-generator/template_id.xml.erb +5 -0
  100. data/lib/hqmf-generator/temporal_relationship.xml.erb +6 -0
  101. data/lib/hqmf-generator/value.xml.erb +24 -0
  102. data/lib/hqmf-generator/variable_criteria.xml.erb +12 -0
  103. data/lib/hqmf-model/attribute.rb +35 -0
  104. data/lib/hqmf-model/data_criteria.json +1123 -0
  105. data/lib/hqmf-model/data_criteria.rb +344 -0
  106. data/lib/hqmf-model/document.rb +178 -0
  107. data/lib/hqmf-model/population_criteria.rb +96 -0
  108. data/lib/hqmf-model/precondition.rb +91 -0
  109. data/lib/hqmf-model/types.rb +319 -0
  110. data/lib/hqmf-model/utilities.rb +52 -0
  111. data/lib/hqmf-parser.rb +56 -0
  112. data/lib/hqmf-parser/1.0/attribute.rb +68 -0
  113. data/lib/hqmf-parser/1.0/comparison.rb +34 -0
  114. data/lib/hqmf-parser/1.0/data_criteria.rb +92 -0
  115. data/lib/hqmf-parser/1.0/data_criteria_oid_xpath.json +91 -0
  116. data/lib/hqmf-parser/1.0/document.rb +203 -0
  117. data/lib/hqmf-parser/1.0/expression.rb +58 -0
  118. data/lib/hqmf-parser/1.0/observation.rb +61 -0
  119. data/lib/hqmf-parser/1.0/population_criteria.rb +75 -0
  120. data/lib/hqmf-parser/1.0/precondition.rb +89 -0
  121. data/lib/hqmf-parser/1.0/range.rb +65 -0
  122. data/lib/hqmf-parser/1.0/restriction.rb +160 -0
  123. data/lib/hqmf-parser/1.0/utilities.rb +41 -0
  124. data/lib/hqmf-parser/2.0/data_criteria.rb +319 -0
  125. data/lib/hqmf-parser/2.0/document.rb +165 -0
  126. data/lib/hqmf-parser/2.0/population_criteria.rb +53 -0
  127. data/lib/hqmf-parser/2.0/precondition.rb +44 -0
  128. data/lib/hqmf-parser/2.0/types.rb +223 -0
  129. data/lib/hqmf-parser/2.0/utilities.rb +30 -0
  130. data/lib/hqmf-parser/converter/pass1/data_criteria_converter.rb +252 -0
  131. data/lib/hqmf-parser/converter/pass1/document_converter.rb +185 -0
  132. data/lib/hqmf-parser/converter/pass1/population_criteria_converter.rb +165 -0
  133. data/lib/hqmf-parser/converter/pass1/precondition_converter.rb +173 -0
  134. data/lib/hqmf-parser/converter/pass1/precondition_extractor.rb +188 -0
  135. data/lib/hqmf-parser/converter/pass1/simple_data_criteria.rb +26 -0
  136. data/lib/hqmf-parser/converter/pass1/simple_operator.rb +89 -0
  137. data/lib/hqmf-parser/converter/pass1/simple_population_criteria.rb +10 -0
  138. data/lib/hqmf-parser/converter/pass1/simple_precondition.rb +51 -0
  139. data/lib/hqmf-parser/converter/pass1/simple_restriction.rb +64 -0
  140. data/lib/hqmf-parser/converter/pass2/comparison_converter.rb +112 -0
  141. data/lib/hqmf-parser/converter/pass2/operator_converter.rb +102 -0
  142. data/lib/hqmf-parser/parser.rb +54 -0
  143. data/lib/hqmf-parser/value_sets/value_set_parser.rb +241 -0
  144. data/lib/util/counter.rb +20 -0
  145. data/templates/{_allergies.c32.erb → c32/_allergies.c32.erb} +0 -0
  146. data/templates/{_allergies_no_current.c32.erb → c32/_allergies_no_current.c32.erb} +0 -0
  147. data/templates/{_care_goals.c32.erb → c32/_care_goals.c32.erb} +0 -0
  148. data/templates/{_code_with_reference.c32.erb → c32/_code_with_reference.c32.erb} +0 -0
  149. data/templates/{_conditions.c32.erb → c32/_conditions.c32.erb} +0 -0
  150. data/templates/{_conditions_no_current.c32.erb → c32/_conditions_no_current.c32.erb} +0 -0
  151. data/templates/{_encounters.c32.erb → c32/_encounters.c32.erb} +0 -0
  152. data/templates/{_immunizations.c32.erb → c32/_immunizations.c32.erb} +0 -0
  153. data/templates/{_medical_equipment.c32.erb → c32/_medical_equipment.c32.erb} +0 -0
  154. data/templates/{_medications.c32.erb → c32/_medications.c32.erb} +0 -0
  155. data/templates/{_medications_no_current.c32.erb → c32/_medications_no_current.c32.erb} +0 -0
  156. data/templates/{_narrative_block.c32.erb → c32/_narrative_block.c32.erb} +0 -0
  157. data/templates/{_procedures.c32.erb → c32/_procedures.c32.erb} +0 -0
  158. data/templates/{_results.c32.erb → c32/_results.c32.erb} +0 -0
  159. data/templates/{_social_history.c32.erb → c32/_social_history.c32.erb} +0 -0
  160. data/templates/{_vital_signs.c32.erb → c32/_vital_signs.c32.erb} +0 -0
  161. data/templates/{show.c32.erb → c32/show.c32.erb} +0 -0
  162. data/templates/cat1/_2.16.840.1.113883.10.20.22.4.85.cat1.erb +18 -0
  163. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.1.cat1.erb +14 -0
  164. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.101.cat1.erb +25 -0
  165. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.103.cat1.erb +12 -0
  166. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.105.cat1.erb +60 -0
  167. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.11.cat1.erb +41 -0
  168. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.12.cat1.erb +50 -0
  169. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.13.cat1.erb +37 -0
  170. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.14.cat1.erb +35 -0
  171. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.17.cat1.erb +22 -0
  172. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.18.cat1.erb +21 -0
  173. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.2.cat1.erb +28 -0
  174. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.20.cat1.erb +20 -0
  175. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.22.cat1.erb +21 -0
  176. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.23.cat1.erb +71 -0
  177. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.28.cat1.erb +20 -0
  178. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.3.cat1.erb +24 -0
  179. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.31.cat1.erb +20 -0
  180. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.32.cat1.erb +15 -0
  181. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.34.cat1.erb +58 -0
  182. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.37.cat1.erb +20 -0
  183. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.38.cat1.erb +16 -0
  184. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.4.cat1.erb +27 -0
  185. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.40.cat1.erb +17 -0
  186. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.41.cat1.erb +38 -0
  187. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.42.cat1.erb +38 -0
  188. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.43.cat1.erb +24 -0
  189. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.44.cat1.erb +24 -0
  190. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.45.cat1.erb +26 -0
  191. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.46.cat1.erb +30 -0
  192. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.47.cat1.erb +26 -0
  193. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.51.cat1.erb +13 -0
  194. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.54.cat1.erb +16 -0
  195. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.55.cat1.erb +10 -0
  196. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.57.cat1.erb +19 -0
  197. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.59.cat1.erb +17 -0
  198. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.62.cat1.erb +36 -0
  199. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.63.cat1.erb +23 -0
  200. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.64.cat1.erb +29 -0
  201. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.66.cat1.erb +34 -0
  202. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.69.cat1.erb +23 -0
  203. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.7.cat1.erb +30 -0
  204. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.76.cat1.erb +32 -0
  205. data/templates/cat1/_measures.cat1.erb +66 -0
  206. data/templates/cat1/_medication_details.cat1.erb +9 -0
  207. data/templates/cat1/_ordinality.cat1.erb +4 -0
  208. data/templates/cat1/_patient_data.cat1.erb +14 -0
  209. data/templates/cat1/_reason.cat1.erb +16 -0
  210. data/templates/cat1/_record_target.cat1.erb +39 -0
  211. data/templates/cat1/_reporting_parameters.cat1.erb +24 -0
  212. data/templates/cat1/_result_value.cat1.erb +16 -0
  213. data/templates/cat1/show.cat1.erb +125 -0
  214. data/templates/{_address.gc32.erb → gc32/_address.gc32.erb} +1 -1
  215. data/templates/gc32/_advance_directive.gc32.erb +5 -0
  216. data/templates/gc32/_allergy.gc32.erb +12 -0
  217. data/templates/{_care_goal.gc32.erb → gc32/_care_goal.gc32.erb} +1 -1
  218. data/templates/gc32/_condition.gc32.erb +10 -0
  219. data/templates/gc32/_encounter.gc32.erb +28 -0
  220. data/templates/gc32/_entry.gc32.erb +3 -0
  221. data/templates/gc32/_entry_attributes.gc32.erb +10 -0
  222. data/templates/gc32/_immunization.gc32.erb +9 -0
  223. data/templates/gc32/_insurance_provider.gc32.erb +28 -0
  224. data/templates/gc32/_medical_equipment.gc32.erb +6 -0
  225. data/templates/gc32/_medication.gc32.erb +91 -0
  226. data/templates/{_name.gc32.erb → gc32/_name.gc32.erb} +0 -0
  227. data/templates/gc32/_organization.gc32.erb +10 -0
  228. data/templates/gc32/_person_attributes.gc32.erb +7 -0
  229. data/templates/gc32/_procedure.gc32.erb +9 -0
  230. data/templates/gc32/_provider.gc32.erb +9 -0
  231. data/templates/gc32/_result.gc32.erb +12 -0
  232. data/templates/gc32/_social_history.gc32.erb +6 -0
  233. data/templates/{_support.gc32.erb → gc32/_support.gc32.erb} +4 -3
  234. data/templates/gc32/_telecom.gc32.erb +1 -0
  235. data/templates/gc32/_vital_sign.gc32.erb +4 -0
  236. data/templates/{record.gc32.erb → gc32/record.gc32.erb} +26 -10
  237. data/templates/html/_entries_by_encounter.html.erb +2 -2
  238. data/templates/html/_entries_by_section.html.erb +1 -1
  239. data/templates/html/_entry.html.erb +16 -21
  240. data/templates/html/_header.html.erb +1 -1
  241. data/templates/html/_section.html.erb +1 -1
  242. data/templates/html/show.html.erb +23 -2
  243. data/templates/metadata.hdata.erb +3 -3
  244. metadata +282 -54
  245. data/lib/health-data-standards/import/c32/allergy_importer.rb +0 -47
  246. data/lib/health-data-standards/import/c32/medical_equipment_importer.rb +0 -45
  247. data/lib/health-data-standards/import/c32/procedure_importer.rb +0 -62
  248. data/lib/health-data-standards/import/c32/result_importer.rb +0 -56
  249. data/templates/_advance_directive.gc32.erb +0 -8
  250. data/templates/_allergy.gc32.erb +0 -23
  251. data/templates/_condition.gc32.erb +0 -9
  252. data/templates/_encounter.gc32.erb +0 -26
  253. data/templates/_entry.gc32.erb +0 -14
  254. data/templates/_immunization.gc32.erb +0 -11
  255. data/templates/_insurance_provider.gc32.erb +0 -0
  256. data/templates/_medical_equipment.gc32.erb +0 -7
  257. data/templates/_medication.gc32.erb +0 -72
  258. data/templates/_organization.gc32.erb +0 -10
  259. data/templates/_procedure.gc32.erb +0 -10
  260. data/templates/_provider.gc32.erb +0 -19
  261. data/templates/_result.gc32.erb +0 -16
  262. data/templates/_social_history.gc32.erb +0 -8
  263. data/templates/_telecom.gc32.erb +0 -1
  264. data/templates/_vital_sign.gc32.erb +0 -7
@@ -0,0 +1,4 @@
1
+ <effectiveTime xsi:type="IVL_TS">
2
+ <%= xml_for_value(effective_time.low, 'low', false) if effective_time.low -%>
3
+ <%= xml_for_value(effective_time.high, 'high', false) if effective_time.high -%>
4
+ </effectiveTime>
@@ -0,0 +1,21 @@
1
+ <entry typeCode="DRIV">
2
+ <encounterCriteria moodCode="EVN" classCode="ENC"<%= " actionNegationInd='true'" if criteria.negation %>>
3
+ <%= xml_for_template(criteria, is_source_data_criteria) %>
4
+ <id>
5
+ <item root="2.16.840.1.113883.3.100.1" extension="<%= criteria.id %>"/>
6
+ </id>
7
+ <%= xml_for_code(criteria) %>
8
+ <%= xml_for_description(criteria) %>
9
+ <%= xml_for_effective_time(criteria) %>
10
+ <%= xml_for_reason(criteria) %>
11
+ <definition>
12
+ <encounterReference moodCode="EVN" classCode="ENC">
13
+ <id root="2.16.840.1.113883.3.100.1" extension="<%= section_name(criteria) %>"/>
14
+ </encounterReference>
15
+ </definition>
16
+ <%= xml_for_temporal_references(criteria) %>
17
+ <%= xml_for_fields(criteria) %>
18
+ <%= xml_for_derivation(criteria) %>
19
+ <%= xml_for_subsets(criteria) %>
20
+ </encounterCriteria>
21
+ </entry>
@@ -0,0 +1,28 @@
1
+ <outboundRelationship typeCode="SUBJ">
2
+ <%- if details[:code] == 'SDLOC' -%>
3
+ <encounterCriteria classCode="ENC" moodCode="EVN">
4
+ <%- if details[:templateId] -%>
5
+ <templateId>
6
+ <item root="<%= details[:template_id] %>"/>
7
+ </templateId>
8
+ <%- end -%>
9
+ <participation typeCode="LOC">
10
+ <role classCode="SDLOC">
11
+ <%= xml_for_value(value, 'code') %>
12
+ </role>
13
+ </participation>
14
+ </encounterCriteria>
15
+ <%- else -%>
16
+ <observationCriteria classCode="OBS" moodCode="EVN">
17
+ <%- if details[:templateId] -%>
18
+ <templateId>
19
+ <item root="<%= details[:template_id] %>"/>
20
+ </templateId>
21
+ <%- end -%>
22
+ <code code="<%= details[:code] %>" codeSystem="<%= details[:code_system] %>" codeSystemName="<%= details[:code_system_name] %>">
23
+ <displayName value="<%= details[:title] %>"/>
24
+ </code>
25
+ <%= xml_for_value(value) %>
26
+ </observationCriteria>
27
+ <%- end -%>
28
+ </outboundRelationship>
@@ -0,0 +1,292 @@
1
+ module HQMF2
2
+ module Generator
3
+
4
+ def self.render_template(name, params)
5
+ template_path = File.expand_path(File.join('..', "#{name}.xml.erb"), __FILE__)
6
+ template_str = File.read(template_path)
7
+ template = ERB.new(template_str, nil, '-', "_templ#{HQMF::Counter.instance.next}")
8
+ context = ErbContext.new(params)
9
+ template.result(context.get_binding)
10
+ end
11
+
12
+ # Class to serialize HQMF::Document as HQMF V2 XML
13
+ class ModelProcessor
14
+ # Convert the supplied model instance to XML
15
+ # @param [HQMF::Document] doc the model instance
16
+ # @return [String] the serialized XML as a String
17
+ def self.to_hqmf(doc)
18
+ HQMF2::Generator.render_template('document', {'doc' => doc})
19
+ end
20
+ end
21
+
22
+ # Utility class used to supply a binding to Erb. Contains utility functions used
23
+ # by the erb templates that are used to generate the HQMF document.
24
+ class ErbContext < OpenStruct
25
+
26
+ def initialize(vars)
27
+ super(vars)
28
+ end
29
+
30
+ # Get a binding that contains all the instance variables
31
+ # @return [Binding]
32
+ def get_binding
33
+ binding
34
+ end
35
+
36
+ def xml_for_reference_id(id)
37
+ reference = HQMF::Reference.new(id)
38
+ xml_for_reference(reference)
39
+ end
40
+
41
+ def xml_for_reference(reference)
42
+ HQMF2::Generator.render_template('reference', {'doc' => doc, 'reference' => reference})
43
+ end
44
+
45
+ def xml_for_attribute(attribute)
46
+ HQMF2::Generator.render_template('attribute', {'attribute' => attribute})
47
+ end
48
+
49
+ def xml_for_fields(criteria)
50
+ fields = []
51
+ if criteria.field_values
52
+ criteria.field_values.each_pair do |key, value|
53
+ details = HQMF::DataCriteria::FIELDS[key]
54
+ details[:code_system_name] = HealthDataStandards::Util::CodeSystemHelper.code_system_for(details[:code_system])
55
+ fields << HQMF2::Generator.render_template('field', {'details' => details, 'value' => value})
56
+ end
57
+ end
58
+ if criteria.specific_occurrence
59
+ fields << HQMF2::Generator.render_template('specific_occurrence', {'source_criteria_id' => criteria.source_data_criteria, 'type' => criteria.specific_occurrence_const, 'id' => criteria.specific_occurrence})
60
+ elsif criteria.source_data_criteria
61
+ fields << HQMF2::Generator.render_template('source', {'source_criteria_id' => criteria.source_data_criteria})
62
+ end
63
+ fields.join
64
+ end
65
+
66
+ def xml_for_value(value, element_name='value', include_type=true)
67
+ HQMF2::Generator.render_template('value', {'doc' => doc, 'value' => value, 'name' => element_name, 'include_type' => include_type})
68
+ end
69
+
70
+ def xml_for_code(criteria, element_name='code', include_type=true)
71
+ HQMF2::Generator.render_template('code', {'doc' => doc, 'criteria' => criteria, 'name' => element_name, 'include_type' => include_type})
72
+ end
73
+
74
+ def xml_for_derivation(data_criteria)
75
+ xml = ''
76
+ if data_criteria.derivation_operator
77
+ xml = HQMF2::Generator.render_template('derivation', {'doc' => doc, 'criteria' => data_criteria})
78
+ end
79
+ xml
80
+ end
81
+
82
+ def xml_for_effective_time(data_criteria)
83
+ xml = ''
84
+ if data_criteria.effective_time
85
+ xml = HQMF2::Generator.render_template('effective_time', {'doc' => doc, 'effective_time' => data_criteria.effective_time})
86
+ end
87
+ xml
88
+ end
89
+
90
+ def xml_for_reason(data_criteria)
91
+ xml = ''
92
+ if data_criteria.negation && data_criteria.negation_code_list_id
93
+ xml = HQMF2::Generator.render_template('reason', {'doc' => doc, 'code_list_id' => data_criteria.negation_code_list_id})
94
+ end
95
+ xml
96
+ end
97
+
98
+ def xml_for_template(data_criteria, is_source_data_criteria)
99
+ xml = ''
100
+ templates = []
101
+ # Add a template ID if one is defined for this data criteria
102
+ template_id = HQMF::DataCriteria.template_id_for_definition(data_criteria.definition, data_criteria.status, data_criteria.negation)
103
+ if template_id
104
+ templates << {:id => template_id, :title => HQMF::DataCriteria.title_for_template_id(template_id)}
105
+ end
106
+ # Add our own template id if this is a source data criteria from HQMF V1. Source
107
+ # data criteria are the 'raw' HQMF V1 data criteria before any restrictions are applied
108
+ # they are only used for negating specific occurrences
109
+ if is_source_data_criteria
110
+ templates << {:id => HQMF::DataCriteria::SOURCE_DATA_CRITERIA_TEMPLATE_ID, :title => HQMF::DataCriteria::SOURCE_DATA_CRITERIA_TEMPLATE_TITLE}
111
+ end
112
+ if templates.length > 0
113
+ xml = HQMF2::Generator.render_template('template_id', {'templates' => templates})
114
+ end
115
+ xml
116
+ end
117
+
118
+ def xml_for_description(data_criteria)
119
+ xml = ''
120
+ if data_criteria.description
121
+ xml = HQMF2::Generator.render_template('description', {'text' => data_criteria.description})
122
+ end
123
+ xml
124
+ end
125
+
126
+ def xml_for_subsets(data_criteria)
127
+ subsets_xml = []
128
+ if data_criteria.subset_operators
129
+ subsets_xml = data_criteria.subset_operators.collect do |operator|
130
+ HQMF2::Generator.render_template('subset', {'doc' => doc, 'subset' => operator, 'criteria' => data_criteria})
131
+ end
132
+ end
133
+ subsets_xml.join()
134
+ end
135
+
136
+ def xml_for_precondition(precondition)
137
+ HQMF2::Generator.render_template('precondition', {'doc' => doc, 'precondition' => precondition})
138
+ end
139
+
140
+ def xml_for_data_criteria(data_criteria, is_source_data_criteria)
141
+ HQMF2::Generator.render_template(data_criteria_template_name(data_criteria), {'doc' => doc, 'criteria' => data_criteria, 'is_source_data_criteria' => is_source_data_criteria})
142
+ end
143
+
144
+ def xml_for_population_criteria(population, criteria_id)
145
+ xml = ''
146
+ population_criteria = doc.population_criteria(population[criteria_id])
147
+ if population_criteria
148
+ xml = HQMF2::Generator.render_template('population_criteria', {'doc' => doc, 'population' => population, 'criteria_id' => criteria_id, 'population_criteria' => population_criteria})
149
+ end
150
+ xml
151
+ end
152
+
153
+ def xml_for_temporal_references(criteria)
154
+ refs = []
155
+ if criteria.temporal_references
156
+ refs = criteria.temporal_references.collect do |reference|
157
+ HQMF2::Generator.render_template('temporal_relationship', {'doc' => doc, 'relationship' => reference})
158
+ end
159
+ end
160
+ refs.join
161
+ end
162
+
163
+ def oid_for_name(code_system_name)
164
+ HealthDataStandards::Util::CodeSystemHelper.oid_for_code_system(code_system_name)
165
+ end
166
+
167
+ def reference_element_name(id)
168
+ referenced_criteria = doc.data_criteria(id)
169
+ element_name_prefix(referenced_criteria)
170
+ end
171
+
172
+ def reference_type_name(id)
173
+ referenced_criteria = doc.data_criteria(id)
174
+ type = nil
175
+ if referenced_criteria
176
+ type = referenced_criteria.type
177
+ elsif id=="MeasurePeriod"
178
+ type = :observation
179
+ end
180
+ if !type
181
+ raise "No data criteria with ID: #{id}"
182
+ end
183
+ case type
184
+ when :encounters
185
+ 'ENC'
186
+ when :procedures
187
+ 'PROC'
188
+ when :medications, :allMedications
189
+ 'SBADM'
190
+ when :medication_supply
191
+ 'SPLY'
192
+ else
193
+ 'OBS'
194
+ end
195
+ end
196
+
197
+ def code_for_characteristic(characteristic)
198
+ case characteristic
199
+ when :birthtime
200
+ '21112-8'
201
+ when :age
202
+ '424144002'
203
+ when :gender
204
+ '263495000'
205
+ when :languages
206
+ '102902016'
207
+ when :maritalStatus
208
+ '125680007'
209
+ when :race
210
+ '103579009'
211
+ else
212
+ raise "Unknown demographic code [#{characteristic}]"
213
+ end
214
+ end
215
+
216
+ def oid_for_characteristic(characteristic)
217
+ case characteristic
218
+ when :birthtime
219
+ '2.16.840.1.113883.6.1'
220
+ else
221
+ '2.16.840.1.113883.6.96'
222
+ end
223
+ end
224
+
225
+ def data_criteria_template_name(data_criteria)
226
+ case data_criteria.definition
227
+ when 'diagnosis', 'diagnosis_family_history'
228
+ 'condition_criteria'
229
+ when 'encounter'
230
+ 'encounter_criteria'
231
+ when 'procedure', 'risk_category_assessment', 'physical_exam', 'communication_from_patient_to_provider', 'communication_from_provider_to_provider', 'device', 'diagnostic_study', 'intervention'
232
+ if data_criteria.value.nil?
233
+ 'procedure_criteria'
234
+ else
235
+ 'observation_criteria'
236
+ end
237
+ when 'medication'
238
+ case data_criteria.status
239
+ when 'dispensed', 'ordered'
240
+ 'supply_criteria'
241
+ else # active or administered
242
+ 'substance_criteria'
243
+ end
244
+ when 'patient_characteristic', 'patient_characteristic_birthdate', 'patient_characteristic_clinical_trial_participant', 'patient_characteristic_expired', 'patient_characteristic_gender', 'patient_characteristic_age', 'patient_characteristic_languages', 'patient_characteristic_marital_status', 'patient_characteristic_race'
245
+ 'characteristic_criteria'
246
+ when 'variable'
247
+ 'variable_criteria'
248
+ else
249
+ 'observation_criteria'
250
+ end
251
+ end
252
+
253
+ def section_name(data_criteria)
254
+ data_criteria.definition.to_s
255
+ end
256
+
257
+ def element_name_prefix(data_criteria)
258
+ type = data_criteria ? data_criteria.type : :observation
259
+ case type
260
+ when :encounters
261
+ 'encounter'
262
+ when :procedures
263
+ 'procedure'
264
+ when :medications, :allMedications
265
+ 'substanceAdministration'
266
+ when :medication_supply
267
+ 'supply'
268
+ else
269
+ 'observation'
270
+ end
271
+ end
272
+
273
+ def population_element_prefix(population_criteria_code)
274
+ case population_criteria_code
275
+ when HQMF::PopulationCriteria::IPP
276
+ 'patientPopulation'
277
+ when HQMF::PopulationCriteria::DENOM
278
+ 'denominator'
279
+ when HQMF::PopulationCriteria::NUMER
280
+ 'numerator'
281
+ when HQMF::PopulationCriteria::DENEXCEP
282
+ 'denominatorException'
283
+ when HQMF::PopulationCriteria::DENEX
284
+ 'denominatorExclusion'
285
+ else
286
+ raise "Unknown population criteria type #{population_criteria_code}"
287
+ end
288
+ end
289
+ end
290
+
291
+ end
292
+ end
@@ -0,0 +1,25 @@
1
+ <entry typeCode="DRIV">
2
+ <observationCriteria moodCode="EVN" classCode="OBS"<%= " actionNegationInd='true'" if criteria.negation %>>
3
+ <%= xml_for_template(criteria, is_source_data_criteria) %>
4
+ <id>
5
+ <item root="2.16.840.1.113883.3.100.1" extension="<%= criteria.id %>"/>
6
+ </id>
7
+ <%= xml_for_code(criteria) %>
8
+ <%= xml_for_description(criteria) %>
9
+ <%= "<statusCode code=\"#{criteria.status}\"/>" if criteria.status %>
10
+ <%= xml_for_effective_time(criteria) %>
11
+ <%= xml_for_reason(criteria) %>
12
+ <%- if criteria.value -%>
13
+ <%= xml_for_value(criteria.value) %>
14
+ <%- end -%>
15
+ <definition>
16
+ <observationReference moodCode="EVN" classCode="OBS">
17
+ <id root="2.16.840.1.113883.3.100.1" extension="<%= section_name(criteria) %>"/>
18
+ </observationReference>
19
+ </definition>
20
+ <%= xml_for_temporal_references(criteria) %>
21
+ <%= xml_for_fields(criteria) %>
22
+ <%= xml_for_derivation(criteria) %>
23
+ <%= xml_for_subsets(criteria) %>
24
+ </observationCriteria>
25
+ </entry>
@@ -0,0 +1,23 @@
1
+ <component typeCode="COMP">
2
+ <<%= population_element_prefix(criteria_id) %>Criteria classCode="OBS" moodCode="EVN">
3
+ <id root="c75181d0-73eb-11de-8a39-0800200c9a66"
4
+ extension="<%= population_criteria.hqmf_id %>"/>
5
+ <code codeSystem="2.16.840.1.113883.5.1063"
6
+ codeSystemName="HL7 Observation Value"
7
+ code="<%= population_criteria.type %>">
8
+ <displayName value="<%= population_criteria.title %>"/>
9
+ </code>
10
+ <isCriterionInd value="true"/>
11
+ <%- if population_criteria.preconditions.present? && population_criteria.preconditions.length > 0 -%>
12
+ <%- population_criteria.preconditions.each do |precondition| -%>
13
+ <%= xml_for_precondition(precondition) %>
14
+ <%- end -%>
15
+ <%- else -%>
16
+ <precondition typeCode="PRCN" nullFlavor="NA">
17
+ <allTrue>
18
+ <id/>
19
+ </allTrue>
20
+ </precondition>
21
+ <%- end -%>
22
+ </<%= population_element_prefix(criteria_id) %>Criteria>
23
+ </component>
@@ -0,0 +1,14 @@
1
+ <precondition typeCode="PRCN">
2
+ <%- if precondition.conjunction? -%>
3
+ <<%= precondition.conjunction_code_with_negation %>>
4
+ <id/>
5
+ <%- precondition.preconditions.each do |child| -%>
6
+ <%= xml_for_precondition(child) %>
7
+ <%- end -%>
8
+ </<%= precondition.conjunction_code_with_negation %>>
9
+ <%- else -%>
10
+ <<%= reference_element_name(precondition.reference.id) %>Reference moodCode="EVN" classCode="<%= reference_type_name(precondition.reference.id) %>">
11
+ <id root="2.16.840.1.113883.3.100.1" extension="<%= precondition.reference.id %>"/>
12
+ </<%= reference_element_name(precondition.reference.id) %>Reference>
13
+ <%- end -%>
14
+ </precondition>
@@ -0,0 +1,22 @@
1
+ <entry typeCode="DRIV">
2
+ <procedureCriteria moodCode="EVN" classCode="PROC"<%= " actionNegationInd='true'" if criteria.negation %>>
3
+ <%= xml_for_template(criteria, is_source_data_criteria) %>
4
+ <id>
5
+ <item root="2.16.840.1.113883.3.100.1" extension="<%= criteria.id %>"/>
6
+ </id>
7
+ <%= xml_for_code(criteria) %>
8
+ <%= xml_for_description(criteria) %>
9
+ <%= "<statusCode code=\"#{criteria.status}\"/>" if criteria.status %>
10
+ <%= xml_for_effective_time(criteria) %>
11
+ <%= xml_for_reason(criteria) %>
12
+ <definition>
13
+ <procedureReference moodCode="EVN" classCode="PROC">
14
+ <id root="2.16.840.1.113883.3.100.1" extension="<%= section_name(criteria) %>"/>
15
+ </procedureReference>
16
+ </definition>
17
+ <%= xml_for_temporal_references(criteria) %>
18
+ <%= xml_for_fields(criteria) %>
19
+ <%= xml_for_derivation(criteria) %>
20
+ <%= xml_for_subsets(criteria) %>
21
+ </procedureCriteria>
22
+ </entry>
@@ -0,0 +1,3 @@
1
+ <reasonCode>
2
+ <item valueSet="<%= code_list_id %>"/>
3
+ </reasonCode>
@@ -0,0 +1,3 @@
1
+ <<%= reference_element_name(reference.id) %>Reference moodCode="EVN" classCode="<%= reference_type_name(reference.id) %>">
2
+ <id root="2.16.840.1.113883.3.100.1" extension="<%= reference.id %>"/>
3
+ </<%= reference_element_name(reference.id) %>Reference>