From fd954a811412c31673fe5103b159160e0d665d02 Mon Sep 17 00:00:00 2001 From: Yunwei Wang <> Date: Thu, 29 Aug 2024 15:16:41 -0500 Subject: [PATCH] Move vs_validator to CommonStructureDefinition --- .../fhir_ext/common_structure_definition.rb | 35 +++++++++++-------- .../r4/fhir_ext/structure_definition.rb | 13 ------- .../r4b/fhir_ext/structure_definition.rb | 14 -------- 3 files changed, 21 insertions(+), 41 deletions(-) diff --git a/lib/fhir_models/fhir_ext/common_structure_definition.rb b/lib/fhir_models/fhir_ext/common_structure_definition.rb index 6d30e3ff..6ceadc14 100644 --- a/lib/fhir_models/fhir_ext/common_structure_definition.rb +++ b/lib/fhir_models/fhir_ext/common_structure_definition.rb @@ -5,27 +5,34 @@ module FHIR module CommonStructureDefinition - extend FHIR::Deprecate - # ------------------------------------------------------------------------- - # Profile Validation - # ------------------------------------------------------------------------- - class << self; attr_accessor :vs_validators end - @vs_validators = {} - - def validates_vs(valueset_uri, &validator_fn) - @vs_validators[valueset_uri] = validator_fn + def self.included(base) + base.extend ClassMethods end - def clear_validates_vs(valueset_uri) - @vs_validators.delete valueset_uri - end + module ClassMethods + def vs_validators + @vs_validators ||= {} + end + + def validates_vs(valueset_uri, &validator_fn) + vs_validators[valueset_uri] = validator_fn + end + + def clear_validates_vs(valueset_uri) + vs_validators.delete valueset_uri + end - def clear_all_validates_vs - @vs_validators = {} + def clear_all_validates_vs + @vs_validators = {} + end end + # ------------------------------------------------------------------------- + # Profile Validation + # ------------------------------------------------------------------------- + def validates_resource?(resource) validate_resource(resource).empty? end diff --git a/lib/fhir_models/r4/fhir_ext/structure_definition.rb b/lib/fhir_models/r4/fhir_ext/structure_definition.rb index 5e9bc712..e2832d5e 100644 --- a/lib/fhir_models/r4/fhir_ext/structure_definition.rb +++ b/lib/fhir_models/r4/fhir_ext/structure_definition.rb @@ -2,20 +2,7 @@ module FHIR module R4 class StructureDefinition include CommonStructureDefinition - class << self; attr_accessor :vs_validators end - @vs_validators = {} - def self.validates_vs(valueset_uri, &validator_fn) - @vs_validators[valueset_uri] = validator_fn - end - - def self.clear_validates_vs(valueset_uri) - @vs_validators.delete valueset_uri - end - - def self.clear_all_validates_vs - @vs_validators = {} - end attr_accessor :finding attr_accessor :errors attr_accessor :warnings diff --git a/lib/fhir_models/r4b/fhir_ext/structure_definition.rb b/lib/fhir_models/r4b/fhir_ext/structure_definition.rb index 6cdd5411..79ff1dd2 100644 --- a/lib/fhir_models/r4b/fhir_ext/structure_definition.rb +++ b/lib/fhir_models/r4b/fhir_ext/structure_definition.rb @@ -2,20 +2,6 @@ module FHIR module R4B class StructureDefinition include CommonStructureDefinition - class << self; attr_accessor :vs_validators end - @vs_validators = {} - - def self.validates_vs(valueset_uri, &validator_fn) - @vs_validators[valueset_uri] = validator_fn - end - - def self.clear_validates_vs(valueset_uri) - @vs_validators.delete valueset_uri - end - - def self.clear_all_validates_vs - @vs_validators = {} - end attr_accessor :finding attr_accessor :errors