Search in sources :

Example 1 with HL7Value

use of org.pentaho.di.trans.steps.hl7input.common.HL7Value 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

Message (ca.uhn.hl7v2.model.Message)1 GenericParser (ca.uhn.hl7v2.parser.GenericParser)1 NoValidation (ca.uhn.hl7v2.validation.impl.NoValidation)1 KettleException (org.pentaho.di.core.exception.KettleException)1 HL7Value (org.pentaho.di.trans.steps.hl7input.common.HL7Value)1