Class: CarinForBlueButtonTestKit::Generator::SearchMetadataExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/carin_for_blue_button_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) ⇒ SearchMetadataExtractor

Returns a new instance of SearchMetadataExtractor.



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

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

Instance Attribute Details

#ig_resourcesObject

Returns the value of attribute ig_resources.



9
10
11
# File 'lib/carin_for_blue_button_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/carin_for_blue_button_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/carin_for_blue_button_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/carin_for_blue_button_test_kit/generator/search_metadata_extractor.rb', line 9

def resource_capabilities
  @resource_capabilities
end

Instance Method Details

#basic_searchesObject



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

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



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

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



22
23
24
# File 'lib/carin_for_blue_button_test_kit/generator/search_metadata_extractor.rb', line 22

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

#include_searchesObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/carin_for_blue_button_test_kit/generator/search_metadata_extractor.rb', line 62

def include_searches
  resource_capabilities.searchInclude.map do |param|
    begin
      {
        names: [param.sub("#{resource}:", "")],
        expectation: 'SHALL',
        include_search: true
      }
    end
  end
end

#no_search_params?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/carin_for_blue_button_test_kit/generator/search_metadata_extractor.rb', line 26

def no_search_params?
  resource_capabilities.searchParam.blank?
end

#search_definitionsObject



79
80
81
82
83
84
# File 'lib/carin_for_blue_button_test_kit/generator/search_metadata_extractor.rb', line 79

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

#search_extensionsObject



43
44
45
# File 'lib/carin_for_blue_button_test_kit/generator/search_metadata_extractor.rb', line 43

def search_extensions
  resource_capabilities.extension
end

#search_param_namesObject



74
75
76
77
# File 'lib/carin_for_blue_button_test_kit/generator/search_metadata_extractor.rb', line 74

def search_param_names
  searches_arr = searches + include_searches
  searches_arr.flat_map { |search| search[:names] }.uniq
end

#searchesObject



18
19
20
# File 'lib/carin_for_blue_button_test_kit/generator/search_metadata_extractor.rb', line 18

def searches
  @searches ||= basic_searches + combo_searches
end