cqm-converter 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 3b311d95023502b8fffba804fa922bc8b822fed027715efeb8428f9fa3c3ad5e
4
- data.tar.gz: 1037ec6ad816da379559dc6e0040892020ba0363fa18c76f2f1dfca28bdb9a97
2
+ SHA1:
3
+ metadata.gz: b9bf0ffa8c1e7ccaee1c1e195bd7496c68478816
4
+ data.tar.gz: b3a1e58694bd32ad2ec739f209a977ea5debd746
5
5
  SHA512:
6
- metadata.gz: ed7862338bac4803ded5a20b807dc26224b6415270ad8111051c364d00060d63b96523219b7888bb6797d79c5c5582812541e0d8544ed64b5b02885da9d04d96
7
- data.tar.gz: 74f6d733a343b15ab6b5fcb05a603fec4fe9fd70c06f52dc3410eafc00b1b4076b15f5ae171160857f26a9f02649a2926e26c4cb3f4083df2254bba5f7886e6c
6
+ metadata.gz: c9bca3f3ff73d4af8ca2500427a74bcee811e8c913583832920ecf894d07c4c9e2e83b5e321f719dd8f45d65a6671e30f5447f7d51469960918ccdabb0dae0fb
7
+ data.tar.gz: cd0c029021db2240019391ab35d4681e04fd3255ec7b21c4fcba10966eec871db1b30d5af88afe86b436a2855d7dbb7b4e91a98556f41ef877b68d7cf776fedc
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'cqm-converter'
6
- spec.version = '0.3.2'
6
+ spec.version = '0.3.3'
7
7
  spec.authors = ['aholmes@mitre.org']
8
8
  spec.email = ['aholmes@mitre.org']
9
9
 
@@ -43,7 +43,7 @@ module CQM::Converter
43
43
  cql_qdm_patient.keys.each do |dc_type|
44
44
  cql_qdm_patient[dc_type].each do |dc|
45
45
  # Convert snake_case to camelCase
46
- dc_fixed_keys = dc.deep_transform_keys { |key| key.to_s.camelize(:lower) }
46
+ dc_fixed_keys = dc.deep_transform_keys { |key| key.to_s.gsub(/^_/, '').camelize(:lower) }
47
47
 
48
48
  # Our Code model uses 'codeSystem' to describe the code system (since system is
49
49
  # a reserved keyword). The cql.Code calls this 'system', so make sure the proper
@@ -51,7 +51,7 @@ module CQM::Converter
51
51
  dc_fixed_keys = dc_fixed_keys.deep_transform_keys { |key| key.to_s == 'system' ? :codeSystem : key }
52
52
  dc_fixed_keys = dc_fixed_keys.deep_transform_keys { |key| key.to_s == 'display' ? :descriptor : key }
53
53
 
54
- patient.dataElements << QDM.const_get(dc_type).new.from_json(dc_fixed_keys.to_json)
54
+ patient.dataElements << generate_qdm_data_element(dc_fixed_keys, dc_type)
55
55
  end
56
56
  end
57
57
 
@@ -125,5 +125,20 @@ module CQM::Converter
125
125
 
126
126
  patient
127
127
  end
128
+
129
+ def generate_qdm_data_element(dc_fixed_keys, dc_type)
130
+ data_element = QDM.const_get(dc_type).new.from_json(dc_fixed_keys.to_json)
131
+
132
+ # Any nested QDM types that need initialization should be handled here
133
+ # when converting from the QDM models to the HDS models.
134
+ # For now, that should just be FacilityLocation objects
135
+ if data_element.is_a?(QDM::EncounterPerformed)
136
+ data_element.facilityLocations = data_element.facilityLocations.map do |facility|
137
+ QDM::FacilityLocation.new.from_json(facility.to_json)
138
+ end
139
+ end
140
+
141
+ data_element
142
+ end
128
143
  end
129
144
  end
@@ -62,7 +62,7 @@ module CQM::Converter
62
62
  # Handle something that has multiple parts.
63
63
  hds_attrs[hds_attr[:low]] = extracted_value.first
64
64
  hds_attrs[hds_attr[:high]] = extracted_value.last if hds_attr[:high]
65
- elsif extracted_value.is_a?(Array) && extracted_value.any? && extracted_value.first.is_a?(Hash) && extracted_value.first[:code]
65
+ elsif extracted_value.is_a?(Array) && extracted_value.any? && extracted_value.first.is_a?(Hash) && extracted_value.first[:code] && hds_attr != 'facility' && hds_attr != 'components'
66
66
  # Handle a result that is returning multiple codes.
67
67
  hds_attrs[hds_attr] = [CodedResultValue.new(codes: Utils.qdm_codes_to_hds_codes(extracted_value), description: extracted_value.first[:title])]
68
68
  elsif extracted_value.is_a?(Array)
@@ -139,15 +139,19 @@ module CQM::Converter
139
139
  date_time_converter(qdm_thing)
140
140
  elsif qdm_thing.is_a?(Hash) && keys.include?(:low) # Is a QDM::Interval.
141
141
  interval_extractor(qdm_thing.symbolize_keys)
142
+ elsif qdm_thing.is_a?(Hash) && keys.include?(:locationPeriod)
143
+ location_extractor(qdm_thing.symbolize_keys)
144
+ elsif qdm_thing.is_a?(Hash) && keys.include?(:result) # is a QDM::CodedResultValue
145
+ component_extractor(qdm_thing.symbolize_keys)
142
146
  elsif qdm_thing.is_a?(Hash) && keys.include?(:code) # Is a QDM::Code.
143
147
  code_extractor(qdm_thing.symbolize_keys)
144
148
  elsif qdm_thing.is_a?(Hash) && keys.include?(:unit) # Is a QDM::Quantity.
145
149
  quantity_extractor(qdm_thing.symbolize_keys)
146
150
  elsif qdm_thing.is_a?(Array) # Is an Array.
147
151
  qdm_thing.collect { |item| extractor(item) }
148
- elsif qdm_thing.is_a?(Numeric) # Is an Number.
152
+ elsif qdm_thing.is_a?(Numeric) # Is a Number.
149
153
  { units: '', scalar: qdm_thing.to_s }
150
- elsif qdm_thing.is_a?(String) # Is an String.
154
+ elsif qdm_thing.is_a?(String) # Is a String.
151
155
  qdm_thing
152
156
  elsif qdm_thing.is_a?(Hash)
153
157
  qdm_thing.each { |k, v| qdm_thing[k] = extractor(v) }
@@ -156,6 +160,15 @@ module CQM::Converter
156
160
  end
157
161
  end
158
162
 
163
+ def location_extractor(facility)
164
+ interval = interval_extractor(facility[:locationPeriod].as_json.symbolize_keys)
165
+ { 'code' => code_extractor(facility[:code].as_json.symbolize_keys), 'locationPeriod' => interval }
166
+ end
167
+
168
+ def component_extractor(component)
169
+ { code: code_extractor(component[:code].symbolize_keys), result: code_extractor(component[:result].symbolize_keys) }
170
+ end
171
+
159
172
  # Extract a QDM::Code to something usable in HDS.
160
173
  def code_extractor(code)
161
174
  { code: code[:code], code_system: code[:codeSystem], title: code[:descriptor] }
@@ -216,10 +229,14 @@ module CQM::Converter
216
229
  return unless hds_attrs.key?('components') && !hds_attrs['components'].nil?
217
230
  hds_attrs['components']['type'] = 'COL'
218
231
  hds_attrs['components'][:values]&.collect do |code_value|
219
- code_value['code'] = code_value.delete('Code')
220
- code_value['result'] = { code: code_value.delete('Result'), title: code_value['code'][:title] }
221
- code_value['code'].delete(:title)
222
- code_value['result'][:code].delete(:title)
232
+ code_value[:code] = code_value.delete('Code') if code_value.key?('Code')
233
+ code_value[:result] = if code_value.key?('Result')
234
+ { code: code_value.delete('Result'), title: code_value['code'][:title] }
235
+ else
236
+ { code: code_value.delete(:result), title: code_value[:code][:title] }
237
+ end
238
+ code_value[:code].delete(:title)
239
+ code_value[:result][:code].delete(:title)
223
240
  { code: code_value }
224
241
  end
225
242
  end
@@ -250,11 +267,11 @@ module CQM::Converter
250
267
  return unless hds_attrs.key?('facility') && !hds_attrs['facility'].empty?
251
268
  hds_attrs['facility']['type'] = 'COL'
252
269
  hds_attrs['facility'][:values]&.each do |value|
253
- value['code'] = value.delete('Code')
270
+ value['code'] = value.delete('Code') if value['Code']
254
271
  value[:display] = value['code'].delete(:title) if value['code']
255
- value[:locationPeriodHigh] = Time.at(value['Locationperiod'].last).utc.strftime('%m/%d/%Y %l:%M %p').split.join(' ')
256
- value[:locationPeriodLow] = Time.at(value['Locationperiod'].first).utc.strftime('%m/%d/%Y %l:%M %p').split.join(' ')
257
- value.delete('Locationperiod')
272
+ value[:locationPeriodHigh] = Time.at(value['locationPeriod'].last).utc.strftime('%m/%d/%Y %l:%M %p').split.join(' ')
273
+ value[:locationPeriodLow] = Time.at(value['locationPeriod'].first).utc.strftime('%m/%d/%Y %l:%M %p').split.join(' ')
274
+ value.delete('locationPeriod')
258
275
  end
259
276
  end
260
277
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cqm-converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - aholmes@mitre.org
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-09 00:00:00.000000000 Z
11
+ date: 2018-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  version: '0'
224
224
  requirements: []
225
225
  rubyforge_project:
226
- rubygems_version: 2.7.6
226
+ rubygems_version: 2.6.11
227
227
  signing_key:
228
228
  specification_version: 4
229
229
  summary: HDS <=> QDM Model Converter