lis 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +12 -2
- data/Rakefile +4 -1
- data/bin/lis2http +2 -2
- data/features/lis.feature +69 -44
- data/features/step_definitions/lis_steps.rb +80 -0
- data/features/support/env.rb +3 -0
- data/lib/lis/commands/application.rb +2 -2
- data/lib/lis/interface_server.rb +22 -7
- data/lib/lis/messages/comment.rb +3 -0
- data/lib/lis/messages/header.rb +27 -0
- data/lib/lis/messages/order.rb +51 -0
- data/lib/lis/messages/patient.rb +57 -0
- data/lib/lis/messages/query.rb +38 -0
- data/lib/lis/messages/result.rb +27 -0
- data/lib/lis/messages/terminator.rb +16 -0
- data/lib/lis/messages.rb +48 -24
- data/lib/lis/transfer/application_protocol.rb +104 -0
- data/lib/lis/transfer/astm_e1394.rb +121 -0
- data/lib/lis/version.rb +4 -0
- data/lib/lis/worklist_manager_interface.rb +10 -1
- data/lib/lis.rb +6 -7
- data/lis.gemspec +4 -1
- data/test/helper.rb +0 -1
- data/test/{test_packetized_protocol.rb → test_astm_e1394.rb} +3 -3
- metadata +45 -18
- data/.document +0 -5
- data/VERSION +0 -1
- data/lib/lis/io_listener.rb +0 -114
- data/test/test_io_listener.rb +0 -34
data/lib/lis/io_listener.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
require 'strscan'
|
2
|
-
|
3
|
-
module LIS::Transfer
|
4
|
-
|
5
|
-
# a chainable IO-Listener that provides two methods:
|
6
|
-
#
|
7
|
-
# {#on_data} ::
|
8
|
-
# a callback that is called whenever a message is received
|
9
|
-
# {#write} ::
|
10
|
-
# can be called so send messages to the underlying IO
|
11
|
-
#
|
12
|
-
# when overriding this class, you need to implement two methods:
|
13
|
-
#
|
14
|
-
# {#receive} ::
|
15
|
-
# is called from an underlying IO whenever a message is received
|
16
|
-
# the message can be handled. Call {#forward} to propagate
|
17
|
-
#
|
18
|
-
# {#write} ::
|
19
|
-
# transform/encode a message before sending it. Call +super+ to propagate
|
20
|
-
#
|
21
|
-
# See {LineBasedProtocol} for a toy implementation which strips
|
22
|
-
# newlines and only forwards complete lines.
|
23
|
-
#
|
24
|
-
class Base
|
25
|
-
|
26
|
-
# @param [Base, #on_data] read data source
|
27
|
-
# @param [Base, IO, #write] write object where messages are written to
|
28
|
-
#
|
29
|
-
def initialize(read, write = read)
|
30
|
-
@reader, @writer = read, write
|
31
|
-
@on_data = nil
|
32
|
-
@reader.on_data { |*data| receive(*data) } if @reader.respond_to?(:on_data)
|
33
|
-
end
|
34
|
-
|
35
|
-
# register a block, to be run whenever the protocol implementation
|
36
|
-
# receives data (by calling {#forward})
|
37
|
-
#
|
38
|
-
# this is used to chain protocol layers together
|
39
|
-
#
|
40
|
-
# @return [self]
|
41
|
-
# @yield [*args] called whenever the protocol implementaion calls {#forward}
|
42
|
-
# @yieldreturn [nil]
|
43
|
-
#
|
44
|
-
def on_data(&block)
|
45
|
-
@on_data = block
|
46
|
-
self
|
47
|
-
end
|
48
|
-
|
49
|
-
# @see #write
|
50
|
-
def <<(*args)
|
51
|
-
write(*args)
|
52
|
-
end
|
53
|
-
|
54
|
-
# write data to underlying interface. override if data needs to be preprocessed
|
55
|
-
#
|
56
|
-
def write(*args)
|
57
|
-
@writer.<<(*args) if @writer
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
protected
|
62
|
-
|
63
|
-
# override this method to handle data received from an underlying interface, for
|
64
|
-
# example splitting it into messages or only passing on complete lines
|
65
|
-
# (see {LineBasedProtocol#receive} for an example)
|
66
|
-
#
|
67
|
-
# call {#forward} to pass it on to higher levels
|
68
|
-
#
|
69
|
-
# @return [nil]
|
70
|
-
#
|
71
|
-
def receive(data)
|
72
|
-
forward(data)
|
73
|
-
end
|
74
|
-
|
75
|
-
def forward(*data)
|
76
|
-
@on_data.call(*data) if @on_data
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
class LineBasedProtocol < Base
|
82
|
-
|
83
|
-
# strip newlines from received data and pass on complete lines
|
84
|
-
#
|
85
|
-
# @param [String] data
|
86
|
-
#
|
87
|
-
def receive(data)
|
88
|
-
@memo ||= ""
|
89
|
-
scanner = StringScanner.new(@memo + data)
|
90
|
-
while s = scanner.scan(/.*?\n/)
|
91
|
-
forward(s.strip)
|
92
|
-
end
|
93
|
-
@memo = scanner.rest
|
94
|
-
nil
|
95
|
-
end
|
96
|
-
|
97
|
-
# add a newline to data and pass it on
|
98
|
-
# @param [String] data
|
99
|
-
#
|
100
|
-
def write(data)
|
101
|
-
super(data + "\n")
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
class IOListener < Base
|
106
|
-
def run!
|
107
|
-
while not @reader.eof?
|
108
|
-
str = @reader.readpartial(4096)
|
109
|
-
forward(str)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
data/test/test_io_listener.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestIOListener < Test::Unit::TestCase
|
4
|
-
context "a server" do
|
5
|
-
setup do
|
6
|
-
r1, w1 = IO.pipe # Immulite -> LIS
|
7
|
-
r2, w2 = IO.pipe # LIS -> Immulite
|
8
|
-
|
9
|
-
@server = LIS::Transfer::IOListener.new(r1, w2)
|
10
|
-
@protocol = LIS::Transfer::LineBasedProtocol.new(@server)
|
11
|
-
@device = Mock::Server.new(r2, w1)
|
12
|
-
end
|
13
|
-
|
14
|
-
should "exist" do
|
15
|
-
assert_not_nil @server
|
16
|
-
end
|
17
|
-
|
18
|
-
should "yield packets written to it" do
|
19
|
-
@packets = []
|
20
|
-
@protocol.on_data { |packet| @packets << packet }
|
21
|
-
|
22
|
-
@device.write("fo").wait.write("o\n").wait.write("bar\n").eof
|
23
|
-
@server.run!
|
24
|
-
|
25
|
-
assert_equal ["foo", "bar"], @packets
|
26
|
-
end
|
27
|
-
|
28
|
-
should "send data" do
|
29
|
-
@protocol << "hello world"
|
30
|
-
data = @device.read_all
|
31
|
-
assert_equal "hello world\n", data
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|