001 package org.vmdb.hl7;
002
003 import java.util.*;
004
005 /**
006 * <p><Title:> Patient Identification (PID) Segment. </p>
007 * <p>Description: HL7 Network Connectivity For VMDB. </p>
008 * <p>Copyright: Copyright (c) 2002-2003. </p>
009 * <p>Company: Veterinary Medical Database (VMDB). </p>
010 * <p>The PID segment is used as the primary means of communicating information
011 * concerning the veterinary patient identification. This segment is required
012 * for all VMDB reporting messages. For VMDB usage, only one PID segment per
013 * message is allowed.<p>
014 * <p>See HL7 Standard Chapter 3 for additional details.</p>
015 * @author Michael K. Martin
016 * @version 1.0
017 */
018
019 public class PIDSegment extends HL7Segment {
020 private String sNm = "PID";
021 private String sRl =
022 "DT[SI][CX]{CX}[{CX}]{XPN}[XPN]TS[IS][XPN][CE]XAD[IS][XTN][XTN][CE]" +
023 "[CE][CE][CX][ST][DLN][CX][CE][ST][ID][NM][CE][CE][CE][TS][ID]" +
024 "[ID][IS][TS][HD]CE[CE][ST][CE]";
025
026 /**
027 * Construct an empty patient identification segment.
028 */
029 public PIDSegment() {
030 setName( sNm );
031 setRule( sRl );
032 }
033
034 /**
035 * Construct an empty patient identification segment, setting its containing message
036 * object.
037 * @param msgParent HL7SegmentContainer (normally a Group 4 loop) object that
038 * contains this segment.
039 */
040 public PIDSegment( HL7SegmentContainer msgParent ) {
041 super( msgParent );
042 setName( sNm );
043 setRule( sRl );
044 }
045
046 /**
047 * Set the sending facility. This version takes only the facility ID.
048 * @param sNamespaceID abbreviation of facility
049 */
050 public void addPatientId( String sId, String sAssigningAuthority ) {
051 CXElement cxE = new CXElement();
052 cxE.setIdentifier( sId );
053 cxE.setAssigningAuthorityName( sAssigningAuthority );
054 cxE.setName( "PID.3" );
055 try {
056 setField( cxE, 3, true );
057 }
058 catch( ArrayIndexOutOfBoundsException ae ) {
059 ae.printStackTrace();
060 }
061 catch( MalformedSegmentException mfe ) {
062 mfe.printStackTrace();
063 }
064 }
065
066 /**
067 * Get the patient identifier list as a Java iterator over the repeating
068 * Field. Each Object in the iteration is a {@link org.vmdb.hl7.CXElement CXElement}
069 * @return Iterator with all CXElements or null if none or error
070 */
071 public Iterator listPatientIds() {
072 return listFields( 3 );
073 }
074
075 /**
076 * Set patient name as just a single string (usually "Confidential")<br><br>
077 * TODO: Make "Confidential" the default for new PIDs?
078 * @param sPatName String of patient name
079 *
080 */
081 public void setPatientName( String sPatName ) {
082 XPNElement e = new XPNElement();
083 e.setValue( sPatName );
084 try {
085 setField( e, 5 );
086 }
087 catch( ArrayIndexOutOfBoundsException ae ) {
088 ae.printStackTrace();
089 }
090 catch( MalformedSegmentException mfe ) {
091 mfe.printStackTrace();
092 }
093 }
094
095 /**
096 * Set full patient name as XPN element defined as completely as you like.
097 * @param xpnName XPNElement with name defined
098 *
099 */
100 public void setPatientName( XPNElement xpnName ) {
101 try {
102 setField( xpnName, 5 );
103 }
104 catch( ArrayIndexOutOfBoundsException ae ) {
105 ae.printStackTrace();
106 }
107 catch( MalformedSegmentException mfe ) {
108 mfe.printStackTrace();
109 }
110 }
111
112 /**
113 * Get just the name string stored in family name.
114 * @return String with family name
115 */
116 public String getPatientNameString() {
117 HL7Element e = getField( 5 );
118 if( e != null )
119 return e.getValue();
120 else
121 return "";
122 }
123
124 /**
125 * Get the full patient name as XPNElement
126 * @return XPNElement with fully defined name
127 *
128 */
129 public XPNElement getPatientName() {
130 return (XPNElement)getField( 5 );
131 }
132
133 /**
134 * Set the date of birth (date time but who's going to include time)
135 * @param sBDate String with date in ISO format
136 */
137 public void setDateOfBirth( String sBDate ) {
138 TSElement tsE = new TSElement();
139 tsE.setDateTime( sBDate );
140 try {
141 setField( tsE, 7 );
142 }
143 catch( ArrayIndexOutOfBoundsException ae ) {
144 ae.printStackTrace();
145 }
146 catch( MalformedSegmentException mfe ) {
147 mfe.printStackTrace();
148 }
149 }
150
151 /**
152 * Set the date of birth (date time but who's going to include time)
153 * @param sBDate String with date in ISO format
154 */
155 public void setDateOfBirth( TSElement tsBDate ) {
156 try {
157 setField( tsBDate, 7 );
158 }
159 catch( ArrayIndexOutOfBoundsException ae ) {
160 ae.printStackTrace();
161 }
162 catch( MalformedSegmentException mfe ) {
163 mfe.printStackTrace();
164 }
165 }
166
167 /**
168 * Get birthdate string
169 * @return String with birthdate in ISO format
170 */
171 public String getDateOfBirth() {
172 TSElement tsE = (TSElement)getField( 7 );
173 if( tsE != null )
174 return tsE.getDateTime();
175 else
176 return "";
177 }
178
179 /**
180 * Set the administrative sex
181 * @param sSex String with gender as M, C, T, F, S, O, U, H, or X
182 */
183 public void setSex( String sSex ) {
184 try {
185 setField( sSex, 8 );
186 }
187 catch( ArrayIndexOutOfBoundsException ae ) {
188 ae.printStackTrace();
189 }
190 }
191
192 /**
193 * Get birthdate string
194 * @return String with sex
195 */
196 public String getSex() {
197 return getField( 8 ).getValue();
198 }
199
200
201 /**
202 * Set patient zipcode as just a single string
203 * @param sZipcode String of patient zipcode
204 *
205 */
206 public void setPatientZipcode( String sZipcode ) {
207 XADElement xadE = (XADElement)getField( 11 );
208 if( xadE != null ) {
209 xadE.setName( "PID.11" );
210 xadE.setPostalCode( sZipcode );
211 }
212 else {
213 (new Exception( "Field 11 NULL in setPatientZipcode" )).printStackTrace();
214 }
215 }
216
217 /**
218 * Set patient country as just a single string (ISO abbreviation prefered)
219 * @param sCountry String of patient country
220 *
221 */
222 public void setPatientCountry( String sCountry ) {
223 XADElement xadE = (XADElement)getField( 11 );
224 if( xadE != null ) {
225 xadE.setName( "PID.11" );
226 xadE.setCountry( sCountry );
227 }
228 else {
229 (new Exception( "Field 11 NULL in setPatientZipcode" )).printStackTrace();
230 }
231 }
232
233 /**
234 * Set full patient address as XAD element defined as completely as you like
235 * @param xadAddress XADElement with address set
236 *
237 */
238 public void setPatientAddress( XADElement xadAddress ) {
239 xadAddress.setName( "PID.11" );
240 try {
241 setField( xadAddress, 11 );
242 }
243 catch( ArrayIndexOutOfBoundsException ae ) {
244 ae.printStackTrace();
245 }
246 catch( MalformedSegmentException mfe ) {
247 mfe.printStackTrace();
248 }
249 }
250
251 /**
252 * Get just the zipcode string from address
253 * @return String with zipcode
254 */
255 public String getPatientZipcode() {
256 XADElement xadE = (XADElement)getField( 11 );
257 if( xadE != null ) {
258 return xadE.getPostalCode();
259 }
260 else
261 return "";
262 }
263
264 /**
265 * Get just the Country string from address
266 * @return String with Country
267 */
268 public String getPatientCountry() {
269 XADElement xadE = (XADElement)getField( 11 );
270 if( xadE != null ) {
271 return xadE.getCountry();
272 }
273 else
274 return "";
275 }
276
277 /**
278 * Get the full patient address as XADElement
279 * @return XADElement with fully defined name
280 *
281 */
282 public XADElement getPatientAddress() {
283 return (XADElement)getField( 11 );
284 }
285
286 /**
287 * Set multiple birth indicator to true or false
288 * @param bMulti boolean true if multiple
289 *
290 */
291 public void setMultipleBirth( boolean bMulti ) {
292 String sMulti = bMulti ? "YES" : "NO";
293 try {
294 setField( sMulti, 24 );
295 }
296 catch( ArrayIndexOutOfBoundsException ae ) {
297 ae.printStackTrace();
298 }
299 }
300
301 /**
302 * Get birthdate string
303 * @return String with sex
304 */
305 public boolean getMultipleBirth() {
306 String sMulti = getField( 24 ).getValue();
307 if( sMulti == null || sMulti.equalsIgnoreCase( "NO" )
308 || sMulti.equalsIgnoreCase( "FALSE" ) )
309 return false;
310 else if ( sMulti.equalsIgnoreCase( "YES" ) || sMulti.equalsIgnoreCase( "TRUE" ) )
311 return true;
312 else {
313 ( new Exception( "Cannot read " + sMulti + " as boolean in Multiple Birth Indicator" ) ).printStackTrace();
314 return false;
315 }
316 }
317
318 /**
319 * Set the coded species. This version takes the fully qualified CE elements
320 * @param sCode code value normally Snomed CT
321 * @param sText spelled out term
322 * @param sSystem normally Snomed CT
323 */
324 public void setSpecies( String sCode, String sText, String sCodeType ) {
325 CEElement ceE = new CEElement( sCode, sText, sCodeType );
326 ceE.setName( "PID.35" );
327 try {
328 setField( ceE, 35 );
329 }
330 catch( ArrayIndexOutOfBoundsException ae ) {
331 ae.printStackTrace();
332 }
333 catch( MalformedSegmentException mfe ) {
334 mfe.printStackTrace();
335 }
336 }
337
338 /**
339 * Set the coded species. This version takes the fully qualified CE elements
340 * @param sCode code value normally Snomed CT
341 * @param sText spelled out term
342 * @param sSystem normally Snomed CT
343 * @param sAltCode alternate code value for the SAME species
344 * @param sAltText spelled out term
345 * @param sAltSystem alternate coding system
346 */
347 public void setSpecies( String sCode, String sText, String sCodeType ,
348 String sAltCode, String sAltText, String sAltCodeType) {
349 CEElement ceE = new CEElement( sCode, sText, sCodeType,
350 sAltCode, sAltText, sAltCodeType );
351 ceE.setName( "PID.35" );
352 try {
353 setField( ceE, 35 );
354 }
355 catch( ArrayIndexOutOfBoundsException ae ) {
356 ae.printStackTrace();
357 }
358 catch( MalformedSegmentException mfe ) {
359 mfe.printStackTrace();
360 }
361 }
362
363 /**
364 * Set the coded species. This version takes the fully qualified CE elements
365 * @param ceSpecies species as preformed CEElement
366 */
367 public void setSpecies( CEElement ceSpecies ) {
368 ceSpecies.setName( "PID.35" );
369 try {
370 setField( ceSpecies, 35 );
371 }
372 catch( ArrayIndexOutOfBoundsException ae ) {
373 ae.printStackTrace();
374 }
375 catch( MalformedSegmentException mfe ) {
376 mfe.printStackTrace();
377 }
378 }
379
380 /**
381 * Get the species code as the complete CEElement
382 * @return CEElement with coded species
383 */
384 public CEElement getSpecies() {
385 return (CEElement)getField( 35 );
386 }
387
388 /**
389 * Get just the universal id of the sending facility, the VMDB
390 * identifier in this case.
391 * @return String with species spelled out
392 */
393 public String getSpeciesText() {
394 CEElement ceE = (CEElement)getField( 35 );
395 if( ceE != null )
396 return ceE.getText();
397 else
398 return "";
399 }
400
401 /**
402 * Get just the universal id of the sending facility, the VMDB
403 * identifier in this case.
404 * @return String with coded (normally snomed) species
405 */
406 public String getSpeciesCode() {
407 CEElement ceE = (CEElement)getField( 35 );
408 if( ceE != null )
409 return ceE.getIdentifier();
410 else
411 return "";
412 }
413
414 /**
415 * Get just the universal id of the sending facility, the VMDB
416 * identifier in this case.
417 * @return String with coding system used for species (normally snomed)
418 */
419 public String getSpeciesCodingSystem() {
420 CEElement ceE = (CEElement)getField( 35 );
421 if( ceE != null )
422 return ceE.getCodingSystem();
423 else
424 return "";
425 }
426
427 /**
428 * Set the coded breed. This version takes the fully qualified CE elements
429 * @param sCode code value normally Snomed CT
430 * @param sText spelled out term
431 * @param sSystem normally Snomed CT
432 */
433 public void setBreed( String sCode, String sText, String sCodeType ) {
434 CEElement ceE = new CEElement( sCode, sText, sCodeType );
435 ceE.setName( "PID.36" );
436 try {
437 setField( ceE, 36 );
438 }
439 catch( ArrayIndexOutOfBoundsException ae ) {
440 ae.printStackTrace();
441 }
442 catch( MalformedSegmentException mfe ) {
443 mfe.printStackTrace();
444 }
445 }
446
447 /**
448 * Set the coded breed. This version takes the fully qualified CE elements
449 * @param sCode code value normally Snomed CT
450 * @param sText spelled out term
451 * @param sSystem normally Snomed CT
452 * @param sAltCode alternate code for the same Breed
453 * @param sAltText spelled out term
454 * @param sAltSystem alternate coding system
455 */
456 public void setBreed( String sCode, String sText, String sCodeType,
457 String sAltCode, String sAltText, String sAltCodeType ) {
458 CEElement ceE = new CEElement( sCode, sText, sCodeType,
459 sAltCode, sAltText, sAltCodeType );
460 ceE.setName( "PID.36" );
461 try {
462 setField( ceE, 36 );
463 }
464 catch( ArrayIndexOutOfBoundsException ae ) {
465 ae.printStackTrace();
466 }
467 catch( MalformedSegmentException mfe ) {
468 mfe.printStackTrace();
469 }
470 }
471
472 /**
473 * Set the coded breed. This version takes the predefined CE element
474 * @param ceSpecies
475 */
476 public void setBreed( CEElement ceSpecies ) {
477 ceSpecies.setName( "PID.36" );
478 try {
479 setField( ceSpecies, 36 );
480 }
481 catch( ArrayIndexOutOfBoundsException ae ) {
482 ae.printStackTrace();
483 }
484 catch( MalformedSegmentException mfe ) {
485 mfe.printStackTrace();
486 }
487 }
488
489 /**
490 * Get the breed code as the complete CEElement
491 * @return CEElement with coded species
492 */
493 public CEElement getBreed() {
494 return (CEElement)getField( 36 );
495 }
496
497 /**
498 * Get just the breed code value.
499 * @return String with id
500 */
501 public String getBreedCode() {
502 CEElement ceE = (CEElement)getField( 36 );
503 if( ceE != null )
504 return ceE.getIdentifier();
505 else
506 return "";
507 }
508
509 /**
510 * Get just the text of the breed code value.
511 * @return String with id
512 */
513 public String getBreedText() {
514 CEElement ceE = (CEElement)getField( 36 );
515 if( ceE != null )
516 return ceE.getText();
517 else
518 return "";
519 }
520
521 /**
522 * Get just the coding system of the breed code value.
523 * @return String with coding system (normally snomed)
524 */
525 public String getBreedCodingSystem() {
526 CEElement ceE = (CEElement)getField( 36 );
527 if( ceE != null )
528 return ceE.getCodingSystem();
529 else
530 return "";
531 }
532
533 /**
534 * Set the Strain
535 * @param sStrain String with strain
536 */
537 public void setStrain( String sStrain ) {
538 try {
539 setField( sStrain, 37 );
540 }
541 catch( ArrayIndexOutOfBoundsException ae ) {
542 ae.printStackTrace();
543 }
544 }
545
546 /**
547 * Get strain string
548 * @return String with strain
549 */
550 public String getStrain() {
551 HL7Element e = getField( 37 );
552 if( e == null )
553 return "";
554 else
555 return e.getValue();
556 }
557
558 }// End Class PIDSegment
559