Class: FHIR::ReferencesResolve
- Defined in:
- lib/rubrics/references_resolve.rb
Class Method Summary collapse
- .check_metadata(fhir_model, record) ⇒ Object
- .local_reference?(reference, record, contained) ⇒ Boolean
- .reference_matchs?(reference, entry) ⇒ Boolean
Methods inherited from Rubrics
Class Method Details
.check_metadata(fhir_model, record) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rubrics/references_resolve.rb', line 23 def self.(fhir_model,record) results = { :eligible_fields => 0, :validated_fields => 0 } # check for metadata # examine all References fhir_model.class::METADATA.each do |key, | field_name = ['local_name'] || key if ['type']=='Reference' results[:eligible_fields] += 1 value = fhir_model.instance_variable_get("@#{field_name}") # check that the field is actually the correct type if !value.nil? if value.is_a?(Array) if !value.empty? # the Array has at least one value results[:eligible_fields] += (value.length-1) value.each do |ref| results[:validated_fields] += 1 if local_reference?(ref,record,fhir_model.contained) end end else # not an Array results[:validated_fields] += 1 if local_reference?(value,record,fhir_model.contained) end end else value = fhir_model.instance_variable_get("@#{field_name}") if !value.nil? if value.is_a?(Array) value.each{|v| results.merge!((v,record)){|k,a,b|a+b} if v.is_a?(FHIR::Model)} else # not an Array results.merge!((value,record)){|k,a,b|a+b} if value.is_a?(FHIR::Model) end end end end results end |
.local_reference?(reference, record, contained) ⇒ Boolean
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rubrics/references_resolve.rb', line 62 def self.local_reference?(reference,record,contained) if contained && reference.reference && reference.reference.start_with?('#') contained.each do |resource| return true if reference.reference[1..-1]==resource.id end end record.entry.each do |entry| return true if reference_matchs?(reference,entry) end false end |
.reference_matchs?(reference, entry) ⇒ Boolean
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rubrics/references_resolve.rb', line 74 def self.reference_matchs?(reference,entry) return false if (reference.nil? || reference.reference.nil?) if reference.reference.start_with?('urn:uuid:') (reference.reference == entry.fullUrl) else # some weaknesses here: # 'Patient/20' will match both 'http://foo/Patient/20/_history/1' and 'http://foo/Patient/20303/_history/1' ((entry.fullUrl =~ /#{reference.reference}/) || (entry.resource && entry.resource.id =~ /#{reference.reference}/ )) end end |