ruby_astm 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5aad9b688056b23b5252d954ec6f6e53d11decab2e5adbd33251613642f5ee0
4
- data.tar.gz: 1b9b7cac6d3122b4cd62a36611a05226254453a124788078ba51ab0ea03f22fd
3
+ metadata.gz: f7633bfcc74d626e2135ceab715f3b91ce9d6a1093a3748829a2e589550c6d9e
4
+ data.tar.gz: ced94d1d9124f265c519a49e9ce9325924d266abe16f6d63acf80c44990ab6b0
5
5
  SHA512:
6
- metadata.gz: 8ca884192d09d41a0982012a22fd79a832f7737697f1b182ba125e28cfc4a194c4908a62d7e5eae127e4acfa6bdf248a3012d26a5d557fcacdb083625bd1fad2
7
- data.tar.gz: 6e1896e259496d069a9aa86e255a38b70c119b4460b3e875958360bbcfc013a86dd88aed79a2a78192c729fad14de321794573bdf4008fe5b0e58a4eaee89fdf
6
+ metadata.gz: '056821d5b0b2c10929205a4d528dfced19bf978d1719ac26cf32fd2212c4cec25666576e25a1fed01761fb3faa871d69b7120b1a994ad022990c5399df9a9ede'
7
+ data.tar.gz: 8d2fff46ffd8615662c856284301c03a07c0c776096e1f6c0c7c2a29a05c17a821b0d97bfce4e628a0c2e01aabb0bc2cd6bfaa145fbf589ca419118f0c179d3f
@@ -45,14 +45,40 @@ class Header
45
45
  puts JSON.pretty_generate(JSON.parse(self.to_json))
46
46
  end
47
47
 
48
+ def build_one_response
49
+ responses = []
50
+ self.queries.each do |query|
51
+ header_response = "1H|\`^&||||||||||P|E 1394-97|#{Time.now.strftime("%Y%m%d%H%M%S")}\r"
52
+ query.build_response.each do |qresponse|
53
+ header_response += qresponse
54
+ #responses << (header_response + qresponse)
55
+ end
56
+ responses << header_response
57
+ end
58
+ responses
59
+ end
60
+
48
61
  ## used to respond to queries.
49
62
  ## @return[String] response_to_query : response to the header query.
50
63
  def build_responses
64
+ responses = []
65
+ self.queries.each do |query|
66
+ header_response = "1H|\`^&||||||||||P|E 1394-97|#{Time.now.strftime("%Y%m%d%H%M%S")}\r"
67
+ query.build_response.each do |qresponse|
68
+ responses << (header_response + qresponse)
69
+ end
70
+ end
71
+ =begin
51
72
  responses = self.queries.map {|query|
52
73
  header_response = "1H|\`^&||||||||||P|E 1394-97|#{Time.now.strftime("%Y%m%d%H%M%S")}\r"
74
+ ## here the queries have multiple responses.
75
+ query.build_response.each do |qresponse|
76
+
77
+ end
53
78
  query.response = header_response + query.build_response
54
79
  query.response
55
80
  }
81
+ =end
56
82
  responses
57
83
  end
58
84
 
@@ -63,7 +63,7 @@ module LabInterface
63
63
 
64
64
  self.data_buffer ||= ''
65
65
 
66
- #puts "incoming data bytes."
66
+ puts "incoming data bytes."
67
67
 
68
68
  concat = ""
69
69
 
@@ -95,12 +95,17 @@ module LabInterface
95
95
 
96
96
 
97
97
  if data.bytes.to_a[-1] == 4
98
- puts self.data_buffer
98
+ #puts self.data_buffer
99
99
  process_text(self.data_buffer)
100
100
  self.data_buffer = ''
101
101
  send_data(ENQ)
102
102
  elsif data.bytes.to_a[0] == 6
103
- self.headers[-1].build_responses.each do |response|
103
+ header_responses = self.headers[-1].build_one_response
104
+ header_responses.each_with_index {|response,key|
105
+ #puts "response is:"
106
+ #response.bytes.to_a.each do |b|
107
+ # puts [b].pack('c*')
108
+ #end
104
109
  message_checksum = checksum(response + terminator + ETX)
105
110
  #puts "Calculated checksum is: #{message_checksum}"
106
111
  final_resp = STX + response + terminator + ETX + message_checksum + "\r"
@@ -108,12 +113,16 @@ module LabInterface
108
113
  final_resp_arr << 10
109
114
  #puts final_resp_arr.to_s
110
115
  if (self.headers[-1].response_sent == false)
116
+ puts "sending the data as follows----------------------------------------------"
117
+ puts "response sent is:"
118
+ puts self.headers[-1].response_sent
119
+ puts final_resp_arr.pack('c*').gsub(/\r/,'\n')
111
120
  send_data(final_resp_arr.pack('c*'))
112
- self.headers[-1].response_sent = true
121
+ self.headers[-1].response_sent = true if (key == (header_responses.size - 1))
113
122
  else
114
123
  send_data(EOT)
115
124
  end
116
- end
125
+ }
117
126
  else
118
127
  ## send the header
119
128
  #puts "--------- SENT ACK -----------"
@@ -41,8 +41,9 @@ class Line
41
41
  end
42
42
 
43
43
  def detect_type
44
- #puts "detecting line type: #{self.text}"
44
+ puts "detecting line type: #{self.text}"
45
45
  line_type = self.fields[0]
46
+ return unless line_type
46
47
  line_type.scan(/(?<ltype>[A-Z]+)/) { |ltype|
47
48
  if Line::TYPES[ltype[0]]
48
49
  self.type = Line::TYPES[ltype[0]]
@@ -117,7 +117,7 @@ class Order
117
117
  #puts "no specimen type has been provided, sending SERUM"
118
118
  end
119
119
 
120
- "O|#{self.sequence_number}|#{self.id}^01||^^^#{self.tests.join('`^^^')}|#{self.priority}||#{Time.now.strftime("%Y%m%d%H%M%S")}||||N||||#{self.specimen_type || 'SERUM'}\r"
120
+ "O|#{self.sequence_number}|#{self.id}|#{Time.now.to_i.to_s}|^^^#{self.tests.join('`^^^')}|#{self.priority}||#{Time.now.strftime("%Y%m%d%H%M%S")}||||N||||#{self.specimen_type || 'SERUM'}\r"
121
121
  end
122
122
 
123
123
  end
@@ -4,17 +4,20 @@ class Query
4
4
 
5
5
  attr_accessor :response
6
6
 
7
+ attr_accessor :sample_ids
8
+
7
9
  def initialize(args)
8
10
  line = args[:line]
9
11
  unless line.fields[2].empty?
10
12
  fields = line.fields[2].split(/\^/)
11
- self.sample_id = fields[1].strip
13
+ sample_id = fields[1].strip
14
+ self.sample_ids = sample_id.split(/\`/)
12
15
  end
13
16
  end
14
17
 
15
- def get_tests
18
+ def get_tests(sample_id)
16
19
  tests = []
17
- sample_tests = $redis.hget(Poller::REQUISITIONS_HASH,self.sample_id)
20
+ sample_tests = $redis.hget(Poller::REQUISITIONS_HASH,sample_id)
18
21
  unless sample_tests.blank?
19
22
  tests = JSON.parse(sample_tests)
20
23
  end
@@ -24,31 +27,31 @@ class Query
24
27
  ## each query will build one patient and one order inside it.
25
28
  ## the order can have many tests.
26
29
  def build_response(variables=nil)
27
- ## so the response is thus incoming.
28
- =begin
29
- variables ||= {
30
- :sequence_number => "0",
31
- :patient_id => "abcde",
32
- :specimen_id => self.sample_id,
33
- :tests => ["TRIG"],
34
- :priority => "R"
35
- }
36
- =end
37
-
38
- ## tests are got from the requisitions hash.
39
- tests = get_tests
40
-
41
- ## default sequence number is 0 (THIS MAY LEAD TO PROBLEMS.)
42
- sequence_number = "0"
43
-
44
- ## default patient id:
45
- patient_id = "abcde#{Time.now.strftime('%b %d, %Y, %H:%M:%S')}"
46
-
47
- patient = Patient.new({:sequence_number => sequence_number, :patient_id => patient_id})
48
30
 
49
- order = Order.new({:sequence_number => patient.sequence_number, :specimen_id => self.sample_id, :tests => tests, :priority => "R"})
31
+ responses = []
32
+
33
+ one_response = ''
34
+
35
+ self.sample_ids.each_with_index {|sid,key|
36
+
37
+ ## tests are got from the requisitions hash.
38
+ tests = get_tests(sid)
39
+
40
+ ## default sequence number is 0 (THIS MAY LEAD TO PROBLEMS.)
41
+ sequence_number = "#{key.to_s}"
42
+
43
+ ## default patient id:
44
+ patient_id = "abcde#{Time.now.to_i.to_s}"
45
+
46
+ patient = Patient.new({:sequence_number => sequence_number, :patient_id => patient_id})
47
+
48
+ order = Order.new({:sequence_number => patient.sequence_number, :specimen_id => sid, :tests => tests, :priority => "R"})
49
+
50
+ responses << (patient.build_response + order.build_response)
51
+
52
+ }
50
53
 
51
- return patient.build_response + order.build_response
54
+ return [one_response]
52
55
 
53
56
  end
54
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_astm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bhargav Raut