Class: ONCCertificationG10TestKit::SMARTScopesTest
- Inherits:
-
Inferno::Test
- Object
- Inferno::Test
- ONCCertificationG10TestKit::SMARTScopesTest
show all
- Includes:
- G10Options
- Defined in:
- lib/onc_certification_g10_test_kit/smart_scopes_test.rb
Constant Summary
collapse
- VALID_RESOURCE_TYPES =
[
'*',
'Patient',
'AllergyIntolerance',
'Binary',
'CarePlan',
'CareTeam',
'Condition',
'Device',
'DiagnosticReport',
'DocumentReference',
'Encounter',
'Goal',
'Immunization',
'Location',
'Medication',
'MedicationOrder',
'MedicationRequest',
'MedicationStatement',
'Observation',
'Organization',
'Person',
'Practitioner',
'PractitionerRole',
'Procedure',
'Provenance',
'RelatedPerson'
].freeze
- V5_VALID_RESOURCE_TYPES =
(VALID_RESOURCE_TYPES + ['ServiceRequest', 'QuestionnaireResponse', 'Media']).freeze
- V6_VALID_RESOURCE_TYPES =
(V5_VALID_RESOURCE_TYPES + ['Coverage', 'MedicationDispense', 'RelatedPerson', 'Specimen']).freeze
- V7_VALID_RESOURCE_TYPES =
(V6_VALID_RESOURCE_TYPES + ['Location'])
- PATIENT_COMPARTMENT_RESOURCE_TYPES =
[
'*',
'Patient',
'AllergyIntolerance',
'CarePlan',
'CareTeam',
'Condition',
'DiagnosticReport',
'DocumentReference',
'Goal',
'Immunization',
'MedicationRequest',
'Observation',
'Procedure',
'Provenance'
].freeze
- V5_PATIENT_COMPARTMENT_RESOURCE_TYPES =
(PATIENT_COMPARTMENT_RESOURCE_TYPES + ['ServiceRequest']).freeze
- V6_PATIENT_COMPARTMENT_RESOURCE_TYPES =
(V5_PATIENT_COMPARTMENT_RESOURCE_TYPES + ['Coverage', 'MedicationDispense', 'Specimen']).freeze
- V7_PATIENT_COMPARTMENT_RESOURCE_TYPES =
(V6_PATIENT_COMPARTMENT_RESOURCE_TYPES + ['Location']).freeze
Constants included
from G10Options
G10Options::BULK_DATA_1, G10Options::BULK_DATA_1_REQUIREMENT, G10Options::BULK_DATA_2, G10Options::BULK_DATA_2_REQUIREMENT, G10Options::SMART_1, G10Options::SMART_1_REQUIREMENT, G10Options::SMART_2, G10Options::SMART_2_2, G10Options::SMART_2_2_REQUIREMENT, G10Options::SMART_2_REQUIREMENT, G10Options::US_CORE_3, G10Options::US_CORE_3_REQUIREMENT, G10Options::US_CORE_4, G10Options::US_CORE_4_REQUIREMENT, G10Options::US_CORE_5, G10Options::US_CORE_5_REQUIREMENT, G10Options::US_CORE_6, G10Options::US_CORE_6_REQUIREMENT, G10Options::US_CORE_7, G10Options::US_CORE_7_REQUIREMENT, G10Options::US_CORE_VERSION_NUMBERS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from G10Options
#us_core_7_and_above?, #us_core_version, #using_us_core_3?, #using_us_core_4?, #using_us_core_5?, #using_us_core_6?, #using_us_core_7?, #versioned_us_core_module
Instance Attribute Details
#received_or_requested ⇒ Object
Returns the value of attribute received_or_requested.
76
77
78
|
# File 'lib/onc_certification_g10_test_kit/smart_scopes_test.rb', line 76
def received_or_requested
@received_or_requested
end
|
Instance Method Details
#access_level_regex ⇒ Object
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/onc_certification_g10_test_kit/smart_scopes_test.rb', line 135
def access_level_regex
case scope_version
when :v1
/\A(\*|read)\b/
when :v2, :v22
/\A(\*|c?ru?d?s?)\b/
else
/\A(\*|read|c?ru?d?s?)\b/
end
end
|
#assert_correct_scope_type(scope, scope_type, resource_type, scope_direction) ⇒ Object
161
162
163
164
165
166
167
168
|
# File 'lib/onc_certification_g10_test_kit/smart_scopes_test.rb', line 161
def assert_correct_scope_type(scope, scope_type, resource_type, scope_direction)
if required_scope_type == 'patient' && patient_compartment_resource_types.exclude?(resource_type)
assert ['user', 'patient'].include?(scope_type),
"#{scope_direction} scope '#{scope}' must begin with either 'user/' or 'patient/'"
else
assert scope_type == required_scope_type, bad_format_message(scope, scope_direction)
end
end
|
146
147
148
149
150
151
|
# File 'lib/onc_certification_g10_test_kit/smart_scopes_test.rb', line 146
def bad_format_message(scope, scope_direction = 'Requested')
%(
#{scope_direction} scope `#{scope}` does not follow the format:
`#{required_scope_type}/[ <ResourceType> | * ].[ #{read_format} ]`
)
end
|
#patient_compartment_resource_types ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/onc_certification_g10_test_kit/smart_scopes_test.rb', line 121
def read_format
v1_read_format = 'read'
v2_read_format = 'c?ru?d?s?'
case scope_version
when :v1
"#{v1_read_format} | *"
when :v2, :v22
"#{v2_read_format} | *"
else
[v1_read_format, v2_read_format, '*'].join(' | ')
end
end
|
#received_scope_test(scopes) ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/onc_certification_g10_test_kit/smart_scopes_test.rb', line 200
def received_scope_test(scopes)
granted_resource_types = []
scopes.each do |full_scope|
scope = strip_experimental_scope_syntax(full_scope)
scope_pieces = scope.split('/')
next unless scope_pieces.length == 2
scope_type, resource_scope = scope_pieces
resource_scope_parts = resource_scope.split('.')
next unless resource_scope_parts.length == 2
resource_type, access_level = resource_scope_parts
next unless access_level =~ access_level_regex
next unless ['patient', 'user', 'system'].include?(scope_type)
assert_correct_scope_type(scope, scope_type, resource_type, 'Received')
granted_resource_types << resource_type
end
missing_resource_types =
if granted_resource_types.include?('*')
[]
else
patient_compartment_resource_types - granted_resource_types - ['*']
end
assert missing_resource_types.empty?,
"Request scopes #{missing_resource_types.join(', ')} were not granted by authorization server."
end
|
#requested_scope_test(scopes) ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/onc_certification_g10_test_kit/smart_scopes_test.rb', line 170
def requested_scope_test(scopes)
correct_scope_type_found = false
scopes.each do |full_scope|
scope = strip_experimental_scope_syntax(full_scope)
scope_pieces = scope.split('/')
assert scope_pieces.length == 2, bad_format_message(scope)
scope_type, resource_scope = scope_pieces
resource_scope_parts = resource_scope.split('.')
assert resource_scope_parts.length == 2, bad_format_message(scope)
resource_type, access_level = resource_scope_parts
assert access_level =~ access_level_regex, bad_format_message(scope)
assert_correct_scope_type(scope, scope_type, resource_type, 'Requested')
assert valid_resource_types.include?(resource_type),
"'#{resource_type}' must be either a permitted resource type or '*'"
correct_scope_type_found = true if scope_type == required_scope_type
end
assert correct_scope_type_found,
"#{required_scope_type.capitalize}-level scope in the format: " \
"`#{required_scope_type}/[ <ResourceType> | * ].[ #{read_format} ]` was not requested."
end
|
#requested_scope_version ⇒ Object
117
118
119
|
# File 'lib/onc_certification_g10_test_kit/smart_scopes_test.rb', line 117
def requested_scope_version
config.options[:requested_scope_version]
end
|
#required_scope_type ⇒ Object
98
99
100
|
# File 'lib/onc_certification_g10_test_kit/smart_scopes_test.rb', line 98
def required_scope_type
config.options[:required_scope_type]
end
|
#required_scopes ⇒ Object
102
103
104
|
# File 'lib/onc_certification_g10_test_kit/smart_scopes_test.rb', line 102
def required_scopes
config.options[:required_scopes]
end
|
#scope_version ⇒ Object
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/onc_certification_g10_test_kit/smart_scopes_test.rb', line 106
def scope_version
case received_or_requested
when 'received'
config.options[:received_scope_version] || config.options[:scope_version]
when 'requested'
config.options[:requested_scope_version] || config.options[:scope_version]
else
config.options[:scope_version]
end
end
|
#strip_experimental_scope_syntax(full_scope) ⇒ Object
153
154
155
156
157
158
159
|
# File 'lib/onc_certification_g10_test_kit/smart_scopes_test.rb', line 153
def strip_experimental_scope_syntax(full_scope)
if scope_version == :v1
full_scope
else
full_scope.split('?').first
end
end
|
#valid_resource_types ⇒ Object