class Header

Attributes

machine_name[RW]
patients[RW]
protocol[RW]
queries[RW]
response_sent[RW]

Public Class Methods

new(args={}) click to toggle source
# File lib/ruby_astm/header.rb, line 21
def initialize(args={})
        self.patients = []
        self.queries = []
        self.response_sent = false
        if line = args[:line]
                set_machine_name(args)
                set_protocol(args)
        end
end

Public Instance Methods

build_one_response(options) click to toggle source

depends on the machine code. if we have that or not.

# File lib/ruby_astm/header.rb, line 56
def build_one_response(options)
        puts "building one response=========="
        puts "queries are:"
        puts self.queries.size.to_s
        responses = []
        self.queries.each do |query|
                puts "doing query"
                puts query.sample_ids
                header_response = get_header_response(options)
                query.build_response(options).each do |qresponse|
                        puts "qresponse is:"
                        puts qresponse
                        header_response += qresponse
                end
                responses << header_response
        end
        responses
end
build_responses() click to toggle source

used to respond to queries. @return response_to_query : response to the header query.

# File lib/ruby_astm/header.rb, line 77
        def build_responses
                responses = []
                self.queries.each do |query|
                        header_response = "1H|\`^&||||||||||P|E 1394-97|#{Time.now.strftime("%Y%m%d%H%M%S")}\r"
                        query.build_response.each do |qresponse|
                                responses << (header_response + qresponse)
                        end
                end
=begin
                responses = self.queries.map {|query|
                        header_response = "1H|\`^&||||||||||P|E 1394-97|#{Time.now.strftime("%Y%m%d%H%M%S")}\r"
                        ## here the queries have multiple responses.
                        query.build_response.each do |qresponse|

                        end
                        query.response = header_response + query.build_response
                        query.response
                }
=end
                responses
        end
commit() click to toggle source

pushes each patient into a redis list called “patients”

# File lib/ruby_astm/header.rb, line 41
def commit
        self.patients.map{|patient| $redis.lpush("patients",patient.to_json)}
        puts JSON.pretty_generate(JSON.parse(self.to_json))
end
get_header_response(options) click to toggle source
# File lib/ruby_astm/header.rb, line 46
def get_header_response(options)
        if (options[:machine_name] && (options[:machine_name] == "cobas-e411"))
                "1H|\\^&|||host^1|||||cobas-e411|TSDWN^REPLY|P|1\r"
        else
                "1H|\`^&||||||||||P|E 1394-97|#{Time.now.strftime("%Y%m%d%H%M%S")}\r"
        end
end
is_astm?() click to toggle source
# File lib/ruby_astm/header.rb, line 8
def is_astm?
        self.protocol == "ASTM"
end
is_hl7?() click to toggle source
# File lib/ruby_astm/header.rb, line 12
def is_hl7?
        self.protocol == "HL7"
end
set_machine_name(args) click to toggle source
# File lib/ruby_astm/header.rb, line 31
def set_machine_name(args)
        if line = args[:line]
                unless line.fields[4].empty?
                        fields = line.fields[4].split(/\^/)
                        self.machine_name = fields[0].strip
                end
        end
end
set_protocol(args) click to toggle source
# File lib/ruby_astm/header.rb, line 17
def set_protocol(args)
        self.protocol = "ASTM"
end
to_json(args={}) click to toggle source
# File lib/ruby_astm/header.rb, line 99
    def to_json(args={})
    hash = {}
    self.instance_variables.each do |x|
        hash[x] = self.instance_variable_get x
    end
    return hash.to_json
end