Class: CarinForBlueButtonTestKit::Generator::SearchDefinitionMetadataExtractor

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



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

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.



8
9
10
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 8

def ig_resources
  @ig_resources
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 8

def name
  @name
end

#profile_elementsObject

Returns the value of attribute profile_elements.



8
9
10
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 8

def profile_elements
  @profile_elements
end

#resourceObject

Returns the value of attribute resource.



8
9
10
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 8

def resource
  @resource
end

Instance Method Details

#chainObject



124
125
126
127
128
129
130
131
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 124

def chain
  return nil if param.nil?
  return nil if param.chain.blank?

  param.chain
       .zip(chain_expectations)
       .map { |chain, expectation| { chain:, expectation: } }
end

#chain_expectationsObject



120
121
122
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 120

def chain_expectations
  chain_extensions.map { |extension| support_expectation(extension) }
end

#chain_extensionsObject



116
117
118
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 116

def chain_extensions
  param_hash['_chain']
end

#comparator_expectation(extension) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 72

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

#comparator_expectation_extensionsObject



64
65
66
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 64

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

#comparatorsObject



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

def comparators
  return if param.nil?

  {}.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)


112
113
114
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 112

def contains_multiple?
  profile_element&.max == '*'
end

#full_pathsObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 42

def full_paths
  @full_paths ||= if !param.nil?
                    path = param.expression.gsub(/.where\((.*)/, '')
                    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
                    path.split('|').map{ |element| element.strip.gsub('Resource.', "#{resource}.") }
                  else
                    []
                  end
end

#multiple_or_expectationObject



133
134
135
136
137
138
139
140
141
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 133

def multiple_or_expectation
  return nil if param_hash.nil?

  begin
    param_hash['_multipleOr']['extension'].first['valueCode']
  rescue NoMethodError
    nil
  end
end

#paramObject



32
33
34
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 32

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

#param_hashObject



36
37
38
39
40
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 36

def param_hash
  return if param.nil?

  param.source_hash
end

#pathsObject



55
56
57
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 55

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

#profile_elementObject



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

def profile_element
  @profile_element ||=
    profile_elements.find { |element| full_paths.include?(element.id) }
end

#search_definitionObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 17

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

#slicesObject



153
154
155
156
157
158
159
160
161
162
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 153

def slices
  return [] unless contains_multiple?

  profile_elements.select do |element|
    full_paths.include?(element.path) &&
      element.sliceName.present? &&
      (element.patternCodeableConcept.present? ||
       element.binding.present? && element.binding.strength == 'required')
  end
end

#support_expectation(extension) ⇒ Object



68
69
70
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 68

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

#target_pathsObject



100
101
102
103
104
105
106
107
108
109
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 100

def target_paths
  return [] if param.nil?
  include_params = []

  target = param.target || []
  paths.each do |path|
    include_params.push({path: path, target: target})
  end
  include_params
end

#typeObject



90
91
92
93
94
95
96
97
98
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 90

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

#value_extractorObject



200
201
202
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 200

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

#valuesObject



143
144
145
146
147
148
149
150
151
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 143

def values
  (values_from_pattern_codeable_concept_slices +
            values_from_required_binding_slices +
            values_from_fixed_codes +
            values_from_pattern_coding +
            values_from_pattern_codeable_concept).uniq.presence ||
    value_extractor.values_from_value_set_binding(profile_element).presence ||
    value_extractor.(paths).presence || []
end

#values_from_fixed_codesObject



178
179
180
181
182
183
184
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 178

def values_from_fixed_codes
  return [] unless type == 'CodeableConcept'

  profile_elements
    .select { |element| element.path == "#{profile_element.path}.coding.code" && element.fixedCode.present? }
    .map(&:fixedCode)
end

#values_from_pattern_codeable_conceptObject



194
195
196
197
198
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 194

def values_from_pattern_codeable_concept
  return [] if type != 'CodeableConcept' || profile_element.patternCodeableConcept.blank?

  [profile_element.patternCodeableConcept.coding.first.code]
end

#values_from_pattern_codeable_concept_slicesObject



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

def values_from_pattern_codeable_concept_slices
  slices.map do |slice|
    slice.patternCodeableConcept.coding.first.code if slice.patternCodeableConcept.present?
  end.compact
end

#values_from_pattern_codingObject



186
187
188
189
190
191
192
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 186

def values_from_pattern_coding
  return [] unless type == 'CodeableConcept'

  profile_elements
    .select { |element| element.path == "#{profile_element.path}.coding" && element.patternCoding.present? }
    .map { |element| element.patternCoding.code }
end

#values_from_required_binding_slicesObject



170
171
172
173
174
175
176
# File 'lib/carin_for_blue_button_test_kit/generator/search_definition_metadata_extractor.rb', line 170

def values_from_required_binding_slices
  slices.map do |slice|
    if slice.binding.present? && slice.binding.strength == 'required'
      value_extractor.values_from_value_set_binding(slice)
    end
  end.flatten.compact
end