91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/onc_certification_g10_test_kit.rb', line 91
def self.setup_validator(us_core_version_requirement) validator_method = if Feature.use_hl7_resource_validator?
method(:fhir_resource_validator)
else
method(:validator)
end
validator_method.call :default, required_suite_options: us_core_version_requirement do
if Feature.use_hl7_resource_validator?
cli_context do
txServer nil
displayWarnings true
disableDefaultResourceFetcher true
end
us_core_version_num = G10Options::US_CORE_VERSION_NUMBERS[us_core_version_requirement[:us_core_version]]
igs("hl7.fhir.us.core##{us_core_version_num}")
else
url ENV.fetch('G10_VALIDATOR_URL', 'http://validator_service:4567')
end
us_core_message_filters =
case (us_core_version_requirement[:us_core_version])
when G10Options::US_CORE_3
USCoreTestKit::USCoreV311::USCoreTestSuite::VALIDATION_MESSAGE_FILTERS
when G10Options::US_CORE_4
USCoreTestKit::USCoreV400::USCoreTestSuite::VALIDATION_MESSAGE_FILTERS
when G10Options::US_CORE_5
USCoreTestKit::USCoreV501::USCoreTestSuite::VALIDATION_MESSAGE_FILTERS
when G10Options::US_CORE_6
USCoreTestKit::USCoreV610::USCoreTestSuite::VALIDATION_MESSAGE_FILTERS
when G10Options::US_CORE_7
USCoreTestKit::USCoreV700::USCoreTestSuite::VALIDATION_MESSAGE_FILTERS
end
exclude_message do |message|
if message.type == 'info' ||
(message.type == 'warning' && WARNING_INCLUSION_FILTERS.none? do |filter|
filter.match? message.message
end) ||
us_core_message_filters.any? { |filter| filter.match? message.message } ||
(message.type == 'error' && ERROR_FILTERS.any? { |filter| message.message.match? filter })
true
else
false
end
end
perform_additional_validation do |resource, profile_url|
versionless_profile_url, profile_version = profile_url.split('|')
profile_version = case profile_version
when '6.1.0'
'610'
when '4.0.0'
'400'
when '5.0.1'
'501'
else
'311'
end
us_core_suite = USCoreTestKit.const_get("USCoreV#{profile_version}")::USCoreTestSuite
metadata = us_core_suite.metadata.find do |metadata_candidate|
metadata_candidate.profile_url == versionless_profile_url
end
next if metadata.nil?
validation_messages = if resource.instance_of?(FHIR::Provenance)
USCoreTestKit::ProvenanceValidator.validate(resource)
else
[]
end
terminology_validation_messages = metadata.bindings
.select { |binding_definition| binding_definition[:strength] == 'required' }
.flat_map do |binding_definition|
TerminologyBindingValidator.validate(resource, binding_definition)
rescue Inferno::UnknownValueSetException, Inferno::UnknownCodeSystemException => e
{ type: 'warning', message: e.message }
end.compact
validation_messages.concat(terminology_validation_messages)
validation_messages
end
end
end
|