module HealthCards::AttributeFilters
Handles behavior related to removing disallowed attributes from FHIR Resources
Constants
- ALL_FHIR_RESOURCES
Public Class Methods
included(base)
click to toggle source
# File lib/health_cards/attribute_filters.rb, line 8 def self.included(base) base.extend ClassMethods end
Public Instance Methods
handle_allowable(resource)
click to toggle source
# File lib/health_cards/attribute_filters.rb, line 59 def handle_allowable(resource) class_allowables = self.class.allowable[resource.class] return unless class_allowables allowed = resource.to_hash.select! { |att| class_allowables.include?(att) } resource.from_hash(allowed) end
handle_disallowable(resource)
click to toggle source
# File lib/health_cards/attribute_filters.rb, line 69 def handle_disallowable(resource) class_disallowable = find_subclass_keys(self.class.disallowable, resource) return if class_disallowable.empty? all_disallowed = class_disallowable.map do |disallowed_class| self.class.disallowable[disallowed_class] end.flatten.uniq allowed = resource.to_hash.delete_if { |att| all_disallowed.include?(att) } resource.from_hash(allowed) end
Protected Instance Methods
find_subclass_keys(hash, resource)
click to toggle source
# File lib/health_cards/attribute_filters.rb, line 85 def find_subclass_keys(hash, resource) subclasses = hash.keys.filter { |class_key| class_key.is_a?(Class) && resource.class <= class_key } # No great way to determine if this is an actual FHIR resource subclasses << ALL_FHIR_RESOURCES if resource.respond_to?(:resourceType) subclasses end