Class: USCoreTestKit::Generator::GroupMetadataExtractor
- Inherits:
-
Object
- Object
- USCoreTestKit::Generator::GroupMetadataExtractor
- Defined in:
- lib/us_core_test_kit/generator/group_metadata_extractor.rb
Instance Attribute Summary collapse
-
#ig_metadata ⇒ Object
Returns the value of attribute ig_metadata.
-
#ig_resources ⇒ Object
Returns the value of attribute ig_resources.
-
#profile_url ⇒ Object
Returns the value of attribute profile_url.
-
#resource_capabilities ⇒ Object
Returns the value of attribute resource_capabilities.
Instance Method Summary collapse
- #base_name ⇒ Object
- #bindings ⇒ Object
-
#category_first_profile? ⇒ Boolean
BEGIN SPECIAL CASES ###.
- #class_name ⇒ Object
- #first_search_params ⇒ Object
- #group_metadata ⇒ Object
- #group_metadata_hash ⇒ Object
- #handle_special_cases ⇒ Object
- #include_params ⇒ Object
-
#initialize(resource_capabilities, profile_url, ig_metadata, ig_resources) ⇒ GroupMetadataExtractor
constructor
A new instance of GroupMetadataExtractor.
- #interactions ⇒ Object
- #mandatory_elements ⇒ Object
- #mark_mandatory_and_must_support_searches ⇒ Object
- #must_support_metadata_extractor ⇒ Object
- #must_supports ⇒ Object
- #name ⇒ Object
- #operations ⇒ Object
-
#profile ⇒ Object
END SPECIAL CASES ###.
- #profile_elements ⇒ Object
- #profile_name ⇒ Object
- #profile_version ⇒ Object
- #references ⇒ Object
- #reformatted_version ⇒ Object
- #required_concepts ⇒ Object
- #resource ⇒ Object
- #resource_conformance_expectation ⇒ Object
- #revincludes ⇒ Object
- #search_definitions ⇒ Object
- #search_metadata_extractor ⇒ Object
- #searches ⇒ Object
- #set_first_search ⇒ Object
- #short_description ⇒ Object
- #terminology_binding_metadata_extractor ⇒ Object
- #title ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(resource_capabilities, profile_url, ig_metadata, ig_resources) ⇒ GroupMetadataExtractor
Returns a new instance of GroupMetadataExtractor.
13 14 15 16 17 18 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 13 def initialize(resource_capabilities, profile_url, , ig_resources) self.resource_capabilities = resource_capabilities self.profile_url = profile_url self. = self.ig_resources = ig_resources end |
Instance Attribute Details
#ig_metadata ⇒ Object
Returns the value of attribute ig_metadata.
11 12 13 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 11 def @ig_metadata end |
#ig_resources ⇒ Object
Returns the value of attribute ig_resources.
11 12 13 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 11 def ig_resources @ig_resources end |
#profile_url ⇒ Object
Returns the value of attribute profile_url.
11 12 13 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 11 def profile_url @profile_url end |
#resource_capabilities ⇒ Object
Returns the value of attribute resource_capabilities.
11 12 13 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 11 def resource_capabilities @resource_capabilities end |
Instance Method Details
#base_name ⇒ Object
142 143 144 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 142 def base_name profile_url.split('StructureDefinition/').last end |
#bindings ⇒ Object
259 260 261 262 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 259 def bindings @bindings ||= .terminology_bindings end |
#category_first_profile? ⇒ Boolean
BEGIN SPECIAL CASES ###
99 100 101 102 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 99 def category_first_profile? SpecialCases::ALL_VERSION_CATEGORY_FIRST_PROFILES.include?(profile_url) || SpecialCases::VERSION_SPECIFIC_CATEGORY_FIRST_PROFILES[profile_url]&.include?(reformatted_version) end |
#class_name ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 150 def class_name base_name .split('-') .map(&:capitalize) .join .gsub('UsCore', "USCore#{.reformatted_version}") .concat('Sequence') end |
#first_search_params ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 104 def first_search_params @first_search_params ||= if category_first_profile? || (profile_url.end_with?('us-core-adi-documentreference') && profile_version.to_i > 7) ['patient', 'category'] elsif resource == 'Observation' ['patient', 'code'] elsif resource == 'MedicationRequest' ['patient', 'intent'] elsif resource == 'CareTeam' ['patient', 'status'] else ['patient'] end end |
#group_metadata ⇒ Object
20 21 22 23 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 20 def @group_metadata ||= GroupMetadata.new() end |
#group_metadata_hash ⇒ Object
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 58 |
# File 'lib/us_core_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, resource_conformance_expectation: resource_conformance_expectation # tests: [] } mark_mandatory_and_must_support_searches handle_special_cases @group_metadata_hash end |
#handle_special_cases ⇒ Object
120 121 122 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 120 def handle_special_cases set_first_search end |
#include_params ⇒ Object
234 235 236 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 234 def include_params resource_capabilities.searchInclude || [] end |
#interactions ⇒ Object
193 194 195 196 197 198 199 200 201 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 193 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_elements ⇒ Object
274 275 276 277 278 279 280 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 274 def mandatory_elements @mandatory_elements ||= profile_elements .select { |element| element.min.positive? } .map { |element| element.path } .uniq end |
#mark_mandatory_and_must_support_searches ⇒ Object
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 96 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 60 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_extractor ⇒ Object
264 265 266 267 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 264 def @must_support_metadata_extractor ||= MustSupportMetadataExtractor.new(profile_elements, profile, resource, ig_resources) end |
#must_supports ⇒ Object
269 270 271 272 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 269 def must_supports @must_supports ||= .must_supports end |
#name ⇒ Object
146 147 148 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 146 def name base_name.tr('-', '_') end |
#operations ⇒ Object
203 204 205 206 207 208 209 210 211 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 203 def operations @operations ||= resource_capabilities.operation.map do |operation| { code: operation.name, expectation: operation.extension.first.valueCode # TODO: fix expectation extension finding } end end |
#profile ⇒ Object
END SPECIAL CASES ###
134 135 136 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 134 def profile @profile ||= ig_resources.profile_by_url(profile_url) end |
#profile_elements ⇒ Object
138 139 140 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 138 def profile_elements @profile_elements ||= profile.snapshot.element end |
#profile_name ⇒ Object
171 172 173 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 171 def profile_name profile.title.gsub(' ', ' ') end |
#profile_version ⇒ Object
175 176 177 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 175 def profile_version profile.version end |
#references ⇒ Object
282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 282 def references @references ||= profile_elements .select { |element| element.type&.first&.code == 'Reference' } .map do |reference_definition| { path: reference_definition.path, profiles: reference_definition.type.first.targetProfile } end end |
#reformatted_version ⇒ Object
163 164 165 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 163 def reformatted_version .reformatted_version end |
#required_concepts ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 242 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') } .uniq end |
#resource ⇒ Object
167 168 169 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 167 def resource resource_capabilities.type end |
#resource_conformance_expectation ⇒ Object
294 295 296 297 298 299 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 294 def resource_conformance_expectation @resource_conformance_expectation ||= resource_capabilities.extension.find do |extension| extension.url == 'http://hl7.org/fhir/StructureDefinition/capabilitystatement-expectation' end&.valueCode end |
#revincludes ⇒ Object
238 239 240 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 238 def revincludes resource_capabilities.searchRevInclude || [] end |
#search_definitions ⇒ Object
230 231 232 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 230 def search_definitions @search_definitions ||= .search_definitions end |
#search_metadata_extractor ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 213 def @search_metadata_extractor ||= SearchMetadataExtractor.new( resource_capabilities, ig_resources, profile_elements, { resource: resource, profile_url: profile_url, must_supports: must_supports } ) end |
#searches ⇒ Object
226 227 228 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 226 def searches @searches ||= .searches end |
#set_first_search ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 124 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_description ⇒ Object
189 190 191 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 189 def short_description "Verify support for the server capabilities required by the #{profile_name}." end |
#terminology_binding_metadata_extractor ⇒ Object
254 255 256 257 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 254 def @terminology_binding_metadata_extractor ||= TerminologyBindingMetadataExtractor.new(profile_elements, ig_resources, resource) end |
#title ⇒ Object
179 180 181 182 183 184 185 186 187 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 179 def title title = profile.title.gsub(/US\s*Core\s*/, '').gsub(/\s*Profile/, '').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(' ') end title end |
#version ⇒ Object
159 160 161 |
# File 'lib/us_core_test_kit/generator/group_metadata_extractor.rb', line 159 def version .ig_version end |