Class: HQMF::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/tpg/ext/value.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.time_to_ts(time) ⇒ Object

Translate a Ruby time object to an HL7 timestamp string (YYYYMMDD).

Returns:

  • An HL7 timestamp string (YYYYMMDD) equivalent to time.



6
7
8
# File 'lib/tpg/ext/value.rb', line 6

def self.time_to_ts(time)
  time.strftime("%Y%m%d%H%M%S")
end

Instance Method Details

#formatObject

Translate an HQMF Value object into a shape that HealthDataStandards understands.

Returns:

  • A Value formatted for storing a HealthDataStandards Record.



13
14
15
16
17
18
19
# File 'lib/tpg/ext/value.rb', line 13

def format
  if type == "PQ"
    { "scalar" => value, "units" => unit }
  elsif type == "TS"
    to_seconds
  end
end

#to_secondsObject

Translate the time stored in this Value into epoch seconds.

Returns:

  • Epoch seconds equivalent to the time stored in this Value.



24
25
26
27
28
# File 'lib/tpg/ext/value.rb', line 24

def to_seconds
  return nil unless type == "TS"

  to_time_object.utc.to_i
end

#to_time_objectObject

Translate the time represented by this Value into a Ruby time object.

Returns:

  • A Ruby time object equivalent to the time represented by this Value.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tpg/ext/value.rb', line 33

def to_time_object
  return nil unless type == "TS"

  year = value[0,4].to_i
  month = value[4,2].to_i
  day = value[6,2].to_i
  hour = 0
  minute = 0
  second = 0
  if (value.length > 8)
    hour = value[8,2].to_i
    minute = value[10,2].to_i
    second = value[12,2].to_i
  end
  
  Time.gm(year, month, day, hour, minute, second)
end