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