ruby_astm 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mappings.json +48 -0
- data/lib/ruby_astm/HL7/hl7_header.rb +77 -6
- data/lib/ruby_astm/HL7/hl7_order.rb +6 -0
- data/lib/ruby_astm/HL7/hl7_patient.rb +14 -0
- data/lib/ruby_astm/header.rb +24 -8
- data/lib/ruby_astm/lab_interface.rb +20 -5
- data/lib/ruby_astm/line.rb +2 -0
- data/lib/ruby_astm/order.rb +49 -1
- data/lib/ruby_astm/patient.rb +13 -6
- data/lib/ruby_astm.rb +4 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ca559f093f64b83516605cf9e8f258e0d22fb13
|
4
|
+
data.tar.gz: 40b5a1d881488650d4fe3c12ae558b33f27d8767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e93d576aed5cadabc970410e761f1f003525b7a3b79b990904af3c45c08c317d6d9f064461c56ade9a8ece1a013103e9b79f3ffc6197ddef3984b563efccb92a
|
7
|
+
data.tar.gz: cc6bf2ff832d15deec84c8e39b67f94723c703f5aec0ee406bba53cc2d145c242dcdca3f90942541047b3f9ba9e103e81ec71ab5f38de9adc9f78ad59b4cb352
|
data/lib/mappings.json
CHANGED
@@ -193,5 +193,53 @@
|
|
193
193
|
"ESR" : {
|
194
194
|
"LIS_CODE" : "ESR",
|
195
195
|
"TUBE" : "ESR"
|
196
|
+
},
|
197
|
+
"GLU" : {
|
198
|
+
"LIS_CODE" : "GLU",
|
199
|
+
"TUBE" : "URINE_CONTAINER"
|
200
|
+
},
|
201
|
+
"BIL" : {
|
202
|
+
"LIS_CODE" : "BIL",
|
203
|
+
"TUBE" : "URINE_CONTAINER"
|
204
|
+
},
|
205
|
+
"KET" : {
|
206
|
+
"LIS_CODE" : "KET",
|
207
|
+
"TUBE" : "URINE_CONTAINER"
|
208
|
+
},
|
209
|
+
"SG" : {
|
210
|
+
"LIS_CODE" : "SG",
|
211
|
+
"TUBE" : "URINE_CONTAINER"
|
212
|
+
},
|
213
|
+
"BLO" : {
|
214
|
+
"LIS_CODE" : "BLO",
|
215
|
+
"TUBE" : "URINE_CONTAINER"
|
216
|
+
},
|
217
|
+
"pH" : {
|
218
|
+
"LIS_CODE" : "pH",
|
219
|
+
"TUBE" : "URINE_CONTAINER"
|
220
|
+
},
|
221
|
+
"PRO" : {
|
222
|
+
"LIS_CODE" : "PRO",
|
223
|
+
"TUBE" : "URINE_CONTAINER"
|
224
|
+
},
|
225
|
+
"URO" : {
|
226
|
+
"LIS_CODE" : "URO",
|
227
|
+
"TUBE" : "URINE_CONTAINER"
|
228
|
+
},
|
229
|
+
"NIT" : {
|
230
|
+
"LIS_CODE" : "NIT",
|
231
|
+
"TUBE" : "URINE_CONTAINER"
|
232
|
+
},
|
233
|
+
"LEU" : {
|
234
|
+
"LIS_CODE" : "LEU",
|
235
|
+
"TUBE" : "URINE_CONTAINER"
|
236
|
+
},
|
237
|
+
"COL" : {
|
238
|
+
"LIS_CODE" : "COL",
|
239
|
+
"TUBE" : "URINE_CONTAINER"
|
240
|
+
},
|
241
|
+
"CLA" : {
|
242
|
+
"LIS_CODE" : "CLA",
|
243
|
+
"TUBE" : "URINE_CONTAINER"
|
196
244
|
}
|
197
245
|
}
|
@@ -5,13 +5,16 @@ class Hl7Header < Header
|
|
5
5
|
attr_accessor :message_type
|
6
6
|
attr_accessor :message_control_id
|
7
7
|
|
8
|
+
def set_protocol(args)
|
9
|
+
self.protocol = "HL7"
|
10
|
+
end
|
11
|
+
|
8
12
|
def initialize(args)
|
9
|
-
super
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
13
|
+
super
|
14
|
+
set_machine_name(args)
|
15
|
+
set_date_time(args)
|
16
|
+
set_message_type(args)
|
17
|
+
set_message_control_id(args)
|
15
18
|
end
|
16
19
|
|
17
20
|
def set_machine_name(args)
|
@@ -46,8 +49,76 @@ class Hl7Header < Header
|
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
52
|
+
################################################################################
|
53
|
+
##
|
54
|
+
##
|
55
|
+
## METHODS FOR generating the acknowledgement to an HL7 Message
|
56
|
+
##
|
57
|
+
##
|
58
|
+
################################################################################
|
59
|
+
|
60
|
+
def seperator
|
61
|
+
"|"
|
62
|
+
end
|
63
|
+
|
64
|
+
def header
|
65
|
+
"MSH"
|
66
|
+
end
|
67
|
+
|
68
|
+
def field_seperators
|
69
|
+
"^~\\&"
|
70
|
+
end
|
71
|
+
|
72
|
+
def sending_application_name
|
73
|
+
"Pathofast_LIS"
|
74
|
+
end
|
75
|
+
|
76
|
+
def sending_facility_name
|
77
|
+
"Pathofast"
|
78
|
+
end
|
79
|
+
|
80
|
+
def sending_date_time
|
81
|
+
Time.now.strftime("%Y%m%d%H%M%S")
|
82
|
+
end
|
83
|
+
|
84
|
+
def ack_message
|
85
|
+
"ACK"
|
86
|
+
end
|
87
|
+
|
88
|
+
def nack_message
|
89
|
+
"NACK"
|
90
|
+
end
|
91
|
+
|
92
|
+
def hl7_version
|
93
|
+
"2.4"
|
94
|
+
end
|
95
|
+
|
49
96
|
def generate_ack_success_response
|
50
97
|
|
98
|
+
ack_msg = ""
|
99
|
+
ack_msg += header + seperator
|
100
|
+
ack_msg += field_seperators + seperator
|
101
|
+
ack_msg += sending_application_name + seperator
|
102
|
+
ack_msg += sending_facility_name + seperator
|
103
|
+
ack_msg += seperator
|
104
|
+
ack_msg += seperator
|
105
|
+
ack_msg += sending_date_time + seperator
|
106
|
+
ack_msg += seperator
|
107
|
+
ack_msg += ack_msg + seperator
|
108
|
+
ack_msg += self.message_control_id + seperator
|
109
|
+
ack_msg += seperator
|
110
|
+
ack_msg += hl7_version + seperator
|
111
|
+
ack_msg += seperator
|
112
|
+
ack_msg += seperator
|
113
|
+
ack_msg += seperator
|
114
|
+
ack_msg += seperator
|
115
|
+
ack_msg += seperator
|
116
|
+
ack_msg += seperator
|
117
|
+
ack_msg += seperator
|
118
|
+
ack_msg += "AA" + seperator
|
119
|
+
ack_msg += sending_date_time + seperator
|
120
|
+
ack_msg
|
121
|
+
|
51
122
|
end
|
52
123
|
|
53
124
|
def generate_ack_failure_response
|
data/lib/ruby_astm/header.rb
CHANGED
@@ -3,30 +3,46 @@ class Header
|
|
3
3
|
attr_accessor :patients
|
4
4
|
attr_accessor :queries
|
5
5
|
attr_accessor :response_sent
|
6
|
+
attr_accessor :protocol
|
7
|
+
|
8
|
+
def is_astm?
|
9
|
+
self.protocol == "ASTM"
|
10
|
+
end
|
11
|
+
|
12
|
+
def is_hl7?
|
13
|
+
self.protocol == "HL7"
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def set_protocol(args)
|
18
|
+
self.protocol = "ASTM"
|
19
|
+
end
|
6
20
|
|
7
21
|
def initialize(args)
|
8
22
|
self.patients = []
|
9
23
|
self.queries = []
|
10
24
|
self.response_sent = false
|
11
|
-
if args[:line]
|
12
|
-
|
13
|
-
|
25
|
+
if line = args[:line]
|
26
|
+
set_machine_name(args)
|
27
|
+
set_protocol(args)
|
14
28
|
else
|
15
29
|
super
|
16
30
|
end
|
17
31
|
end
|
18
32
|
|
19
|
-
def set_machine_name(
|
20
|
-
|
21
|
-
|
22
|
-
|
33
|
+
def set_machine_name(args)
|
34
|
+
if line = args[:line]
|
35
|
+
unless line.fields[4].empty?
|
36
|
+
fields = line.fields[4].split(/\^/)
|
37
|
+
self.machine_name = fields[0].strip
|
38
|
+
end
|
23
39
|
end
|
24
40
|
end
|
25
41
|
|
26
42
|
## pushes each patient into a redis list called "patients"
|
27
43
|
def commit
|
28
44
|
self.patients.map{|patient| $redis.lpush("patients",patient.to_json)}
|
29
|
-
|
45
|
+
puts JSON.pretty_generate(JSON.parse(self.to_json))
|
30
46
|
end
|
31
47
|
|
32
48
|
## used to respond to queries.
|
@@ -29,7 +29,9 @@ module LabInterface
|
|
29
29
|
def process_text_file(full_file_path)
|
30
30
|
#full_file_path ||= File.join root,'../test','resources','sysmex_550_sample.txt'
|
31
31
|
IO.read(full_file_path).each_line do |line|
|
32
|
-
|
32
|
+
line.split('\\r').each do |txt|
|
33
|
+
process_text(txt)
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
@@ -98,7 +100,15 @@ module LabInterface
|
|
98
100
|
else
|
99
101
|
## send the header
|
100
102
|
puts "--------- SENT ACK -----------"
|
101
|
-
|
103
|
+
if self.headers[-1].is_astm?
|
104
|
+
send_data(ACK)
|
105
|
+
elsif self.headers[-1].is_hl7?
|
106
|
+
if self.headers.size > 0
|
107
|
+
## commit should return the jsonified thing, if possible.
|
108
|
+
self.headers[-1].commit
|
109
|
+
send_data(self.headers[-1].generate_ack_success_response)
|
110
|
+
end
|
111
|
+
end
|
102
112
|
end
|
103
113
|
end
|
104
114
|
|
@@ -109,6 +119,8 @@ module LabInterface
|
|
109
119
|
end
|
110
120
|
|
111
121
|
def process_text(text)
|
122
|
+
## should replace carriage returns with new lines, before processing any file.
|
123
|
+
## or text.
|
112
124
|
text.split("\n").each do |l|
|
113
125
|
line = Line.new({:text => l})
|
114
126
|
process_type(line)
|
@@ -125,9 +137,11 @@ module LabInterface
|
|
125
137
|
hl7_observation = Hl7Observation.new({:line => line})
|
126
138
|
self.headers[-1].patients[-1].orders[-1].results[hl7_observation.name] = hl7_observation
|
127
139
|
when "Hl7_Patient"
|
128
|
-
|
129
|
-
|
130
|
-
|
140
|
+
hl7_patient = Hl7Patient.new({:line => line})
|
141
|
+
self.headers[-1].patients << hl7_patient
|
142
|
+
when "Hl7_Order"
|
143
|
+
hl7_order = Hl7Order.new({:line => line, :patient_id => self.headers[-1].patients[-1].patient_id})
|
144
|
+
self.headers[-1].patients[-1].orders << hl7_order
|
131
145
|
when "Header"
|
132
146
|
header = Header.new({:line => line})
|
133
147
|
self.headers ||= []
|
@@ -145,6 +159,7 @@ module LabInterface
|
|
145
159
|
result = Result.new({:line => line})
|
146
160
|
self.headers[-1].patients[-1].orders[-1].results[result.name] = result
|
147
161
|
when "Terminator"
|
162
|
+
## it didn't terminate so there was no commit being called.
|
148
163
|
self.headers[-1].commit
|
149
164
|
end
|
150
165
|
end
|
data/lib/ruby_astm/line.rb
CHANGED
data/lib/ruby_astm/order.rb
CHANGED
@@ -34,7 +34,55 @@ class Order
|
|
34
34
|
## index (11)
|
35
35
|
attr_accessor :action_code
|
36
36
|
|
37
|
+
def set_id(args)
|
38
|
+
if line = args[:line]
|
39
|
+
if !line.fields[2].strip.blank?
|
40
|
+
line.fields[2].strip.scan(/(?<specimen_id>[^\^]+)/) { |specimen_id|
|
41
|
+
self.id ||= specimen_id
|
42
|
+
}
|
43
|
+
elsif !line.fields[3].strip.blank?
|
44
|
+
## for the sysmex xn-550 this is the regex.
|
45
|
+
line.fields[3].strip.scan(/(?<tube_rack>\d+\^)+(?<patient_id>.+)\^/) { |tube_rack,patient_id| self.id = patient_id.strip}
|
46
|
+
end
|
47
|
+
else
|
48
|
+
self.id = args[:specimen_id]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_sequence_number(args)
|
53
|
+
self.sequence_number = args[:sequence_number]
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_tests(args)
|
57
|
+
self.tests = args[:tests]
|
58
|
+
end
|
59
|
+
|
60
|
+
def set_specimen_type(args)
|
61
|
+
self.specimen_type = args[:specimen_type]
|
62
|
+
end
|
63
|
+
|
64
|
+
def set_date_time(args)
|
65
|
+
self.date_time = args[:date_time]
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_priority(args)
|
69
|
+
self.priority = args[:priority]
|
70
|
+
end
|
71
|
+
|
72
|
+
def set_action_Code(args)
|
73
|
+
self.action_code = args[:args]
|
74
|
+
end
|
75
|
+
|
37
76
|
def initialize(args)
|
77
|
+
set_id(args)
|
78
|
+
set_priority(args)
|
79
|
+
set_sequence_number(args)
|
80
|
+
set_tests(args)
|
81
|
+
set_specimen_type(args)
|
82
|
+
set_date_time(args)
|
83
|
+
set_priority(args)
|
84
|
+
set_action_Code(args)
|
85
|
+
=begin
|
38
86
|
if args[:line]
|
39
87
|
line = args[:line]
|
40
88
|
if !line.fields[2].strip.blank?
|
@@ -50,11 +98,11 @@ class Order
|
|
50
98
|
self.tests = args[:tests]
|
51
99
|
self.id = args[:specimen_id]
|
52
100
|
self.specimen_type = args[:specimen_type]
|
53
|
-
self.tests = args[:tests]
|
54
101
|
self.date_time = args[:date_time]
|
55
102
|
self.priority = args[:priority]
|
56
103
|
self.action_code = args[:action_code]
|
57
104
|
end
|
105
|
+
=end
|
58
106
|
self.results = {}
|
59
107
|
end
|
60
108
|
|
data/lib/ruby_astm/patient.rb
CHANGED
@@ -5,17 +5,24 @@ class Patient
|
|
5
5
|
attr_accessor :patient_id
|
6
6
|
attr_accessor :orders
|
7
7
|
|
8
|
-
def
|
9
|
-
if args[:line]
|
10
|
-
|
11
|
-
self.sequence_number = line.fields[1].to_i
|
12
|
-
self.orders = []
|
8
|
+
def set_sequence_number(args)
|
9
|
+
if line = args[:line]
|
10
|
+
self.sequence_number = line.fields[-1].to_i
|
13
11
|
else
|
14
12
|
self.sequence_number = args[:sequence_number]
|
15
|
-
self.patient_id = args[:patient_id]
|
16
13
|
end
|
17
14
|
end
|
18
15
|
|
16
|
+
def set_patient_id(args)
|
17
|
+
self.patient_id = args[:patient_id]
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(args)
|
21
|
+
set_sequence_number(args)
|
22
|
+
set_patient_id(args)
|
23
|
+
self.orders = []
|
24
|
+
end
|
25
|
+
|
19
26
|
## patient id.
|
20
27
|
def build_response
|
21
28
|
"P|#{self.sequence_number}|#{self.patient_id}|||||||||||||||\r"
|
data/lib/ruby_astm.rb
CHANGED
@@ -10,4 +10,7 @@ require "ruby_astm/astm_server"
|
|
10
10
|
require "publisher/adapter"
|
11
11
|
require "publisher/google_lab_interface"
|
12
12
|
require "publisher/poller"
|
13
|
-
require "ruby_astm/HL7/hl7_header"
|
13
|
+
require "ruby_astm/HL7/hl7_header"
|
14
|
+
require "ruby_astm/HL7/hl7_patient"
|
15
|
+
require "ruby_astm/HL7/hl7_order"
|
16
|
+
require "ruby_astm/HL7/hl7_observation"
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bhargav Raut
|
@@ -122,6 +122,8 @@ files:
|
|
122
122
|
- lib/ruby_astm.rb
|
123
123
|
- lib/ruby_astm/HL7/hl7_header.rb
|
124
124
|
- lib/ruby_astm/HL7/hl7_observation.rb
|
125
|
+
- lib/ruby_astm/HL7/hl7_order.rb
|
126
|
+
- lib/ruby_astm/HL7/hl7_patient.rb
|
125
127
|
- lib/ruby_astm/astm_server.rb
|
126
128
|
- lib/ruby_astm/frame.rb
|
127
129
|
- lib/ruby_astm/header.rb
|
@@ -155,4 +157,6 @@ rubygems_version: 2.6.14.1
|
|
155
157
|
signing_key:
|
156
158
|
specification_version: 4
|
157
159
|
summary: A Ruby gem to interface with Medical instruments that work on the ASTM protocol
|
160
|
+
and HL7 protocol. Offers limited bidirectionality for ASTM. Bidirectionality is
|
161
|
+
currently not supported for HL7
|
158
162
|
test_files: []
|