class HealthDataStandards::Validate::DataValidator
Constants
- HL7_QRDA_OIDS
Public Class Methods
new(bundle, measure_ids)
click to toggle source
# File lib/health-data-standards/validate/data_validator.rb, line 51 def initialize(bundle, measure_ids) @bundle = bundle measures = @bundle.measures.in(hqmf_id: measure_ids) @oids = measures.collect{|m| m.oids}.flatten.uniq + HL7_QRDA_OIDS end
Public Instance Methods
validate(file, options={})
click to toggle source
# File lib/health-data-standards/validate/data_validator.rb, line 58 def validate(file, options={}) doc = get_document(file) doc.xpath("//*[@sdtc:valueSet]").inject([]) do |errors, node| oid = node.at_xpath("@sdtc:valueSet") vs = @bundle.value_sets.where({"oid" => oid}).first code = node.at_xpath("@code") code_system = node.at_xpath("@codeSystem") null_flavor = node.at_xpath("@nullFlavor") if !vs errors << build_error("The valueset #{oid} declared in the document cannot be found", node.path, options[:file_name]) elsif !@oids.include?(oid.value) errors << build_error("File appears to contain data criteria outside that required by the measures. Valuesets in file not in measures tested #{oid}'", node.path, options[:file_name]) elsif vs.concepts.where({"code" => code, "code_system"=>code_system}).count() == 0 if !null_flavor errors << build_error("The code #{code} in codeSystem #{code_system} cannot be found in the declared valueset #{oid}", node.path, options[:file_name]) end end errors end end