hqmf-parser 1.0.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.
- data/Gemfile +23 -0
- data/README.md +903 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/lib/hqmf-generator/hqmf-generator.rb +308 -0
- data/lib/hqmf-model/attribute.rb +35 -0
- data/lib/hqmf-model/data_criteria.rb +322 -0
- data/lib/hqmf-model/document.rb +172 -0
- data/lib/hqmf-model/population_criteria.rb +90 -0
- data/lib/hqmf-model/precondition.rb +85 -0
- data/lib/hqmf-model/types.rb +318 -0
- data/lib/hqmf-model/utilities.rb +52 -0
- data/lib/hqmf-parser.rb +54 -0
- data/lib/hqmf-parser/1.0/attribute.rb +68 -0
- data/lib/hqmf-parser/1.0/comparison.rb +34 -0
- data/lib/hqmf-parser/1.0/data_criteria.rb +105 -0
- data/lib/hqmf-parser/1.0/document.rb +209 -0
- data/lib/hqmf-parser/1.0/expression.rb +52 -0
- data/lib/hqmf-parser/1.0/population_criteria.rb +79 -0
- data/lib/hqmf-parser/1.0/precondition.rb +89 -0
- data/lib/hqmf-parser/1.0/range.rb +65 -0
- data/lib/hqmf-parser/1.0/restriction.rb +157 -0
- data/lib/hqmf-parser/1.0/utilities.rb +41 -0
- data/lib/hqmf-parser/2.0/data_criteria.rb +319 -0
- data/lib/hqmf-parser/2.0/document.rb +165 -0
- data/lib/hqmf-parser/2.0/population_criteria.rb +53 -0
- data/lib/hqmf-parser/2.0/precondition.rb +44 -0
- data/lib/hqmf-parser/2.0/types.rb +223 -0
- data/lib/hqmf-parser/2.0/utilities.rb +30 -0
- data/lib/hqmf-parser/converter/pass1/data_criteria_converter.rb +254 -0
- data/lib/hqmf-parser/converter/pass1/document_converter.rb +183 -0
- data/lib/hqmf-parser/converter/pass1/population_criteria_converter.rb +135 -0
- data/lib/hqmf-parser/converter/pass1/precondition_converter.rb +164 -0
- data/lib/hqmf-parser/converter/pass1/precondition_extractor.rb +159 -0
- data/lib/hqmf-parser/converter/pass1/simple_data_criteria.rb +35 -0
- data/lib/hqmf-parser/converter/pass1/simple_operator.rb +89 -0
- data/lib/hqmf-parser/converter/pass1/simple_population_criteria.rb +10 -0
- data/lib/hqmf-parser/converter/pass1/simple_precondition.rb +63 -0
- data/lib/hqmf-parser/converter/pass1/simple_restriction.rb +64 -0
- data/lib/hqmf-parser/converter/pass2/comparison_converter.rb +91 -0
- data/lib/hqmf-parser/converter/pass2/operator_converter.rb +169 -0
- data/lib/hqmf-parser/converter/pass3/specific_occurrence_converter.rb +86 -0
- data/lib/hqmf-parser/converter/pass3/specific_occurrence_converter_bak.rb +70 -0
- data/lib/hqmf-parser/parser.rb +22 -0
- data/lib/hqmf-parser/value_sets/value_set_parser.rb +206 -0
- data/lib/tasks/coverme.rake +8 -0
- data/lib/tasks/hqmf.rake +141 -0
- data/lib/tasks/value_sets.rake +23 -0
- metadata +159 -0
@@ -0,0 +1,172 @@
|
|
1
|
+
module HQMF
|
2
|
+
# Class representing an HQMF document
|
3
|
+
class Document
|
4
|
+
|
5
|
+
MEASURE_PERIOD_ID = "MeasurePeriod"
|
6
|
+
|
7
|
+
STRATIFIED_POPULATION_TEMPLATE_ID = '2.16.840.1.113883.3.100.1.2'
|
8
|
+
STRATIFIED_POPULATION_TEMPLATE_TITLE = 'Stratified'
|
9
|
+
|
10
|
+
include HQMF::Conversion::Utilities
|
11
|
+
|
12
|
+
attr_reader :id, :title, :description, :measure_period, :attributes, :populations, :source_data_criteria, :hqmf_id, :hqmf_set_id, :hqmf_version_number
|
13
|
+
|
14
|
+
# Create a new HQMF::Document which can be converted to JavaScript
|
15
|
+
# @param [String] id
|
16
|
+
# @param [String] hqmf_id
|
17
|
+
# @param [String] hqmf_set_id
|
18
|
+
# @param [String] hqmf_version_number
|
19
|
+
# @param [String] title
|
20
|
+
# @param [String] description
|
21
|
+
# @param [Array#PopulationCritera] population_criteria
|
22
|
+
# @param [Array#DataCriteria] data_criteria
|
23
|
+
# @param [Array#DataCriteria] source_data_criteria
|
24
|
+
# @param [Array#Attribute] attributes
|
25
|
+
# @param [Array#Hash] populations
|
26
|
+
# @param [Range] measure_period
|
27
|
+
def initialize(id, hqmf_id, hqmf_set_id, hqmf_version_number, title, description, population_criteria, data_criteria, source_data_criteria, attributes, measure_period, populations=nil)
|
28
|
+
@id = id
|
29
|
+
@hqmf_id = hqmf_id
|
30
|
+
@hqmf_set_id = hqmf_set_id
|
31
|
+
@hqmf_version_number = hqmf_version_number
|
32
|
+
@title = title
|
33
|
+
@description = description
|
34
|
+
@population_criteria = population_criteria
|
35
|
+
@data_criteria = data_criteria
|
36
|
+
@source_data_criteria = source_data_criteria
|
37
|
+
@attributes = attributes
|
38
|
+
@populations = populations || [
|
39
|
+
{
|
40
|
+
HQMF::PopulationCriteria::IPP => HQMF::PopulationCriteria::IPP,
|
41
|
+
HQMF::PopulationCriteria::DENOM => HQMF::PopulationCriteria::DENOM,
|
42
|
+
HQMF::PopulationCriteria::NUMER => HQMF::PopulationCriteria::NUMER,
|
43
|
+
HQMF::PopulationCriteria::EXCEP => HQMF::PopulationCriteria::EXCEP,
|
44
|
+
HQMF::PopulationCriteria::DENEX => HQMF::PopulationCriteria::DENEX
|
45
|
+
}
|
46
|
+
]
|
47
|
+
@measure_period = measure_period
|
48
|
+
end
|
49
|
+
|
50
|
+
# Create a new HQMF::Document from a JSON hash keyed with symbols
|
51
|
+
def self.from_json(json)
|
52
|
+
id = json["id"]
|
53
|
+
hqmf_id = json["hqmf_id"]
|
54
|
+
hqmf_set_id = json["hqmf_set_id"]
|
55
|
+
hqmf_version_number = json["hqmf_version_number"]
|
56
|
+
title = json["title"]
|
57
|
+
description = json["description"]
|
58
|
+
|
59
|
+
population_criterias = []
|
60
|
+
json["population_criteria"].each do |key, population_criteria|
|
61
|
+
population_criterias << HQMF::PopulationCriteria.from_json(key.to_s, population_criteria)
|
62
|
+
end if json['population_criteria']
|
63
|
+
|
64
|
+
data_criterias = []
|
65
|
+
json["data_criteria"].each do |key, data_criteria|
|
66
|
+
data_criterias << HQMF::DataCriteria.from_json(key.to_s, data_criteria)
|
67
|
+
end
|
68
|
+
|
69
|
+
source_data_criterias = []
|
70
|
+
json["source_data_criteria"].each do |key, data_criteria|
|
71
|
+
source_data_criterias << HQMF::DataCriteria.from_json(key.to_s, data_criteria)
|
72
|
+
end
|
73
|
+
|
74
|
+
populations = json["populations"] if json["populations"]
|
75
|
+
|
76
|
+
attributes = json["attributes"].map {|attribute| HQMF::Attribute.from_json(attribute)} if json["attributes"]
|
77
|
+
|
78
|
+
measure_period = HQMF::Range.from_json(json["measure_period"]) if json["measure_period"]
|
79
|
+
HQMF::Document.new(id, hqmf_id, hqmf_set_id, hqmf_version_number, title, description, population_criterias, data_criterias, source_data_criterias, attributes, measure_period,populations)
|
80
|
+
end
|
81
|
+
|
82
|
+
def to_json
|
83
|
+
json = build_hash(self, [:id, :hqmf_id, :hqmf_set_id, :hqmf_version_number, :title, :description])
|
84
|
+
|
85
|
+
json[:population_criteria] = {}
|
86
|
+
@population_criteria.each do |population|
|
87
|
+
json[:population_criteria].merge! population.to_json
|
88
|
+
end
|
89
|
+
|
90
|
+
json[:data_criteria] = {}
|
91
|
+
@data_criteria.each do |data|
|
92
|
+
json[:data_criteria].merge! data.to_json
|
93
|
+
end
|
94
|
+
|
95
|
+
json[:source_data_criteria] = {}
|
96
|
+
@source_data_criteria.each do |data|
|
97
|
+
json[:source_data_criteria].merge! data.to_json
|
98
|
+
end
|
99
|
+
|
100
|
+
x = nil
|
101
|
+
json[:attributes] = x if x = json_array(@attributes)
|
102
|
+
|
103
|
+
json[:populations] = @populations
|
104
|
+
|
105
|
+
json[:measure_period] = @measure_period.to_json
|
106
|
+
|
107
|
+
json
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# Get all the population criteria defined by the measure
|
112
|
+
# @return [Array] an array of HQMF::PopulationCriteria
|
113
|
+
def all_population_criteria
|
114
|
+
@population_criteria
|
115
|
+
end
|
116
|
+
|
117
|
+
# Get a specific population criteria by id.
|
118
|
+
# @param [String] id the population identifier
|
119
|
+
# @return [HQMF::PopulationCriteria] the matching criteria, raises an Exception if not found
|
120
|
+
def population_criteria(id)
|
121
|
+
find(@population_criteria, :id, id)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Get all the data criteria defined by the measure
|
125
|
+
# @return [Array] an array of HQMF::DataCriteria describing the data elements used by the measure
|
126
|
+
def all_data_criteria
|
127
|
+
@data_criteria
|
128
|
+
end
|
129
|
+
|
130
|
+
# Get the source data criteria that are specific occurrences
|
131
|
+
# @return [Array] an array of HQMF::DataCriteria describing the data elements used by the measure that are specific occurrences
|
132
|
+
def specific_occurrence_source_data_criteria
|
133
|
+
return [] if @source_data_criteria.nil?
|
134
|
+
@source_data_criteria.select {|dc| !dc.specific_occurrence.nil?}
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
# @return [Array] an array of HQMF::DataCriteria ids that are actually used in the measure
|
139
|
+
def referenced_data_criteria
|
140
|
+
data_criteria_ids = []
|
141
|
+
@population_criteria.each do |population|
|
142
|
+
data_criteria_ids.concat(population.referenced_data_criteria)
|
143
|
+
end
|
144
|
+
references = []
|
145
|
+
data_criteria_ids.each do |id|
|
146
|
+
dc = data_criteria(id)
|
147
|
+
references << id
|
148
|
+
from_dc = dc.referenced_data_criteria(self)
|
149
|
+
references.concat(from_dc)
|
150
|
+
end
|
151
|
+
used_dc = []
|
152
|
+
references.uniq.each do |id|
|
153
|
+
used_dc << data_criteria(id)
|
154
|
+
end
|
155
|
+
used_dc
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
# Get a specific data criteria by id.
|
160
|
+
# @param [String] id the data criteria identifier
|
161
|
+
# @return [HQMF::DataCriteria] the matching data criteria, raises an Exception if not found
|
162
|
+
def data_criteria(id)
|
163
|
+
find(@data_criteria, :id, id)
|
164
|
+
end
|
165
|
+
|
166
|
+
private
|
167
|
+
|
168
|
+
def find(collection, attribute, value)
|
169
|
+
collection.find {|e| e.send(attribute)==value}
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module HQMF
|
2
|
+
# Represents an HQMF population criteria, also supports all the same methods as
|
3
|
+
# HQMF::Precondition
|
4
|
+
class PopulationCriteria
|
5
|
+
|
6
|
+
include HQMF::Conversion::Utilities
|
7
|
+
|
8
|
+
attr_reader :preconditions, :id, :type, :title, :hqmf_id
|
9
|
+
|
10
|
+
IPP = 'IPP'
|
11
|
+
DENOM = 'DENOM'
|
12
|
+
NUMER = 'NUMER'
|
13
|
+
EXCEP = 'EXCEP'
|
14
|
+
DENEX = 'DENEX'
|
15
|
+
|
16
|
+
ALL_POPULATION_CODES = [IPP, DENOM, NUMER, EXCEP, DENEX]
|
17
|
+
|
18
|
+
# Create a new population criteria
|
19
|
+
# @param [String] id
|
20
|
+
# @param [String] hqmf_id
|
21
|
+
# @param [Array#Precondition] preconditions
|
22
|
+
# @param [String] title (optional)
|
23
|
+
def initialize(id, hqmf_id, type, preconditions, title='')
|
24
|
+
@id = id
|
25
|
+
@hqmf_id = hqmf_id
|
26
|
+
@preconditions = preconditions
|
27
|
+
@type = type
|
28
|
+
@title=title
|
29
|
+
end
|
30
|
+
|
31
|
+
# Create a new population criteria from a JSON hash keyed off symbols
|
32
|
+
def self.from_json(id, json)
|
33
|
+
preconditions = json["preconditions"].map do |precondition|
|
34
|
+
HQMF::Precondition.from_json(precondition)
|
35
|
+
end if json['preconditions']
|
36
|
+
type = json["type"]
|
37
|
+
title = json['title']
|
38
|
+
hqmf_id = json['hqmf_id']
|
39
|
+
|
40
|
+
HQMF::PopulationCriteria.new(id, hqmf_id, type, preconditions, title)
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_json
|
44
|
+
{self.id.to_sym => base_json}
|
45
|
+
end
|
46
|
+
|
47
|
+
def base_json
|
48
|
+
x = nil
|
49
|
+
json = build_hash(self, [:conjunction?, :type, :title, :hqmf_id])
|
50
|
+
json[:preconditions] = x if x = json_array(@preconditions)
|
51
|
+
json
|
52
|
+
end
|
53
|
+
|
54
|
+
# Return true of this precondition represents a conjunction with nested preconditions
|
55
|
+
# or false of this precondition is a reference to a data criteria
|
56
|
+
def conjunction?
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
# Get the conjunction code, e.g. allTrue, atLeastOneTrue
|
61
|
+
# @return [String] conjunction code
|
62
|
+
def conjunction_code
|
63
|
+
|
64
|
+
case @type
|
65
|
+
when IPP, DENOM, NUMER
|
66
|
+
HQMF::Precondition::ALL_TRUE
|
67
|
+
when EXCEP, DENEX, EXCEP
|
68
|
+
HQMF::Precondition::AT_LEAST_ONE_TRUE
|
69
|
+
else
|
70
|
+
raise "Unknown population type [#{@type}]"
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
# Can't have negation on population so this is the same as conjunction_code
|
76
|
+
def conjunction_code_with_negation
|
77
|
+
conjunction_code
|
78
|
+
end
|
79
|
+
|
80
|
+
def referenced_data_criteria
|
81
|
+
data_criteria_ids = []
|
82
|
+
@preconditions.each do |precondition|
|
83
|
+
data_criteria_ids.concat(precondition.referenced_data_criteria)
|
84
|
+
end if @preconditions
|
85
|
+
data_criteria_ids
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module HQMF
|
2
|
+
|
3
|
+
class Precondition
|
4
|
+
|
5
|
+
include HQMF::Conversion::Utilities
|
6
|
+
|
7
|
+
AT_LEAST_ONE_TRUE = 'atLeastOneTrue'
|
8
|
+
AT_LEAST_ONE_FALSE = 'atLeastOneFalse'
|
9
|
+
ALL_TRUE = 'allTrue'
|
10
|
+
ALL_FALSE = 'allFalse'
|
11
|
+
NEGATIONS = {
|
12
|
+
AT_LEAST_ONE_TRUE => ALL_FALSE,
|
13
|
+
ALL_FALSE => AT_LEAST_ONE_TRUE,
|
14
|
+
ALL_TRUE => AT_LEAST_ONE_FALSE,
|
15
|
+
AT_LEAST_ONE_FALSE => ALL_TRUE
|
16
|
+
}
|
17
|
+
|
18
|
+
attr_reader :id, :preconditions, :reference, :conjunction_code
|
19
|
+
attr_accessor :negation
|
20
|
+
|
21
|
+
# Create a new population criteria
|
22
|
+
# @param [Array#Precondition] preconditions
|
23
|
+
# @param [Reference] reference
|
24
|
+
# @param [String] conjunction_code
|
25
|
+
def initialize(id, preconditions, reference, conjunction_code, negation)
|
26
|
+
@preconditions = preconditions || []
|
27
|
+
@reference = reference
|
28
|
+
@conjunction_code = conjunction_code
|
29
|
+
@negation = negation
|
30
|
+
@id = id
|
31
|
+
end
|
32
|
+
|
33
|
+
def conjunction_code_with_negation
|
34
|
+
if negation
|
35
|
+
NEGATIONS[conjunction_code]
|
36
|
+
else
|
37
|
+
conjunction_code
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Create a new population criteria from a JSON hash keyed off symbols
|
42
|
+
def self.from_json(json)
|
43
|
+
preconditions = []
|
44
|
+
id = json["id"] if json["id"]
|
45
|
+
preconditions = json["preconditions"].map {|precondition| HQMF::Precondition.from_json(precondition)} if json["preconditions"]
|
46
|
+
reference = Reference.new(json["reference"]) if json["reference"]
|
47
|
+
conjunction_code = json["conjunction_code"] if json["conjunction_code"]
|
48
|
+
negation = json["negation"] if json["negation"]
|
49
|
+
|
50
|
+
HQMF::Precondition.new(id, preconditions, reference, conjunction_code, negation)
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_json
|
54
|
+
x = nil
|
55
|
+
json = {}
|
56
|
+
json[:id] = self.id
|
57
|
+
json[:reference] = self.reference.id if self.reference
|
58
|
+
json[:preconditions] = x if x = json_array(@preconditions)
|
59
|
+
json[:conjunction_code] = self.conjunction_code if self.conjunction_code
|
60
|
+
json[:negation] = self.negation if self.negation
|
61
|
+
json
|
62
|
+
end
|
63
|
+
|
64
|
+
# Return true of this precondition represents a conjunction with nested preconditions
|
65
|
+
# or false of this precondition is a reference to a data criteria
|
66
|
+
def conjunction?
|
67
|
+
@preconditions.length>0
|
68
|
+
end
|
69
|
+
|
70
|
+
def referenced_data_criteria
|
71
|
+
data_criteria_ids = []
|
72
|
+
if @preconditions.empty?
|
73
|
+
data_criteria_ids << self.reference.id
|
74
|
+
else
|
75
|
+
@preconditions.each do |precondition|
|
76
|
+
data_criteria_ids.concat(precondition.referenced_data_criteria)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
data_criteria_ids
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,318 @@
|
|
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
|
+
operator = ""
|
121
|
+
if (@high && @low)
|
122
|
+
if (@high.value == @low.value and @high.inclusive? and low.inclusive?)
|
123
|
+
"#{@low.stringify}"
|
124
|
+
else
|
125
|
+
">#{@low.stringify} and <#{@high.stringify}}"
|
126
|
+
end
|
127
|
+
elsif (@high)
|
128
|
+
"<#{@high.stringify}"
|
129
|
+
elsif (@low)
|
130
|
+
">#{@low.stringify}"
|
131
|
+
else
|
132
|
+
raise "cannot convert range to string"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def ==(other)
|
137
|
+
check_equality(self,other)
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
# Represents a HQMF effective time which is a specialization of a interval
|
144
|
+
class EffectiveTime < Range
|
145
|
+
def initialize(low,high,width)
|
146
|
+
super('IVL_TS', low, high, width)
|
147
|
+
end
|
148
|
+
|
149
|
+
def type
|
150
|
+
'IVL_TS'
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
# Represents a HQMF CD value which has a code and codeSystem
|
156
|
+
class Coded
|
157
|
+
include HQMF::Conversion::Utilities
|
158
|
+
attr_reader :type, :system, :code, :code_list_id, :title
|
159
|
+
|
160
|
+
# Create a new HQMF::Coded
|
161
|
+
# @param [String] type
|
162
|
+
# @param [String] system
|
163
|
+
# @param [String] code
|
164
|
+
# @param [String] code_list_id
|
165
|
+
def initialize(type,system,code,code_list_id=nil,title=nil)
|
166
|
+
@type = type
|
167
|
+
@system = system
|
168
|
+
@code = code
|
169
|
+
@code_list_id = code_list_id
|
170
|
+
@title = title
|
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.from_json(json)
|
182
|
+
type = json["type"] if json["type"]
|
183
|
+
system = json["system"] if json["system"]
|
184
|
+
code = json["code"] if json["code"]
|
185
|
+
code_list_id = json["code_list_id"] if json["code_list_id"]
|
186
|
+
title = json["title"] if json["title"]
|
187
|
+
|
188
|
+
HQMF::Coded.new(type,system,code,code_list_id,title)
|
189
|
+
end
|
190
|
+
|
191
|
+
def to_json
|
192
|
+
build_hash(self, [:type,:system,:code,:code_list_id,:title])
|
193
|
+
end
|
194
|
+
|
195
|
+
def value
|
196
|
+
code
|
197
|
+
end
|
198
|
+
|
199
|
+
def derived?
|
200
|
+
false
|
201
|
+
end
|
202
|
+
|
203
|
+
def unit
|
204
|
+
nil
|
205
|
+
end
|
206
|
+
|
207
|
+
def ==(other)
|
208
|
+
check_equality(self,other)
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
class TemporalReference
|
214
|
+
include HQMF::Conversion::Utilities
|
215
|
+
|
216
|
+
TYPES = ['DURING','SBS','SAS','SBE','SAE','EBS','EAS','EBE','EAE','SDU','EDU','ECW','SCW','CONCURRENT']
|
217
|
+
INVERSION = {'SBS' => 'SAS','EAE' => 'EBE','SAS' => 'SBS','EBE' => 'EAE','SBE' => 'EAS','EAS' => 'SBE','SAE' => 'EBS','EBS' => 'SAE'}
|
218
|
+
|
219
|
+
attr_reader :type, :reference, :range
|
220
|
+
|
221
|
+
# @param [String] type
|
222
|
+
# @param [Reference] reference
|
223
|
+
# @param [Range] range
|
224
|
+
def initialize(type, reference, range)
|
225
|
+
@type = type
|
226
|
+
@reference = reference
|
227
|
+
if (range.is_a? HQMF::Value)
|
228
|
+
@range = HQMF::Range.new('IVL_PQ', range, range, nil)
|
229
|
+
else
|
230
|
+
@range = range
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def self.from_json(json)
|
235
|
+
type = json["type"] if json["type"]
|
236
|
+
reference = HQMF::Reference.new(json["reference"]) if json["reference"]
|
237
|
+
range = HQMF::Range.from_json(json["range"]) if json["range"]
|
238
|
+
|
239
|
+
HQMF::TemporalReference.new(type,reference,range)
|
240
|
+
end
|
241
|
+
|
242
|
+
|
243
|
+
def to_json
|
244
|
+
x = nil
|
245
|
+
json = build_hash(self, [:type])
|
246
|
+
json[:reference] = @reference.to_json if @reference
|
247
|
+
json[:range] = @range.to_json if @range
|
248
|
+
json
|
249
|
+
end
|
250
|
+
|
251
|
+
def ==(other)
|
252
|
+
check_equality(self,other)
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
class SubsetOperator
|
258
|
+
include HQMF::Conversion::Utilities
|
259
|
+
|
260
|
+
TYPES = ['COUNT', 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'FIFTH', 'RECENT', 'LAST', 'MIN', 'MAX', 'DATEDIFF']
|
261
|
+
|
262
|
+
attr_accessor :type, :value
|
263
|
+
# @param [String] type
|
264
|
+
# @param [Value] value
|
265
|
+
def initialize(type,value)
|
266
|
+
@type = type
|
267
|
+
if (value.is_a? HQMF::Value)
|
268
|
+
value.inclusive = true
|
269
|
+
@value = HQMF::Range.new('IVL_PQ',value,value,nil)
|
270
|
+
else
|
271
|
+
@value = value
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def self.from_json(json)
|
276
|
+
type = json["type"] if json["type"]
|
277
|
+
value = HQMF::Range.from_json(json["value"]) if json["value"]
|
278
|
+
|
279
|
+
HQMF::SubsetOperator.new(type,value)
|
280
|
+
end
|
281
|
+
|
282
|
+
|
283
|
+
def to_json
|
284
|
+
x = nil
|
285
|
+
json = build_hash(self, [:type])
|
286
|
+
json[:value] = @value.to_json if @value
|
287
|
+
json
|
288
|
+
end
|
289
|
+
|
290
|
+
def ==(other)
|
291
|
+
check_equality(self,other)
|
292
|
+
end
|
293
|
+
|
294
|
+
end
|
295
|
+
|
296
|
+
|
297
|
+
# Represents a HQMF reference from a precondition to a data criteria
|
298
|
+
class Reference
|
299
|
+
include HQMF::Conversion::Utilities
|
300
|
+
attr_accessor :id
|
301
|
+
|
302
|
+
# Create a new HQMF::Reference
|
303
|
+
# @param [String] id
|
304
|
+
def initialize(id)
|
305
|
+
@id = id
|
306
|
+
end
|
307
|
+
|
308
|
+
def to_json
|
309
|
+
@id
|
310
|
+
end
|
311
|
+
|
312
|
+
def ==(other)
|
313
|
+
check_equality(self,other)
|
314
|
+
end
|
315
|
+
|
316
|
+
end
|
317
|
+
|
318
|
+
end
|