Class: DaVinciPlanNetTestKit::Generator::TerminologyBindingMetadataExtractor
- Inherits:
-
Object
- Object
- DaVinciPlanNetTestKit::Generator::TerminologyBindingMetadataExtractor
- Defined in:
- lib/davinci_plan_net_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_has_optional_binding_slice?(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/davinci_plan_net_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/davinci_plan_net_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/davinci_plan_net_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/davinci_plan_net_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/davinci_plan_net_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_has_optional_binding_slice?(element) ⇒ Boolean
30 31 32 |
# File 'lib/davinci_plan_net_test_kit/generator/terminology_binding_metadata_extractor.rb', line 30 def element_has_optional_binding_slice?(element) element.sliceName.present? && element.min == 0 end |
#element_terminology_bindings ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/davinci_plan_net_test_kit/generator/terminology_binding_metadata_extractor.rb', line 42 def element_terminology_bindings profile_elements_with_bindings.map do |element| binding = { 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}.", '') } if element.sliceName.present? && element.min > 0 binding[:required_binding_slice] = true end binding end end |
#extension_profile_elements ⇒ Object
60 61 62 63 64 |
# File 'lib/davinci_plan_net_test_kit/generator/terminology_binding_metadata_extractor.rb', line 60 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
66 67 68 |
# File 'lib/davinci_plan_net_test_kit/generator/terminology_binding_metadata_extractor.rb', line 66 def extension_profile_url(extension) extension.type.first.profile&.first end |
#extension_terminology_bindings ⇒ Object
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 |
# File 'lib/davinci_plan_net_test_kit/generator/terminology_binding_metadata_extractor.rb', line 70 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
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/davinci_plan_net_test_kit/generator/terminology_binding_metadata_extractor.rb', line 96 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
34 35 36 37 38 |
# File 'lib/davinci_plan_net_test_kit/generator/terminology_binding_metadata_extractor.rb', line 34 def profile_elements_with_bindings profile_elements .select { |element| element.binding.present? && element.binding.strength == 'required'} .reject { |element| element_has_fixed_value?(element) || element_has_optional_binding_slice?(element) } end |
#terminology_bindings ⇒ Object
12 13 14 15 16 17 |
# File 'lib/davinci_plan_net_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 |