| 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 | ▶ | use 5.004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use Net::HL7::Message; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 54 | bless my $self = {}, $class; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 54 | ▶ | $self->_init(@_) || return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 50 | return $self; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub _init { | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 54 | ▶ | my ($self, $name, $fieldsRef) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # Is the name 3 upper case characters? | ||||||||||||||||||||||||||||
| 70 | # | ||||||||||||||||||||||||||||
| 71 | 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
| |||||||||||||||||||||||||||||
| 72 | 51 | ▶ | (uc($name) eq $name) || return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 50 | $self->{FIELDS} = []; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 50 | $self->{FIELDS}->[0] = $name; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 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"
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 27 | ▶ | for (my $i = 0; $i < @{ $fieldsRef }; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 186 | $self->setField($i + 1, $fieldsRef->[$i]); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 50 | return 1; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =pod | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =item B<setField($index, $value)> | ||||||||||||||||||||||||||||
| 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 | ▶ | my ($self, $index, $value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
setField: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 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
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 192 | $self->{FIELDS}->[$index] = $value; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 192 | return 1; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =pod | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =item B<getField($index)> | ||||||||||||||||||||||||||||
| 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 | ▶ | my ($self, $index) = @_; | ||||||||||||||||||||||||||
|
Subroutine
getField: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 226 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 34 | ▶ | if (ref($self->{FIELDS}->[$index]) eq "ARRAY") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 4 | return @{ $self->{FIELDS}->[$index]}; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||
| 144 | 30 | return ($self->{FIELDS}->[$index]); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | else { | ||||||||||||||||||||||||||||
| 148 | 192 | return $self->{FIELDS}->[$index]; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =pod | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =item B<getFieldAsString()> | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | Get the string representation of the field | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | sub getFieldAsString { | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 84 | ▶ | my ($self, $index) = @_; | ||||||||||||||||||||||||||
|
Subroutine
getFieldAsString: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 84 | my $fieldStr = ""; | |||||||||||||||||||||||||||
| 167 | 84 | my $field = $self->{FIELDS}->[$index]; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 84 | ▶ | if (ref($field) eq "ARRAY") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 9 | ▶ | for (my $i = 0; $i < @{ $field }; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 23 | ▶ | if (ref($field->[$i]) eq "ARRAY") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 5 | $fieldStr .= join($Net::HL7::SUBCOMPONENT_SEPARATOR, @{ $field->[$i] }); | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | else { | ||||||||||||||||||||||||||||
| 178 | 18 | $fieldStr .= $field->[$i]; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 23 | ▶ | if ($i < (@{ $field } - 1)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 14 | $fieldStr .= $Net::HL7::COMPONENT_SEPARATOR; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | else { | ||||||||||||||||||||||||||||
| 187 | 75 | $fieldStr .= $field; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 84 | return $fieldStr; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | =pod | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =item B<size()> | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | Get the number of fields for this segment, not including the name | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =cut | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | sub size { | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 22 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 22 | return @{ $self->{FIELDS} } - 1; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =pod | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =item B<getFields([$from, [$to]])> | ||||||||||||||||||||||||||||
| 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 | ▶ | my ($self, $from, $to) = @_; | ||||||||||||||||||||||||||
|
Subroutine
getFields: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 9 | ▶ | $from || ($from = 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 9 | ▶ | $to || ($to = $#{$self->{FIELDS}}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 9 | return @{ $self->{FIELDS} }[$from..$to]; | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | =pod | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =item B<getName()> | ||||||||||||||||||||||||||||
| 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
getName: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 64 | return $self->{FIELDS}->[0]; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 7 | 1; | |||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | =pod | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | D.A.Dokter <dokter@wyldebeast-wunderliebe.com> | ||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||