-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathHL7.php
243 lines (204 loc) · 6.73 KB
/
HL7.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 D.A.Dokter |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | [email protected] so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: D.A.Dokter <[email protected]> |
// +----------------------------------------------------------------------+
//
// $Id: HL7.php,v 1.7 2004/08/06 07:38:54 wyldebeast Exp $
/**
* The Net_HL7 class is a factory class for HL7 messages.
*
* The factory class provides the convenience of changing several
* defaults for HL7 messaging globally, like separators, etc. Note
* that some default settings use characters that have special meaning
* in PHP, like the HL7 escape character. To be able to set these
* values, escape the special characters.
*
* @version 0.1.0
* @author D.A.Dokter <[email protected]>
* @access public
* @category Networking
* @package Net_HL7
* @license http://www.php.net/license/3_0.txt PHP License 3.0
*/
class Net_HL7
{
/**
* Holds all global HL7 settings.
*/
var $_hl7Globals = array();
/**
* Create a new instance of the HL7 factory, and set global
* defaults.
*/
function Net_HL7() {
$this->_hl7Globals['SEGMENT_SEPARATOR'] = '\015';
$this->_hl7Globals['FIELD_SEPARATOR'] = '|';
$this->_hl7Globals['NULL'] = '""';
$this->_hl7Globals['COMPONENT_SEPARATOR'] = '^';
$this->_hl7Globals['REPETITION_SEPARATOR'] = '~';
$this->_hl7Globals['ESCAPE_CHARACTER'] = '\\';
$this->_hl7Globals['SUBCOMPONENT_SEPARATOR'] = '&';
$this->_hl7Globals['HL7_VERSION'] = '2.2';
}
/**
* Create a new Net_HL7_Message, using the global HL7 variables as
* defaults.
*
* @param string Text representation of an HL7 message
* @return object Net_HL7_Message
* @access public
*/
function &createMessage($msgStr = "")
{
$msg =& new Net_HL7_Message($msgStr, $this->_hl7Globals);
return $msg;
}
/**
* Create a new Net_HL7_Segments_MSH segment, using the global HL7
* variables as defaults.
*
* @return object Net_HL7_Segments_MSH
* @access public
*/
function &createMSH()
{
$msh =& new Net_HL7_Segments_MSH($this->_hl7Globals);
return $msh;
}
/**
* Set the component separator to be used by the factory. Should
* be a single character. Default ^
*
* @param string Component separator char.
* @return boolean true if value has been set.
* @access public
*/
function setComponentSeparator($value)
{
if (strlen($value) != 1) return false;
return $this->_setGlobal('COMPONENT_SEPARATOR', $value);
}
/**
* Set the subcomponent separator to be used by the factory. Should
* be a single character. Default: &
*
* @param string Subcomponent separator char.
* @return boolean true if value has been set.
* @access public
*/
function setSubcomponentSeparator($value)
{
if (strlen($value) != 1) return false;
return $this->_setGlobal('SUBCOMPONENT_SEPARATOR', $value);
}
/**
* Set the repetition separator to be used by the factory. Should
* be a single character. Default: ~
*
* @param string Repetition separator char.
* @return boolean true if value has been set.
* @access public
*/
function setRepetitionSeparator($value)
{
if (strlen($value) != 1) return false;
return $this->_setGlobal('REPETITION_SEPARATOR', $value);
}
/**
* Set the field separator to be used by the factory. Should
* be a single character. Default: |
*
* @param string Field separator char.
* @return boolean true if value has been set.
* @access public
*/
function setFieldSeparator($value)
{
if (strlen($value) != 1) return false;
return $this->_setGlobal('FIELD_SEPARATOR', $value);
}
/**
* Set the segment separator to be used by the factory. Should
* be a single character. Default: \015
*
* @param string Segment separator char.
* @return boolean true if value has been set.
* @access public
*/
function setSegmentSeparator($value)
{
if (strlen($value) != 1) return false;
return $this->_setGlobal('SEGMENT_SEPARATOR', $value);
}
/**
* Set the escape character to be used by the factory. Should
* be a single character. Default: \
*
* @param string Escape character.
* @return boolean true if value has been set.
* @access public
*/
function setEscapeCharacter($value)
{
if (strlen($value) != 1) return false;
return $this->_setGlobal('ESCAPE_CHARACTER', $value);
}
/**
* Set the HL7 version to be used by the factory.
*
* @param string HL7 version character.
* @return boolean true if value has been set.
* @access public
*/
function setHL7Version($value)
{
return $this->_setGlobal('HL7_VERSION', $value);
}
/**
* Set the NULL string to be used by the factory.
*
* @param string NULL string.
* @return boolean true if value has been set.
* @access public
*/
function setNull($value)
{
return $this->_setGlobal('NULL', $value);
}
/**
* Convenience method for obtaining the special NULL value.
*
* @return string null value
* @access public
*/
function getNull() {
return $this->_hl7Globals['NULL'];
}
/**
* Set the HL7 global variable
*
* @access private
* @param string name
* @param string value
* @return boolean True when value has been set, false otherwise.
*/
function _setGlobal($name, $value)
{
$this->_hl7Globals[$name] = $value;
return true;
}
}
?>