Class: FHIR::CodesUmlsPreferredDescriptions

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

Class Method Summary collapse

Methods inherited from Rubrics

apply, response, rubric

Class Method Details

.check_coding(coding, supposed_to_be_umls, declared_binding) ⇒ Object

This method checks whether or not the coding is eligible and checks the description. A coding is eligible if it is supposed to be UMLS (as declared in the resource metadata) or it is locally declared as one of the UMLS systems. If the coding is eligible, then the description is checked against the preferred description.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rubrics/codes_umls_preferred_descriptions.rb', line 73

def self.check_coding(coding,supposed_to_be_umls,declared_binding)
  result = {
    :eligible_fields => 0,
    :correct_descriptions => 0
  } 
  if coding.nil?
    result[:eligible_fields] += 1 if supposed_to_be_umls
  else
    local_binding = coding.system || declared_binding
    if supposed_to_be_umls || FHIR::Terminology::CODE_SYSTEMS[local_binding]
      result[:eligible_fields] += 1 
      preferred = FHIR::Terminology.get_description(FHIR::Terminology::CODE_SYSTEMS[local_binding],coding.code)
      result[:correct_descriptions] +=1 if preferred==coding.display
    end
  end
  result
end

.check_fields(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
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rubrics/codes_umls_preferred_descriptions.rb', line 22

def self.check_fields(fhir_model)
  results = {
    :eligible_fields => 0,
    :correct_descriptions => 0
  }
  # check each codeable field
  fhir_model.class::METADATA.each do |key, meta|
    field_name = meta['local_name'] || key
    declared_binding = eligible_binding(meta)
    supposed_to_be_umls = !declared_binding.nil?
    value = fhir_model.instance_variable_get("@#{field_name}")

    if meta['type']=='Coding'
      if value.is_a?(Array)
        value.each do |v| 
          results.merge!(check_coding(v,supposed_to_be_umls,declared_binding)){|k,a,b|a+b}            
        end
      else
        results.merge!(check_coding(value,supposed_to_be_umls,declared_binding)){|k,a,b|a+b}
      end
    elsif meta['type']=='CodeableConcept'
      if value.is_a?(Array)
        value.each do |cc|
          cc.coding.each do |c|
            results.merge!(check_coding(c,supposed_to_be_umls,declared_binding)){|k,a,b|a+b}
          end
        end
      else
        if value.nil?
          results[:eligible_fields] += 1 if supposed_to_be_umls
        else
          value.coding.each do |c|
            results.merge!(check_coding(c,supposed_to_be_umls,declared_binding)){|k,a,b|a+b}
          end
        end
      end
    elsif !value.nil?
      if value.is_a?(Array)
        value.each{|v| results.merge!(check_fields(v)){|k,a,b|a+b} if v.is_a?(FHIR::Model)}
      else # not an Array
        results.merge!(check_fields(value)){|k,a,b|a+b} if value.is_a?(FHIR::Model)
      end
    end
  end
  results
end

.eligible_binding(metadata) ⇒ Object

This method checks the metadata on this field and returns the binding key (e.g. ‘SNOMED’) if one of the UMLS code systems was specified. Otherwise, it returns nil.



93
94
95
96
97
98
99
100
101
102
# File 'lib/rubrics/codes_umls_preferred_descriptions.rb', line 93

def self.eligible_binding()
  vs_binding = ['binding']
  matching_binding = FHIR::Terminology::CODE_SYSTEMS[vs_binding['uri']] if !vs_binding.nil? && vs_binding['uri']

  valid_codes = ['valid_codes']
  matching_code_system = valid_codes.keys.find{|k| FHIR::Terminology::CODE_SYSTEMS[k]} if !valid_codes.nil?
  matching_code_system = FHIR::Terminology::CODE_SYSTEMS[matching_code_system] if matching_code_system

  matching_binding || matching_code_system
end