Class: HQMF::Value
- Inherits:
-
Object
- Object
- HQMF::Value
- Defined in:
- lib/tpg/ext/value.rb
Class Method Summary collapse
-
.time_to_ts(time) ⇒ Object
Translate a Ruby time object to an HL7 timestamp string (YYYYMMDD).
Instance Method Summary collapse
-
#format ⇒ Object
Translate an HQMF Value object into a shape that HealthDataStandards understands.
-
#to_seconds ⇒ Object
Translate the time stored in this Value into epoch seconds.
-
#to_time_object ⇒ Object
Translate the time represented by this Value into a Ruby time object.
Class Method Details
.time_to_ts(time) ⇒ Object
Translate a Ruby time object to an HL7 timestamp string (YYYYMMDD).
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
#format ⇒ Object
Translate an HQMF Value object into a shape that HealthDataStandards understands.
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_seconds ⇒ Object
Translate the time stored in this Value into epoch seconds.
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_object ⇒ Object
Translate the time represented by this Value into a Ruby time object.
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 |