Class: CqmValidators::DataValidator

Inherits:
Object
  • Object
show all
Includes:
BaseValidator
Defined in:
lib/data_validator.rb

Constant Summary collapse

HL7_QRDA_OIDS =
['2.16.840.1.113883.3.221.5',
'2.16.840.1.113883.3.88.12.3221.8.7',
'2.16.840.1.113883.3.88.12.3221.8.9',
'2.16.840.1.113883.1.11.12839',
'2.16.840.1.113883.3.88.12.3221.8.11',
'2.16.840.1.113883.3.88.12.3221.6.2',
'2.16.840.1.113883.11.20.9.40',
'2.16.840.1.113883.11.20.9.23',
'2.16.840.1.113883.3.88.12.3221.7.4',
'2.16.840.1.113883.11.20.9.18',
'2.16.840.1.113883.11.20.9.22',
'2.16.840.1.113883.1.11.16866',
'2.16.840.1.113883.1.11.20275',
'2.16.840.1.113883.11.20.9.34',
'2.16.840.1.113883.3.88.12.3221.7.2',
'2.16.840.1.113883.3.88.12.80.17',
'2.16.840.1.113883.3.88.12.80.22',
'2.16.840.1.113883.3.88.12.80.64',
'2.16.840.1.113883.3.88.12.3221.6.8',
'2.16.840.1.113883.1.11.78',
'2.16.840.1.113883.11.20.9.25',
'2.16.840.1.113883.11.20.9.39',
'2.16.840.1.113883.3.88.12.80.32',
'2.16.840.1.113883.11.20.9.21',
'2.16.840.1.113883.3.88.12.80.68',
'2.16.840.1.113883.1.11.20.12',
'2.16.840.1.113883.11.20.9.24',
'2.16.840.1.113883.11.20.9.41',
'2.16.840.1.113883.1.11.16926',
'2.16.840.1.113883.1.11.12212',
'2.16.840.1.113883.1.11.19185',
'2.16.840.1.113883.1.11.14914',
'2.16.840.1.114222.4.11.837',
'2.16.840.1.113883.1.11.19563',
'2.16.840.1.113883.1.11.11526',
'2.16.840.1.113883.11.20.9.20',
'2.16.840.1.113883.3.88.12.80.2',
'2.16.840.1.113883.3.88.12.80.63',
'2.16.840.1.113883.1.11.12249',
'2.16.840.1.113883.1.11.1',
'2.16.840.1.113883.1.11.12199',
'2.16.840.1.113883.11.20.9.33',
'2.16.840.1.114222.4.11.1066',
'2.16.840.1.113883.1.11.19579'].freeze

Instance Method Summary collapse

Methods included from BaseValidator

#build_error, #get_document

Constructor Details

#initialize(measure_ids) ⇒ DataValidator

Returns a new instance of DataValidator.



52
53
54
55
# File 'lib/data_validator.rb', line 52

def initialize(measure_ids)
  measures = CQM::Measure.find(measure_ids)
  @value_set_ids = measures.collect { |m| m.value_sets.map(&:_id) }.flatten.uniq
end

Instance Method Details

#validate(file, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/data_validator.rb', line 57

def validate(file, options = {})
  doc = get_document(file)

  doc.xpath('//*[@sdtc:valueSet]').each_with_object([]) do |node, errors|
    oid = node.at_xpath('@sdtc:valueSet')
    vs = CQM::ValueSet.where('oid' => oid, '_id' => { '$in' => @value_set_ids }).first
    next unless vs

    code = node.at_xpath('@code')
    code_system_oid = node.at_xpath('@codeSystem')
    null_flavor = node.at_xpath('@nullFlavor')
    next unless vs.concepts.where(code: code, code_system_oid: code_system_oid).count.zero?

    unless null_flavor
      errors << build_error("The code #{code} in codeSystem #{code_system_oid} cannot be found in the declared valueset #{oid}",
                            node.path, options[:file_name])
    end
  end
end