Class: DaVinciUSDrugFormularyTestKit::Generator::GroupMetadataExtractor
- Inherits:
-
Object
- Object
- DaVinciUSDrugFormularyTestKit::Generator::GroupMetadataExtractor
- Defined in:
- lib/davinci_us_drug_formulary_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
- #add_must_support_choices ⇒ Object
- #base_name ⇒ Object
- #class_name ⇒ Object
- #element_references ⇒ Object
- #extension_references ⇒ Object
- #filter_drug_values ⇒ Object
-
#first_search_params ⇒ Object
BEGIN SPECIAL CASES ###.
- #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
def bindings @bindings ||= terminology_binding_metadata_extractor.terminology_bindings end.
- #must_supports ⇒ Object
- #name ⇒ Object
- #parents_are_mandatory?(element) ⇒ Boolean
-
#profile ⇒ Object
END SPECIAL CASES ###.
- #profile_elements ⇒ Object
- #profile_name ⇒ Object
- #profile_version ⇒ Object
- #references ⇒ Object
- #reformatted_version ⇒ Object
- #resource ⇒ Object
- #search_definitions ⇒ Object
-
#search_metadata_extractor ⇒ Object
def operations @operations ||= resource_capabilities.operation.map do |operation| { code: operation.name, expectation: operation.extension.first.valueCode # TODO: fix expectation extension finding } end end.
- #searches ⇒ Object
- #set_first_search ⇒ Object
- #short_description ⇒ Object
- #title ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(resource_capabilities, profile_url, ig_metadata, ig_resources) ⇒ GroupMetadataExtractor
Returns a new instance of GroupMetadataExtractor.
12 13 14 15 16 17 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 12 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.
10 11 12 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 10 def @ig_metadata end |
#ig_resources ⇒ Object
Returns the value of attribute ig_resources.
10 11 12 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 10 def ig_resources @ig_resources end |
#profile_url ⇒ Object
Returns the value of attribute profile_url.
10 11 12 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 10 def profile_url @profile_url end |
#resource_capabilities ⇒ Object
Returns the value of attribute resource_capabilities.
10 11 12 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 10 def resource_capabilities @resource_capabilities end |
Instance Method Details
#add_must_support_choices ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 143 def add_must_support_choices choices = [] case profile.type when 'Location' choices << { paths: ['address'], extension_ids: ['Location.extension:region'] } end must_supports[:choices] = choices if choices.present? end |
#base_name ⇒ Object
164 165 166 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 164 def base_name profile_url.split('StructureDefinition/').last end |
#class_name ⇒ Object
172 173 174 175 176 177 178 179 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 172 def class_name base_name .split('-') .map(&:capitalize) .join .gsub('USDF', "USDF#{.reformatted_version}") .concat('Sequence') end |
#element_references ⇒ Object
292 293 294 295 296 297 298 299 300 301 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 292 def element_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 |
#extension_references ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 303 def extension_references profile_elements .select { |element| element.type.any? { |type| type.code == 'Extension' && type.profile.present? } } .map do |element| extension_url = element.type.first.profile.first target_profiles = ig_resources .profile_by_url(extension_url) &.snapshot &.element &.find { |profile_element| profile_element.id == 'Extension.value[x]:valueReference' } &.type &.first &.targetProfile next if target_profiles.blank? { path: "#{element.path}.where(url='#{extension_url}').valueReference", target_profiles: } end.compact end |
#filter_drug_values ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 134 def filter_drug_values search_definitions[:doseform][:values] = [] unless search_definitions[:doseform].nil? return if search_definitions[:code].nil? return unless search_definitions[:code][:full_paths] == ['MedicationKnowledge.code'] search_definitions[:code][:values] = [] end |
#first_search_params ⇒ Object
BEGIN SPECIAL CASES ###
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 109 def first_search_params @first_search_params ||= if resource == 'Location' ['_id'] elsif resource == 'Basic' ['code'] else ['status'] end end |
#group_metadata ⇒ Object
19 20 21 22 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 19 def @group_metadata ||= GroupMetadata.new() end |
#group_metadata_hash ⇒ Object
24 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 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 24 def @group_metadata_hash ||= { name:, class_name:, version:, reformatted_version:, resource:, profile_url:, profile_name:, profile_version:, title:, short_description:, interactions:, # operations: operations, searches:, # searches: searches, search_definitions:, # search_definitions: search_definitions include_params:, # revincludes: revincludes, must_supports:, mandatory_elements:, # bindings: bindings, references: } mark_mandatory_and_must_support_searches handle_special_cases @group_metadata_hash end |
#handle_special_cases ⇒ Object
120 121 122 123 124 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 120 def handle_special_cases set_first_search filter_drug_values add_must_support_choices end |
#include_params ⇒ Object
243 244 245 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 243 def include_params resource_capabilities.searchInclude || [] end |
#interactions ⇒ Object
210 211 212 213 214 215 216 217 218 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 210 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
271 272 273 274 275 276 277 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 271 def mandatory_elements @mandatory_elements ||= profile_elements .select { |element| element.min.positive? && parents_are_mandatory?(element) } .map(&:path) .uniq end |
#mark_mandatory_and_must_support_searches ⇒ Object
55 56 57 58 59 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 97 98 99 100 101 102 103 104 105 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 55 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] .map { |path| path.gsub(/\AResource\./, "#{resource}.") } # Fix for Resource.meta.* 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_must_support_extensions = must_supports[:extensions].any? do |extension| full_must_support_paths = ["#{resource}.#{extension[:path]}.where(url='#{extension[:url]}').value"] full_paths.any? { |path| full_must_support_paths.include?(path) } end any_mandatory_elements = mandatory_elements.any? do |element| full_paths.include?(element) end any_must_support_elements || any_must_support_slices || any_must_support_extensions || any_mandatory_elements end search[:must_support_or_mandatory] = search[:names_not_must_support_or_mandatory].empty? end end |
#must_support_metadata_extractor ⇒ Object
def bindings
@bindings ||=
.terminology_bindings
end
261 262 263 264 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 261 def @must_support_metadata_extractor ||= MustSupportMetadataExtractor.new(profile_elements, profile, resource, ig_resources) end |
#must_supports ⇒ Object
266 267 268 269 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 266 def must_supports @must_supports ||= .must_supports end |
#name ⇒ Object
168 169 170 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 168 def name base_name.tr('-', '_') end |
#parents_are_mandatory?(element) ⇒ Boolean
279 280 281 282 283 284 285 286 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 279 def parents_are_mandatory?(element) return true if element.path.count('.') < 2 parent_path = element.path.split('.')[0..-2].join('.') parent_element = profile_elements.find { |profile_element| profile_element.path == parent_path } parent_element&.min&.positive? && parents_are_mandatory?(parent_element) end |
#profile ⇒ Object
END SPECIAL CASES ###
156 157 158 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 156 def profile @profile ||= ig_resources.profile_by_url(profile_url) end |
#profile_elements ⇒ Object
160 161 162 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 160 def profile_elements @profile_elements ||= profile.snapshot.element end |
#profile_name ⇒ Object
193 194 195 196 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 193 def profile_name binding.pry if profile.nil? profile.title.gsub(' ', ' ') end |
#profile_version ⇒ Object
198 199 200 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 198 def profile_version profile.version end |
#references ⇒ Object
288 289 290 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 288 def references @references ||= element_references + extension_references end |
#reformatted_version ⇒ Object
185 186 187 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 185 def reformatted_version .reformatted_version end |
#resource ⇒ Object
189 190 191 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 189 def resource resource_capabilities.type end |
#search_definitions ⇒ Object
239 240 241 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 239 def search_definitions @search_definitions ||= .search_definitions end |
#search_metadata_extractor ⇒ Object
def operations
@operations ||=
resource_capabilities.operation.map do |operation|
{
code: operation.name,
expectation: operation.extension.first.valueCode # TODO: fix expectation extension finding
}
end
end
230 231 232 233 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 230 def @search_metadata_extractor ||= SearchMetadataExtractor.new(resource_capabilities, ig_resources, resource, profile_elements) end |
#searches ⇒ Object
235 236 237 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 235 def searches @searches ||= .searches end |
#set_first_search ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 126 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
206 207 208 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 206 def short_description "Verify support for the server capabilities required by the #{profile_name}." end |
#title ⇒ Object
202 203 204 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 202 def title profile.title.gsub(/US\s*Core\s*/, '').gsub(/\s*Profile/, '').strip end |
#version ⇒ Object
181 182 183 |
# File 'lib/davinci_us_drug_formulary_test_kit/generator/group_metadata_extractor.rb', line 181 def version .ig_version end |