Sha256: a94285d1e84273040f96e74c464f53aff4806790dde36faaac65f7777963be09

Contents?: true

Size: 914 Bytes

Versions: 60

Compression:

Stored size: 914 Bytes

Contents

module HealthDataStandards
  module Util
    # General helpers for working with HL7 data types
    class HL7Helper
      
      # Converts an HL7 timestamp into an Integer
      # @param [String] timestamp the HL7 timestamp. Expects YYYYMMDD format
      # @return [Integer] Date in seconds since the epoch
      def self.timestamp_to_integer(timestamp)
        if timestamp && timestamp.length >= 4
          year = timestamp[0..3].to_i
          month = timestamp.length >= 6 ? timestamp[4..5].to_i : 1
          day = timestamp.length >= 8 ? timestamp[6..7].to_i : 1
          hour = timestamp.length >= 10 ? timestamp[8..9].to_i : 0
          min = timestamp.length >= 12 ? timestamp[10..11].to_i : 0
          sec = timestamp.length >= 14 ? timestamp[12..13].to_i : 0
          
          Time.gm(year, month, day, hour, min, sec).to_i
        else
          nil
        end
      end
      
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
health-data-standards-4.3.5 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.3.4 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.3.3 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.3.2 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.3.1 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.3.0 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.2.0 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.1.0 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.0.6 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.0.5 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.0.4 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.0.3 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.0.2 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.0.1 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-4.0.0 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-3.7.0 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-3.6.1 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-3.5.3 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-3.5.2 lib/health-data-standards/util/hl7_helper.rb
health-data-standards-3.5.1 lib/health-data-standards/util/hl7_helper.rb