Class: DaVinciPlanNetTestKit::Generator::SearchDefinitionMetadataExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, ig_resources, resource, profile_elements) ⇒ SearchDefinitionMetadataExtractor

Returns a new instance of SearchDefinitionMetadataExtractor.



8
9
10
11
12
13
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 8

def initialize(name, ig_resources, resource, profile_elements)
  self.name = name
  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.



6
7
8
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 6

def ig_resources
  @ig_resources
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 6

def name
  @name
end

#profile_elementsObject

Returns the value of attribute profile_elements.



6
7
8
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 6

def profile_elements
  @profile_elements
end

#resourceObject

Returns the value of attribute resource.



6
7
8
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 6

def resource
  @resource
end

Instance Method Details

#chainObject



156
157
158
159
160
161
162
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 156

def chain
  return nil if param.chain.blank?

  param.chain
    .zip(chain_expectations)
    .map { |chain, expectation| { chain: chain, expectation: expectation.present? ? expectation : 'SHALL' } }
end

#chain_expectationsObject



148
149
150
151
152
153
154
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 148

def chain_expectations
  if chain_extensions.present?
    chain_extensions.map { |extension| support_expectation(extension) }
  else
    []
  end
end

#chain_extensionsObject



144
145
146
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 144

def chain_extensions
  param_hash['_chain']
end

#comparator_expectation(extension) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 98

def comparator_expectation(extension)
  if extension.nil?
    'MAY'
  else
    support_expectation(extension)
  end
end

#comparator_expectation_extensionsObject



90
91
92
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 90

def comparator_expectation_extensions
  @comparator_expectation_extensions ||= param_hash['_comparator'] || []
end

#comparatorsObject



106
107
108
109
110
111
112
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 106

def comparators
  {}.tap do |comparators|
    param.comparator&.each_with_index do |comparator, index|
      comparators[comparator.to_sym] = comparator_expectation(comparator_expectation_extensions[index])
    end
  end
end

#contains_multiple?Boolean

Returns:

  • (Boolean)


128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 128

def contains_multiple?
  if profile_element.present?
    if profile_element.id.start_with?('Extension') && extension_definition.present?
      # Find the extension instance in a profile
      target_element = profile_elements.find do |element|
        element.type.any? { |type| type.code == "Extension" && type.profile.include?(extension_definition.url) }
      end
      target_element&.max == '*'
    else
      profile_element.max == '*'
    end
  else
    false
  end
end

#extension_definitionObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 78

def extension_definition
   @extension_definition ||=
      begin
        ext_definition = nil
        extensions&.each do ||
          ext_definition = ig_resources.profile_by_url([:url])
          break if ext_definition.present?
        end
        ext_definition
      end
end

#extensionsObject



64
65
66
67
68
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 64

def extensions
  @extensions ||= full_paths.select { |a_path| a_path.include?('extension.where') }
                            .map { |a_path| { url: a_path[/(?<=extension.where\(url=').*(?='\))/] }}
                            .presence
end

#full_pathsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 38

def full_paths
  @full_paths ||=
    begin
      path = param.expression.gsub(/.where\(resolve\((.*)/, '').gsub(/url = '/, 'url=\'')
      path = path[1..-2] if path.start_with?('(') && path.end_with?(')')
      path.scan(/[. ]as[( ]([^)]*)[)]?/).flatten.map do |as_type|
        path.gsub!(/[. ]as[( ](#{as_type}[^)]*)[)]?/, as_type.upcase_first) if as_type.present?
      end

      full_paths = path.split('|').map { |a_path| a_path.strip } # For Lists

      full_paths
    end
end

#multiple_or_expectationObject



164
165
166
167
168
169
170
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 164

def multiple_or_expectation
  if param_hash['_multipleOr'].present?
    param_hash['_multipleOr']['extension'].first['valueCode']
  else
    ''
  end
end

#paramObject



30
31
32
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 30

def param
  @param ||= ig_resources.search_param_by_resource_and_name(resource, name)
end

#param_hashObject



34
35
36
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 34

def param_hash
  param.source_hash
end

#pathsObject



60
61
62
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 60

def paths
  @paths ||= full_paths.map { |a_path| a_path.gsub("#{resource}.", '') }
end

#profile_elementObject



70
71
72
73
74
75
76
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 70

def profile_element
  @profile_element ||=
    (
      profile_elements.find { |element| full_paths.include?(element.id) } ||
      extension_definition&.differential&.element&.find { |element| element.id == 'Extension.value[x]'}
    )
end

#remove_additional_extension_from_asserted_date(full_paths) ⇒ Object



53
54
55
56
57
58
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 53

def remove_additional_extension_from_asserted_date(full_paths)
  full_paths.each do |full_path|
    next unless full_path.include?('http://hl7.org/fhir/StructureDefinition/condition-assertedDate')
    full_path.gsub!(/\).extension./, ').')
  end
end

#search_definitionObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 15

def search_definition
  @search_definition ||=
    {
      paths: paths,
      full_paths: full_paths,
      comparators: comparators,
      values: values,
      type: type,
      target: target,
      contains_multiple: contains_multiple?,
      multiple_or: multiple_or_expectation,
      chain: chain
    }.compact
end

#support_expectation(extension) ⇒ Object



94
95
96
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 94

def support_expectation(extension)
  extension['extension'].first['valueCode']
end

#targetObject



124
125
126
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 124

def target
  param.target.first
end

#typeObject



114
115
116
117
118
119
120
121
122
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 114

def type
  if profile_element.present?
    profile_element.type.first.code
  else
    # search is a variable type, eg. Condition.onsetDateTime - element
    # in profile def is Condition.onset[x]
    param.type
  end
end

#value_extractorObject



188
189
190
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 188

def value_extractor
  @value_extractor ||= ValueExactor.new(ig_resources, resource, profile_elements)
end

#valuesObject



172
173
174
175
176
177
178
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 172

def values
    value_extractor.values_from_slicing(profile_element, type).presence ||
    value_extractor.values_from_required_binding(profile_element).presence ||
    value_extractor.values_from_value_set_binding(profile_element).presence ||
    (paths).presence ||
    []
end

#values_from_resource_metadata(paths) ⇒ Object



180
181
182
183
184
185
186
# File 'lib/davinci_plan_net_test_kit/generator/search_definition_metadata_extractor.rb', line 180

def (paths)
  if multiple_or_expectation == 'SHALL' || paths.any? { |path| path.downcase.include?('status') }
    value_extractor.(paths)
  else
    []
  end
end