Class: IpaTestKit::Generator::GroupMetadataExtractor

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

Constant Summary collapse

CATEGORY_FIRST_PROFILES =

BEGIN SPECIAL CASES ###

[
  # 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-careplan',
  # 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-diagnosticreport-lab',
  # 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-diagnosticreport-note',
  # 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-clinical-test',
  # 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-imaging',
  # 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab',
  # 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-sdoh-assessment',
  # 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-social-history',
  # 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-survey'
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of GroupMetadataExtractor.



12
13
14
15
16
17
18
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 12

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

Instance Attribute Details

#base_search_paramsObject

Returns the value of attribute base_search_params.



10
11
12
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 10

def base_search_params
  @base_search_params
end

#ig_metadataObject

Returns the value of attribute ig_metadata.



10
11
12
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 10

def 
  @ig_metadata
end

#ig_resourcesObject

Returns the value of attribute ig_resources.



10
11
12
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 10

def ig_resources
  @ig_resources
end

#profile_urlObject

Returns the value of attribute profile_url.



10
11
12
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 10

def profile_url
  @profile_url
end

#resource_capabilitiesObject

Returns the value of attribute resource_capabilities.



10
11
12
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 10

def resource_capabilities
  @resource_capabilities
end

Instance Method Details

#base_nameObject



146
147
148
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 146

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

#bindingsObject



255
256
257
258
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 255

def bindings
  @bindings ||=
    .terminology_bindings
end

#category_first_profile?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 111

def category_first_profile?
  CATEGORY_FIRST_PROFILES.include?(profile_url)
end

#class_nameObject



154
155
156
157
158
159
160
161
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 154

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

#first_search_paramsObject



115
116
117
118
119
120
121
122
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 115

def first_search_params
  @first_search_params ||=
  if category_first_profile?
    ['patient', 'category']
  else
    ['patient']
  end
end

#group_metadataObject



20
21
22
23
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 20

def 
  @group_metadata ||=
    GroupMetadata.new()
end

#group_metadata_hashObject



25
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
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 25

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

  mark_mandatory_and_must_support_searches
  handle_special_cases

  @group_metadata_hash
end

#handle_special_casesObject



124
125
126
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 124

def handle_special_cases
  set_first_search
end

#include_paramsObject



231
232
233
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 231

def include_params
  resource_capabilities.searchInclude || []
end

#interactionsObject



198
199
200
201
202
203
204
205
206
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 198

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



270
271
272
273
274
275
276
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 270

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

#mark_mandatory_and_must_support_searchesObject



59
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
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 59

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



260
261
262
263
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 260

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

#must_supportsObject



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

def must_supports
  @must_supports ||=
    .must_supports
end

#nameObject



150
151
152
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 150

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

#operationsObject



208
209
210
211
212
213
214
215
216
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 208

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

#profileObject

END SPECIAL CASES ###



138
139
140
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 138

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

#profile_elementsObject



142
143
144
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 142

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

#profile_nameObject



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

def profile_name
  binding.pry if profile.nil?
  profile.title.gsub('  ', ' ')
end

#profile_versionObject



180
181
182
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 180

def profile_version
  profile.version
end

#referencesObject



278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 278

def references
  @references ||=
    profile_elements
      .select { |element| element.type&.any? { |type| type&.code == 'Reference' } }
      .map do |reference_definition|
        reference_type = reference_definition.type.find { |type| type.code == 'Reference' }
        {
          path: reference_definition.path.gsub('[x]', 'Reference'),
          profiles: reference_type.targetProfile
        }
      end
end

#reformatted_versionObject



167
168
169
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 167

def reformatted_version
  .reformatted_version
end

#required_conceptsObject



239
240
241
242
243
244
245
246
247
248
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 239

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') }
end

#resourceObject



171
172
173
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 171

def resource
  resource_capabilities.type
end

#revincludesObject



235
236
237
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 235

def revincludes
  resource_capabilities.searchRevInclude || []
end

#search_definitionsObject



227
228
229
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 227

def search_definitions
  @search_definitions ||= .search_definitions
end

#search_metadata_extractorObject



218
219
220
221
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 218

def 
  @search_metadata_extractor ||=
    SearchMetadataExtractor.new(resource_capabilities, ig_resources, resource, profile_elements, base_search_params)
end

#searchesObject



223
224
225
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 223

def searches
  @searches ||= .searches
end

#set_first_searchObject



128
129
130
131
132
133
134
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 128

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



194
195
196
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 194

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

#terminology_binding_metadata_extractorObject



250
251
252
253
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 250

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

#titleObject



184
185
186
187
188
189
190
191
192
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 184

def title
  title = profile.title.gsub(/IPA\-/, ' ').strip

  if (Naming.resources_with_multiple_profiles.include?(resource)) && !title.start_with?(resource) && version != 'v3.1.1'
    title = "#{resource} (#{title.split(resource).map(&:strip).join(' ').gsub(/\-/, ' ')})".titleize
  end

  title
end

#versionObject



163
164
165
# File 'lib/ipa_test_kit/generator/group_metadata_extractor.rb', line 163

def version
  .ig_version
end