ruby_astm 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_astm.rb +1 -0
- data/lib/ruby_astm/HL7/hl7_header.rb +57 -0
- data/lib/ruby_astm/HL7/hl7_observation.rb +48 -0
- data/lib/ruby_astm/header.rb +11 -7
- data/lib/ruby_astm/lab_interface.rb +15 -16
- data/lib/ruby_astm/line.rb +4 -15
- data/lib/ruby_astm/order.rb +1 -1
- data/lib/ruby_astm/query.rb +1 -1
- data/lib/ruby_astm/result.rb +59 -4
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba3587cb0b287c214f34b23f5d4675ee5078d1a5
|
4
|
+
data.tar.gz: 9aaa09bb81f96f74ecb7cf83a0e7e97a62e3e2e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c2d9545de7424d3d45eeb26e8c7275616d9c2ad8b5e28537832202aa5b6963cc45182c15527a7861436a849c764408c25e42b5fca3c2bfc94d1e2fa29206813
|
7
|
+
data.tar.gz: 49dbdffab677b6fd5fea75e8475bdc7b506b6ec0b7c9f979959510b75a72b5ca97c024c5f1f068e71aba3d6912c554fd13dc937ee620dd780890006a9d68a382
|
data/lib/ruby_astm.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "ruby_astm/header"
|
2
|
+
class Hl7Header < Header
|
3
|
+
## overriding from header.
|
4
|
+
attr_accessor :date_time
|
5
|
+
attr_accessor :message_type
|
6
|
+
attr_accessor :message_control_id
|
7
|
+
|
8
|
+
def initialize(args)
|
9
|
+
super.tap do |r|
|
10
|
+
set_machine_name(args)
|
11
|
+
set_date_time(args)
|
12
|
+
set_message_type(args)
|
13
|
+
set_message_control_id(args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_machine_name(args)
|
18
|
+
if line = args[:line]
|
19
|
+
unless line.fields[2].blank?
|
20
|
+
self.machine_name = line.fields[2]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_date_time(args)
|
26
|
+
if line = args[:line]
|
27
|
+
unless line.fields[7].blank?
|
28
|
+
self.date_time = line.fields[7]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_message_type(args)
|
34
|
+
if line = args[:line]
|
35
|
+
unless line.fields[8].blank?
|
36
|
+
line.fields[8].strip.scan(/(?<message_type>[A-Z]+)\^/) { |message_type| self.message_type = message_type[0] }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_message_control_id(args)
|
42
|
+
if line = args[:line]
|
43
|
+
unless line.fields[9].blank?
|
44
|
+
self.message_control_id = line.fields[9]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def generate_ack_success_response
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def generate_ack_failure_response
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "ruby_astm/result"
|
2
|
+
class Hl7Observation < Result
|
3
|
+
## first we start with the name.
|
4
|
+
def set_name(args)
|
5
|
+
if line = args[:line]
|
6
|
+
self.name = lookup_mapping(line.fields[3].strip)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_value(args)
|
11
|
+
if line = args[:line]
|
12
|
+
self.value = line.fields[5].strip
|
13
|
+
if transform_expression = lookup_transform(line.fields[5].strip)
|
14
|
+
self.value = eval(transform_expression)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_flags(args)
|
20
|
+
if line = args[:line]
|
21
|
+
self.flags = line.fields[8].strip unless line.fields[8].blank?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_units(args)
|
26
|
+
if line = args[:line]
|
27
|
+
self.units = line.fields[6].strip unless line.fields[6].blank?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_timestamp(args)
|
32
|
+
if line = args[:line]
|
33
|
+
line.fields[19].strip.scan(/(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})(?<hours>\d{2})(?<minutes>\d{2})(?<seconds>\d{2})/) {|year,month,day,hours,minutes,seconds|
|
34
|
+
self.timestamp = Time.new(year,month,day,hours,minutes,seconds)
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_reference_ranges(args)
|
40
|
+
if line = args[:line]
|
41
|
+
self.reference_ranges = line.fields[7].strip unless line.fields[7].blank?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_dilution(args)
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/ruby_astm/header.rb
CHANGED
@@ -5,18 +5,22 @@ class Header
|
|
5
5
|
attr_accessor :response_sent
|
6
6
|
|
7
7
|
def initialize(args)
|
8
|
+
self.patients = []
|
9
|
+
self.queries = []
|
10
|
+
self.response_sent = false
|
8
11
|
if args[:line]
|
9
12
|
line = args[:line]
|
10
|
-
|
11
|
-
fields = line.fields[4].split(/\^/)
|
12
|
-
self.machine_name = fields[0].strip
|
13
|
-
end
|
13
|
+
line
|
14
14
|
else
|
15
15
|
super
|
16
16
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_machine_name(line)
|
20
|
+
unless line.fields[4].empty?
|
21
|
+
fields = line.fields[4].split(/\^/)
|
22
|
+
self.machine_name = fields[0].strip
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
## pushes each patient into a redis list called "patients"
|
@@ -33,6 +33,7 @@ module LabInterface
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
|
36
37
|
def terminator
|
37
38
|
"L|1|N\r"
|
38
39
|
end
|
@@ -41,9 +42,7 @@ module LabInterface
|
|
41
42
|
def checksum(input)
|
42
43
|
strString = input
|
43
44
|
checksum = strString.sum
|
44
|
-
#puts "checksum before to_s is: #{checksum}"
|
45
45
|
b = checksum.to_s(16)
|
46
|
-
#puts "b is: #{b}"
|
47
46
|
strCksm = b[-2..-1]
|
48
47
|
if strCksm.length < 2
|
49
48
|
for i in strString.length..1
|
@@ -59,7 +58,6 @@ module LabInterface
|
|
59
58
|
|
60
59
|
concat = ""
|
61
60
|
|
62
|
-
|
63
61
|
puts data.bytes.to_a.to_s
|
64
62
|
|
65
63
|
data.bytes.to_a.each do |byte|
|
@@ -77,35 +75,25 @@ module LabInterface
|
|
77
75
|
end
|
78
76
|
|
79
77
|
#puts "concat is:"
|
80
|
-
puts concat.to_s
|
78
|
+
#puts concat.to_s
|
81
79
|
process_text(concat)
|
82
80
|
|
83
81
|
if data.bytes.to_a[0] == 4
|
84
|
-
puts "sent ENQ"
|
85
82
|
send_data(ENQ)
|
86
83
|
elsif data.bytes.to_a[0] == 6
|
87
|
-
## so now the middle part has to be
|
88
|
-
=begin
|
89
|
-
response = STX + "1H|\`^&||||||||||P|E 1394-97|#{Time.now.strftime("%Y%m%d%H%M%S")}\r" + terminator + ETX + checksum("1H|\`^&||||||||||P|E 1394-97|#{Time.now.strftime("%Y%m%d%H%M%S")}\r" + terminator) + "\r"
|
90
|
-
response = response.bytes.to_a
|
91
|
-
response << 10
|
92
|
-
send_data(response.pack('c*'))
|
93
|
-
=end
|
94
84
|
self.headers[-1].build_responses.each do |response|
|
95
85
|
message_checksum = checksum(response + terminator + ETX)
|
96
|
-
puts "Calculated checksum is: #{message_checksum}"
|
86
|
+
#puts "Calculated checksum is: #{message_checksum}"
|
97
87
|
final_resp = STX + response + terminator + ETX + message_checksum + "\r"
|
98
88
|
final_resp_arr = final_resp.bytes.to_a
|
99
89
|
final_resp_arr << 10
|
100
|
-
puts final_resp_arr.to_s
|
90
|
+
#puts final_resp_arr.to_s
|
101
91
|
if (self.headers[-1].response_sent == false)
|
102
92
|
send_data(final_resp_arr.pack('c*'))
|
103
93
|
self.headers[-1].response_sent = true
|
104
94
|
else
|
105
|
-
puts "response was already sent."
|
106
95
|
send_data(EOT)
|
107
96
|
end
|
108
|
-
|
109
97
|
end
|
110
98
|
else
|
111
99
|
## send the header
|
@@ -129,6 +117,17 @@ module LabInterface
|
|
129
117
|
|
130
118
|
def process_type(line)
|
131
119
|
case line.type
|
120
|
+
when "Hl7_Header"
|
121
|
+
hl7_header = Hl7Header.new({:line => line})
|
122
|
+
self.headers ||= []
|
123
|
+
self.headers << hl7_header
|
124
|
+
when "Hl7_Observation"
|
125
|
+
hl7_observation = Hl7Observation.new({:line => line})
|
126
|
+
self.headers[-1].patients[-1].orders[-1].results[hl7_observation.name] = hl7_observation
|
127
|
+
when "Hl7_Patient"
|
128
|
+
## like a patient
|
129
|
+
when "Hl7_Patient_Visti"
|
130
|
+
## like an order.
|
132
131
|
when "Header"
|
133
132
|
header = Header.new({:line => line})
|
134
133
|
self.headers ||= []
|
data/lib/ruby_astm/line.rb
CHANGED
@@ -2,6 +2,8 @@ class Line
|
|
2
2
|
|
3
3
|
TYPES = {
|
4
4
|
"H" => "Header",
|
5
|
+
"MSH" => "Hl7_Header",
|
6
|
+
"OBX" => "Hl7_Observation",
|
5
7
|
"P" => "Patient",
|
6
8
|
"Q" => "Query",
|
7
9
|
"O" => "Order",
|
@@ -23,8 +25,6 @@ class Line
|
|
23
25
|
##
|
24
26
|
########################################################
|
25
27
|
|
26
|
-
|
27
|
-
|
28
28
|
## sets the types, and fields
|
29
29
|
## we can have processing based on line.
|
30
30
|
def initialize(args)
|
@@ -41,23 +41,12 @@ class Line
|
|
41
41
|
def detect_type
|
42
42
|
#puts "detecting line type: #{self.text}"
|
43
43
|
line_type = self.fields[0]
|
44
|
-
line_type.scan(/(?<ltype>[A-Z])/) { |ltype|
|
45
|
-
#puts "got ltype as: #{ltype[0]}"
|
46
|
-
#puts Line::TYPES.to_s
|
44
|
+
line_type.scan(/(?<ltype>[A-Z]+)/) { |ltype|
|
47
45
|
if Line::TYPES[ltype[0]]
|
48
46
|
self.type = Line::TYPES[ltype[0]]
|
49
|
-
#puts "assigning type as: #{self.type}"
|
50
47
|
end
|
51
48
|
}
|
52
|
-
|
53
|
-
=begin
|
54
|
-
if self.fields[0][1..-1] =~/#{type}/
|
55
|
-
puts "got type: #{Line::TYPES[type]}"
|
56
|
-
self.type = Line::TYPES[type]
|
57
|
-
break
|
58
|
-
end
|
59
|
-
=end
|
60
|
-
|
49
|
+
|
61
50
|
end
|
62
51
|
|
63
52
|
|
data/lib/ruby_astm/order.rb
CHANGED
@@ -69,7 +69,7 @@ class Order
|
|
69
69
|
#puts "no specimen type has been provided, sending SERUM"
|
70
70
|
end
|
71
71
|
|
72
|
-
"O|#{self.sequence_number}|#{self.id}^01||^^^#{self.tests.join('
|
72
|
+
"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"
|
73
73
|
end
|
74
74
|
|
75
75
|
end
|
data/lib/ruby_astm/query.rb
CHANGED
data/lib/ruby_astm/result.rb
CHANGED
@@ -7,8 +7,66 @@ class Result
|
|
7
7
|
attr_accessor :reference_ranges
|
8
8
|
attr_accessor :dilution
|
9
9
|
|
10
|
+
def set_name(args)
|
11
|
+
if line = args[:line]
|
12
|
+
line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|
|
13
|
+
self.name = lookup_mapping(name)
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_value(args)
|
19
|
+
if line = args[:line]
|
20
|
+
self.value = line.fields[3].strip
|
21
|
+
line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|
|
22
|
+
if transform_expression = lookup_transform(name)
|
23
|
+
self.value = eval(transform_expression)
|
24
|
+
end
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_flags(args)
|
30
|
+
if line = args[:line]
|
31
|
+
self.flags = line.fields[6].strip
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_units(args)
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_timestamp(args)
|
40
|
+
if line = args[:line]
|
41
|
+
line.fields[12].strip.scan(/(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})(?<hours>\d{2})(?<minutes>\d{2})(?<seconds>\d{2})/) {|year,month,day,hours,minutes,seconds|
|
42
|
+
self.timestamp = Time.new(year,month,day,hours,minutes,seconds)
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def set_reference_ranges(args)
|
48
|
+
if line = args[:line]
|
49
|
+
self.reference_ranges = line.fields[5].strip
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_dilution(args)
|
54
|
+
if line = args[:line]
|
55
|
+
line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|
|
56
|
+
self.dilution = dilution
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
10
61
|
## here will call mappings and check the result correlation
|
11
62
|
def initialize(args)
|
63
|
+
set_name(args)
|
64
|
+
set_flags(args)
|
65
|
+
set_value(args)
|
66
|
+
set_timestamp(args)
|
67
|
+
set_dilution(args)
|
68
|
+
set_units(args)
|
69
|
+
=begin
|
12
70
|
if args[:line]
|
13
71
|
line = args[:line]
|
14
72
|
transform_expression = nil
|
@@ -18,13 +76,9 @@ class Result
|
|
18
76
|
transform_expression = lookup_transform(name)
|
19
77
|
}
|
20
78
|
self.value = line.fields[3].strip
|
21
|
-
|
22
79
|
if transform_expression
|
23
|
-
#puts "got transform expression, now evalling it."
|
24
80
|
self.value = eval(transform_expression)
|
25
|
-
#puts "Value after eval: #{self.value}"
|
26
81
|
end
|
27
|
-
#eval(transform_expression) unless transform_expression.blank?
|
28
82
|
self.reference_ranges = line.fields[5].strip
|
29
83
|
self.flags = line.fields[6].strip
|
30
84
|
line.fields[12].strip.scan(/(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})(?<hours>\d{2})(?<minutes>\d{2})(?<seconds>\d{2})/) {|year,month,day,hours,minutes,seconds|
|
@@ -33,6 +87,7 @@ class Result
|
|
33
87
|
else
|
34
88
|
super
|
35
89
|
end
|
90
|
+
=end
|
36
91
|
end
|
37
92
|
|
38
93
|
## @return[String] the name defined in the mappings.json file, or the name that wqs passed in.
|
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.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bhargav Raut
|
@@ -120,6 +120,8 @@ files:
|
|
120
120
|
- lib/publisher/google_lab_interface.rb
|
121
121
|
- lib/publisher/poller.rb
|
122
122
|
- lib/ruby_astm.rb
|
123
|
+
- lib/ruby_astm/HL7/hl7_header.rb
|
124
|
+
- lib/ruby_astm/HL7/hl7_observation.rb
|
123
125
|
- lib/ruby_astm/astm_server.rb
|
124
126
|
- lib/ruby_astm/frame.rb
|
125
127
|
- lib/ruby_astm/header.rb
|