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,24 @@
1
+ module HealthDataStandards
2
+ module Import
3
+ module CDA
4
+ class MedicalEquipmentImporter < SectionImporter
5
+ def initialize(entry_finder=EntryFinder.new("//cda:section[cda:templateId/@root='2.16.840.1.113883.3.88.11.83.128']/cda:entry/cda:supply"))
6
+ super(entry_finder)
7
+ @code_xpath = "./cda:participant/cda:participantRole/cda:playingDevice/cda:code"
8
+ @entry_class = MedicalEquipment
9
+ end
10
+
11
+ def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
12
+ medical_equipment = super
13
+ extract_manufacturer(entry_element, medical_equipment)
14
+ medical_equipment
15
+ end
16
+
17
+ def extract_manufacturer(entry_element, entry)
18
+ manufacturer = entry_element.at_xpath("./cda:participant/cda:participantRole/cda:scopingEntity/cda:desc").try(:inner_text)
19
+ entry.manufacturer = manufacturer.strip if manufacturer
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,6 +1,6 @@
1
1
  module HealthDataStandards
2
2
  module Import
3
- module C32
3
+ module CDA
4
4
 
5
5
  # TODO: Coded Product Name, Free Text Product Name, Coded Brand Name and Free Text Brand name need to be pulled out separatelty
6
6
  # This would mean overriding extract_codes
@@ -11,23 +11,19 @@ module HealthDataStandards
11
11
  # dose indicator is not implemented.
12
12
  # TODO: Fill Status is not implemented. Couldn't figure out which entryRelationship it should be nested in
13
13
  class MedicationImporter < SectionImporter
14
-
15
- def initialize
16
- @entry_xpath = "//cda:section[cda:templateId/@root='2.16.840.1.113883.3.88.11.83.112']/cda:entry/cda:substanceAdministration"
14
+ def initialize(entry_finder=EntryFinder.new("//cda:section[cda:templateId/@root='2.16.840.1.113883.3.88.11.83.112']/cda:entry/cda:substanceAdministration"))
15
+ super(entry_finder)
17
16
  @code_xpath = "./cda:consumable/cda:manufacturedProduct/cda:manufacturedMaterial/cda:code"
18
17
  @description_xpath = "./cda:consumable/cda:manufacturedProduct/cda:manufacturedMaterial/cda:code/cda:originalText/cda:reference[@value]"
19
18
  @type_of_med_xpath = "./cda:entryRelationship[@typeCode='SUBJ']/cda:observation[cda:templateId/@root='2.16.840.1.113883.3.88.11.83.8.1']/cda:code"
20
19
  @indication_xpath = "./cda:entryRelationship[@typeCode='RSON']/cda:observation[cda:templateId/@root='2.16.840.1.113883.10.20.1.28']/cda:code"
21
20
  @vehicle_xpath = "cda:participant/cda:participantRole[cda:code/@code='412307009' and cda:code/@codeSystem='2.16.840.1.113883.6.96']/cda:playingEntity/cda:code"
22
21
  @fill_number_xpath = "./cda:entryRelationship[@typeCode='COMP']/cda:sequenceNumber/@value"
23
- @check_for_usable = true # Pilot tools will set this to false
22
+ @entry_class = Medication
24
23
  end
25
-
26
- def create_entry(entry_element, id_map={})
27
- medication = Medication.new
28
- extract_codes(entry_element, medication)
29
- extract_dates(entry_element, medication)
30
- extract_description(entry_element, medication, id_map)
24
+
25
+ def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
26
+ medication = super
31
27
 
32
28
  if medication.description.present?
33
29
  medication.free_text = medication.description
@@ -56,7 +52,7 @@ module HealthDataStandards
56
52
  end
57
53
 
58
54
  private
59
-
55
+
60
56
  def extract_fulfillment_history(parent_element, medication)
61
57
  fhs = parent_element.xpath("./cda:entryRelationship/cda:supply[@moodCode='EVN']")
62
58
  if fhs
@@ -82,7 +78,10 @@ module HealthDataStandards
82
78
  if order_elements
83
79
  order_elements.each do |order_element|
84
80
  order_information = OrderInformation.new
85
-
81
+ actor_element = order_element.at_xpath('./cda:author')
82
+ if actor_element
83
+ order_information.provider = ProviderImporter.instance.extract_provider(actor_element, "assignedAuthor")
84
+ end
86
85
  order_information.order_number = order_element.at_xpath('./cda:id').try(:[], 'root')
87
86
  order_information.fills = order_element.at_xpath('./cda:repeatNumber').try(:[], 'value').try(:to_i)
88
87
  order_information.quantity_ordered = extract_scalar(order_element, "./cda:quantity")
@@ -115,8 +114,7 @@ module HealthDataStandards
115
114
  medication.dose_restriction = dr
116
115
  end
117
116
  end
118
-
119
117
  end
120
118
  end
121
119
  end
122
- end
120
+ end
@@ -0,0 +1,35 @@
1
+ module HealthDataStandards
2
+ module Import
3
+ module CDA
4
+ class NarrativeReferenceHandler
5
+ def initialize
6
+ @id_map = {}
7
+ end
8
+
9
+ def build_id_map(doc)
10
+ path = "//*[@ID]"
11
+ ids = doc.xpath(path)
12
+ ids.each do |id|
13
+ tag = id['ID']
14
+ value = id.content
15
+ @id_map[tag] = value
16
+ end
17
+ end
18
+
19
+ # @param [String] tag
20
+ # @return [String] text description of tag
21
+ def lookup_tag(tag)
22
+ value = @id_map[tag]
23
+ # Not sure why, but sometimes the reference is #<Reference> and the ID value is <Reference>, and
24
+ # sometimes it is #<Reference>. We look for both.
25
+ if !value and tag[0] == '#'
26
+ tag = tag[1,tag.length]
27
+ value = @id_map[tag]
28
+ end
29
+
30
+ value
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,6 +1,6 @@
1
1
  module HealthDataStandards
2
2
  module Import
3
- module C32
3
+ module CDA
4
4
  class OrganizationImporter < SectionImporter
5
5
  include Singleton
6
6
 
@@ -0,0 +1,35 @@
1
+ module HealthDataStandards
2
+ module Import
3
+ module CDA
4
+ class ProcedureImporter < SectionImporter
5
+
6
+ #scoped to not look in the plan of care section so planned procedures do not end up mixed with
7
+ #past procedures
8
+ def initialize(entry_finder=EntryFinder.new("//cda:section[cda:templateId/@root!='2.16.840.1.113883.3.88.11.83.124']//cda:procedure"))
9
+ super(entry_finder)
10
+ @entry_class = Procedure
11
+ end
12
+
13
+ def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
14
+ procedure = super
15
+ extract_performer(entry_element, procedure)
16
+ extract_site(entry_element, procedure)
17
+ extract_negation(entry_element, procedure)
18
+ procedure
19
+ end
20
+
21
+ private
22
+
23
+ def extract_performer(parent_element, procedure)
24
+ performer_element = parent_element.at_xpath("./cda:performer")
25
+ procedure.performer = import_actor(performer_element) if performer_element
26
+ end
27
+
28
+ def extract_site(parent_element, procedure)
29
+ procedure.site = extract_code(parent_element, "./cda:targetSiteCode")
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -3,7 +3,7 @@ require "date"
3
3
 
4
4
  module HealthDataStandards
5
5
  module Import
6
- module C32
6
+ module CDA
7
7
  class ProviderImporter < SectionImporter
8
8
 
9
9
 
@@ -28,9 +28,10 @@ module HealthDataStandards
28
28
 
29
29
  private
30
30
 
31
- def extract_provider_data(performer, use_dates=true)
31
+ def extract_provider_data(performer, use_dates=true, entity_path="./cda:assignedEntity")
32
32
  provider = {}
33
- entity = performer.xpath("./cda:assignedEntity")
33
+ entity = performer.xpath(entity_path)
34
+
34
35
  name = entity.xpath("./cda:assignedPerson/cda:name")
35
36
  provider[:title] = extract_data(name, "./cda:prefix")
36
37
  provider[:given_name] = extract_data(name, "./cda:given[1]")
@@ -52,11 +53,6 @@ module HealthDataStandards
52
53
  provider[:npi] = npi if Provider.valid_npi?(npi)
53
54
  provider
54
55
  end
55
-
56
- def find_or_create_provider(provider_hash)
57
- provider = Provider.where(npi: provider_hash[:npi]).first if provider_hash[:npi]
58
- provider ||= Provider.create(provider_hash)
59
- end
60
56
 
61
57
  def extract_date(subject,query)
62
58
  date = extract_data(subject,query)
@@ -0,0 +1,31 @@
1
+ module HealthDataStandards
2
+ module Import
3
+ module CDA
4
+ class ResultImporter < SectionImporter
5
+ def initialize(entry_finder=EntryFinder.new("//cda:observation[cda:templateId/@root='2.16.840.1.113883.3.88.11.83.15.1'] | //cda:observation[cda:templateId/@root='2.16.840.1.113883.3.88.11.83.15']"))
6
+ super(entry_finder)
7
+ @entry_class = LabResult
8
+ end
9
+
10
+ def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
11
+ result = super
12
+ extract_value(entry_element, result)
13
+ extract_interpretation(entry_element, result)
14
+ extract_negation(entry_element, result)
15
+ result
16
+ end
17
+
18
+ private
19
+ def extract_interpretation(parent_element, result)
20
+ interpretation_element = parent_element.at_xpath("./cda:interpretationCode")
21
+ if interpretation_element
22
+ code = interpretation_element['code']
23
+ code_system = CodeSystemHelper.code_system_for(interpretation_element['codeSystem'])
24
+ result.interpretation = {'code' => code, 'codeSystem' => code_system}
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,56 +1,33 @@
1
1
  module HealthDataStandards
2
2
  module Import
3
- module C32
4
- # Class that can be used to create an importer for a section of a HITSP C32 document. It usually
5
- # operates by selecting all CDA entries in a section and then creates entries for them.
3
+ module CDA
6
4
  class SectionImporter
7
- include HealthDataStandards::Import::C32::LocatableImportUtils
5
+ attr_accessor :check_for_usable, :status_xpath, :code_xpath
6
+
8
7
  include HealthDataStandards::Util
9
-
10
- attr_accessor :check_for_usable
11
- # Creates a new SectionImporter
12
- # @param [Hash] id_map A hash of all ID tags to values for the enclosing document. Used to look up descriptions.
13
- # @param [String] entry_xpath An XPath expression that can be used to find the desired entries
14
- # @param [String] code_xpath XPath expression to find the code element as a child of the desired CDA entry.
15
- # Defaults to "./cda:code"
16
- # @param [String] status_xpath XPath expression to find the status element as a child of the desired CDA
17
- # entry. Defaults to nil. If not provided, a status will not be checked for since it is not applicable
18
- # to all enrty types
19
- def initialize(entry_xpath, code_xpath="./cda:code", status_xpath=nil,priority_xpath=nil, description_xpath="./cda:code/cda:originalText/cda:reference[@value] | ./cda:text/cda:reference[@value] ")
20
- @entry_xpath = entry_xpath
21
- @code_xpath = code_xpath
22
- @status_xpath = status_xpath
23
- @priority_xpath = priority_xpath
24
- @description_xpath = description_xpath
25
- @check_for_usable = true # Pilot tools will set this to false
8
+ include LocatableImportUtils
9
+
10
+ def initialize(entry_finder)
11
+ @entry_finder = entry_finder
12
+ @code_xpath = "./cda:code"
13
+ @status_xpath = nil
14
+ @priority_xpath = nil
15
+ @description_xpath = "./cda:code/cda:originalText/cda:reference[@value] | ./cda:text/cda:reference[@value]"
16
+ @check_for_usable = true
17
+ @entry_class = Entry
26
18
  end
27
19
 
28
- # @param [String] tag
29
- # @param [Hash] id_map A map of ids to all tagged text in the narrative portion of a document
30
- # @return [String] text description of tag
31
- def lookup_tag(tag, id_map)
32
- value = id_map[tag]
33
- # Not sure why, but sometimes the reference is #<Reference> and the ID value is <Reference>, and
34
- # sometimes it is #<Reference>. We look for both.
35
- if !value and tag[0] == '#'
36
- tag = tag[1,tag.length]
37
- value = id_map[tag]
38
- end
39
-
40
- value
41
- end
42
-
43
- # Traverses that HITSP C32 document passed in using XPath and creates an Array of Entry
20
+ # Traverses an HL7 CDA document passed in and creates an Array of Entry
44
21
  # objects based on what it finds
45
22
  # @param [Nokogiri::XML::Document] doc It is expected that the root node of this document
46
23
  # will have the "cda" namespace registered to "urn:hl7-org:v3"
47
24
  # measure definition
48
25
  # @return [Array] will be a list of Entry objects
49
- def create_entries(doc,id_map = {})
26
+ def create_entries(doc, nrh = NarrativeReferenceHandler.new)
50
27
  entry_list = []
51
- entry_elements = doc.xpath(@entry_xpath)
28
+ entry_elements = @entry_finder.entries(doc)
52
29
  entry_elements.each do |entry_element|
53
- entry = create_entry(entry_element, id_map)
30
+ entry = create_entry(entry_element, nrh)
54
31
  if @check_for_usable
55
32
  entry_list << entry if entry.usable?
56
33
  else
@@ -59,17 +36,18 @@ module HealthDataStandards
59
36
  end
60
37
  entry_list
61
38
  end
62
-
63
- def create_entry(entry_element, id_map={})
64
- entry = Entry.new
39
+
40
+ def create_entry(entry_element, nrh = NarrativeReferenceHandler.new)
41
+ entry = @entry_class.new
65
42
  extract_codes(entry_element, entry)
66
43
  extract_dates(entry_element, entry)
67
44
  extract_value(entry_element, entry)
45
+ entry.free_text = entry_element.at_xpath("./cda:text").try("text")
68
46
  if @status_xpath
69
47
  extract_status(entry_element, entry)
70
48
  end
71
49
  if @description_xpath
72
- extract_description(entry_element, entry, id_map)
50
+ extract_description(entry_element, entry, nrh)
73
51
  end
74
52
  entry
75
53
  end
@@ -83,11 +61,11 @@ module HealthDataStandards
83
61
  end
84
62
  end
85
63
 
86
- def extract_description(parent_element, entry, id_map)
64
+ def extract_description(parent_element, entry, nrh)
87
65
  code_elements = parent_element.xpath(@description_xpath)
88
66
  code_elements.each do |code_element|
89
67
  tag = code_element['value']
90
- entry.description = lookup_tag(tag, id_map)
68
+ entry.description = nrh.lookup_tag(tag)
91
69
  end
92
70
  end
93
71
 
@@ -198,8 +176,8 @@ module HealthDataStandards
198
176
  nil
199
177
  end
200
178
  end
179
+
201
180
  end
202
181
  end
203
182
  end
204
- end
205
-
183
+ end
@@ -1,10 +1,9 @@
1
1
  module HealthDataStandards
2
2
  module Import
3
- module C32
3
+ module CDA
4
4
  class VitalSignImporter < ResultImporter
5
5
  def initialize
6
- super
7
- @entry_xpath = "//cda:observation[cda:templateId/@root='2.16.840.1.113883.3.88.11.83.14']"
6
+ super(EntryFinder.new("//cda:observation[cda:templateId/@root='2.16.840.1.113883.3.88.11.83.14']"))
8
7
  end
9
8
  end
10
9
  end
@@ -89,7 +89,7 @@ module HealthDataStandards
89
89
 
90
90
  return {} unless node_value
91
91
 
92
- {"scalar" => node_value, "unit" => node_units}
92
+ {"scalar" => node_value, "units" => node_units}
93
93
  end
94
94
 
95
95
  def extract_value(element, entry)
@@ -111,14 +111,15 @@ module HealthDataStandards
111
111
 
112
112
  def extract_organization(organization_element)
113
113
  org_id = extract_node_text(organization_element.xpath("./gc32:id"))
114
- organization = org_id ? Organization.find_or_create_by(id: org_id) : Organization.new
115
- if organization.new_record?
116
- else
114
+ organization = org_id ? Organization.find(org_id) : Organization.new
115
+ organization ||= Organization.new
116
+ # if organization.new_record?
117
+ # else
117
118
  organization.name = extract_node_text(organization_element.xpath("./gc32:name"))
118
119
  organization.addresses = organization_element.xpath("./gc32:address").map { |addr| extract_address(addr) }
119
120
  organization.telecoms = organization_element.xpath("./gc32:telecom").map { |tele| extract_telecom(tele) }
120
- organization.save!
121
- end
121
+ # organization.save!
122
+ # end
122
123
 
123
124
  return organization
124
125
  end
@@ -142,6 +143,7 @@ module HealthDataStandards
142
143
  def extract_address(address_element)
143
144
  return unless address_element
144
145
  address = Address.new
146
+ address.use = address_element['use']
145
147
  address.street = address_element.xpath("./gc32:street").map { |st| extract_node_text(st) }
146
148
  address.city = extract_node_text(address_element.xpath("./gc32:city"))
147
149
  address.state = extract_node_text(address_element.xpath("./gc32:state"))
@@ -1,7 +1,7 @@
1
1
  module ProviderImportUtils
2
2
 
3
- def extract_provider(performer)
4
- provider_data = extract_provider_data(performer, false)
3
+ def extract_provider(performer, element_name="assignedEntity")
4
+ provider_data = extract_provider_data(performer, false, "./cda:#{element_name}")
5
5
  find_or_create_provider(provider_data)
6
6
  end
7
7
 
@@ -1,7 +1,7 @@
1
1
  class Address
2
2
  include Mongoid::Document
3
3
 
4
- field :street, type: Array
4
+ field :street, type: Array, default: []
5
5
  field :city, type: String
6
6
  field :state, type: String
7
7
  field :zip, type: String
@@ -1,10 +1,11 @@
1
1
  class Condition < Entry
2
- field :type, type: String
3
- field :causeOfDeath, type: Boolean
4
- field :priority, type: Integer
5
- field :name, type: String
6
- field :ordinality, type: Hash
7
- field :severity, type: Hash # Currently unsupported by any importers
2
+ field :type, type: String
3
+ field :causeOfDeath, type: Boolean
4
+ field :time_of_death, type: Integer
5
+ field :priority, type: Integer
6
+ field :name, type: String
7
+ field :ordinality, type: Hash
8
+ field :severity, type: Hash # Currently unsupported by any importers
8
9
 
9
10
  embeds_many :treating_provider, class_name: "Provider"
10
11