Class: CarinForBlueButtonTestKit::Generator::TerminologyBindingMetadataExtractor
- Inherits:
-
Object
- Object
- CarinForBlueButtonTestKit::Generator::TerminologyBindingMetadataExtractor
- Defined in:
- lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb
Instance Attribute Summary collapse
-
#ig_resources ⇒ Object
Returns the value of attribute ig_resources.
-
#profile_elements ⇒ Object
Returns the value of attribute profile_elements.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
- #element_has_fixed_value?(element) ⇒ Boolean
- #element_terminology_bindings ⇒ Object
- #extension_profile_elements ⇒ Object
- #extension_profile_url(extension) ⇒ Object
- #extension_terminology_bindings ⇒ Object
-
#initialize(profile_elements, ig_resources, resource) ⇒ TerminologyBindingMetadataExtractor
constructor
A new instance of TerminologyBindingMetadataExtractor.
- #nested_extension_terminology_bindings(elements, extension_url) ⇒ Object
- #profile_elements_with_bindings ⇒ Object
- #terminology_bindings ⇒ Object
Constructor Details
#initialize(profile_elements, ig_resources, resource) ⇒ TerminologyBindingMetadataExtractor
Returns a new instance of TerminologyBindingMetadataExtractor.
6 7 8 9 10 |
# File 'lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb', line 6 def initialize(profile_elements, ig_resources, resource) self.profile_elements = profile_elements self.ig_resources = ig_resources self.resource = resource end |
Instance Attribute Details
#ig_resources ⇒ Object
Returns the value of attribute ig_resources.
4 5 6 |
# File 'lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb', line 4 def ig_resources @ig_resources end |
#profile_elements ⇒ Object
Returns the value of attribute profile_elements.
4 5 6 |
# File 'lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb', line 4 def profile_elements @profile_elements end |
#resource ⇒ Object
Returns the value of attribute resource.
4 5 6 |
# File 'lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb', line 4 def resource @resource end |
Instance Method Details
#element_has_fixed_value?(element) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb', line 19 def element_has_fixed_value?(element) case element.type.first.code when 'Quantity' code = profile_elements.find { |e| e.path == "#{element.path}.code" } system = profile_elements.find { |e| e.path == "#{element.path}.system" } code&.fixedCode || system&.fixedUri when 'code' element.fixedCode.present? end end |
#element_terminology_bindings ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb', line 36 def element_terminology_bindings profile_elements_with_bindings.map do |element| { type: element.type.first.code, strength: element.binding.strength, # Goal.target.detail has an unbound binding system: element.binding.valueSet&.split('|')&.first, path: element.path.gsub('[x]', '').gsub("#{resource}.", '') } end end |
#extension_profile_elements ⇒ Object
48 49 50 51 52 |
# File 'lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb', line 48 def extension_profile_elements profile_elements .select { |element| element.type&.first&.code == 'Extension' } .select { |element| extension_profile_url(element).present? } end |
#extension_profile_url(extension) ⇒ Object
54 55 56 |
# File 'lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb', line 54 def extension_profile_url(extension) extension.type.first.profile&.first end |
#extension_terminology_bindings ⇒ Object
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 |
# File 'lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb', line 58 def extension_terminology_bindings extension_profile_elements .flat_map do |extension_profile_element| url = extension_profile_url(extension_profile_element) extension = ig_resources.profile_by_url(url) # TODO: Temporaray fix for extension defined out of US Core. FI-1623 next if extension.nil? elements = extension.snapshot.element elements_with_bindings = elements.select do |element| element.binding.present? && !element.id.include?('Extension.extension') end elements_with_bindings.map do |element| { type: element.type.first.code, strength: element.binding.strength, system: element.binding.valueSet&.split('|')&.first, path: element.path.gsub('[x]', '').gsub('Extension.', ''), extensions: [url] } end + nested_extension_terminology_bindings(elements, url) end end |
#nested_extension_terminology_bindings(elements, extension_url) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb', line 84 def nested_extension_terminology_bindings(elements, extension_url) nested_extensions = elements.select { |element| element.path == 'Extension.extension' } nested_extensions.flat_map do |nested_extension| nested_extension_element = elements.find { |element| element.id == "#{nested_extension.id}.url" } next unless nested_extension_element.present? nested_extension_url = nested_extension_element.fixedUri nested_elements_with_bindings = elements.select do |element| element.id.include?(nested_extension.id) && element.binding.present? end nested_elements_with_bindings.map do |element| { type: element.type.first.code, strength: element.binding.strength, system: element.binding.valueSet&.split('|')&.first, path: element.path.gsub('[x]', '').gsub('Extension.extension.', ''), extensions: [extension_url, nested_extension_url] } end end end |
#profile_elements_with_bindings ⇒ Object
30 31 32 33 34 |
# File 'lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb', line 30 def profile_elements_with_bindings profile_elements .select { |element| element.binding.present? } .reject { |element| element_has_fixed_value? element } end |
#terminology_bindings ⇒ Object
12 13 14 15 16 17 |
# File 'lib/carin_for_blue_button_test_kit/generator/terminology_binding_metadata_extractor.rb', line 12 def terminology_bindings (element_terminology_bindings + extension_terminology_bindings).compact # add_terminology_bindings_from_extensions # profile_elements.select { |element| element.type&.first&.code == 'Extension' } # .each { |extension| add_terminology_bindings_from_extension(extension) } end |