Search in sources :

Example 6 with Structure

use of ca.uhn.hl7v2.model.Structure 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 7 with Structure

use of ca.uhn.hl7v2.model.Structure in project pentaho-kettle by pentaho.

the class HL7KettleParser method parseStructure.

private static void parseStructure(List<HL7Value> values, Message message, Terser terser, Structure structure, String structureNumber) throws Exception {
    Map<String, List<String>> nameMap = NamesUtil.getInstance().getMap();
    if (structure instanceof Segment) {
        Segment segment = (Segment) structure;
        String[] names = segment.getNames();
        for (int n = 1; n <= segment.numFields(); n++) {
            Type[] types = segment.getField(n);
            for (int t = 0; t < types.length; t++) {
                int nrComponents = Terser.numComponents(types[t]);
                for (int c = 1; c <= nrComponents; c++) {
                    int nrSub = Terser.numSubComponents(types[t], c);
                    for (int sc = 1; sc <= nrSub; sc++) {
                        String string = Terser.get(segment, n, t, c, sc);
                        // Primitive primitive = Terser.getPrimitive(types[t], c, sc);
                        String description = "?";
                        List<String> list = nameMap.get(types[t].getName());
                        if (list != null && c - 1 < list.size()) {
                            description = list.get(c - 1);
                        }
                        Group group = structure.getParent();
                        Group rootGroup = structure.getMessage();
                        String coordinates = n + "." + (t + 1) + "." + c + "." + sc;
                        HL7Value value = new HL7Value(message.getVersion(), rootGroup.getName(), group.getName(), structure.getName(), structureNumber, names[n - 1], coordinates, types[t].getName(), description, string);
                        values.add(value);
                    }
                }
            }
        }
    } else if (structure instanceof Group) {
        Group group = (Group) structure;
        String[] names = group.getNames();
        for (int n = 1; n <= names.length; n++) {
            String name = names[n - 1];
            Structure subStructure = group.get(name);
            parseStructure(values, message, terser, subStructure, structureNumber + "." + n);
        }
    } else {
        throw new Exception("oops, not handled yet!");
    }
}
Also used : Group(ca.uhn.hl7v2.model.Group) Segment(ca.uhn.hl7v2.model.Segment) Type(ca.uhn.hl7v2.model.Type) List(java.util.List) ArrayList(java.util.ArrayList) Structure(ca.uhn.hl7v2.model.Structure)

Example 8 with Structure

use of ca.uhn.hl7v2.model.Structure in project streamsx.health by IBMStreams.

the class HapiMessageHandler method processMessage.

@Override
public Message processMessage(Message theMessage, Map<String, Object> arg1) throws ReceivingApplicationException, HL7Exception {
    server.messageArrived(theMessage);
    Message ack;
    try {
        // Always use the default parser to generate an ack
        // HAPI seems to get into trouble if the ADT_AXX superstructure
        // is used.  
        // Internally, when it tries to generate an ack message
        // the super structure setting in the model class factory causes the ADT_AXX message
        // to get created instead of the ACK getting created.  This is to override the model
        // class factory so that the proper class can be generated.
        theMessage.setParser(ackParser);
        ack = theMessage.generateACK();
        return ack;
    } catch (IOException e) {
        TRACE.log(TraceLevel.ERROR, "Unable to generate ack message", e);
    }
    return theMessage;
}
Also used : Message(ca.uhn.hl7v2.model.Message) IOException(java.io.IOException)

Example 9 with Structure

use of ca.uhn.hl7v2.model.Structure in project tdi-studio-se by Talend.

the class HL7MessageTreeContentProvider method getChildren.

public Object[] getChildren(Object parentElement) {
    List values = new ArrayList();
    if (parentElement instanceof Message) {
        Message messParent = (Message) parentElement;
        String[] childNames = messParent.getNames();
        if (!values.isEmpty()) {
            values.clear();
        }
        for (int i = 0; i < childNames.length; i++) {
            try {
                Structure[] childReps = messParent.getAll(childNames[i]);
                for (int j = 0; j < childReps.length; j++) {
                    if (childReps[j] instanceof Message) {
                        values.add(childReps[j]);
                    }
                    if (childReps[j] instanceof Group) {
                        values.add((Group) childReps[j]);
                        allSegmentFromGroup.clear();
                        getAllSegmentsFromGroup((Group) childReps[j]);
                    }
                    if (childReps[j] instanceof Segment) {
                        SegmentModel sModel = new SegmentModel((Segment) childReps[j], messParent, i, j);
                        if (sModel.getTypes() != null && sModel.getTypes().length > 0) {
                            values.add(sModel);
                            if (!allSegmentsForMessage.contains(sModel)) {
                                allSegmentsForMessage.add(sModel);
                            }
                        }
                    }
                }
            // values.addAll(Arrays.asList(childReps));
            } catch (HL7Exception e) {
                e.printStackTrace();
            }
        }
        return values.toArray();
    }
    if (parentElement instanceof Segment) {
        values.clear();
        Segment segment = (Segment) parentElement;
        SegmentModel sm = new SegmentModel(segment, segment, 0, 0);
        return sm.getTypes();
    }
    if (parentElement instanceof SegmentModel) {
        SegmentModel sm = (SegmentModel) parentElement;
        return sm.getTypes();
    }
    if (parentElement instanceof TypeModel) {
        TypeModel tm = (TypeModel) parentElement;
        return tm.getPrimitives();
    }
    if (parentElement instanceof Group) {
        values.clear();
        Group group = (Group) parentElement;
        String[] childNames = group.getNames();
        for (int i = 0; i < childNames.length; i++) {
            try {
                Structure[] childReps = group.getAll(childNames[i]);
                for (int j = 0; j < childReps.length; j++) {
                    if (childReps[j] instanceof Segment) {
                        SegmentModel sm = new SegmentModel((Segment) childReps[j], group, i, j);
                        if (sm.getTypes() != null && sm.getTypes().length > 0) {
                            values.add(sm);
                        }
                    } else {
                        values.add(childReps[j]);
                    }
                }
            // values.addAll(Arrays.asList(childReps));
            } catch (HL7Exception e) {
                e.printStackTrace();
            }
        }
        return values.toArray();
    }
    return new Object[0];
}
Also used : Group(ca.uhn.hl7v2.model.Group) Message(ca.uhn.hl7v2.model.Message) ArrayList(java.util.ArrayList) TypeModel(org.talend.designer.hl7.model.TypeModel) Segment(ca.uhn.hl7v2.model.Segment) HL7Exception(ca.uhn.hl7v2.HL7Exception) ArrayList(java.util.ArrayList) List(java.util.List) Structure(ca.uhn.hl7v2.model.Structure) SegmentModel(org.talend.designer.hl7.model.SegmentModel)

Example 10 with Structure

use of ca.uhn.hl7v2.model.Structure in project tdi-studio-se by Talend.

the class HL7PublicUtil method getChildList.

public Object[] getChildList(Object parentElement) {
    List values = new ArrayList();
    if (parentElement instanceof Message) {
        Message messParent = (Message) parentElement;
        String[] childNames = messParent.getNames();
        if (!values.isEmpty()) {
            values.clear();
        }
        for (int i = 0; i < childNames.length; i++) {
            try {
                Structure[] childReps = messParent.getAll(childNames[i]);
                for (int j = 0; j < childReps.length; j++) {
                    if (childReps[j] instanceof Message) {
                        values.add(childReps[j]);
                    }
                    if (childReps[j] instanceof Group) {
                        allSegmentFromGroup.clear();
                        getAllSegmentsFromGroup((Group) childReps[j]);
                        if (allSegmentFromGroup.size() > 0) {
                            values.addAll(Arrays.asList(allSegmentFromGroup.toArray(new SegmentModel[0])));
                        }
                    }
                    if (childReps[j] instanceof Segment) {
                        SegmentModel sModel = new SegmentModel((Segment) childReps[j], messParent, i, j);
                        if (sModel.getTypes() != null && sModel.getTypes().length > 0) {
                            values.add(sModel);
                            if (!allSegmentsForMessage.contains(sModel)) {
                                allSegmentsForMessage.add(sModel);
                            }
                        }
                    }
                }
            // values.addAll(Arrays.asList(childReps));
            } catch (HL7Exception e) {
                e.printStackTrace();
            }
        }
        return values.toArray();
    }
    if (parentElement instanceof Segment) {
        values.clear();
        Segment segment = (Segment) parentElement;
        SegmentModel sm = new SegmentModel(segment, segment, 0, 0);
        return sm.getTypes();
    }
    if (parentElement instanceof SegmentModel) {
        SegmentModel sm = (SegmentModel) parentElement;
        return sm.getTypes();
    }
    if (parentElement instanceof TypeModel) {
        TypeModel tm = (TypeModel) parentElement;
        return tm.getPrimitives();
    }
    if (parentElement instanceof Group) {
        values.clear();
        Group group = (Group) parentElement;
        String[] childNames = group.getNames();
        for (int i = 0; i < childNames.length; i++) {
            try {
                Structure[] childReps = group.getAll(childNames[i]);
                for (int j = 0; j < childReps.length; j++) {
                    if (childReps[j] instanceof Segment) {
                        SegmentModel sm = new SegmentModel((Segment) childReps[j], group, i, j);
                        if (sm.getTypes() != null && sm.getTypes().length > 0) {
                            values.add(sm);
                        }
                    } else {
                        values.add(childReps[j]);
                    }
                }
            // values.addAll(Arrays.asList(childReps));
            } catch (HL7Exception e) {
                e.printStackTrace();
            }
        }
        return values.toArray();
    }
    return new Object[0];
}
Also used : Group(ca.uhn.hl7v2.model.Group) Message(ca.uhn.hl7v2.model.Message) ArrayList(java.util.ArrayList) TypeModel(org.talend.designer.hl7.model.TypeModel) Segment(ca.uhn.hl7v2.model.Segment) HL7Exception(ca.uhn.hl7v2.HL7Exception) ArrayList(java.util.ArrayList) List(java.util.List) Structure(ca.uhn.hl7v2.model.Structure) SegmentModel(org.talend.designer.hl7.model.SegmentModel)

Aggregations

Structure (ca.uhn.hl7v2.model.Structure)10 Group (ca.uhn.hl7v2.model.Group)6 Message (ca.uhn.hl7v2.model.Message)6 Segment (ca.uhn.hl7v2.model.Segment)6 ArrayList (java.util.ArrayList)6 HL7Exception (ca.uhn.hl7v2.HL7Exception)5 List (java.util.List)4 SegmentModel (org.talend.designer.hl7.model.SegmentModel)4 TypeModel (org.talend.designer.hl7.model.TypeModel)4 Type (ca.uhn.hl7v2.model.Type)2 DTM (ca.uhn.hl7v2.model.v26.datatype.DTM)1 PL (ca.uhn.hl7v2.model.v26.datatype.PL)1 ORU_R01_OBSERVATION (ca.uhn.hl7v2.model.v26.group.ORU_R01_OBSERVATION)1 ORU_R01_ORDER_OBSERVATION (ca.uhn.hl7v2.model.v26.group.ORU_R01_ORDER_OBSERVATION)1 ORU_R01_PATIENT (ca.uhn.hl7v2.model.v26.group.ORU_R01_PATIENT)1 ORU_R01_PATIENT_RESULT (ca.uhn.hl7v2.model.v26.group.ORU_R01_PATIENT_RESULT)1 ORU_R01_VISIT (ca.uhn.hl7v2.model.v26.group.ORU_R01_VISIT)1 ORU_R01 (ca.uhn.hl7v2.model.v26.message.ORU_R01)1 MSH (ca.uhn.hl7v2.model.v26.segment.MSH)1 OBR (ca.uhn.hl7v2.model.v26.segment.OBR)1