Java Code Examples for ca.uhn.hl7v2.model.Message#get()

The following examples show how to use ca.uhn.hl7v2.model.Message#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SampleApp.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Message processMessage(Message theIn) throws ApplicationException, HL7Exception {

    String encodedMessage = new PipeParser().encode(theIn);
    System.out.println("Received message:\n" + encodedMessage + "\n\n");

    // Now we need to generate a message to return. This will generally be an ACK message.
    Segment msh = (Segment) theIn.get("MSH");
    Message retVal;
    try {
        // This method takes in the MSH segment of an incoming message, and generates an
        // appropriate ACK
        retVal = DefaultApplication.makeACK(msh);
    } catch (IOException e) {
        throw new HL7Exception(e);
    }

    return retVal;
}
 
Example 2
Source File: XdsTest.java    From openxds with Apache License 2.0 6 votes vote down vote up
protected void createPatient(String patientId) throws Exception {
	if (!validatePatient)
		return ;
	
	patientId = patientId.replace("&", "&");
	//If it is a valid patient, then no need to re-create.
	if (isValidPatient(patientId))
		return; 
	
	String msg = "MSH|^~\\&|OTHER_KIOSK|HIMSSSANDIEGO|PAT_IDENTITY_X_REF_MGR_MISYS|ALLSCRIPTS|20090512132906-0300||ADT^A04^ADT_A01|7723510070655179915|P|2.3.1\r" + 
      "EVN||20090512132906-0300\r" +
      "PID|||"+ patientId +"||FARNSWORTH^STEVE||19781208|M|||820 JORIE BLVD^^CHICAGO^IL^60523\r" +
      "PV1||O|";
	PipeParser pipeParser = new PipeParser();
	Message adt = pipeParser.parse(msg);
	ConnectionHub connectionHub = ConnectionHub.getInstance();
	Connection connection = connectionHub.attach(hostName, pixRegistryPort, new PipeParser(), MinLowerLayerProtocol.class);
	Initiator initiator = connection.getInitiator();
	Message response = initiator.sendAndReceive(adt);
	String responseString = pipeParser.encode(response);	        
	System.out.println("Received response:\n" + responseString);
		MSA msa = (MSA)response.get("MSA");
	assertEquals("AA", msa.getAcknowledgementCode().getValue());
}
 
Example 3
Source File: MergePatientTest.java    From openxds with Apache License 2.0 5 votes vote down vote up
private void SendPIX(String msg) throws Exception {
PipeParser pipeParser = new PipeParser();
Message adt = pipeParser.parse(msg);
ConnectionHub connectionHub = ConnectionHub.getInstance();
Connection connection = connectionHub.attach(hostName, pixRegistryPort, new PipeParser(), MinLowerLayerProtocol.class);
Initiator initiator = connection.getInitiator();
Message response = initiator.sendAndReceive(adt);
String responseString = pipeParser.encode(response);	        
System.out.println("Received response:\n" + responseString);
MSA msa = (MSA)response.get("MSA");
assertEquals("AA", msa.getAcknowledgementCode().getValue());    	
  }
 
Example 4
Source File: HL7MLLPInput.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public Result execute( Result previousResult, int nr ) {
  Result result = previousResult;

  try {

    String serverName = environmentSubstitute( server );
    int portNumber = Integer.parseInt( environmentSubstitute( port ) );
    String messageVariable = environmentSubstitute( messageVariableName );
    String messageTypeVariable = environmentSubstitute( messageTypeVariableName );
    String versionVariable = environmentSubstitute( versionVariableName );

    MLLPSocketCacheEntry entry = MLLPSocketCache.getInstance().getServerSocketStreamSource( serverName, portNumber );
    if ( entry.getJobListener() != null ) {
      parentJob.addJobListener( entry.getJobListener() );
    }
    MLLPTransport transport = entry.getTransport();

    // Get the next value...
    //
    synchronized ( transport ) {
      Transportable transportable = transport.doReceive();
      String message = transportable.getMessage();

      logDetailed( "Received message: " + message );

      parentJob.setVariable( messageVariable, message );

      // Parse the message and extract the control ID.
      //
      Parser parser = new GenericParser();
      ValidationContext validationContext = new NoValidation();
      parser.setValidationContext( validationContext );
      Message msg = parser.parse( message );
      Structure structure = msg.get( "MSH" );
      String messageType = null;
      String version = msg.getVersion();

      if ( structure instanceof ca.uhn.hl7v2.model.v21.segment.MSH ) {
        messageType = ( (ca.uhn.hl7v2.model.v21.segment.MSH) structure ).getMESSAGETYPE().encode();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v22.segment.MSH ) {
        messageType = ( (ca.uhn.hl7v2.model.v22.segment.MSH) structure ).getMessageType().encode();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v23.segment.MSH ) {
        messageType = ( (ca.uhn.hl7v2.model.v23.segment.MSH) structure ).getMessageType().encode();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v231.segment.MSH ) {
        messageType =
            ( (ca.uhn.hl7v2.model.v231.segment.MSH) structure ).getMessageType().getMessageStructure().getValue();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v24.segment.MSH ) {
        messageType =
            ( (ca.uhn.hl7v2.model.v24.segment.MSH) structure ).getMessageType().getMessageStructure().getValue();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v25.segment.MSH ) {
        messageType =
            ( (ca.uhn.hl7v2.model.v25.segment.MSH) structure ).getMessageType().getMessageStructure().getValue();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v251.segment.MSH ) {
        messageType =
            ( (ca.uhn.hl7v2.model.v251.segment.MSH) structure ).getMessageType().getMessageStructure().getValue();
      } else if ( structure instanceof ca.uhn.hl7v2.model.v26.segment.MSH ) {
        messageType =
            ( (ca.uhn.hl7v2.model.v26.segment.MSH) structure ).getMessageType().getMessageStructure().getValue();
      } else {
        logError( "This job entry does not support the HL7 dialect used. Found MSH class: "
            + structure.getClass().getName() );
      }

      if ( !Utils.isEmpty( messageTypeVariable ) ) {
        parentJob.setVariable( messageTypeVariable, messageType );
      }
      if ( !Utils.isEmpty( versionVariable ) ) {
        parentJob.setVariable( versionVariable, version );
      }
    }

    // All went well..
    //
    result.setNrErrors( 0 );
    result.setResult( true );

  } catch ( Exception e ) {
    log.logError( BaseMessages.getString( PKG, "HL7MLLPInput.Exception.UnexpectedError" ), e );
    result.setNrErrors( 1 );
    result.setResult( false );
  }

  return result;
}