001 package org.vmdb.hl7; 002 003 import java.util.*; 004 005 /** 006 * <p><Title:> Query By Pattern Response (RSP) Message. </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>This is a quickly assembled message type used to demonstrate 011 * extensibility of the general library model. A more production ready 012 * solution would have been to develope a full, general purpose QBP/RSP 013 * pair of messages and extend them to the specific case of the QBP-Z01 014 * defined here, but the point was to show a quick and easy extension example.</p> 015 * @author Michael K. Martin 016 * @version 1.0 017 */ 018 019 public class RSPMessage extends HL7Message { 020 private String sNm = "RSP_Z01"; 021 private String sRl = "MSH MSA[ERR]QAK QPD OBX[DSC]"; 022 private static final String MESSAGE_TYPE = "RSP"; 023 private static final String EVENT_TYPE = "Z01"; 024 025 /** 026 * Construct an empty RSP Message with type and event set. This object 027 * is ready to either build via a series of set and add calls, or to read in 028 * an HL7 or XML (future) message. 029 */ 030 public RSPMessage() { 031 super(); 032 setName( sNm ); 033 setRule( sRl ); 034 setMessageName( MESSAGE_TYPE, EVENT_TYPE ); 035 initialize(); 036 } 037 038 /** 039 * This is a brute-force intialization routine to create a populated 040 * message. This is faster and easier than implementing the full 041 * getXXX() logic used in "production" message classes. Note 042 * that the getXXX() method implementation could be extended 043 * without changing the interface. 044 */ 045 private void initialize() { 046 if( vSegments == null ) 047 vSegments = new Vector(); 048 MSASegment msa = new MSASegment(); 049 msa.initialize(); 050 vSegments.add( msa ); 051 QAKSegment qak = new QAKSegment(); 052 qak.initialize(); 053 vSegments.add( qak ); 054 QPDSegment qpd = new QPDSegment(); 055 qpd.initialize(); 056 vSegments.add( qpd ); 057 OBXSegment obx = new OBXSegment(); 058 obx.initialize(); 059 vSegments.add( obx ); 060 CEElement ceQName = new CEElement( "Z01", "Get Prevalence", "VMDB" ); 061 QPDSegment sQPD = getQPD(); 062 sQPD.setQueryName( ceQName ); 063 QAKSegment sQAK = getQAK(); 064 sQAK.setQueryName( ceQName ); 065 } 066 067 /** 068 * Get the Message Acknowledgment segment from this message 069 * @return MSASegment object 070 */ 071 public MSASegment getMSA() { 072 return (MSASegment)findSegment( "MSA" ); 073 } 074 075 /** 076 * Get the Error segment from this message 077 * @return ErrSegment object 078 */ 079 public ERRSegment getERR() { 080 ERRSegment sErr = (ERRSegment)findSegment( "ERR" ); 081 if( sErr == null ) { 082 sErr = new ERRSegment(); 083 sErr.initialize(); 084 vSegments.insertElementAt(sErr, 2); 085 } 086 return sErr; 087 } 088 089 /** 090 * Get the Query Acknowledgment segment from this message 091 * @return QAKSegment object 092 */ 093 public QAKSegment getQAK() { 094 return (QAKSegment)findSegment( "QAK" ); 095 } 096 097 /** 098 * Get the Input Parameter Field Description and Commentary 099 * segment from this message 100 * @return QPDSegment object 101 */ 102 public QPDSegment getQPD() { 103 return (QPDSegment)findSegment( "QPD" ); 104 } 105 106 /** 107 * Get the Observation segment (containing results) from this message 108 * @return OBXSegment object 109 */ 110 public OBXSegment getOBX() { 111 return (OBXSegment)findSegment( "OBX" ); 112 } 113 114 // The accessors and mutators are based on VMDB usage of the RSP Message 115 // and are designed to provide easy access to message details 116 117 /** 118 * Set the message Acknowledgment Code. 119 * @param sMessageId String with unique identifier 120 */ 121 public void setAcknowledgmentCode( String sAcknowledgmentCode ) { 122 MSASegment msa = getMSA(); 123 msa.setAcknowledgmentCode( sAcknowledgmentCode ); 124 } 125 126 /** 127 * Get the message Acknowledgment Code. 128 * @return String with unique identifier 129 */ 130 public String getAcknowledgmentCode() { 131 MSASegment msa = getMSA(); 132 return msa.getAcknowledgmentCode(); 133 } 134 135 /** 136 * Set the message control id in the MSA (ie sender's mcId). 137 * @param sMessageId String with unique identifier 138 */ 139 public void setOriginalMessageControlId( String sMessageControlId ) { 140 MSASegment msa = getMSA(); 141 msa.setMessageControlId( sMessageControlId ); 142 } 143 144 /** 145 * Get the message control id in the MSA (ie sender's mcId). 146 * @return String with unique identifier 147 */ 148 public String getOriginalMessageControlId() { 149 MSASegment msa = getMSA(); 150 return msa.getMessageControlId(); 151 } 152 153 /** 154 * Set the value in the observation segment which in this case 155 * is defined to include the prevalence of the submitted diagnosis in 156 * animals like the one described in the submitted PID segment. 157 * @param dPrev The prevalence rate as a double type numeric. 158 */ 159 public void setPrevalenceRate( double dPrev ) { 160 try { 161 String sPrev = Double.toString( dPrev ); 162 OBXSegment obx = getOBX(); 163 CEElement obsId = new CEElement( "","Prevalence Rate","" ); 164 obx.setObservationIdentifier( obsId ); 165 obx.setObservationValueType("NM"); 166 obx.setObservationValue( sPrev ); 167 } catch( MalformedFieldException mse ) { 168 mse.printStackTrace(); 169 } 170 } 171 172 173 /** 174 * Get the value in the observation segment which in this case 175 * is defined to include the prevalence of the submitted diagnosis in 176 * animals like the one described in the submitted PID segment. 177 * @return The prevalence rate as a double type numeric. Returns negative 178 * one for errors or no value. 179 */ 180 public double getPrevalenceRate() { 181 double dPrev = -1.0; 182 try { 183 OBXSegment obx = getOBX(); 184 String sPrev = obx.getObservationValue().getValue(); 185 dPrev = Double.parseDouble( sPrev ); 186 } catch( NumberFormatException nfe ) { 187 nfe.printStackTrace(); 188 } 189 return dPrev; 190 } 191 192 } // end class RSPMessage 193