Class: IpaTestKit::Generator::SearchMetadataExtractor

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

Constant Summary collapse

COMBO_EXTENSION_URL =
'http://hl7.org/fhir/StructureDefinition/capabilitystatement-search-parameter-combination'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_capabilities, ig_resources, resource, profile_elements, base_search_params) ⇒ SearchMetadataExtractor

Returns a new instance of SearchMetadataExtractor.



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

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

Instance Attribute Details

#base_search_paramsObject

Returns the value of attribute base_search_params.



9
10
11
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 9

def base_search_params
  @base_search_params
end

#ig_resourcesObject

Returns the value of attribute ig_resources.



9
10
11
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 9

def ig_resources
  @ig_resources
end

#profile_elementsObject

Returns the value of attribute profile_elements.



9
10
11
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 9

def profile_elements
  @profile_elements
end

#resourceObject

Returns the value of attribute resource.



9
10
11
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 9

def resource
  @resource
end

#resource_capabilitiesObject

Returns the value of attribute resource_capabilities.



9
10
11
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 9

def resource_capabilities
  @resource_capabilities
end

Instance Method Details

#basic_searchesObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 31

def basic_searches
  return [] if no_search_params?

  resource_capabilities.searchParam
    .select { |search_param| ['SHALL', 'SHOULD'].include? conformance_expectation(search_param) }
    .map do |search_param|
      {
        names: [search_param.name],
        expectation: conformance_expectation(search_param)
      }
    end
end

#combo_searchesObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 48

def combo_searches
  return [] if search_extensions.blank?

  search_extensions
    .select { |extension| extension.url == COMBO_EXTENSION_URL }
    .select { |extension| ['SHALL', 'SHOULD'].include? conformance_expectation(extension) }
    .map do |extension|
      names = extension.extension.select { |param| param.valueString.present? }.map(&:valueString)
      {
        expectation: conformance_expectation(extension),
        names: names
      }
    end
end

#conformance_expectation(search_param) ⇒ Object



23
24
25
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 23

def conformance_expectation(search_param)
  search_param.extension.first.valueCode # TODO: fix expectation extension finding
end

#no_search_params?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 27

def no_search_params?
  resource_capabilities.searchParam.blank?
end

#search_definitionsObject



67
68
69
70
71
72
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 67

def search_definitions
  search_param_names.each_with_object({}) do |name, definitions|
    definitions[name.to_sym] =
      SearchDefinitionMetadataExtractor.new(name, ig_resources, resource, profile_elements, base_search_params).search_definition
  end
end

#search_extensionsObject



44
45
46
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 44

def search_extensions
  resource_capabilities.extension
end

#search_param_namesObject



63
64
65
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 63

def search_param_names
  searches.flat_map { |search| search[:names] }.uniq
end

#searchesObject



19
20
21
# File 'lib/ipa_test_kit/generator/search_metadata_extractor.rb', line 19

def searches
  @searches ||= basic_searches + combo_searches
end