ca.uhn.hl7v2.parser.Parser Java Examples

The following examples show how to use ca.uhn.hl7v2.parser.Parser. 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: MLLPContext.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public MLLPContext(IOSession session, CharsetDecoder decoder, boolean autoAck, boolean validateMessage,
                   Parser preProcessorParser, BufferFactory bufferFactory) {
    this.session = session;
    this.codec = new HL7Codec(decoder);
    this.autoAck = autoAck;
    this.validateMessage = validateMessage;
    this.preProcessorParser = preProcessorParser;
    this.bufferFactory = bufferFactory;
    this.expiry = MLLPConstants.DEFAULT_HL7_TIMEOUT;
    this.requestBuffer = new StringBuffer();
    this.responseBuffer = new StringBuffer();

    if (preProcessorParser == null) {
        preProcess = false;
    }

}
 
Example #2
Source File: HL7_ORU_R01.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Reads an ORU_R01 HL7 file
 * 
 * @param text
 *            ISO-8559-1 String
 * @param readWithValidation
 *            True for parsing with validation, False for parsing without validation
 * @return The ORU_R01 message
 * @throws HL7Exception
 */
public ORU_R01 read(String text, boolean readWithValidation) throws HL7Exception{
	Parser p = new PipeParser();
	if (readWithValidation) {
		p.setValidationContext(new ElexisValidation());
	} else {
		p.setValidationContext(new NoValidation());
	}
	Message hl7Msg = p.parse(text);
	if (hl7Msg instanceof ORU_R01) {
		return (ORU_R01) hl7Msg;
	} else {
		addError(
			MessageFormat.format(Messages.HL7_ORU_R01_Error_WrongMsgType, hl7Msg.getName()));
	}
	return null;
}
 
Example #3
Source File: HL7_ADT_A08.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates an ORU_R01 message
 * 
 * @param patient
 * @param consultation
 * @param labItem
 * @param labwert
 * 
 * @return
 */
public String createText(final HL7Patient patient, HL7Konsultation consultation)
	throws DataTypeException, HL7Exception{
	
	ADT_A08 adt = new ADT_A08();
	// Message
	fillMSH(adt.getMSH(), "ADT", "A08", mandant, this.uniqueMessageControlID, //$NON-NLS-1$ //$NON-NLS-2$
		"8859/1", patient); //$NON-NLS-1$ //$NON-NLS-2$
	
	fillEVN(adt.getEVN());
	
	// Patient
	fillPID(adt.getPID(), patient);
	
	// Patient Visit
	fillPV1(adt.getPV1(), consultation);
	
	// Now, let's encode the message and look at the output
	HapiContext context = new DefaultHapiContext();
	Parser parser = context.getPipeParser();
	return parser.encode(adt);
}
 
Example #4
Source File: HL7_OML_O21.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates an OMG_O19 message
 * 
 * @param patient
 * @param kostentraeger
 * @param rechnungsempfaenger
 * @param auftragsNummer
 * @param plan
 *            Abrechnungssystem (MV, UVG, VVG, KVG, usw)
 * @param beginDate
 * @param vnr
 *            Versicherungs-, Fall- oder Unfallnr
 * @return
 */
public String createText(final HL7Patient patient, final HL7Kostentraeger rechnungsempfaenger,
	final HL7Kostentraeger kostentraeger, final String plan, final Date beginDate,
	final String fallNr, final long auftragsNummer) throws DataTypeException, HL7Exception{
	
	OML_O21 omg = new OML_O21();
	fillMSH(omg.getMSH(), "OML", "O21", mandant, this.uniqueMessageControlID, //$NON-NLS-1$ //$NON-NLS-2$
		this.uniqueProcessingID, patient); //$NON-NLS-1$ //$NON-NLS-2$
	fillPID(omg.getPATIENT().getPID(), patient);
	fillNK1(omg.getPATIENT().getNK1(), rechnungsempfaenger);
	fillPV1(omg.getPATIENT().getPATIENT_VISIT().getPV1(), patient, beginDate);
	fillIN1(omg.getPATIENT().getINSURANCE().getIN1(), patient, kostentraeger, plan, fallNr);
	fillORC(omg.getORDER().getORC(), "1", auftragsNummer); //$NON-NLS-1$
	
	// Now, let's encode the message and look at the output
	Parser parser = new PipeParser();
	return parser.encode(omg);
}
 
Example #5
Source File: HL7_ORU_R01.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates an ORU_R01 message
 * 
 * @param patient
 * @param labItem
 * @param labwert
 * 
 * @return
 */
public String createText(final HL7Patient patient, final HL7LaborItem labItem,
	final HL7LaborWert labwert) throws DataTypeException, HL7Exception{
	
	ORU_R01 oru = new ORU_R01();
	// Message
	fillMSH(oru.getMSH(), "ORU", "R01", mandant, this.uniqueMessageControlID, //$NON-NLS-1$ //$NON-NLS-2$
		this.uniqueProcessingID, patient); //$NON-NLS-1$ //$NON-NLS-2$
	
	// Patient
	PID pid = oru.getPATIENT_RESULT().getPATIENT().getPID();
	fillPID(pid, patient);
	
	ORU_R01_ORDER_OBSERVATION orderObservation = oru.getPATIENT_RESULT().getORDER_OBSERVATION();
	fillORC(orderObservation.getORC(), "RE", null); //$NON-NLS-1$
	
	addResultInternal(oru, patient, labItem, labwert, 0);
	
	// Now, let's encode the message and look at the output
	Parser parser = new PipeParser();
	return parser.encode(oru);
}
 
Example #6
Source File: HL7_ORU_R01.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Adds a ORU_R01 observation result
 * 
 * @param oru
 * @param patient
 * @param labItem
 * @param labwert
 * @param initial
 * @return
 */
private String addResultInternal(final ORU_R01 oru, final HL7Patient patient,
	final HL7LaborItem labItem, final HL7LaborWert labwert, int orderObservationIndex)
	throws DataTypeException, HL7Exception{
	
	// Observation
	ORU_R01_ORDER_OBSERVATION orderObservation =
		(ORU_R01_ORDER_OBSERVATION) oru.getPATIENT_RESULT().getORDER_OBSERVATION(
			orderObservationIndex);
	fillOBR(orderObservation.getOBR(), orderObservationIndex, labItem);
	fillOBX(orderObservation.getOBSERVATION().getOBX(), patient, labItem, labwert);
	if (labwert.getKommentar() != null && labwert.getKommentar().length() > 0) {
		fillNTE(orderObservation.getNTE(), labwert);
	}
	// Now, let's encode the message and look at the output
	Parser parser = new PipeParser();
	return parser.encode(oru);
}
 
Example #7
Source File: MLLPContextFactory.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static MLLPContext createMLLPContext(IOSession session, HL7Processor processor) {
    InboundProcessorParams inboundParams = (InboundProcessorParams) processor.getInboundParameterMap()
            .get(MLLPConstants.INBOUND_PARAMS);

    CharsetDecoder decoder = (CharsetDecoder) processor.getInboundParameterMap()
            .get(MLLPConstants.HL7_CHARSET_DECODER);
    boolean autoAck = processor.isAutoAck();
    boolean validate = Boolean.valueOf(inboundParams.getProperties().getProperty(MLLPConstants.PARAM_HL7_VALIDATE));
    Parser preParser = (Parser) processor.getInboundParameterMap().get(MLLPConstants.HL7_PRE_PROC_PARSER_CLASS);
    BufferFactory bufferFactory = (BufferFactory) processor.getInboundParameterMap()
            .get(MLLPConstants.INBOUND_HL7_BUFFER_FACTORY);

    return new MLLPContext(session, decoder, autoAck, validate, preParser, bufferFactory);
}
 
Example #8
Source File: HL7IntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("resource")
public void testMarshalUnmarshal() throws Exception {

    final String msg = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4\r";
    final HL7DataFormat format = new HL7DataFormat();

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .marshal(format)
            .unmarshal(format)
            .to("mock:result");
        }
    });

    camelctx.start();
    try {
        HapiContext context = new DefaultHapiContext();
        Parser p = context.getGenericParser();
        Message hapimsg = p.parse(msg);

        ProducerTemplate producer = camelctx.createProducerTemplate();
        Message result = (Message) producer.requestBody("direct:start", hapimsg);
        Assert.assertEquals(hapimsg.toString(), result.toString());
    } finally {
        camelctx.close();
    }
}
 
Example #9
Source File: HL7_ORU_R01.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Reads an ORU_R01 HL7 file
 * 
 * @param text
 *            ISO-8559-1 String
 * @return
 * @throws HL7Exception
 */
public ORU_R01 read(String text) throws HL7Exception{
	Parser p = new PipeParser();
	p.setValidationContext(new ElexisValidation());
	Message hl7Msg = p.parse(text);
	if (hl7Msg instanceof ORU_R01) {
		return (ORU_R01) hl7Msg;
	} else {
		addError(MessageFormat.format(
			Messages.HL7_ORU_R01_Error_WrongMsgType, hl7Msg.getName())); //$NON-NLS-1$
	}
	return null;
}
 
Example #10
Source File: MLLPContext.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
public Parser getPreProcessParser() {
    return preProcessorParser;
}
 
Example #11
Source File: HL7MessageUtils.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
public static Message parse(String msg, final Parser preProcessor) throws HL7Exception {
    return preProcessor.parse(msg);
}
 
Example #12
Source File: HL7Server.java    From openxds with Apache License 2.0 4 votes vote down vote up
/**
* Constructor. Creates a new instance of SimpleServer that listens
* on the given port.   
*/
public HL7Server(IConnectionDescription conn, LowerLayerProtocol llp, Parser parser) {
   super(parser, llp);
   this.connection = conn;
}
 
Example #13
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;
}