Class: Header

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_astm/header.rb

Direct Known Subclasses

Hl7Header

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Header

Returns a new instance of Header.



21
22
23
24
25
26
27
28
29
# 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

Instance Attribute Details

#machine_nameObject

Returns the value of attribute machine_name.



2
3
4
# File 'lib/ruby_astm/header.rb', line 2

def machine_name
  @machine_name
end

#patientsObject

Returns the value of attribute patients.



3
4
5
# File 'lib/ruby_astm/header.rb', line 3

def patients
  @patients
end

#protocolObject

Returns the value of attribute protocol.



6
7
8
# File 'lib/ruby_astm/header.rb', line 6

def protocol
  @protocol
end

#queriesObject

Returns the value of attribute queries.



4
5
6
# File 'lib/ruby_astm/header.rb', line 4

def queries
  @queries
end

#response_sentObject

Returns the value of attribute response_sent.



5
6
7
# File 'lib/ruby_astm/header.rb', line 5

def response_sent
  @response_sent
end

Instance Method Details

#build_one_response(options) ⇒ Object

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



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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_responsesObject

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



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# 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

#commitObject

pushes each patient into a redis list called “patients”



41
42
43
44
# 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) ⇒ Object



46
47
48
49
50
51
52
# 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?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/ruby_astm/header.rb', line 8

def is_astm?
	self.protocol == "ASTM"
end

#is_hl7?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/ruby_astm/header.rb', line 12

def is_hl7?
	self.protocol == "HL7"
end

#set_machine_name(args) ⇒ Object



31
32
33
34
35
36
37
38
# 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) ⇒ Object



17
18
19
# File 'lib/ruby_astm/header.rb', line 17

def set_protocol(args)
	self.protocol = "ASTM"
end

#to_json(args = {}) ⇒ Object



99
100
101
102
103
104
105
# 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