Sha256: afe09a3655c1d1e8f91741f5e8b806783e7c6a499840da43d19949707779d136

Contents?: true

Size: 1.24 KB

Versions: 45

Compression:

Stored size: 1.24 KB

Contents

module HQMF1
  
  class Expression
  
    include HQMF1::Utilities
    
    attr_reader :text, :value, :type
  
    def initialize(entry)
      @entry = entry
      @text = @entry.xpath('./*/cda:derivationExpr').text.strip
      type = attr_val('./*/cda:value/@xsi:type')
      case type
      when 'IVL_PQ'
        @value = Range.new(@entry.xpath('./*/cda:value'))
      when 'PQ'
        @value = Value.new(@entry.xpath('./*/cda:value'))
      when 'ANYNonNull'
        @value = HQMF::AnyValue.new
      when nil
        @value = HQMF::AnyValue.new
      else
        raise "Unknown expression value type #{type}"
      end
      @type = match_type
    end
    
    def match_type
      case @text
        when /^COUNT(.*)$/
          "COUNT"
        when /^MIN(.*)$/
          "MIN"
        when /^MAX(.*)$/
          "MAX"
        when /^DATEDIFF(.*)$/
          "DATEDIFF"
        when /^TIMEDIFF(.*)$/
          "TIMEDIFF"
        when /^MEDIAN(.*)$/
          "MEDIAN"
        when /^AVG(.*)$/
          "MEAN"
        else
          raise "unknown expression type: #{@text}"
      end
    end
    
    def to_json
      
      json = build_hash(self, [:text,:type])
      json[:value] = self.value.to_json if self.value
      json
      
    end
    
  end
  
  
end

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
health-data-standards-3.5.0 lib/hqmf-parser/1.0/expression.rb
health-data-standards-3.4.6 lib/hqmf-parser/1.0/expression.rb
health-data-standards-3.4.5 lib/hqmf-parser/1.0/expression.rb
health-data-standards-3.4.4 lib/hqmf-parser/1.0/expression.rb
health-data-standards-3.4.3 lib/hqmf-parser/1.0/expression.rb