ca.uhn.hl7v2.validation.impl.NoValidation Java Examples

The following examples show how to use ca.uhn.hl7v2.validation.impl.NoValidation. 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: 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 #2
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;
}
 
Example #3
Source File: HL7Input.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (HL7InputMeta) smi;
  data = (HL7InputData) sdi;

  Object[] r = getRow(); // get row, set busy!
  if ( r == null ) { // no more input to be expected...
    setOutputDone();
    return false;
  }

  if ( first ) {
    data.messageFieldIndex = getInputRowMeta().indexOfValue( meta.getMessageField() );
    if ( data.messageFieldIndex < 0 ) {
      throw new KettleException( "Unable to find field [" + meta.getMessageField() + "] in the input fields." );
    }

    data.outputRowMeta = getInputRowMeta().clone();
    meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

    data.parser = new GenericParser();
    data.parser.setValidationContext( new NoValidation() );
  }

  String messageString = getInputRowMeta().getString( r, data.messageFieldIndex );

  try {
    Message message = data.parser.parse( messageString );
    List<HL7Value> values = HL7KettleParser.extractValues( message );

    for ( HL7Value value : values ) {
      Object[] output = RowDataUtil.createResizedCopy( r, data.outputRowMeta.size() );
      int outputIndex = getInputRowMeta().size();

      output[outputIndex++] = value.getParentGroup();
      output[outputIndex++] = value.getGroupName();
      output[outputIndex++] = value.getVersion();
      output[outputIndex++] = value.getStructureName();
      output[outputIndex++] = value.getStructureNumber();
      output[outputIndex++] = value.getFieldName();
      output[outputIndex++] = value.getCoordinate();
      output[outputIndex++] = value.getDataType();
      output[outputIndex++] = value.getDescription();
      output[outputIndex++] = value.getValue();

      putRow( data.outputRowMeta, output );
    }
  } catch ( Exception e ) {
    throw new KettleException( "Error parsing message", e );
  }

  if ( checkFeedback( getLinesWritten() ) ) {
    if ( log.isBasic() ) {
      logBasic( BaseMessages.getString( PKG, "HL7Input.Log.LineNumber" ) + getLinesWritten() );
    }
  }

  return true;
}