Sha256: 5a5abd05dbec2c78d49c21df53e991a5cabfa0b023ffbe6c85c28266dba625bd

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

class Entry

  include Mongoid::Document

  embedded_in :entry_list, polymorphic: true

  field :description, type: String
  field :time, type: Integer
  field :start_time, type: Integer
  field :end_time, type: Integer
  field :status, type: Symbol
  field :codes, type: Hash
  field :value, type: Hash

  def single_code_value?
    codes.size == 1 && codes.first[1].size == 1
  end

  def codes_to_s
    codes.map {|code_set, codes| "#{code_set}: #{codes.join(', ')}"}.join(' ')
  end
  
  def times_to_s
    if start_time.present? || end_time.present?
      start_string = start_time ? Time.at(start_time).to_formatted_s(:long_ordinal) : 'UNK'
      end_string = end_time ? Time.at(end_time).to_formatted_s(:long_ordinal) : 'UNK'
      "#{start_string} - #{end_string}"
    elsif time.present?
      Time.at(time).to_formatted_s(:long_ordinal)
    end
  end
  
  def to_effective_time(xml)
    if time.present?
      xml.effectiveTime("value" => Time.at(time).utc.to_formatted_s(:number))
    else
      xml.effectiveTime do
        if start_time.present?
          xml.low("value" => Time.at(start_time).utc.to_formatted_s(:number))
        else
          xml.low("nullFlavor" => "UNK")
        end
        if end_time.present?
          xml.high("value" => Time.at(end_time).utc.to_formatted_s(:number))          
        else
          xml.high("nullFlavor" => "UNK")          
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
health-data-standards-0.3.0 lib/health-data-standards/models/entry.rb
health-data-standards-0.2.0 lib/health-data-standards/models/entry.rb
health-data-standards-0.1.0 lib/health-data-standards/models/entry.rb