WatersOfOblivion-heychell7 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/heychell7.rb +67 -109
- metadata +1 -1
data/lib/heychell7.rb
CHANGED
@@ -2,23 +2,41 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
module Heychell7
|
5
|
-
VERSION = '0.0.
|
5
|
+
VERSION = '0.0.2'
|
6
6
|
|
7
|
-
class
|
8
|
-
def message &block
|
9
|
-
Message.instance_eval &block
|
10
|
-
end
|
11
|
-
end
|
7
|
+
class ParseError < Exception; end
|
12
8
|
|
13
9
|
class Parser
|
14
10
|
def initialize
|
15
11
|
@buffer = ""
|
16
|
-
@segments = []
|
17
|
-
@fields = []
|
18
|
-
@items = []
|
19
12
|
@stack = []
|
20
13
|
end
|
21
14
|
|
15
|
+
def parse_trigger &block
|
16
|
+
@trigger = block
|
17
|
+
Proc.new { |data|
|
18
|
+
parse data
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_io io
|
23
|
+
while (buf = io.read).length > 0 do
|
24
|
+
parse buf
|
25
|
+
end
|
26
|
+
message
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_string str
|
30
|
+
parse "\x0b#{str}\x1c\r" unless str =~ /^\x0b.*\x1c\r$/
|
31
|
+
message
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_file filename
|
35
|
+
parse_io File.open(filename, "r")
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
22
40
|
def parse str
|
23
41
|
@buffer += str.to_s
|
24
42
|
parse_re = /\n|\||\^|^\x0b|\x1c\r$/
|
@@ -34,21 +52,8 @@ module Heychell7
|
|
34
52
|
|
35
53
|
@buffer = $'
|
36
54
|
end
|
37
|
-
|
38
|
-
reduce Segment, Message
|
39
|
-
@stack.pop
|
40
|
-
end
|
41
|
-
|
42
|
-
def parse_string str
|
43
|
-
parse "\x0b#{str}\x1c\r" unless str =~ /^\x0b.*\x1c\r$/
|
44
55
|
end
|
45
56
|
|
46
|
-
def parse_file filename
|
47
|
-
parse_string File.open(filename, "r").read
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
57
|
def emit_segment data
|
53
58
|
emit_field data
|
54
59
|
reduce Field, Segment
|
@@ -64,16 +69,17 @@ module Heychell7
|
|
64
69
|
end
|
65
70
|
|
66
71
|
def emit_start
|
67
|
-
@items, @fields, @segments = [], [], []
|
68
72
|
@stack = []
|
69
73
|
end
|
70
74
|
|
71
75
|
def emit_end data
|
72
76
|
emit_segment data unless data.empty?
|
77
|
+
reduce Segment, Message
|
78
|
+
@trigger.call message if @trigger
|
73
79
|
end
|
74
80
|
|
75
81
|
def emit_error
|
76
|
-
|
82
|
+
raise ParseError.new("Unexpected #{$&}")
|
77
83
|
end
|
78
84
|
|
79
85
|
def reduce source, target
|
@@ -85,12 +91,16 @@ module Heychell7
|
|
85
91
|
tmp.reverse.each { |src| target << src }
|
86
92
|
@stack.push target
|
87
93
|
end
|
94
|
+
|
95
|
+
def message
|
96
|
+
@stack.last.is_a?(Message) ? @stack.pop : nil
|
97
|
+
end
|
88
98
|
end
|
89
99
|
|
90
100
|
class Message
|
91
101
|
attr_accessor :segments
|
92
102
|
|
93
|
-
def initialize segments
|
103
|
+
def initialize *segments
|
94
104
|
@segments = segments
|
95
105
|
end
|
96
106
|
|
@@ -110,7 +120,7 @@ module Heychell7
|
|
110
120
|
class Segment
|
111
121
|
attr_accessor :fields
|
112
122
|
|
113
|
-
def initialize fields
|
123
|
+
def initialize *fields
|
114
124
|
@fields = fields
|
115
125
|
end
|
116
126
|
|
@@ -126,7 +136,7 @@ module Heychell7
|
|
126
136
|
class Field
|
127
137
|
attr_accessor :items
|
128
138
|
|
129
|
-
def initialize items
|
139
|
+
def initialize *items
|
130
140
|
@items = items
|
131
141
|
end
|
132
142
|
|
@@ -154,99 +164,47 @@ module Heychell7
|
|
154
164
|
=begin
|
155
165
|
message do
|
156
166
|
segment :evn do
|
157
|
-
|
158
|
-
|
159
|
-
field :planned_date
|
160
|
-
field :reason_code
|
161
|
-
field :operator_id
|
162
|
-
field :event_occurred
|
163
|
-
field :event_facility
|
167
|
+
fields :type_code, :recorded_date, :planned_date, :reason_code,
|
168
|
+
:operator_id, :event_occurred, :event_facility
|
164
169
|
end
|
165
170
|
|
166
|
-
segment :
|
167
|
-
|
168
|
-
|
169
|
-
field :text
|
170
|
-
field :expected_seq
|
171
|
-
field :delayed_ack_type
|
172
|
-
field :error_cond
|
171
|
+
segment :msa do
|
172
|
+
fields :ack_code, :control_id, :text, :expected_seq, :delayed_ack_type,
|
173
|
+
:error_cond
|
173
174
|
end
|
174
175
|
|
175
176
|
segment :msh do
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
field :time
|
182
|
-
field :security
|
183
|
-
field :message_type
|
184
|
-
field :message_control_id
|
185
|
-
field :processing_id
|
186
|
-
field :version_id
|
187
|
-
field :seq
|
188
|
-
field :continue_ptr
|
189
|
-
field :accept_ack_type
|
190
|
-
field :app_ack_type
|
191
|
-
field :country_code
|
192
|
-
field :charset
|
177
|
+
fields :enc_chars, :sending_app, :sending_facility, :recv_app,
|
178
|
+
:recv_facility, :time, :security, :message_type,
|
179
|
+
:message_control_id, :processing_id, :version_id, :seq,
|
180
|
+
:continue_ptr, :accept_ack_type, :app_ack_type, :country_code,
|
181
|
+
:charset
|
193
182
|
end
|
194
183
|
|
195
184
|
segment :nte do
|
196
|
-
|
197
|
-
field :source
|
198
|
-
field :comment
|
199
|
-
field :comment_type
|
185
|
+
fields :set_id, :source, :comment, :comment_type
|
200
186
|
end
|
201
187
|
|
202
188
|
segment :obr do
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
field :filer_field_1
|
223
|
-
field :filer_field_2
|
224
|
-
field :results_status_change_date
|
225
|
-
field :charge_to_practice
|
226
|
-
field :parent_result
|
227
|
-
field :quantity_timing
|
228
|
-
field :result_copies_to
|
229
|
-
field :parent
|
230
|
-
field :transport_mode
|
231
|
-
field :reason_for_study
|
232
|
-
field :principal_result_interpreter
|
233
|
-
field :assistant_result_interpreter
|
234
|
-
field :technician
|
235
|
-
field :transcriptionist
|
236
|
-
field :scheduled_date
|
237
|
-
field :number_of_sample_containers
|
238
|
-
field :transport_logistics_of_sample
|
239
|
-
field :collectors_comment
|
240
|
-
field :transport_arrangement_responsibility
|
241
|
-
field :transport_arranged
|
242
|
-
field :escort_required
|
243
|
-
field :planned_patient_transport_comment
|
244
|
-
field :procedure_code
|
245
|
-
field :procedure_code_modified
|
246
|
-
field :placer_supplemental_service_info
|
247
|
-
field :filler_supplemental_service_info
|
248
|
-
field :medically_necessary_dup_procedure_reason
|
249
|
-
field :result_handling
|
189
|
+
fields :set_id, :placer_order_number, :filler_order_number,
|
190
|
+
:universal_service_id, :priority, :requested_date,
|
191
|
+
:observation_date, :observation_end_date, :collection_volume,
|
192
|
+
:colletor_identifier, :specimen_action_code, :danger_code,
|
193
|
+
:relevant_clinical_info, :specimen_received_date, :specimen_source,
|
194
|
+
:ordering_provider, :order_callback_phone_number, :placer_field_1,
|
195
|
+
:placer_field_2, :filer_field_1, :filer_field_2,
|
196
|
+
:results_status_change_date, :charge_to_practice, :parent_result,
|
197
|
+
:quantity_timing, :result_copies_to, :parent, :transport_mode,
|
198
|
+
:reason_for_study, :principal_result_interpreter,
|
199
|
+
:assistant_result_interpreter, :technician, :transcriptionist,
|
200
|
+
:scheduled_date, :number_of_sample_containers,
|
201
|
+
:transport_logistics_of_sample, :collectors_comment,
|
202
|
+
:transport_arrangement_responsibility, :transport_arranged,
|
203
|
+
:escort_required, :planned_patient_transport_comment,
|
204
|
+
:procedure_code, :procedure_code_modified,
|
205
|
+
:placer_supplemental_service_info,
|
206
|
+
:filler_supplemental_service_info,
|
207
|
+
:medically_necessary_dup_procedure_reason, :result_handling
|
250
208
|
end
|
251
209
|
|
252
210
|
segment :obx do
|