Class: AUCoreTestKit::Generator::GroupMetadataExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/au_core_test_kit/generator/group_metadata_extractor.rb

Constant Summary collapse

ALL_VERSION_CATEGORY_FIRST_PROFILES =

BEGIN SPECIAL CASES ###

[
  'http://hl7.org.au/fhir/core/StructureDefinition/au-core-diagnosticresult-path',
  'http://hl7.org.au/fhir/core/StructureDefinition/au-core-diagnosticresult-imag'
].freeze
ALL_VERSION_PATIENT_FIRST_PROFILES =
[
  'http://hl7.org.au/fhir/core/StructureDefinition/au-core-observation',
].freeze
ALL_VERSION_ID_FIRST_PROFILES =
[
  'http://hl7.org.au/fhir/core/StructureDefinition/au-core-organization',
  'http://hl7.org.au/fhir/core/StructureDefinition/au-core-practitioner'
].freeze
ALL_VERSION_NAME_FIRST_PROFILES =
[
  'http://hl7.org.au/fhir/core/StructureDefinition/au-core-healthcareservice'
].freeze
VERSION_SPECIFIC_CATEGORY_FIRST_PROFILES =

Usage example

{
  # 'http://hl7.org.au/fhir/core/StructureDefinition/au-core-healthcareservice' => ['v030']
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_capabilities, profile_url, ig_metadata, ig_resources) ⇒ GroupMetadataExtractor

Returns a new instance of GroupMetadataExtractor.



14
15
16
17
18
19
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 14

def initialize(resource_capabilities, profile_url, , ig_resources)
  self.resource_capabilities = resource_capabilities
  self.profile_url = profile_url
  self. = 
  self.ig_resources = ig_resources
end

Instance Attribute Details

#ig_metadataObject

Returns the value of attribute ig_metadata.



12
13
14
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 12

def 
  
end

#ig_resourcesObject

Returns the value of attribute ig_resources.



12
13
14
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 12

def ig_resources
  @ig_resources
end

#profile_urlObject

Returns the value of attribute profile_url.



12
13
14
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 12

def profile_url
  @profile_url
end

#resource_capabilitiesObject

Returns the value of attribute resource_capabilities.



12
13
14
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 12

def resource_capabilities
  @resource_capabilities
end

Instance Method Details

#base_nameObject



183
184
185
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 183

def base_name
  profile_url.split('StructureDefinition/').last
end

#bindingsObject



298
299
300
301
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 298

def bindings
  @bindings ||=
    .terminology_bindings
end

#category_first_profile?Boolean

Returns:

  • (Boolean)


131
132
133
134
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 131

def category_first_profile?
  ALL_VERSION_CATEGORY_FIRST_PROFILES.include?(profile_url) ||
    VERSION_SPECIFIC_CATEGORY_FIRST_PROFILES[profile_url]&.include?(reformatted_version)
end

#class_nameObject



191
192
193
194
195
196
197
198
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 191

def class_name
  base_name
    .split('-')
    .map(&:capitalize)
    .join
    .gsub('AUCore', "AUCore#{ig_metadata.reformatted_version}")
    .concat('Sequence')
end

#first_search_paramsObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 140

def first_search_params
  @first_search_params ||=
    if category_first_profile?
      %w[patient category]
    elsif patient_first_profile?
      ['patient']
    elsif id_first_profile?
      ['_id']
    elsif name_first_profile?
      ['name']
    elsif resource == 'Observation'
      %w[patient code]
    elsif resource == 'MedicationRequest'
      ['patient']
    elsif resource == 'CareTeam'
      %w[patient status]
    else
      ['patient']
    end
end

#group_metadataObject



21
22
23
24
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 21

def 
   ||=
    .new()
end

#group_metadata_hashObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 26

def 
   ||=
    {
      name:,
      class_name:,
      version:,
      reformatted_version:,
      # test_id_prefix: test_id_prefix,
      resource:,
      profile_url:,
      profile_name:,
      profile_version:,
      title:,
      short_description:,
      interactions:,
      operations:,
      searches:,
      search_definitions:,
      include_params:,
      revincludes:,
      required_concepts:,
      must_supports:,
      mandatory_elements:,
      bindings:,
      references:
      # tests: []
    }

  mark_mandatory_and_must_support_searches
  handle_special_cases

  
end

#handle_special_casesObject



161
162
163
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 161

def handle_special_cases
  set_first_search
end

#id_first_profile?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 127

def id_first_profile?
  ALL_VERSION_ID_FIRST_PROFILES.include? profile_url
end

#include_paramsObject



273
274
275
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 273

def include_params
  resource_capabilities.searchInclude || []
end

#interactionsObject



232
233
234
235
236
237
238
239
240
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 232

def interactions
  @interactions ||=
    resource_capabilities.interaction.map do |interaction|
      {
        code: interaction.code,
        expectation: interaction.extension.first.valueCode # TODO: fix expectation extension finding
      }
    end
end

#mandatory_elementsObject



313
314
315
316
317
318
319
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 313

def mandatory_elements
  @mandatory_elements ||=
    profile_elements
    .select { |element| element.min.positive? }
    .map(&:path)
    .uniq
end

#mark_mandatory_and_must_support_searchesObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 60

def mark_mandatory_and_must_support_searches
  searches.each do |search|
    search[:names_not_must_support_or_mandatory] = search[:names].reject do |name|
      full_paths = search_definitions[name.to_sym][:full_paths]
      any_must_support_elements = must_supports[:elements].any? do |element|
        full_must_support_paths = ["#{resource}.#{element[:original_path]}", "#{resource}.#{element[:path]}"]

        full_paths.any? do |path|
          # allow for non-choice, choice types, and _id
          name == '_id' || full_must_support_paths.include?(path) || full_must_support_paths.include?("#{path}[x]")
        end
      end

      any_must_support_slices = must_supports[:slices].any? do |slice|
        # only handle type slices because that is all we need for now
        # for a slice like Observation.effective[x]:effectiveDateTime, the search parameter's expression could be
        # either Observation.effective or Observation.effectiveDateTime.
        if slice[:discriminator] && slice[:discriminator][:type] == 'type'
          full_must_support_path = "#{resource}.#{slice[:path].sub('[x]', slice[:discriminator][:code])}"
          base_must_support_path = "#{resource}.#{slice[:path].sub('[x]', '')}"

          full_paths.intersection([full_must_support_path, base_must_support_path]).present?
        else
          false
        end
      end

      any_mandatory_elements = mandatory_elements.any? do |element|
        full_paths.include?(element)
      end

      any_must_support_elements || any_must_support_slices || any_mandatory_elements
    end

    search[:must_support_or_mandatory] = search[:names_not_must_support_or_mandatory].empty?
  end
end

#must_support_metadata_extractorObject



303
304
305
306
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 303

def 
   ||=
    MustSupportMetadataExtractor.new(profile_elements, profile, resource, ig_resources)
end

#must_supportsObject



308
309
310
311
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 308

def must_supports
  @must_supports ||=
    .must_supports
end

#nameObject



187
188
189
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 187

def name
  base_name.tr('-', '_')
end

#name_first_profile?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 123

def name_first_profile?
  ALL_VERSION_NAME_FIRST_PROFILES.include? profile_url
end

#operationsObject



242
243
244
245
246
247
248
249
250
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 242

def operations
  @operations ||=
    resource_capabilities.operation.map do |operation|
      {
        code: operation.name,
        expectation: operation.extension.first.valueCode # TODO: fix expectation extension finding
      }
    end
end

#patient_first_profile?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 136

def patient_first_profile?
  ALL_VERSION_PATIENT_FIRST_PROFILES.include?(profile_url)
end

#profileObject

END SPECIAL CASES ###



175
176
177
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 175

def profile
  @profile ||= ig_resources.profile_by_url(profile_url)
end

#profile_elementsObject



179
180
181
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 179

def profile_elements
  @profile_elements ||= profile.snapshot.element
end

#profile_nameObject



212
213
214
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 212

def profile_name
  profile.title.gsub('  ', ' ')
end

#profile_versionObject



216
217
218
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 216

def profile_version
  profile.version
end

#referencesObject



321
322
323
324
325
326
327
328
329
330
331
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 321

def references
  @references ||=
    profile_elements
    .select { |element| element.type&.first&.code == 'Reference' }
    .map do |reference_definition|
      {
        path: reference_definition.path,
        profiles: reference_definition.type.first.targetProfile,
      }
    end
end

#reformatted_versionObject



204
205
206
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 204

def reformatted_version
  .reformatted_version
end

#required_conceptsObject



281
282
283
284
285
286
287
288
289
290
291
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 281

def required_concepts
  # The base FHIR vital signs profile has a required binding that isn't
  # relevant for any of its child profiles
  return [] if resource == 'Observation'

  profile_elements
    .select { |element| element.type&.any? { |type| type.code == 'CodeableConcept' } }
    .select { |element| element.binding&.strength == 'required' }
    .map { |element| element.path.gsub("#{resource}.", '').gsub('[x]', 'CodeableConcept') }
    .uniq
end

#resourceObject



208
209
210
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 208

def resource
  resource_capabilities.type
end

#revincludesObject



277
278
279
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 277

def revincludes
  resource_capabilities.searchRevInclude || []
end

#search_definitionsObject



269
270
271
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 269

def search_definitions
  @search_definitions ||= .search_definitions
end

#search_metadata_extractorObject



252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 252

def 
   ||= SearchMetadataExtractor.new(
    resource_capabilities,
    ig_resources,
    profile_elements,
    {
      resource:,
      profile_url:,
      must_supports:
    }
  )
end

#searchesObject



265
266
267
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 265

def searches
  @searches ||= .searches
end

#set_first_searchObject



165
166
167
168
169
170
171
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 165

def set_first_search
  search = searches.find { |param| param[:names] == first_search_params }
  return if search.nil?

  searches.delete(search)
  searches.unshift(search)
end

#short_descriptionObject



228
229
230
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 228

def short_description
  "Verify support for the server capabilities required by the #{profile_name}."
end

#terminology_binding_metadata_extractorObject



293
294
295
296
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 293

def 
   ||=
    TerminologyBindingMetadataExtractor.new(profile_elements, ig_resources, resource)
end

#titleObject



220
221
222
223
224
225
226
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 220

def title
  title = profile.title.gsub(/AU\s*Core\s*/, '').gsub(/\s*Profile/, '').strip

  title = "#{resource} #{title.split(resource).map(&:strip).join(' ')}" if Naming.resources_with_multiple_profiles.include?(resource) && !title.start_with?(resource) && version != 'v3.1.1'

  title
end

#versionObject



200
201
202
# File 'lib/au_core_test_kit/generator/group_metadata_extractor.rb', line 200

def version
  .ig_version
end