Class: FHIR::DateTimesIso8601

Inherits:
Rubrics
  • Object
show all
Defined in:
lib/rubrics/datetimes_iso8601.rb

Class Method Summary collapse

Methods inherited from Rubrics

apply, response, rubric

Class Method Details

.check_metadata(fhir_model) ⇒ Object



22
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
# File 'lib/rubrics/datetimes_iso8601.rb', line 22

def self.(fhir_model)
  results = {
    :datetime_fields => 0,
    :iso8601_fields => 0
  }
  # check for metadata
  # count all codeable fields
  fhir_model.class::METADATA.each do |key, meta|
    field_name = meta['local_name'] || key
    if ['date','time','dateTime','instant'].include?(meta['type'])
      results[:datetime_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[:iso8601_fields] += 1 if value.any?{|x|type_okay(meta['type'],x)}
          end
        else # not an Array
          results[:iso8601_fields] += 1 if type_okay(meta['type'],value)
        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)){|k,a,b|a+b} if v.is_a?(FHIR::Model)}
        else # not an Array
          results.merge!((value)){|k,a,b|a+b} if value.is_a?(FHIR::Model)
        end
      end            
    end
  end
  results
end

.type_okay(type, item) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rubrics/datetimes_iso8601.rb', line 58

def self.type_okay(type,item)
  okay = false
  begin
    time = Time.iso8601(item)
    okay = true
    if time.year
      okay = (time.year > 1900) && (time.year < (Time.now + (10 * 365 * 24 * 60 * 60)).year)
    end
  rescue Exception => e
    okay = false
  end
  okay
end