| 1 | package Net::HL7::Segment; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use 5.004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use Net::HL7::Message; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | 54 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 54 | my $class = shift; | |||||||||||||||||||||||||||
| 47 | 54 | bless my $self = {}, $class; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 54 | ▶ | $self->_init(@_) || return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 50 | return $self; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 54 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 54 | my ($self, $name, $fieldsRef) = @_; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # Is the name 3 upper case characters? | ||||||||||||||||||||||||||||
| 60 | # | ||||||||||||||||||||||||||||
| 61 | 54 | ▶ | ($name && (length($name) == 3)) || return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$name and length $name == 3
MC/DC100%2/2
$name and length $name == 3
$name
length $name == 3
Truth table100%3/3
A and B
A= $nameB= length $name == 3
| |||||||||||||||||||||||||||||
| 62 | 51 | ▶ | (uc($name) eq $name) || return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 50 | $self->{FIELDS} = []; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 50 | $self->{FIELDS}->[0] = $name; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 50 | ▶ | if ($fieldsRef && ref($fieldsRef) eq "ARRAY") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$fieldsRef and ref $fieldsRef eq "ARRAY"
MC/DC50%1/2
$fieldsRef and ref $fieldsRef eq "ARRAY"
$fieldsRef
ref $fieldsRef eq "ARRAY"
Truth table66%2/3
A and B
A= $fieldsRefB= ref $fieldsRef eq "ARRAY"
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 27 | ▶ | for (my $i = 0; $i < @{ $fieldsRef }; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 186 | $self->setField($i + 1, $fieldsRef->[$i]); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 50 | return 1; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =pod | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =item B<setField($index, $value)> | ||||||||||||||||||||||||||||
| 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 | 299 | ▶ | sub setField { | ||||||||||||||||||||||||||
|
Subroutine
setField: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 299 | my ($self, $index, $value) = @_; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 299 | ▶ | return undef unless ($index and defined($value)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$index and defined $value
MC/DC100%2/2
$index and defined $value
$index
defined $value
Truth table100%3/3
A and B
A= $indexB= defined $value
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 192 | $self->{FIELDS}->[$index] = $value; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 192 | return 1; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =pod | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =item B<getField($index)> | ||||||||||||||||||||||||||||
| 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 | 226 | ▶ | sub getField { | ||||||||||||||||||||||||||
|
Subroutine
getField: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 226 | my ($self, $index) = @_; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 226 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 34 | ▶ | if (ref($self->{FIELDS}->[$index]) eq "ARRAY") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 4 | return @{ $self->{FIELDS}->[$index]}; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | else { | ||||||||||||||||||||||||||||
| 134 | 30 | return ($self->{FIELDS}->[$index]); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | else { | ||||||||||||||||||||||||||||
| 138 | 192 | return $self->{FIELDS}->[$index]; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =pod | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =item B<getFieldAsString()> | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | Get the string representation of the field | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =cut | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 84 | ▶ | sub getFieldAsString { | ||||||||||||||||||||||||||
|
Subroutine
getFieldAsString: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 84 | my ($self, $index) = @_; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 84 | my $fieldStr = ""; | |||||||||||||||||||||||||||
| 157 | 84 | my $field = $self->{FIELDS}->[$index]; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 84 | ▶ | if (ref($field) eq "ARRAY") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 9 | ▶ | for (my $i = 0; $i < @{ $field }; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 23 | ▶ | if (ref($field->[$i]) eq "ARRAY") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 5 | $fieldStr .= join($Net::HL7::SUBCOMPONENT_SEPARATOR, @{ $field->[$i] }); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | else { | ||||||||||||||||||||||||||||
| 168 | 18 | $fieldStr .= $field->[$i]; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 23 | ▶ | if ($i < (@{ $field } - 1)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 14 | $fieldStr .= $Net::HL7::COMPONENT_SEPARATOR; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | else { | ||||||||||||||||||||||||||||
| 177 | 75 | $fieldStr .= $field; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 84 | return $fieldStr; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =pod | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =item B<size()> | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | Get the number of fields for this segment, not including the name | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | =cut | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 22 | ▶ | sub size { | ||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 22 | my $self = shift; | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 22 | return @{ $self->{FIELDS} } - 1; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =pod | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | =item B<getFields([$from, [$to]])> | ||||||||||||||||||||||||||||
| 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 | 9 | ▶ | sub getFields { | ||||||||||||||||||||||||||
|
Subroutine
getFields: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 9 | my ($self, $from, $to) = @_; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 9 | ▶ | $from || ($from = 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 9 | ▶ | $to || ($to = $#{$self->{FIELDS}}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 9 | return @{ $self->{FIELDS} }[$from..$to]; | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =pod | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =item B<getName()> | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | Get the name of the segment. This is basically the value at index 0 | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =back | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | =cut | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 64 | ▶ | sub getName { | ||||||||||||||||||||||||||
|
Subroutine
getName: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 64 | my $self = shift; | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 64 | return $self->{FIELDS}->[0]; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 7 | 1; | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | =pod | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | D.A.Dokter <dokter@wyldebeast-wunderliebe.com> | ||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||