| 1 | ################################################################################ | ||||||||||
| 2 | # | ||||||||||
| 3 | # File : Segment.pm | ||||||||||
| 4 | # Author : Duco Dokter | ||||||||||
| 5 | # Created : Tue Mar 4 13:03:00 2003 | ||||||||||
| 6 | # Version : $Id: MSH.pm,v 1.6 2004/02/10 14:31:54 wyldebeast Exp $ | ||||||||||
| 7 | # Copyright : Wyldebeast & Wunderliebe | ||||||||||
| 8 | # | ||||||||||
| 9 | ################################################################################ | ||||||||||
| 10 | |||||||||||
| 11 | package Net::HL7::Segments::MSH; | ||||||||||
| 12 | |||||||||||
| 13 | 5 | ▶ | use 5.004; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 5 | ▶ | use base qw(Net::HL7::Segment); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 5 | ▶ | use POSIX qw(strftime); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | =pod | ||||||||||
| 19 | |||||||||||
| 20 | =head1 NAME | ||||||||||
| 21 | |||||||||||
| 22 | Net::HL7::Segments::MSH | ||||||||||
| 23 | |||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||
| 25 | |||||||||||
| 26 | my $seg = new Net::HL7::Segments::MSH(); | ||||||||||
| 27 | |||||||||||
| 28 | $seg->setField(9, "ADT^A24"); | ||||||||||
| 29 | print $seg->getField(1); | ||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | =head1 DESCRIPTION | ||||||||||
| 33 | |||||||||||
| 34 | The Net::HL7::Segments::MSH is an implementation of the | ||||||||||
| 35 | L<Net::HL7::Segment|Net::HL7::Segment> class. The MSH segment is a bit | ||||||||||
| 36 | different from other segments, in that the first field is the field | ||||||||||
| 37 | separator after the segment name. Other fields thus start counting | ||||||||||
| 38 | from 2! The setting for the field separator for a whole message can | ||||||||||
| 39 | be changed by the setField method on index 1 of the MSH for that | ||||||||||
| 40 | message. The MSH segment also contains the default settings for field | ||||||||||
| 41 | 2, COMPONENT_SEPARATOR, REPETITION_SEPARATOR, ESCAPE_CHARACTER and | ||||||||||
| 42 | SUBCOMPONENT_SEPARATOR. These fields default to ^, ~, \ and & | ||||||||||
| 43 | respectively. | ||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | =head1 METHODS | ||||||||||
| 47 | |||||||||||
| 48 | =over 4 | ||||||||||
| 49 | |||||||||||
| 50 | =item B<$msh = new Net::HL7::Segments::MSH([$fields])> | ||||||||||
| 51 | |||||||||||
| 52 | Create an instance of the MSH segment. If a reference to an array is | ||||||||||
| 53 | given, all fields will be filled from that array. Note that for | ||||||||||
| 54 | composed fields and subcomponents, the array may hold subarrays and | ||||||||||
| 55 | subsubarrays. If the reference is not given, the MSH segment will be | ||||||||||
| 56 | created with the MSH 1,2,7,10 and 12 fields filled in for convenience. | ||||||||||
| 57 | |||||||||||
| 58 | =cut | ||||||||||
| 59 | |||||||||||
| 60 | 25 | ▶ | sub _init { | ||||||||
|
Subroutine
_init: called CC=2 SCAR=6.9
| |||||||||||
| 61 | |||||||||||
| 62 | 25 | my ($self, $fieldsRef) = @_; | |||||||||
| 63 | |||||||||||
| 64 | 25 | $self->SUPER::_init("MSH", $fieldsRef); | |||||||||
| 65 | |||||||||||
| 66 | # Only fill default fields if no fields ref is given | ||||||||||
| 67 | # | ||||||||||
| 68 | 25 | ▶ | if (! $fieldsRef) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 7 | $self->setField(1, $Net::HL7::FIELD_SEPARATOR); | |||||||||
| 70 | 7 | $self->setField( | |||||||||
| 71 | 2, | ||||||||||
| 72 | $Net::HL7::COMPONENT_SEPARATOR . | ||||||||||
| 73 | $Net::HL7::REPETITION_SEPARATOR . | ||||||||||
| 74 | $Net::HL7::ESCAPE_CHARACTER . | ||||||||||
| 75 | $Net::HL7::SUBCOMPONENT_SEPARATOR | ||||||||||
| 76 | ); | ||||||||||
| 77 | |||||||||||
| 78 | 7 | $self->setField(7, strftime("%Y%m%d%H%M%S", localtime)); | |||||||||
| 79 | |||||||||||
| 80 | # Set ID field | ||||||||||
| 81 | # | ||||||||||
| 82 | 7 | my $ext = rand(1); | |||||||||
| 83 | 7 | $ext =~ s/[^0-9]//g; | |||||||||
| 84 | 7 | $ext = "." . substr($ext, 1, 5); | |||||||||
| 85 | |||||||||||
| 86 | 7 | $self->setField(10, $self->getField(7) . $ext); | |||||||||
| 87 | 7 | $self->setField(12, $Net::HL7::HL7_VERSION); | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 25 | return $self; | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | |||||||||||
| 94 | =pod | ||||||||||
| 95 | |||||||||||
| 96 | =item B<setField($index, $value)> | ||||||||||
| 97 | |||||||||||
| 98 | Set the field specified by index to value. Indices start at 1, to stay | ||||||||||
| 99 | with the HL7 standard. Trying to set the value at index 0 has no | ||||||||||
| 100 | effect. Setting the value on index 1, will effectively change the | ||||||||||
| 101 | value of Net::HL7::Message::FIELD_SEPARATOR for the message containing | ||||||||||
| 102 | this segment, if the value has length 1; setting the field on index 2 | ||||||||||
| 103 | will change the values of COMPONENT_SEPARATOR, REPETITION_SEPARATOR, | ||||||||||
| 104 | ESCAPE_CHARACTER and SUBCOMPONENT_SEPARATOR for the message, if the | ||||||||||
| 105 | string is of length 4. | ||||||||||
| 106 | |||||||||||
| 107 | =back | ||||||||||
| 108 | |||||||||||
| 109 | =cut | ||||||||||
| 110 | |||||||||||
| 111 | 242 | ▶ | sub setField { | ||||||||
|
Subroutine
setField: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 112 | |||||||||||
| 113 | 242 | my ($self, $index, $value) = @_; | |||||||||
| 114 | |||||||||||
| 115 | 242 | ▶ | if ($index == 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | 28 | ▶ | if (length($value) != 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | 1 | return undef; | |||||||||
| 118 | } | ||||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | 241 | ▶ | if ($index == 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | 28 | ▶ | if (length($value) != 4) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 1 | return undef; | |||||||||
| 124 | } | ||||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | 240 | return $self->SUPER::setField($index, $value); | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | |||||||||||
| 131 | 5 | 1; | |||||||||
| 132 | |||||||||||
| 133 | |||||||||||
| 134 | =head1 AUTHOR | ||||||||||
| 135 | |||||||||||
| 136 | D.A.Dokter <dokter@wyldebeast-wunderliebe.com> | ||||||||||
| 137 | |||||||||||
| 138 | =head1 LICENSE | ||||||||||
| 139 | |||||||||||
| 140 | Copyright (c) 2002 D.A.Dokter. All rights reserved. This program is | ||||||||||
| 141 | free software; you can redistribute it and/or modify it under the same | ||||||||||
| 142 | terms as Perl itself. | ||||||||||
| 143 | |||||||||||
| 144 | =cut | ||||||||||