quality-measure-engine 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,138 +0,0 @@
1
- module QME
2
- module Importer
3
- # Class that can be used to create an importer for a section of a HITSP C32 document. It usually
4
- # operates by selecting all CDA entries in a section and then creates entries for them.
5
- class SectionImporter
6
- attr_accessor :check_for_usable
7
- # Creates a new SectionImporter
8
- # @param [Hash] id_map A hash of all ID tags to values for the enclosing document. Used to look up descriptions.
9
- # @param [String] entry_xpath An XPath expression that can be used to find the desired entries
10
- # @param [String] code_xpath XPath expression to find the code element as a child of the desired CDA entry.
11
- # Defaults to "./cda:code"
12
- # @param [String] status_xpath XPath expression to find the status element as a child of the desired CDA
13
- # entry. Defaults to nil. If not provided, a status will not be checked for since it is not applicable
14
- # to all enrty types
15
- def initialize(entry_xpath, code_xpath="./cda:code", status_xpath=nil, description_xpath="./cda:code/cda:originalText/cda:reference[@value] | ./cda:text/cda:reference[@value] ")
16
- @entry_xpath = entry_xpath
17
- @code_xpath = code_xpath
18
- @status_xpath = status_xpath
19
- @description_xpath = description_xpath
20
- @check_for_usable = true # Pilot tools will set this to false
21
- @id_map = {}
22
- end
23
-
24
-
25
- # @param [String] tag
26
- # @return [String] text description of tag
27
- def lookup_tag(tag)
28
- value = @id_map[tag]
29
- # Not sure why, but sometimes the reference is #<Reference> and the ID value is <Reference>, and
30
- # sometimes it is #<Reference>. We look for both.
31
- if !value and tag[0] == '#'
32
- tag = tag[1,tag.length]
33
- value = @id_map[tag]
34
- end
35
-
36
- value
37
- end
38
-
39
- # Traverses that HITSP C32 document passed in using XPath and creates an Array of Entry
40
- # objects based on what it finds
41
- # @param [Nokogiri::XML::Document] doc It is expected that the root node of this document
42
- # will have the "cda" namespace registered to "urn:hl7-org:v3"
43
- # measure definition
44
- # @return [Array] will be a list of Entry objects
45
- def create_entries(doc,id_map = {})
46
- @id_map = id_map
47
- entry_list = []
48
- entry_elements = doc.xpath(@entry_xpath)
49
- entry_elements.each do |entry_element|
50
- entry = Entry.new
51
- extract_codes(entry_element, entry)
52
- extract_dates(entry_element, entry)
53
- extract_value(entry_element, entry)
54
- if @status_xpath
55
- extract_status(entry_element, entry)
56
- end
57
- if @description_xpath
58
- extract_description(entry_element, entry, id_map)
59
- end
60
- if @check_for_usable
61
- entry_list << entry if entry.usable?
62
- else
63
- entry_list << entry
64
- end
65
- end
66
- entry_list
67
- end
68
-
69
- private
70
-
71
- def extract_status(parent_element, entry)
72
- status_element = parent_element.at_xpath(@status_xpath)
73
- if status_element
74
- case status_element['code']
75
- when '55561003'
76
- entry.status = :active
77
- when '73425007'
78
- entry.status = :inactive
79
- when '413322009'
80
- entry.status = :resolved
81
- end
82
- end
83
- end
84
-
85
- def extract_description(parent_element, entry, id_map)
86
- code_elements = parent_element.xpath(@description_xpath)
87
- code_elements.each do |code_element|
88
- tag = code_element['value']
89
- entry.description = lookup_tag(tag)
90
- end
91
- end
92
-
93
- def extract_codes(parent_element, entry)
94
- code_elements = parent_element.xpath(@code_xpath)
95
- code_elements.each do |code_element|
96
- add_code_if_present(code_element, entry)
97
- translations = code_element.xpath('cda:translation')
98
- translations.each do |translation|
99
- add_code_if_present(translation, entry)
100
- end
101
- end
102
- end
103
-
104
- def add_code_if_present(code_element, entry)
105
- if code_element['codeSystem'] && code_element['code']
106
- entry.add_code(code_element['code'], CodeSystemHelper.code_system_for(code_element['codeSystem']))
107
- end
108
- end
109
-
110
- def extract_dates(parent_element, entry)
111
- if parent_element.at_xpath('cda:effectiveTime')
112
- entry.time = HL7Helper.timestamp_to_integer(parent_element.at_xpath('cda:effectiveTime')['value'])
113
- end
114
- if parent_element.at_xpath('cda:effectiveTime/cda:low')
115
- entry.start_time = HL7Helper.timestamp_to_integer(parent_element.at_xpath('cda:effectiveTime/cda:low')['value'])
116
- end
117
- if parent_element.at_xpath('cda:effectiveTime/cda:high')
118
- entry.end_time = HL7Helper.timestamp_to_integer(parent_element.at_xpath('cda:effectiveTime/cda:high')['value'])
119
- end
120
- if parent_element.at_xpath('cda:effectiveTime/cda:center')
121
- entry.time = HL7Helper.timestamp_to_integer(parent_element.at_xpath('cda:effectiveTime/cda:center')['value'])
122
- end
123
- end
124
-
125
- def extract_value(parent_element, entry)
126
- value_element = parent_element.at_xpath('cda:value')
127
- if value_element
128
- value = value_element['value']
129
- unit = value_element['unit']
130
- if value
131
- entry.set_value(value, unit)
132
- end
133
- end
134
- end
135
- end
136
- end
137
- end
138
-