cqm-parsers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +29 -0
  3. data/README.md +21 -0
  4. data/Rakefile +19 -0
  5. data/lib/ext/code.rb +10 -0
  6. data/lib/ext/data_element.rb +24 -0
  7. data/lib/hqmf-model/attribute.rb +63 -0
  8. data/lib/hqmf-model/data_criteria.rb +467 -0
  9. data/lib/hqmf-model/document.rb +253 -0
  10. data/lib/hqmf-model/population_criteria.rb +102 -0
  11. data/lib/hqmf-model/precondition.rb +94 -0
  12. data/lib/hqmf-model/types.rb +457 -0
  13. data/lib/hqmf-model/utilities.rb +52 -0
  14. data/lib/hqmf-parser.rb +116 -0
  15. data/lib/hqmf-parser/1.0/attribute.rb +121 -0
  16. data/lib/hqmf-parser/1.0/comparison.rb +34 -0
  17. data/lib/hqmf-parser/1.0/data_criteria.rb +92 -0
  18. data/lib/hqmf-parser/1.0/document.rb +195 -0
  19. data/lib/hqmf-parser/1.0/expression.rb +60 -0
  20. data/lib/hqmf-parser/1.0/observation.rb +61 -0
  21. data/lib/hqmf-parser/1.0/population_criteria.rb +75 -0
  22. data/lib/hqmf-parser/1.0/precondition.rb +90 -0
  23. data/lib/hqmf-parser/1.0/range.rb +76 -0
  24. data/lib/hqmf-parser/1.0/restriction.rb +162 -0
  25. data/lib/hqmf-parser/1.0/utilities.rb +55 -0
  26. data/lib/hqmf-parser/2.0/data_criteria.rb +372 -0
  27. data/lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb +80 -0
  28. data/lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb +201 -0
  29. data/lib/hqmf-parser/2.0/data_criteria_helpers/dc_post_processing.rb +85 -0
  30. data/lib/hqmf-parser/2.0/data_criteria_helpers/dc_specific_occurrences_and_source_data_criteria_extract.rb +117 -0
  31. data/lib/hqmf-parser/2.0/document.rb +304 -0
  32. data/lib/hqmf-parser/2.0/document_helpers/doc_population_helper.rb +173 -0
  33. data/lib/hqmf-parser/2.0/document_helpers/doc_utilities.rb +131 -0
  34. data/lib/hqmf-parser/2.0/field_value_helper.rb +251 -0
  35. data/lib/hqmf-parser/2.0/population_criteria.rb +134 -0
  36. data/lib/hqmf-parser/2.0/precondition.rb +73 -0
  37. data/lib/hqmf-parser/2.0/source_data_criteria_helper.rb +112 -0
  38. data/lib/hqmf-parser/2.0/types.rb +448 -0
  39. data/lib/hqmf-parser/2.0/utilities.rb +45 -0
  40. data/lib/hqmf-parser/2.0/value_set_helper.rb +104 -0
  41. data/lib/hqmf-parser/converter/pass1/data_criteria_converter.rb +257 -0
  42. data/lib/hqmf-parser/converter/pass1/document_converter.rb +133 -0
  43. data/lib/hqmf-parser/converter/pass1/population_criteria_converter.rb +185 -0
  44. data/lib/hqmf-parser/converter/pass1/precondition_converter.rb +173 -0
  45. data/lib/hqmf-parser/converter/pass1/precondition_extractor.rb +201 -0
  46. data/lib/hqmf-parser/converter/pass1/simple_data_criteria.rb +26 -0
  47. data/lib/hqmf-parser/converter/pass1/simple_operator.rb +89 -0
  48. data/lib/hqmf-parser/converter/pass1/simple_population_criteria.rb +10 -0
  49. data/lib/hqmf-parser/converter/pass1/simple_precondition.rb +51 -0
  50. data/lib/hqmf-parser/converter/pass1/simple_restriction.rb +64 -0
  51. data/lib/hqmf-parser/converter/pass2/comparison_converter.rb +112 -0
  52. data/lib/hqmf-parser/converter/pass2/operator_converter.rb +102 -0
  53. data/lib/hqmf-parser/cql/data_criteria.rb +57 -0
  54. data/lib/hqmf-parser/cql/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb +79 -0
  55. data/lib/hqmf-parser/cql/data_criteria_helpers/dc_post_processing.rb +43 -0
  56. data/lib/hqmf-parser/cql/document.rb +78 -0
  57. data/lib/hqmf-parser/cql/document_helpers/doc_population_helper.rb +124 -0
  58. data/lib/hqmf-parser/cql/value_set_helper.rb +103 -0
  59. data/lib/hqmf-parser/parser.rb +100 -0
  60. data/lib/qrda-export/catI-r5/qrda1_r5.rb +125 -0
  61. data/lib/qrda-export/helper/cat_1_view_helper.rb +142 -0
  62. data/lib/qrda-export/helper/code_system_helper.rb +77 -0
  63. data/lib/qrda-export/helper/date_helper.rb +81 -0
  64. data/lib/qrda-import/base-importers/demographics_importer.rb +47 -0
  65. data/lib/qrda-import/base-importers/medication_importer.rb +22 -0
  66. data/lib/qrda-import/base-importers/section_importer.rb +196 -0
  67. data/lib/qrda-import/cda_identifier.rb +19 -0
  68. data/lib/qrda-import/data-element-importers/adverse_event_importer.rb +23 -0
  69. data/lib/qrda-import/data-element-importers/allergy_intolerance_importer.rb +21 -0
  70. data/lib/qrda-import/data-element-importers/assessment_performed_importer.rb +23 -0
  71. data/lib/qrda-import/data-element-importers/communication_from_patient_to_provider_importer.rb +18 -0
  72. data/lib/qrda-import/data-element-importers/communication_from_provider_to_patient_importer.rb +18 -0
  73. data/lib/qrda-import/data-element-importers/communication_from_provider_to_provider_importer.rb +20 -0
  74. data/lib/qrda-import/data-element-importers/device_applied_importer.rb +23 -0
  75. data/lib/qrda-import/data-element-importers/device_order_importer.rb +18 -0
  76. data/lib/qrda-import/data-element-importers/diagnosis_importer.rb +23 -0
  77. data/lib/qrda-import/data-element-importers/diagnostic_study_order_importer.rb +20 -0
  78. data/lib/qrda-import/data-element-importers/diagnostic_study_performed_importer.rb +30 -0
  79. data/lib/qrda-import/data-element-importers/encounter_order_importer.rb +20 -0
  80. data/lib/qrda-import/data-element-importers/encounter_performed_importer.rb +41 -0
  81. data/lib/qrda-import/data-element-importers/immunization_administered_importer.rb +18 -0
  82. data/lib/qrda-import/data-element-importers/intervention_order_importer.rb +18 -0
  83. data/lib/qrda-import/data-element-importers/intervention_performed_importer.rb +22 -0
  84. data/lib/qrda-import/data-element-importers/laboratory_test_order_importer.rb +20 -0
  85. data/lib/qrda-import/data-element-importers/laboratory_test_performed_importer.rb +28 -0
  86. data/lib/qrda-import/data-element-importers/medication_active_importer.rb +17 -0
  87. data/lib/qrda-import/data-element-importers/medication_administered_importer.rb +17 -0
  88. data/lib/qrda-import/data-element-importers/medication_discharge_importer.rb +19 -0
  89. data/lib/qrda-import/data-element-importers/medication_dispensed_importer.rb +19 -0
  90. data/lib/qrda-import/data-element-importers/medication_order_importer.rb +16 -0
  91. data/lib/qrda-import/data-element-importers/patient_characteristic_expired.rb +21 -0
  92. data/lib/qrda-import/data-element-importers/physical_exam_performed_importer.rb +26 -0
  93. data/lib/qrda-import/data-element-importers/procedure_order_importer.rb +26 -0
  94. data/lib/qrda-import/data-element-importers/procedure_performed_importer.rb +34 -0
  95. data/lib/qrda-import/data-element-importers/substance_administered_importer.rb +16 -0
  96. data/lib/qrda-import/entry_finder.rb +20 -0
  97. data/lib/qrda-import/entry_package.rb +16 -0
  98. data/lib/qrda-import/narrative_reference_handler.rb +33 -0
  99. data/lib/qrda-import/patient_importer.rb +105 -0
  100. data/lib/util/code_system_helper.rb +76 -0
  101. data/lib/util/counter.rb +20 -0
  102. data/lib/util/hqmf_template_helper.rb +39 -0
  103. metadata +340 -0
@@ -0,0 +1,457 @@
1
+ module HQMF
2
+
3
+ # Used to represent 'any value' in criteria that require a value be present but
4
+ # don't specify any restrictions on that value
5
+ class AnyValue
6
+ include HQMF::Conversion::Utilities
7
+ attr_reader :type
8
+
9
+ def initialize(type='ANYNonNull')
10
+ @type = type
11
+ end
12
+
13
+ def derived?
14
+ false
15
+ end
16
+
17
+ def self.from_json(json)
18
+ type = json["type"] || 'ANYNonNull'
19
+ HQMF::AnyValue.new(type)
20
+ end
21
+
22
+ def to_json
23
+ hash = build_hash(self, [:type])
24
+ hash
25
+ end
26
+ end
27
+
28
+ # Represents a bound within a HQMF pauseQuantity, has a value, a unit and an
29
+ # inclusive/exclusive indicator
30
+ class Value
31
+ include HQMF::Conversion::Utilities
32
+ attr_reader :unit,:expression
33
+ attr_accessor :type, :value, :inclusive
34
+
35
+ # Create a new HQMF::Value
36
+ # @param [String] type
37
+ # @param [String] unit
38
+ # @param [String] value
39
+ # @param [Boolean] inclusive
40
+ # @param [Boolean] derived
41
+ # @param [String] expression
42
+ def initialize(type,unit,value,inclusive,derived,expression)
43
+ @type = type || 'PQ'
44
+ @unit = unit
45
+ @value = value
46
+ @inclusive = inclusive == nil ? true : inclusive
47
+ @derived = derived || false
48
+ @expression = expression
49
+ end
50
+
51
+ def self.from_json(json)
52
+ type = json["type"] if json["type"]
53
+ unit = json["unit"] if json["unit"]
54
+ value = json["value"] if json["value"]
55
+ inclusive = json["inclusive?"] unless json["inclusive?"].nil?
56
+ derived = json["derived?"] unless json["derived?"].nil?
57
+ expression = json["expression"] if json["expression"]
58
+
59
+ HQMF::Value.new(type,unit,value,inclusive,derived,expression)
60
+ end
61
+
62
+
63
+ def inclusive?
64
+ @inclusive
65
+ end
66
+
67
+ def derived?
68
+ @derived
69
+ end
70
+
71
+ def to_json
72
+ build_hash(self, [:type,:unit,:value,:inclusive?,:derived?,:expression])
73
+ end
74
+
75
+ def stringify
76
+ "#{inclusive? ? '=' : ''}#{value}#{unit ? ' '+unit : ''}"
77
+ end
78
+
79
+ def ==(other)
80
+ check_equality(self,other)
81
+ end
82
+
83
+ end
84
+
85
+ # Represents a HQMF physical quantity which can have low and high bounds
86
+ class Range
87
+ include HQMF::Conversion::Utilities
88
+ attr_accessor :type, :low, :high, :width
89
+
90
+ # Create a new HQMF::Value
91
+ # @param [String] type
92
+ # @param [Value] low
93
+ # @param [Value] high
94
+ # @param [Value] width
95
+ def initialize(type,low,high,width)
96
+ @type = type || 'IVL_PQ'
97
+ @low = low
98
+ @high = high
99
+ @width = width
100
+ end
101
+
102
+ def self.from_json(json)
103
+ type = json["type"] if json["type"]
104
+ low = HQMF::Value.from_json(json["low"]) if json["low"]
105
+ high = HQMF::Value.from_json(json["high"]) if json["high"]
106
+ width = HQMF::Value.from_json(json["width"]) if json["width"]
107
+
108
+ HQMF::Range.new(type,low,high,width)
109
+ end
110
+
111
+ def to_json
112
+ json = build_hash(self, [:type])
113
+ json[:low] = self.low.to_json if self.low
114
+ json[:high] = self.high.to_json if self.high
115
+ json[:width] = self.width.to_json if self.width
116
+ json
117
+ end
118
+
119
+ def stringify
120
+ if (@high && @low)
121
+ if (@high.value == @low.value and @high.inclusive? and low.inclusive?)
122
+ "#{@low.stringify}"
123
+ else
124
+ ">#{@low.stringify} and <#{@high.stringify}}"
125
+ end
126
+ elsif (@high)
127
+ "<#{@high.stringify}"
128
+ elsif (@low)
129
+ ">#{@low.stringify}"
130
+ else
131
+ raise "cannot convert range to string"
132
+ end
133
+ end
134
+
135
+ def ==(other)
136
+ check_equality(self,other)
137
+ end
138
+
139
+
140
+ end
141
+
142
+ # Represents a HQMF effective time which is a specialization of a interval
143
+ class EffectiveTime < Range
144
+ def initialize(low,high,width)
145
+ super('IVL_TS', low, high, width)
146
+ end
147
+
148
+ def type
149
+ 'IVL_TS'
150
+ end
151
+
152
+ end
153
+
154
+ # Represents a HQMF CD value which has a code and codeSystem
155
+ class Coded
156
+ include HQMF::Conversion::Utilities
157
+ attr_reader :type, :system, :code, :code_list_id, :title, :null_flavor, :original_text
158
+ # Create a new HQMF::Coded
159
+ # @param [String] type
160
+ # @param [String] system
161
+ # @param [String] code
162
+ # @param [String] code_list_id
163
+ def initialize(type,system,code,code_list_id=nil,title=nil,null_flavor=nil,original_text=nil)
164
+ @type = type
165
+ @system = system
166
+ @code = code
167
+ @code_list_id = code_list_id
168
+ @title = title
169
+ @null_flavor = null_flavor
170
+ @original_text = original_text
171
+ end
172
+
173
+ def self.for_code_list(code_list_id,title=nil)
174
+ HQMF::Coded.new('CD',nil,nil,code_list_id,title)
175
+ end
176
+
177
+ def self.for_single_code(system,code,title=nil)
178
+ HQMF::Coded.new('CD',system,code,nil,title)
179
+ end
180
+
181
+ def self.for_null_flavor(null_flavor,original_text=nil)
182
+ HQMF::Coded.new('CD',nil,nil,nil,nil,null_flavor,original_text)
183
+ end
184
+
185
+ def self.from_json(json)
186
+ json = json.with_indifferent_access
187
+ type = json["type"] if json["type"]
188
+ system = json["system"] if json["system"]
189
+ code = json["code"] if json["code"]
190
+ code_list_id = json["code_list_id"] if json["code_list_id"]
191
+ title = json["title"] if json["title"]
192
+ null_flavor = json["null_flavor"] if json["null_flavor"]
193
+ original_text = json["original_text"] if json["original_text"]
194
+
195
+ HQMF::Coded.new(type,system,code,code_list_id,title, null_flavor, original_text)
196
+ end
197
+
198
+ def to_json
199
+ build_hash(self, [:type,:system,:code,:code_list_id,:title,:null_flavor,:original_text])
200
+ end
201
+
202
+ def value
203
+ code
204
+ end
205
+
206
+ def derived?
207
+ false
208
+ end
209
+
210
+ def unit
211
+ nil
212
+ end
213
+
214
+ def ==(other)
215
+ check_equality(self,other)
216
+ end
217
+
218
+ end
219
+
220
+ class TemporalReference
221
+ include HQMF::Conversion::Utilities
222
+
223
+ TYPES = ['DURING','OVERLAP','SBS','SAS','SBE','SAE','EBS','EAS','EBE','EAE','SDU','EDU','ECW','SCW','ECWS','SCWE','SBCW','SBCWE','SACW','SACWE','SBDU','EBCW','EBCWS','EACW','EACWS','EADU','CONCURRENT']
224
+ INVERSION = {'SBS' => 'SAS','EAE' => 'EBE','SAS' => 'SBS','EBE' => 'EAE','SBE' => 'EAS','EAS' => 'SBE','SAE' => 'EBS','EBS' => 'SAE'}
225
+
226
+ attr_reader :type, :reference, :range
227
+
228
+ # @param [String] type
229
+ # @param [Reference] reference
230
+ # @param [Range] range
231
+ def initialize(type, reference, range)
232
+ @type = type
233
+ @reference = reference
234
+ if (range.is_a? HQMF::Value)
235
+ @range = HQMF::Range.new('IVL_PQ', range, range, nil)
236
+ else
237
+ @range = range
238
+ end
239
+ end
240
+
241
+ def self.from_json(json)
242
+ type = json["type"] if json["type"]
243
+ reference = HQMF::Reference.new(json["reference"]) if json["reference"]
244
+ range = HQMF::Range.from_json(json["range"]) if json["range"]
245
+
246
+ HQMF::TemporalReference.new(type,reference,range)
247
+ end
248
+
249
+
250
+ def to_json
251
+ json = build_hash(self, [:type])
252
+ json[:reference] = @reference.to_json if @reference
253
+ json[:range] = @range.to_json if @range
254
+ json
255
+ end
256
+
257
+ def ==(other)
258
+ check_equality(self,other)
259
+ end
260
+
261
+ end
262
+
263
+ class SubsetOperator
264
+ include HQMF::Conversion::Utilities
265
+
266
+ TYPES = ['COUNT', 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'FIFTH', 'RECENT', 'LAST', 'MIN', 'MAX', 'DATEDIFF', 'TIMEDIFF', 'DATETIMEDIFF', 'MEDIAN', 'MEAN', 'SUM']
267
+
268
+ attr_accessor :type, :value
269
+ # @param [String] type
270
+ # @param [Value] value
271
+ def initialize(type,value)
272
+ @type = type
273
+ if (value.is_a? HQMF::Value)
274
+ value.inclusive = true
275
+ @value = HQMF::Range.new('IVL_PQ',value,value,nil)
276
+ else
277
+ @value = value
278
+ end
279
+ end
280
+
281
+ def supports_grouper_criteria?
282
+ ['FIRST', 'SECOND', 'THIRD', 'FOURTH', 'FIFTH', 'RECENT', 'LAST'].include? @type
283
+ end
284
+
285
+ def self.from_json(json)
286
+ type = json["type"] if json["type"]
287
+ value = HQMF::DataCriteria.convert_value(json["value"]) if json["value"]
288
+ HQMF::SubsetOperator.new(type,value)
289
+ end
290
+
291
+
292
+ def to_json
293
+ json = build_hash(self, [:type])
294
+ json[:value] = @value.to_json if @value
295
+ json
296
+ end
297
+
298
+ def ==(other)
299
+ check_equality(self,other)
300
+ end
301
+
302
+ end
303
+
304
+ # Represents a HQMF reference from a precondition to a data criteria
305
+ class TypedReference
306
+ include HQMF::Conversion::Utilities
307
+ attr_accessor :reference, :type, :mood
308
+
309
+ # Create a new HQMF::Reference
310
+ # @param [String] id
311
+ def initialize(reference,type,mood=nil)
312
+ @reference = reference
313
+ @type = type
314
+ @mood = mood
315
+ end
316
+
317
+ def self.from_json(json)
318
+ type = json["type"]
319
+ reference = json["reference"]
320
+ mood = json["mood"]
321
+ new(reference,type,mood)
322
+ end
323
+
324
+ def to_json
325
+ build_hash(self, [:type, :reference,:mood])
326
+ end
327
+
328
+ def ==(other)
329
+ check_equality(self,other)
330
+ end
331
+
332
+ end
333
+
334
+ # Represents a HQMF reference from a precondition to a data criteria
335
+ class Reference
336
+ include HQMF::Conversion::Utilities
337
+ attr_accessor :id
338
+
339
+ # Create a new HQMF::Reference
340
+ # @param [String] id
341
+ def initialize(id)
342
+ @id = id
343
+ end
344
+
345
+ def to_json
346
+ @id
347
+ end
348
+
349
+ def ==(other)
350
+ check_equality(self,other)
351
+ end
352
+
353
+ end
354
+
355
+ class Identifier
356
+ include HQMF::Conversion::Utilities
357
+ attr_accessor :type, :root, :extension
358
+
359
+ def initialize(type, root, extension=nil)
360
+ @type = type || 'II'
361
+ @root = root
362
+ @extension = extension
363
+ end
364
+
365
+ def self.from_json(json)
366
+ json = json.with_indifferent_access
367
+ HQMF::Identifier.new(json['type'], json['root'], json['extension'])
368
+ end
369
+
370
+ def to_json
371
+ build_hash(self, [:type, :root, :extension])
372
+ end
373
+
374
+ def ==(other)
375
+ check_equality(self,other)
376
+ end
377
+ end
378
+
379
+ # What does ED stand for?
380
+ # ED has a lot more elements / attributes to represent, but only caring about what I see used...
381
+ class ED
382
+ include HQMF::Conversion::Utilities
383
+ attr_accessor :type, :value, :media_type
384
+
385
+ def initialize(type, value, media_type)
386
+ @type = type || 'ED'
387
+ @value = value
388
+ @media_type = media_type
389
+ end
390
+
391
+ def self.from_json(json)
392
+ json = json.with_indifferent_access
393
+ HQMF::ED.new(json['type'], json['value'], json['media_type'])
394
+ end
395
+
396
+ def to_json
397
+ build_hash(self, [:type, :value, :media_type])
398
+ end
399
+
400
+ def ==(other)
401
+ check_equality(self,other)
402
+ end
403
+ end
404
+
405
+ class GenericValueContainer
406
+ include HQMF::Conversion::Utilities
407
+ attr_accessor :type, :value
408
+
409
+ def initialize(type, value)
410
+ @type = type
411
+ @value = value
412
+ end
413
+
414
+ def self.from_json(json)
415
+ json = json.with_indifferent_access
416
+ HQMF::GenericValueContainer.new(json['type'], json['value'])
417
+ end
418
+
419
+ def to_json
420
+ build_hash(self, [:type, :value])
421
+ end
422
+
423
+ def ==(other)
424
+ check_equality(self,other)
425
+ end
426
+ end
427
+
428
+ class Collection
429
+ include HQMF::Conversion::Utilities
430
+ attr_accessor :type, :values
431
+
432
+ def initialize(type, values)
433
+ @type = type || 'COL'
434
+ @values = values || []
435
+ end
436
+
437
+ def self.from_json(json)
438
+ json = json.with_indifferent_access
439
+ values = []
440
+ type = json['type']
441
+ json['values'].each { |value| values.push(HQMF::DataCriteria.convert_value(value))}
442
+ HQMF::Collection.new(type, values)
443
+ end
444
+
445
+ def to_json
446
+ json = build_hash(self, [:type])
447
+ json[:values] = []
448
+ @values.each {|value| json[:values] << value.to_json }
449
+ json
450
+ end
451
+
452
+ def ==(other)
453
+ check_equality(self,other)
454
+ end
455
+ end
456
+
457
+ end