Skip to content

Commit

Permalink
Move vs_validator to CommonStructureDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunwei Wang committed Aug 29, 2024
1 parent 8aca25d commit fd954a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 41 deletions.
35 changes: 21 additions & 14 deletions lib/fhir_models/fhir_ext/common_structure_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions lib/fhir_models/r4/fhir_ext/structure_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions lib/fhir_models/r4b/fhir_ext/structure_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fd954a8

Please sign in to comment.