line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
################################################################################ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# File : Segment.pm |
4
|
|
|
|
|
|
|
# Author : Duco Dokter |
5
|
|
|
|
|
|
|
# Created : Tue Mar 4 13:03:00 2003 |
6
|
|
|
|
|
|
|
# Version : $Id: Segment.pm,v 1.15 2014/09/11 09:17:20 wyldebeast Exp $ |
7
|
|
|
|
|
|
|
# Copyright : Wyldebeast & Wunderliebe |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
################################################################################ |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Net::HL7::Segment; |
12
|
|
|
|
|
|
|
|
13
|
7
|
|
|
7
|
|
1265
|
use 5.004; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
237
|
|
14
|
7
|
|
|
7
|
|
27
|
use strict; |
|
7
|
|
|
|
|
6
|
|
|
7
|
|
|
|
|
174
|
|
15
|
7
|
|
|
7
|
|
716
|
use Net::HL7::Message; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
3332
|
|
16
|
|
|
|
|
|
|
#use Net::HL7::Segments::CtrlImpl; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=pod |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 NAME |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Net::HL7::Segment |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $seg = new Net::HL7::Segment("PID"); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$seg->setField(3, "12345678"); |
30
|
|
|
|
|
|
|
print $seg->getField(1); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
The Net::HL7::Segment class represents segments of the HL7 message. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 METHODS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=over 4 |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item B<$seg = new Net::HL7::Segment($name, [$fields])> |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Create an instance of this segment. A segment may be created with just |
43
|
|
|
|
|
|
|
a name or a name and a reference to an array of field values. If the |
44
|
|
|
|
|
|
|
name is not given, no segment is created. The segment name should be |
45
|
|
|
|
|
|
|
three characters long, and upper case. If it isn't, no segment is |
46
|
|
|
|
|
|
|
created, and undef is returned. If a reference to an array is given, |
47
|
|
|
|
|
|
|
all fields will be filled from that array. Note that for composed |
48
|
|
|
|
|
|
|
fields and subcomponents, the array may hold subarrays and |
49
|
|
|
|
|
|
|
subsubarrays. Repeated fields can not be supported the same way, since |
50
|
|
|
|
|
|
|
we can't distinguish between composed fields and repeated fields. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub new { |
55
|
|
|
|
|
|
|
|
56
|
54
|
|
|
54
|
1
|
1619
|
my $class = shift; |
57
|
54
|
|
|
|
|
116
|
bless my $self = {}, $class; |
58
|
|
|
|
|
|
|
|
59
|
54
|
100
|
|
|
|
151
|
$self->_init(@_) || return undef; |
60
|
|
|
|
|
|
|
|
61
|
50
|
|
|
|
|
110
|
return $self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _init { |
66
|
|
|
|
|
|
|
|
67
|
54
|
|
|
54
|
|
68
|
my ($self, $name, $fieldsRef) = @_; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Is the name 3 upper case characters? |
70
|
|
|
|
|
|
|
# |
71
|
54
|
100
|
100
|
|
|
268
|
($name && (length($name) == 3)) || return undef; |
72
|
51
|
100
|
|
|
|
124
|
(uc($name) eq $name) || return undef; |
73
|
|
|
|
|
|
|
|
74
|
50
|
|
|
|
|
130
|
$self->{FIELDS} = []; |
75
|
|
|
|
|
|
|
|
76
|
50
|
|
|
|
|
86
|
$self->{FIELDS}->[0] = $name; |
77
|
|
|
|
|
|
|
|
78
|
50
|
100
|
66
|
|
|
168
|
if ($fieldsRef && ref($fieldsRef) eq "ARRAY") { |
79
|
|
|
|
|
|
|
|
80
|
27
|
|
|
|
|
31
|
for (my $i = 0; $i < @{ $fieldsRef }; $i++) { |
|
213
|
|
|
|
|
356
|
|
81
|
|
|
|
|
|
|
|
82
|
186
|
|
|
|
|
372
|
$self->setField($i + 1, $fieldsRef->[$i]); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
50
|
|
|
|
|
87
|
return 1; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=pod |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item B |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Set the field specified by index to value, and return some true value |
95
|
|
|
|
|
|
|
if the operation succeeded. Indices start at 1, to stay with the HL7 |
96
|
|
|
|
|
|
|
standard. Trying to set the value at index 0 has no effect. The value |
97
|
|
|
|
|
|
|
may also be a reference to an array (that may itself contain arrays) |
98
|
|
|
|
|
|
|
to support composed fields (and subcomponents). |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
To set a field to the HL7 null value, instead of omitting a field, can |
101
|
|
|
|
|
|
|
be achieved with the Net::HL7::NULL type, like: |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$segment->setField(8, $Net::HL7::NULL); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This will render the field as the double quote (""). |
106
|
|
|
|
|
|
|
If values are not provided at all, the method will just return. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub setField { |
111
|
|
|
|
|
|
|
|
112
|
299
|
|
|
299
|
1
|
488
|
my ($self, $index, $value) = @_; |
113
|
|
|
|
|
|
|
|
114
|
299
|
100
|
100
|
|
|
965
|
return undef unless ($index and defined($value)); |
115
|
|
|
|
|
|
|
|
116
|
192
|
|
|
|
|
255
|
$self->{FIELDS}->[$index] = $value; |
117
|
|
|
|
|
|
|
|
118
|
192
|
|
|
|
|
256
|
return 1; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=pod |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item B |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Get the field at index. If the field is a composed field, you might |
127
|
|
|
|
|
|
|
ask for the result to be an array like so: |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my @subfields = $seg->getField(9) |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
otherwise the thing returned will be a reference to an array. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub getField { |
136
|
|
|
|
|
|
|
|
137
|
226
|
|
|
226
|
1
|
205
|
my ($self, $index) = @_; |
138
|
|
|
|
|
|
|
|
139
|
226
|
100
|
|
|
|
318
|
if (wantarray) { |
140
|
34
|
100
|
|
|
|
57
|
if (ref($self->{FIELDS}->[$index]) eq "ARRAY") { |
141
|
4
|
|
|
|
|
4
|
return @{ $self->{FIELDS}->[$index]}; |
|
4
|
|
|
|
|
15
|
|
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
else { |
144
|
30
|
|
|
|
|
65
|
return ($self->{FIELDS}->[$index]); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
else { |
148
|
192
|
|
|
|
|
1092
|
return $self->{FIELDS}->[$index]; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=pod |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item B |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Get the string representation of the field |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub getFieldAsString { |
163
|
|
|
|
|
|
|
|
164
|
84
|
|
|
84
|
1
|
73
|
my ($self, $index) = @_; |
165
|
|
|
|
|
|
|
|
166
|
84
|
|
|
|
|
68
|
my $fieldStr = ""; |
167
|
84
|
|
|
|
|
92
|
my $field = $self->{FIELDS}->[$index]; |
168
|
|
|
|
|
|
|
|
169
|
84
|
100
|
|
|
|
100
|
if (ref($field) eq "ARRAY") { |
170
|
|
|
|
|
|
|
|
171
|
9
|
|
|
|
|
9
|
for (my $i = 0; $i < @{ $field }; $i++) { |
|
32
|
|
|
|
|
53
|
|
172
|
|
|
|
|
|
|
|
173
|
23
|
100
|
|
|
|
36
|
if (ref($field->[$i]) eq "ARRAY") { |
174
|
|
|
|
|
|
|
|
175
|
5
|
|
|
|
|
5
|
$fieldStr .= join($Net::HL7::SUBCOMPONENT_SEPARATOR, @{ $field->[$i] }); |
|
5
|
|
|
|
|
9
|
|
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
else { |
178
|
18
|
|
|
|
|
14
|
$fieldStr .= $field->[$i]; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
23
|
100
|
|
|
|
15
|
if ($i < (@{ $field } - 1)) { |
|
23
|
|
|
|
|
36
|
|
182
|
14
|
|
|
|
|
13
|
$fieldStr .= $Net::HL7::COMPONENT_SEPARATOR; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
else { |
187
|
75
|
|
|
|
|
75
|
$fieldStr .= $field; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
84
|
|
|
|
|
135
|
return $fieldStr; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=pod |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item B |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Get the number of fields for this segment, not including the name |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub size { |
203
|
|
|
|
|
|
|
|
204
|
22
|
|
|
22
|
1
|
26
|
my $self = shift; |
205
|
|
|
|
|
|
|
|
206
|
22
|
|
|
|
|
12
|
return @{ $self->{FIELDS} } - 1; |
|
22
|
|
|
|
|
66
|
|
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=pod |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item B |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Get the fields in the specified range, or all if nothing specified. If |
215
|
|
|
|
|
|
|
only the 'from' value is provided, all fields from this index till the |
216
|
|
|
|
|
|
|
end of the segment will be returned. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub getFields { |
221
|
|
|
|
|
|
|
|
222
|
9
|
|
|
9
|
1
|
836
|
my ($self, $from, $to) = @_; |
223
|
|
|
|
|
|
|
|
224
|
9
|
100
|
|
|
|
26
|
$from || ($from = 0); |
225
|
9
|
100
|
|
|
|
17
|
$to || ($to = $#{$self->{FIELDS}}); |
|
8
|
|
|
|
|
17
|
|
226
|
|
|
|
|
|
|
|
227
|
9
|
|
|
|
|
25
|
return @{ $self->{FIELDS} }[$from..$to]; |
|
9
|
|
|
|
|
45
|
|
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=pod |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item B |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Get the name of the segment. This is basically the value at index 0 |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=back |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub getName { |
242
|
|
|
|
|
|
|
|
243
|
64
|
|
|
64
|
1
|
59
|
my $self = shift; |
244
|
|
|
|
|
|
|
|
245
|
64
|
|
|
|
|
170
|
return $self->{FIELDS}->[0]; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
1; |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=pod |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 AUTHOR |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
D.A.Dokter |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 LICENSE |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Copyright (c) 2002 D.A.Dokter. All rights reserved. This program is |
261
|
|
|
|
|
|
|
free software; you can redistribute it and/or modify it under the same |
262
|
|
|
|
|
|
|
terms as Perl itself. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=cut |