ruby-hl7 0.1.23

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ # $Id: evn.rb 13 2007-03-09 04:42:29Z segfault $
2
+ require 'ruby-hl7'
3
+ class HL7::Message::Segment::EVN < HL7::Message::Segment
4
+ weight 0 # should occur after the MSH segment
5
+ add_field :name=>:type_code, :idx=>1
6
+ add_field :name=>:recorded_date, :idx=>2
7
+ add_field :name=>:planned_date, :idx=>3
8
+ add_field :name=>:reason_code, :idx=>4
9
+ add_field :name=>:operator_id, :idx=>5
10
+ add_field :name=>:event_occurred, :idx=>6
11
+ add_field :name=>:event_facility, :idx=>6
12
+ end
@@ -0,0 +1,12 @@
1
+ # $Id: msa.rb 15 2007-03-11 05:21:09Z segfault $
2
+ require 'ruby-hl7'
3
+ class HL7::Message::Segment::MSA < HL7::Message::Segment
4
+ weight 0 # should occur after the msh segment
5
+ add_field :name=>:ack_code
6
+ add_field :name=>:control_id
7
+ add_field :name=>:text
8
+ add_field :name=>:expected_seq
9
+ add_field :name=>:delayed_ack_type
10
+ add_field :name=>:error_cond
11
+ end
12
+
@@ -0,0 +1,22 @@
1
+ # $Id: msh.rb 13 2007-03-09 04:42:29Z segfault $
2
+ require 'ruby-hl7'
3
+ class HL7::Message::Segment::MSH < HL7::Message::Segment
4
+ weight -1 # the msh should always start a message
5
+ add_field :name=>:enc_chars, :idx=>1
6
+ add_field :name=>:sending_app, :idx=>2
7
+ add_field :name=>:sending_facility, :idx=>3
8
+ add_field :name=>:recv_app, :idx=>4
9
+ add_field :name=>:recv_facility, :idx=>5
10
+ add_field :name=>:time, :idx=>6
11
+ add_field :name=>:security, :idx=>7
12
+ add_field :name=>:message_type, :idx=>8
13
+ add_field :name=>:message_control_id, :idx=>9
14
+ add_field :name=>:processing_id, :idx=>10
15
+ add_field :name=>:version_id, :idx=>11
16
+ add_field :name=>:seq, :idx=>12
17
+ add_field :name=>:continue_ptr, :idx=>13
18
+ add_field :name=>:accept_ack_type, :idx=>14
19
+ add_field :name=>:app_ack_type, :idx=>15
20
+ add_field :name=>:country_code, :idx=>16
21
+ add_field :name=>:charset, :idx=>17
22
+ end
@@ -0,0 +1,9 @@
1
+ # $Id: nte.rb 13 2007-03-09 04:42:29Z segfault $
2
+ require 'ruby-hl7'
3
+ class HL7::Message::Segment::NTE < HL7::Message::Segment
4
+ weight 4
5
+ add_field :name=>:set_id, :idx=>1
6
+ add_field :name=>:source, :idx=>2
7
+ add_field :name=>:comment, :idx=>3
8
+ add_field :name=>:comment_type, :idx=>4
9
+ end
@@ -0,0 +1,52 @@
1
+ # $Id: obr.rb 16 2007-03-14 05:06:36Z segfault $
2
+ require 'ruby-hl7'
3
+ class HL7::Message::Segment::OBR < HL7::Message::Segment
4
+ weight 89 # obr.weight-1
5
+ has_children
6
+ add_field :name=>:set_id
7
+ add_field :name=>:placer_order_number
8
+ add_field :name=>:filler_order_number
9
+ add_field :name=>:priority
10
+ add_field :name=>:requested_date
11
+ add_field :name=>:observation_date
12
+ add_field :name=>:observation_end_date
13
+ add_field :name=>:collection_volume
14
+ add_field :name=>:collector_identifier
15
+ add_field :name=>:specimen_action_code
16
+ add_field :name=>:danger_code
17
+ add_field :name=>:relevant_clinical_info
18
+ add_field :name=>:specimen_received_date
19
+ add_field :name=>:specimen_source
20
+ add_field :name=>:ordering_provider
21
+ add_field :name=>:order_callback_phone_number
22
+ add_field :name=>:placer_field_1
23
+ add_field :name=>:placer_field_2
24
+ add_field :name=>:filer_field_1
25
+ add_field :name=>:filer_field_2
26
+ add_field :name=>:results_status_change_date
27
+ add_field :name=>:charge_to_practice
28
+ add_field :name=>:parent_result
29
+ add_field :name=>:quantity_timing
30
+ add_field :name=>:result_copies_to
31
+ add_field :name=>:parent
32
+ add_field :name=>:transport_mode
33
+ add_field :name=>:reason_for_study
34
+ add_field :name=>:principal_result_interpreter
35
+ add_field :name=>:assistant_result_interpreter
36
+ add_field :name=>:technician
37
+ add_field :name=>:transcriptionist
38
+ add_field :name=>:scheduled_date
39
+ add_field :name=>:number_of_sample_containers
40
+ add_field :name=>:transport_logistics_of_sample
41
+ add_field :name=>:collectors_comment
42
+ add_field :name=>:transport_arrangement_responsibility
43
+ add_field :name=>:transport_arranged
44
+ add_field :name=>:escort_required
45
+ add_field :name=>:planned_patient_transport_comment
46
+ add_field :name=>:procedure_code
47
+ add_field :name=>:procedure_code_modifier
48
+ add_field :name=>:placer_supplemental_service_info
49
+ add_field :name=>:filler_supplemental_service_info
50
+ add_field :name=>:medically_necessary_dup_procedure_reason #longest method name ever. sry.
51
+ add_field :name=>:result_handling
52
+ end
@@ -0,0 +1,24 @@
1
+ # $Id: obx.rb 16 2007-03-14 05:06:36Z segfault $
2
+ require 'ruby-hl7'
3
+ class HL7::Message::Segment::OBX < HL7::Message::Segment
4
+ weight 90
5
+ add_field :name=>:set_id
6
+ add_field :name=>:value_type
7
+ add_field :name=>:observation_id
8
+ add_field :name=>:observation_sub_id
9
+ add_field :name=>:observation_value
10
+ add_field :name=>:units
11
+ add_field :name=>:references_range
12
+ add_field :name=>:probability
13
+ add_field :name=>:nature_of_abnormal_test
14
+ add_field :name=>:observation_result_status
15
+ add_field :name=>:effective_date_of_reference_range
16
+ add_field :name=>:user_defined_access_checks
17
+ add_field :name=>:observation_date
18
+ add_field :name=>:producer_id
19
+ add_field :name=>:responsible_observer
20
+ add_field :name=>:observation_method
21
+ add_field :name=>:equipment_instance_id
22
+ add_field :name=>:analysis_date
23
+ end
24
+
@@ -0,0 +1,4 @@
1
+ # $Id: oru.rb 13 2007-03-09 04:42:29Z segfault $
2
+ require 'ruby-hl7'
3
+ class HL7::Message::Segment::ORU < HL7::Message::Segment
4
+ end
@@ -0,0 +1,49 @@
1
+ # $Id: pid.rb 21 2007-03-17 04:49:50Z segfault $
2
+ require 'ruby-hl7'
3
+ class HL7::Message::Segment::PID < HL7::Message::Segment
4
+ weight 1
5
+ add_field :name=>:set_id
6
+ add_field :name=>:patient_id
7
+ add_field :name=>:patient_id_list
8
+ add_field :name=>:alt_patient_id
9
+ add_field :name=>:patient_name
10
+ add_field :name=>:mother_maiden_name
11
+ add_field :name=>:patient_dob
12
+ add_field :name=>:admin_sex do |sex|
13
+ unless /^[FMOUAN]$/.match(sex) || sex == nil
14
+ raise HL7::InvalidDataError.new( "bad administrative sex value (not F|M|O|U|A|N)" )
15
+ end
16
+ sex = "" unless sex
17
+ sex
18
+ end
19
+ add_field :name=>:patient_alias
20
+ add_field :name=>:race
21
+ add_field :name=>:address
22
+ add_field :name=>:country_code
23
+ add_field :name=>:phone_home
24
+ add_field :name=>:phone_business
25
+ add_field :name=>:primary_language
26
+ add_field :name=>:marital_status
27
+ add_field :name=>:religion
28
+ add_field :name=>:account_number
29
+ add_field :name=>:social_security_num
30
+ add_field :name=>:mothers_id
31
+ add_field :name=>:ethnic_group
32
+ add_field :name=>:birthplace
33
+ add_field :name=>:multi_birth
34
+ add_field :name=>:birth_order
35
+ add_field :name=>:citizenship
36
+ add_field :name=>:vet_status
37
+ add_field :name=>:nationality
38
+ add_field :name=>:death_date
39
+ add_field :name=>:death_indicator
40
+ add_field :name=>:id_unknown_indicator
41
+ add_field :name=>:id_readability_code
42
+ add_field :name=>:last_update_date
43
+ add_field :name=>:last_update_facility
44
+ add_field :name=>:species_code
45
+ add_field :name=>:breed_code
46
+ add_field :name=>:strain
47
+ add_field :name=>:production_class_code
48
+ add_field :name=>:tribal_citizenship
49
+ end
@@ -0,0 +1,57 @@
1
+ # $Id: pv1.rb 15 2007-03-11 05:21:09Z segfault $
2
+ require 'ruby-hl7'
3
+ class HL7::Message::Segment::PV1 < HL7::Message::Segment
4
+ weight 2
5
+ add_field :name=>:set_id
6
+ add_field :name=>:patient_class
7
+ add_field :name=>:assigned_location
8
+ add_field :name=>:admission_type
9
+ add_field :name=>:preadmit_number
10
+ add_field :name=>:prior_location
11
+ add_field :name=>:attending_doctor
12
+ add_field :name=>:referring_doctor
13
+ add_field :name=>:consulting_doctor
14
+ add_field :name=>:hospital_service
15
+ add_field :name=>:temporary_location
16
+ add_field :name=>:preadmit_indicator
17
+ add_field :name=>:readmit_indicator
18
+ add_field :name=>:admit_source
19
+ add_field :name=>:ambulatory_status
20
+ add_field :name=>:vip_indicator
21
+ add_field :name=>:admitting_doctor
22
+ add_field :name=>:patient_type
23
+ add_field :name=>:visit_number
24
+ add_field :name=>:financial_class
25
+ add_field :name=>:charge_price_indicator
26
+ add_field :name=>:courtesy_code
27
+ add_field :name=>:credit_rating
28
+ add_field :name=>:contract_code
29
+ add_field :name=>:contract_effective_date
30
+ add_field :name=>:contract_amount
31
+ add_field :name=>:contract_period
32
+ add_field :name=>:interest_code
33
+ add_field :name=>:transfer_bad_debt_code
34
+ add_field :name=>:transfer_bad_debt_date
35
+ add_field :name=>:bad_debt_agency_code
36
+ add_field :name=>:bad_debt_transfer_amount
37
+ add_field :name=>:bad_debt_recovery_amount
38
+ add_field :name=>:delete_account_indicator
39
+ add_field :name=>:delete_account_date
40
+ add_field :name=>:discharge_disposition
41
+ add_field :name=>:discharge_to_location
42
+ add_field :name=>:diet_type
43
+ add_field :name=>:servicing_facility
44
+ add_field :name=>:bed_status
45
+ add_field :name=>:account_status
46
+ add_field :name=>:pending_location
47
+ add_field :name=>:prior_temporary_location
48
+ add_field :name=>:admit_date
49
+ add_field :name=>:discharge_date
50
+ add_field :name=>:current_patient_balance
51
+ add_field :name=>:total_charges
52
+ add_field :name=>:total_adjustments
53
+ add_field :name=>:total_payments
54
+ add_field :name=>:alternate_visit_id
55
+ add_field :name=>:visit_indicator
56
+ add_field :name=>:other_healthcare_provider
57
+ end
@@ -0,0 +1,53 @@
1
+ # $Id: pv2.rb 15 2007-03-11 05:21:09Z segfault $
2
+ require 'ruby-hl7'
3
+ class HL7::Message::Segment::PV2 < HL7::Message::Segment
4
+ weight 3
5
+ add_field :name=>:prior_pending_location
6
+ add_field :name=>:accommodation_code
7
+ add_field :name=>:admit_reason
8
+ add_field :name=>:transfer_reason
9
+ add_field :name=>:patient_valuables
10
+ add_field :name=>:patient_valuables_location
11
+ add_field :name=>:visit_user_code
12
+ add_field :name=>:expected_admit_date
13
+ add_field :name=>:expected_discharge_date
14
+ add_field :name=>:estimated_inpatient_stay_length
15
+ add_field :name=>:actual_inpatient_stay_length
16
+ add_field :name=>:visit_description
17
+ add_field :name=>:referral_source_code
18
+ add_field :name=>:previous_service_date
19
+ add_field :name=>:employment_illness_related_indicator
20
+ add_field :name=>:purge_status_code
21
+ add_field :name=>:purge_status_date
22
+ add_field :name=>:special_program_code
23
+ add_field :name=>:retention_indicator
24
+ add_field :name=>:expected_number_of_insurance_plans
25
+ add_field :name=>:visit_publicity_code
26
+ add_field :name=>:visit_protection_indicator
27
+ add_field :name=>:clinic_organization_name
28
+ add_field :name=>:patient_status_code
29
+ add_field :name=>:visit_priority_code
30
+ add_field :name=>:previous_treatment_date
31
+ add_field :name=>:expected_discharge_disposition
32
+ add_field :name=>:signature_on_file
33
+ add_field :name=>:first_similar_illness_date
34
+ add_field :name=>:patient_charge_adjustment_code
35
+ add_field :name=>:recurring_service_code
36
+ add_field :name=>:billing_media_code
37
+ add_field :name=>:expected_surgery_date
38
+ add_field :name=>:military_partnership_code
39
+ add_field :name=>:military_non_availibility_code
40
+ add_field :name=>:newborn_baby_indicator
41
+ add_field :name=>:baby_detained_indicator
42
+ add_field :name=>:mode_of_arrival_code
43
+ add_field :name=>:recreational_drug_use_code
44
+ add_field :name=>:precaution_code
45
+ add_field :name=>:patient_condition_code
46
+ add_field :name=>:living_will_code
47
+ add_field :name=>:organ_donor_code
48
+ add_field :name=>:advance_directive_code
49
+ add_field :name=>:patient_status_effective_date
50
+ add_field :name=>:expected_loa_return_date
51
+ add_field :name=>:expected_preadmission_testing_date
52
+ add_field :name=>:notify_clergy_code
53
+ end
@@ -0,0 +1,17 @@
1
+ # $Id: qrd.rb 17 2007-03-14 05:25:11Z segfault $
2
+ require 'ruby-hl7'
3
+ class HL7::Message::Segment::QRD < HL7::Message::Segment
4
+ weight 84
5
+ add_field :name=>:query_date
6
+ add_field :name=>:query_format_code
7
+ add_field :name=>:query_priority
8
+ add_field :name=>:query_id
9
+ add_field :name=>:deferred_response_type
10
+ add_field :name=>:deferred_response_date
11
+ add_field :name=>:quantity_limited_request
12
+ add_field :name=>:who_subject_filter
13
+ add_field :name=>:what_subject_filter
14
+ add_field :name=>:what_department_code
15
+ add_field :name=>:what_data_code
16
+ add_field :name=>:query_results_level
17
+ end
@@ -0,0 +1,15 @@
1
+ # $Id: qrf.rb 17 2007-03-14 05:25:11Z segfault $
2
+ require 'ruby-hl7'
3
+ class HL7::Message::Segment::QRF < HL7::Message::Segment
4
+ weight 85
5
+ add_field :name=>:where_subject_filter
6
+ add_field :name=>:when_start_date
7
+ add_field :name=>:when_end_date
8
+ add_field :name=>:what_user_qualifier
9
+ add_field :name=>:other_qry_subject_filter
10
+ add_field :name=>:which_date_qualifier
11
+ add_field :name=>:which_date_status_qualifier
12
+ add_field :name=>:date_selection_qualifier
13
+ add_field :name=>:when_timing_qualifier
14
+ add_field :name=>:search_confidence_threshold
15
+ end
@@ -0,0 +1,306 @@
1
+ # $Id: test_basic_parsing.rb 21 2007-03-17 04:49:50Z segfault $
2
+ $: << '../lib'
3
+ require 'test/unit'
4
+ require 'ruby-hl7'
5
+
6
+ class BasicParsing < Test::Unit::TestCase
7
+ def setup
8
+ @simple_msh_txt = open( './test_data/test.hl7' ).readlines.first
9
+ @base_msh = "MSH|^~\\&|LAB1||DESTINATION||19910127105114||ORU^R03|LAB1003929"
10
+ end
11
+
12
+ def test_simple_msh
13
+ msg = HL7::Message.new
14
+ msg.parse @simple_msh_txt
15
+ assert_equal( @simple_msh_txt, msg.to_hl7 )
16
+ end
17
+
18
+ def test_constructor_parse
19
+ msg = HL7::Message.new( @simple_msh_txt )
20
+ assert_equal( @simple_msh_txt, msg.to_hl7 )
21
+ end
22
+
23
+ def test_class_parse
24
+ msg = HL7::Message.parse( @simple_msh_txt )
25
+ assert_equal( @simple_msh_txt, msg.to_hl7 )
26
+ end
27
+
28
+ def test_not_string_or_enumerable
29
+ assert_raise( HL7::ParseError ) do
30
+ msg = HL7::Message.parse( :MSHthis_shouldnt_parse_at_all )
31
+ end
32
+ end
33
+
34
+ def test_message_to_string
35
+ msg = HL7::Message.new
36
+ msg.parse @simple_msh_txt
37
+ orig = @simple_msh_txt.gsub( /\r/, '\n' )
38
+ assert_equal( orig, msg.to_s )
39
+ end
40
+
41
+ def test_to_s_vs_to_hl7
42
+ msg = HL7::Message.new( @simple_msh_txt )
43
+ assert_not_equal( msg.to_s, msg.to_hl7 )
44
+ end
45
+
46
+ def test_segment_numeric_accessor
47
+ msg = HL7::Message.new
48
+ msg.parse @simple_msh_txt
49
+ assert_equal( @base_msh, msg[0].to_s )
50
+ end
51
+
52
+ def test_segment_string_accessor
53
+ msg = HL7::Message.new
54
+ msg.parse @simple_msh_txt
55
+ assert_equal( @base_msh, msg["MSH"].to_s )
56
+ end
57
+
58
+ def test_segment_symbol_accessor
59
+ msg = HL7::Message.new
60
+ msg.parse @simple_msh_txt
61
+ assert_equal( @base_msh, msg[:MSH].to_s )
62
+ end
63
+
64
+ def test_segment_numeric_mutator
65
+ msg = HL7::Message.new
66
+ msg.parse @simple_msh_txt
67
+ inp = HL7::Message::Segment::Default.new
68
+ msg[1] = inp
69
+ assert_equal( inp, msg[1] )
70
+
71
+ assert_raise( HL7::Exception ) do
72
+ msg[2] = Class.new
73
+ end
74
+ end
75
+
76
+ def test_segment_string_mutator
77
+ msg = HL7::Message.new
78
+ msg.parse @simple_msh_txt
79
+ inp = HL7::Message::Segment::NTE.new
80
+ msg["NTE"] = inp
81
+ assert_equal( inp, msg["NTE"] )
82
+
83
+ assert_raise( HL7::Exception ) do
84
+ msg["NTE"] = Class.new
85
+ end
86
+ end
87
+
88
+ def test_segment_symbol_accessor
89
+ msg = HL7::Message.new
90
+ msg.parse @simple_msh_txt
91
+ inp = HL7::Message::Segment::NTE.new
92
+ msg[:NTE] = inp
93
+ assert_equal( inp, msg[:NTE] )
94
+
95
+ assert_raise( HL7::Exception ) do
96
+ msg[:NTE] = Class.new
97
+ end
98
+ end
99
+
100
+ def test_element_accessor
101
+ msg = HL7::Message.new
102
+ msg.parse @simple_msh_txt
103
+ assert_equal( "LAB1", msg[:MSH].sending_app )
104
+ end
105
+
106
+ def test_element_mutator
107
+ msg = HL7::Message.new
108
+ msg.parse @simple_msh_txt
109
+ msg[:MSH].sending_app = "TEST"
110
+ assert_equal( "TEST", msg[:MSH].sending_app )
111
+ end
112
+
113
+ def test_element_missing_accessor
114
+ msg = HL7::Message.new
115
+ msg.parse @simple_msh_txt
116
+ assert_raise( HL7::Exception, NoMethodError ) do
117
+ msg[:MSH].does_not_really_exist_here
118
+ end
119
+ end
120
+
121
+ def test_element_missing_mutator
122
+ msg = HL7::Message.new
123
+ msg.parse @simple_msh_txt
124
+ assert_raise( HL7::Exception, NoMethodError ) do
125
+ msg[:MSH].does_not_really_exist_here = "TEST"
126
+ end
127
+ end
128
+
129
+ def test_element_numeric_accessor
130
+ msg = HL7::Message.new( @simple_msh_txt )
131
+
132
+ assert_equal( "LAB1", msg[:MSH].e2 )
133
+ assert_equal( "", msg[:MSH].e3 )
134
+ end
135
+
136
+ def test_element_numeric_mutator
137
+ msg = HL7::Message.parse( @simple_msh_txt )
138
+ msg[:MSH].e2 = "TESTING1234"
139
+ assert_equal( "TESTING1234", msg[:MSH].e2 )
140
+ end
141
+
142
+ def test_segment_append
143
+ msg = HL7::Message.new
144
+ assert_nothing_raised do
145
+ msg << HL7::Message::Segment::MSH.new
146
+ msg << HL7::Message::Segment::NTE.new
147
+ end
148
+
149
+ assert_raises( HL7::Exception ) do
150
+ msg << Class.new
151
+ end
152
+ end
153
+
154
+
155
+ def test_segment_sort
156
+ msg = HL7::Message.new
157
+ pv1 = HL7::Message::Segment::PV1.new
158
+ msg << pv1
159
+ msh = HL7::Message::Segment::MSH.new
160
+ msg << msh
161
+ nte = HL7::Message::Segment::NTE.new
162
+ msg << nte
163
+ nte2 = HL7::Message::Segment::NTE.new
164
+ msg << nte
165
+ msh.sending_app = "TEST"
166
+
167
+
168
+ initial = msg.to_s
169
+ sorted = msg.sort
170
+ final = sorted.to_s
171
+ assert_not_equal( initial, final )
172
+ end
173
+
174
+ def test_segment_auto_set_id
175
+ msg = HL7::Message.new
176
+ msh = HL7::Message::Segment::MSH.new
177
+ msg << msh
178
+ ntea = HL7::Message::Segment::NTE.new
179
+ ntea.comment = "first"
180
+ msg << ntea
181
+ nteb = HL7::Message::Segment::NTE.new
182
+ nteb.comment = "second"
183
+ msg << nteb
184
+ ntec = HL7::Message::Segment::NTE.new
185
+ ntec.comment = "third"
186
+ msg << ntec
187
+ assert_equal( "1", ntea.set_id )
188
+ assert_equal( "2", nteb.set_id )
189
+ assert_equal( "3", ntec.set_id )
190
+ end
191
+
192
+ def test_enumerable_parsing
193
+ test_file = open( './test_data/test.hl7' )
194
+ assert_not_nil( test_file )
195
+
196
+ msg = HL7::Message.new( test_file )
197
+ assert_equal( @simple_msh_txt, msg.to_hl7 )
198
+ end
199
+
200
+ def test_segment_to_info
201
+ msg = HL7::Message.new( @simple_msh_txt )
202
+ assert_not_nil( msg[1].to_info )
203
+ end
204
+
205
+ def test_segment_use_raw_array
206
+ inp = "NTE|1|ME TOO"
207
+ nte = HL7::Message::Segment::NTE.new( inp.split( '|' ) )
208
+ assert_equal( inp, nte.to_s )
209
+ end
210
+
211
+ def test_mllp_output
212
+ msg = HL7::Message.new( @simple_msh_txt )
213
+ expect = "\x0b%s\x1c\r" % msg.to_hl7
214
+ assert_equal( expect, msg.to_mllp )
215
+ end
216
+
217
+ def test_parse_mllp
218
+ raw = "\x0b%s\x1c\r" % @simple_msh_txt
219
+ msg = HL7::Message.parse( raw )
220
+ assert_not_nil( msg )
221
+ assert_equal( @simple_msh_txt, msg.to_hl7 )
222
+ assert_equal( raw, msg.to_mllp )
223
+ end
224
+
225
+ def test_mllp_output_parse
226
+ msg = HL7::Message.parse( @simple_msh_txt )
227
+ assert_not_nil( msg )
228
+ assert_nothing_raised do
229
+ post_mllp = HL7::Message.parse( msg.to_mllp )
230
+ assert_not_nil( post_mllp )
231
+ assert_equal( msg.to_hl7, post_mllp.to_hl7 )
232
+ end
233
+ end
234
+
235
+ def test_child_segment_accessor
236
+ obr = HL7::Message::Segment::OBR.new
237
+ assert_nothing_raised do
238
+ assert_not_nil( obr.children )
239
+ assert_equal( 0, obr.children.length )
240
+ end
241
+ end
242
+
243
+ def test_child_segment_addition
244
+ obr = HL7::Message::Segment::OBR.new
245
+ assert_nothing_raised do
246
+ assert_equal( 0, obr.children.length )
247
+ (1..5).each do |x|
248
+ obr.children << HL7::Message::Segment::OBX.new
249
+ assert_equal( x, obr.children.length )
250
+ end
251
+ end
252
+ end
253
+
254
+ def test_child_segment_invalid_addition
255
+ obr = HL7::Message::Segment::OBR.new
256
+ assert_raises(HL7::Exception) do
257
+ obr.children << Class.new
258
+ end
259
+ end
260
+
261
+ def test_grouped_sequenced_segments
262
+ #multible obr's with multiple obx's
263
+ msg = HL7::Message.parse( @simple_msh_txt )
264
+ orig_output = msg.to_hl7
265
+ (1..10).each do |obr_id|
266
+ obr = HL7::Message::Segment::OBR.new
267
+ msg << obr
268
+ (1..10).each do |obx_id|
269
+ obx = HL7::Message::Segment::OBX.new
270
+ obr.children << obx
271
+ end
272
+ end
273
+
274
+ assert_not_nil( msg[:OBR] )
275
+ assert_equal( 11, msg[:OBR].length )
276
+ assert_not_nil( msg[:OBX] )
277
+ assert_equal( 2, msg[:OBX].length )
278
+ assert_equal( "2", msg[:OBR][4].children[1].set_id ) # confirm the id's
279
+ assert_equal( "2", msg[:OBR][5].children[1].set_id ) # confirm the id's
280
+
281
+ final_output = msg.to_hl7
282
+ assert_not_equal( orig_output, final_output )
283
+ end
284
+
285
+ def test_index_accessor
286
+ msg = HL7::Message.parse( @simple_msh_txt )
287
+ assert_equal( 1, msg.index( "PID" ) )
288
+ assert_equal( 1, msg.index( :PID ) )
289
+ assert_equal( 2, msg.index( "PV1" ) )
290
+ assert_equal( 2, msg.index( :PV1 ) )
291
+ assert_equal( nil, msg.index( "TACOBELL" ) )
292
+ assert_equal( nil, msg.index( nil ) )
293
+ assert_equal( nil, msg.index( 1 ) )
294
+ end
295
+
296
+ def test_segment_field_block
297
+ pid = HL7::Message::Segment::PID.new
298
+ assert_raises( HL7::InvalidDataError ) do
299
+ pid.admin_sex = "TEST"
300
+ end
301
+ assert_nothing_raised do
302
+ pid.admin_sex = "F"
303
+ end
304
+ end
305
+
306
+ end