001 package org.vmdb.hl7;
002
003 import java.util.*;
004
005 /**
006 * <p><Title:> PATIENT_RESULT Loop. </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 XML representation of HL7 2.x introduces the concepts of groups and lists
011 * that, while present in the construction rules of delimited HL7, are not explicitly
012 * named or labelled in the messages themselves. This class follows the XML
013 * version with explicitly constructed groups and lists
014 * which we've combined under the general term (borrowed from X12) of "loop."</p>
015 * <p>Most of the repetion and grouping facilitated by this "loop" logic is not
016 * used in the VMDB version of the ORU message but is maintained to retain full
017 * standard compliance and to allow extending this model without fear of losing
018 * interoperability.</p>
019 * <p>Loop and Segment Nesting: The outline below shows how the loops and minimum
020 * required segments nest. {OBX} indicates that any number of OBX segments may
021 * appear at this location.</p>
022 *
023 <pre>
024 MSH
025 <b>PATIENT_RESULT</b>
026 PATIENT
027 PID
028 PATIENT_VISIT
029 PV1
030 ORDER_OBSERVATION
031 [ORC]
032 OBR
033 OBSERVATION
034 OBX
035 </pre>
036 * @author Michael K. Martin
037 * @version 1.0
038 */
039
040 public class PATIENT_RESULTLoop extends HL7Loop {
041 private String sNm = "PATIENT_RESULT";
042 private String sRl = "PATIENT ORDER_OBSERVATION";
043
044 public PATIENT_RESULTLoop() {
045 super();
046 setName( sNm );
047 setRule( sRl );
048 }
049
050 /**
051 * Get the PATIENTLoop loop that should be nested within this loop. If
052 * it does not exist, take the necessary steps to create it in the appropriate
053 * nested loop structure.
054 * @return PATIENTLoop object located at the appropriate place in the loop.
055 */
056 public PATIENTLoop getPATIENT() {
057 PATIENTLoop loop = null;
058 if( vSegments == null ) vSegments = new Vector();
059 for( Iterator i = vSegments.iterator(); i.hasNext(); ) {
060 HL7Object o = (HL7Object)i.next();
061 if( o.getName().equals( "PATIENT" ) ) {
062 loop = (PATIENTLoop)o;
063 break;
064 }
065 }
066 if( loop == null ) {
067 loop = new PATIENTLoop();
068 vSegments.add(0,loop);
069 }
070 return loop;
071 }
072
073 /**
074 * Get the ORDER_OBSERVATIONLoop loop that should be nested within this loop. If
075 * it does not exist, take the necessary steps to create it in the appropriate
076 * location.<br><br>
077 * Note: The semantics here only work correctly for segments that exist singly
078 * in a message. We break with generic HL7 here in that only under VMDB are
079 * we restricted to a single observation request per message. If we drop this limitation
080 * we will need to create more complex (addORDER_OBSERVATION) semantics.
081 * @return ORDER_OBSERVATIONLoop object located at the appropriate place in the loop.
082 */
083 public ORDER_OBSERVATIONLoop getORDER_OBSERVATION() {
084 ORDER_OBSERVATIONLoop loop = null;
085 if( vSegments == null ) vSegments = new Vector();
086 for( Iterator i = vSegments.iterator(); i.hasNext(); ) {
087 HL7Object o = (HL7Object)i.next();
088 if( o.getName().equals( "ORDER_OBSERVATION" ) ) {
089 loop = (ORDER_OBSERVATIONLoop)o;
090 break;
091 }
092 }
093 if( loop == null ) {
094 loop = new ORDER_OBSERVATIONLoop();
095 // locate at end
096 vSegments.add(loop);
097 }
098 return loop;
099 }
100
101 /**
102 * Get the ORDER_OBSERVATIONLoop loop that should be nested within this loop. If
103 * it does not exist, take the necessary steps to create it in the appropriate
104 * location.<br><br>
105 * Note: This is something of a nonsense method since we've already specified
106 * that we will have only one ORDER_OBSERVATION loop per message we shouldn't
107 * need to search for a specific OrderControl value.
108 * @return ORDER_OBSERVATIONLoop object located at the appropriate place in the loop.
109 */
110 public ORDER_OBSERVATIONLoop getORDER_OBSERVATION( String sOrderControl ) {
111 ORDER_OBSERVATIONLoop loop = null;
112 if( vSegments == null ) vSegments = new Vector();
113 for( Iterator i = vSegments.iterator(); i.hasNext(); ) {
114 HL7Object o = (HL7Object)i.next();
115 if( o.getName().equals( "ORDER_OBSERVATION" ) ) {
116 loop = (ORDER_OBSERVATIONLoop)o;
117 ORCSegment orc = loop.getORC();
118 if( orc != null ) {
119 String sOC = orc.getOrderControl();
120 // If there was no order control or it matches return this group
121 if( sOC.length() == 0 || sOC.equals( sOrderControl ) )
122 break;
123 }
124 loop = null;
125 }
126 }
127 if( loop == null ) {
128 loop = new ORDER_OBSERVATIONLoop();
129 ORCSegment orc = loop.getORC();
130 orc.setOrderControl( sOrderControl );
131 vSegments.add(0,loop);
132 }
133 return loop;
134 }
135
136 }// End class PATIENT_RESULTLoop
137