Search in sources :

Example 1 with GenericParser

use of ca.uhn.hl7v2.parser.GenericParser in project tdi-studio-se by Talend.

the class HL7Parse method getHL7MessageInput.

/**
     * DOC gcui Comment method "getHL7MessageInput".
     * 
     * @param messageText
     * @return
     */
public Message getHL7MessageInput(String messageText) {
    GenericParser p = new GenericParser();
    // force use novalidation
    p.setValidationContext(new NoValidation());
    Message message = null;
    try {
        if (messageText != null) {
            messageText = messageText.replace('\n', '\r');
            message = p.parse(messageText);
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        MessageBox errorBox = new MessageBox(new Shell(), SWT.APPLICATION_MODAL | SWT.OK);
        //$NON-NLS-1$
        errorBox.setText("Parse error");
        //$NON-NLS-1$
        errorBox.setMessage("The content can't be parsed correctly,please check the file");
        if (errorBox.open() == SWT.OK) {
            errorBox.getParent().getShell().close();
        }
    }
    return message;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Message(ca.uhn.hl7v2.model.Message) NoValidation(ca.uhn.hl7v2.validation.impl.NoValidation) IOException(java.io.IOException) GenericParser(ca.uhn.hl7v2.parser.GenericParser) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 2 with GenericParser

use of ca.uhn.hl7v2.parser.GenericParser in project camel by apache.

the class HL7ValidateTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    HapiContext hapiContext = new DefaultHapiContext();
    hapiContext.setValidationContext(new NoValidation());
    Parser p = new GenericParser(hapiContext);
    hl7 = new HL7DataFormat();
    hl7.setParser(p);
    /*
         * Let's start by adding a validation rule to the default validation
         * that disallows PID-2 to be empty.
         */
    ValidationRuleBuilder builder = new ValidationRuleBuilder() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void configure() {
            forVersion(Version.V24).message("ADT", "*").terser("PID-2", not(empty()));
        }
    };
    ValidationContext customValidationContext = ValidationContextFactory.fromBuilder(builder);
    HapiContext customContext = new DefaultHapiContext(customValidationContext);
    final Parser customParser = new GenericParser(customContext);
    return new RouteBuilder() {

        public void configure() throws Exception {
            from("direct:unmarshalFailed").unmarshal().hl7().to("mock:unmarshal");
            from("direct:unmarshalOk").unmarshal().hl7(false).to("mock:unmarshal");
            from("direct:unmarshalOkCustom").unmarshal(hl7).to("mock:unmarshal");
            from("direct:start1").marshal().hl7(customParser).to("mock:end");
            from("direct:start2").marshal().hl7(true).to("mock:end");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) NoValidation(ca.uhn.hl7v2.validation.impl.NoValidation) HapiContext(ca.uhn.hl7v2.HapiContext) DefaultHapiContext(ca.uhn.hl7v2.DefaultHapiContext) ValidationRuleBuilder(ca.uhn.hl7v2.validation.builder.ValidationRuleBuilder) Parser(ca.uhn.hl7v2.parser.Parser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) ValidationContext(ca.uhn.hl7v2.validation.ValidationContext)

Example 3 with GenericParser

use of ca.uhn.hl7v2.parser.GenericParser in project pentaho-kettle by pentaho.

the class HL7MLLPAcknowledge method execute.

public Result execute(Result previousResult, int nr) {
    Result result = previousResult;
    try {
        String serverName = environmentSubstitute(server);
        int portNumber = Integer.parseInt(environmentSubstitute(port));
        String variable = environmentSubstitute(variableName);
        MLLPSocketCacheEntry entry = MLLPSocketCache.getInstance().getServerSocketStreamSource(serverName, portNumber);
        MLLPTransport transport = entry.getTransport();
        // 
        synchronized (transport) {
            String message = getVariable(variable);
            // Parse the message and extract the acknowledge message.
            // 
            Parser parser = new GenericParser();
            ValidationContext validationContext = new NoValidation();
            parser.setValidationContext(validationContext);
            Message msg = parser.parse(message);
            Message ack = msg.generateACK();
            String ackMessage = ack.encode();
            String APPNAME = "PDI4";
            if (ack instanceof ca.uhn.hl7v2.model.v21.message.ACK) {
                ca.uhn.hl7v2.model.v21.message.ACK mod = (ca.uhn.hl7v2.model.v21.message.ACK) ack;
                mod.getMSH().getSENDINGAPPLICATION().setValue(APPNAME);
                mod.getMSH().getSENDINGFACILITY().setValue(APPNAME);
                ackMessage = mod.encode();
            } else if (ack instanceof ca.uhn.hl7v2.model.v22.message.ACK) {
                ca.uhn.hl7v2.model.v22.message.ACK mod = (ca.uhn.hl7v2.model.v22.message.ACK) ack;
                mod.getMSH().getSendingApplication().setValue(APPNAME);
                mod.getMSH().getSendingFacility().setValue(APPNAME);
                ackMessage = mod.encode();
            } else if (ack instanceof ca.uhn.hl7v2.model.v23.message.ACK) {
                ca.uhn.hl7v2.model.v23.message.ACK mod = (ca.uhn.hl7v2.model.v23.message.ACK) ack;
                mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
                mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
                ackMessage = mod.encode();
            } else if (ack instanceof ca.uhn.hl7v2.model.v231.message.ACK) {
                ca.uhn.hl7v2.model.v231.message.ACK mod = (ca.uhn.hl7v2.model.v231.message.ACK) ack;
                mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
                mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
                ackMessage = mod.encode();
            } else if (ack instanceof ca.uhn.hl7v2.model.v24.message.ACK) {
                ca.uhn.hl7v2.model.v24.message.ACK mod = (ca.uhn.hl7v2.model.v24.message.ACK) ack;
                mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
                mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
                ackMessage = mod.encode();
            } else if (ack instanceof ca.uhn.hl7v2.model.v25.message.ACK) {
                ca.uhn.hl7v2.model.v25.message.ACK mod = (ca.uhn.hl7v2.model.v25.message.ACK) ack;
                mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
                mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
                ackMessage = mod.encode();
            } else if (ack instanceof ca.uhn.hl7v2.model.v251.message.ACK) {
                ca.uhn.hl7v2.model.v251.message.ACK mod = (ca.uhn.hl7v2.model.v251.message.ACK) ack;
                mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
                mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
                ackMessage = mod.encode();
            } else if (ack instanceof ca.uhn.hl7v2.model.v26.message.ACK) {
                ca.uhn.hl7v2.model.v26.message.ACK mod = (ca.uhn.hl7v2.model.v26.message.ACK) ack;
                mod.getMSH().getSendingApplication().getNamespaceID().setValue(APPNAME);
                mod.getMSH().getSendingFacility().getNamespaceID().setValue(APPNAME);
                ackMessage = mod.encode();
            } else {
                logError("This job entry does not support the HL7 dialect used. Found ACK class: " + ack.getClass().getName());
            }
            Transportable transportable = new TransportableImpl(ackMessage);
            transport.doSend(transportable);
        }
        // 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;
}
Also used : Message(ca.uhn.hl7v2.model.Message) Result(org.pentaho.di.core.Result) MLLPSocketCacheEntry(org.pentaho.di.trans.steps.hl7input.common.MLLPSocketCacheEntry) Transportable(ca.uhn.hl7v2.protocol.Transportable) TransportableImpl(ca.uhn.hl7v2.protocol.impl.TransportableImpl) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Parser(ca.uhn.hl7v2.parser.Parser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) ValidationContext(ca.uhn.hl7v2.validation.ValidationContext) MLLPTransport(ca.uhn.hl7v2.protocol.impl.MLLPTransport) NoValidation(ca.uhn.hl7v2.validation.impl.NoValidation)

Example 4 with GenericParser

use of ca.uhn.hl7v2.parser.GenericParser in project pentaho-kettle by pentaho.

the class HL7MLLPInput method execute.

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();
        // 
        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;
}
Also used : Message(ca.uhn.hl7v2.model.Message) Result(org.pentaho.di.core.Result) MLLPSocketCacheEntry(org.pentaho.di.trans.steps.hl7input.common.MLLPSocketCacheEntry) Structure(ca.uhn.hl7v2.model.Structure) Transportable(ca.uhn.hl7v2.protocol.Transportable) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Parser(ca.uhn.hl7v2.parser.Parser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) ValidationContext(ca.uhn.hl7v2.validation.ValidationContext) MLLPTransport(ca.uhn.hl7v2.protocol.impl.MLLPTransport) NoValidation(ca.uhn.hl7v2.validation.impl.NoValidation)

Example 5 with GenericParser

use of ca.uhn.hl7v2.parser.GenericParser in project pentaho-kettle by pentaho.

the class HL7Input method processRow.

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (HL7InputMeta) smi;
    data = (HL7InputData) sdi;
    // get row, set busy!
    Object[] r = getRow();
    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;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Message(ca.uhn.hl7v2.model.Message) NoValidation(ca.uhn.hl7v2.validation.impl.NoValidation) HL7Value(org.pentaho.di.trans.steps.hl7input.common.HL7Value) KettleException(org.pentaho.di.core.exception.KettleException) GenericParser(ca.uhn.hl7v2.parser.GenericParser)

Aggregations

GenericParser (ca.uhn.hl7v2.parser.GenericParser)6 NoValidation (ca.uhn.hl7v2.validation.impl.NoValidation)6 Message (ca.uhn.hl7v2.model.Message)4 Parser (ca.uhn.hl7v2.parser.Parser)4 ValidationContext (ca.uhn.hl7v2.validation.ValidationContext)3 KettleException (org.pentaho.di.core.exception.KettleException)3 DefaultHapiContext (ca.uhn.hl7v2.DefaultHapiContext)2 HapiContext (ca.uhn.hl7v2.HapiContext)2 Transportable (ca.uhn.hl7v2.protocol.Transportable)2 MLLPTransport (ca.uhn.hl7v2.protocol.impl.MLLPTransport)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 Result (org.pentaho.di.core.Result)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)2 MLLPSocketCacheEntry (org.pentaho.di.trans.steps.hl7input.common.MLLPSocketCacheEntry)2 Structure (ca.uhn.hl7v2.model.Structure)1 TransportableImpl (ca.uhn.hl7v2.protocol.impl.TransportableImpl)1 ValidationRuleBuilder (ca.uhn.hl7v2.validation.builder.ValidationRuleBuilder)1 IOException (java.io.IOException)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1