Search in sources :

Example 1 with Message

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

the class HL7Parse method doParse.

/**
     * DOC gcui Comment method "doParse".
     * 
     * @param filePath
     * @param hl7Manager
     * @param msgContentList
     * @return
     */
public List<Message> doParse(String filePath, HL7Manager hl7Manager, List<String> msgContentList, String startChar, String endChar) {
    List<Message> messageList = new ArrayList<Message>();
    String filePathNoQuotes = TalendTextUtils.removeQuotes(filePath);
    File file = Path.fromOSString(filePathNoQuotes).toFile();
    if (file.exists()) {
        msgContentList.clear();
        ByteArray array = PropertiesFactory.eINSTANCE.createByteArray();
        try {
            array.setInnerContentFromFile(file);
            TalendHL7Reader talendHL7Reader = new TalendHL7Reader(new java.io.FileInputStream(file), "ISO-8859-15");
            String HL7InputTem = null;
            if (startChar != null) {
                talendHL7Reader.setStartMsgChar(stringParse2Char(startChar));
            }
            if (endChar != null) {
                talendHL7Reader.setEndMsgChar(stringParse2Char(endChar));
            }
            while ((HL7InputTem = talendHL7Reader.getMessage()) != null) {
                msgContentList.add(HL7InputTem);
                Message message = getHL7MessageInput(HL7InputTem);
                messageList.add(message);
            }
            if (msgContentList == null || msgContentList.size() == 0) {
                String msgText = new String(array.getInnerContent());
                msgContentList.add(msgText);
                Message message = getHL7MessageInput(msgText);
                messageList.add(message);
            }
            hl7Manager.getUiManager().getHl7UI().getContentProvider().getAllSegmentsForMessage().clear();
            hl7Manager.getUiManager().getHl7UI().getMessageViewer().setInput(messageList.toArray());
            hl7Manager.getUiManager().getHl7UI().getHeader().setMsgIsChange(true);
            hl7Manager.getUiManager().getHl7UI().initSchemaCombo(null);
            hl7Manager.getUiManager().getHl7UI().getMetadataEditor().removeAll();
            hl7Manager.getUiManager().getHl7UI().redrawLinkers();
        } catch (IOException ex) {
            ExceptionHandler.process(ex);
        }
    }
    return messageList;
}
Also used : Message(ca.uhn.hl7v2.model.Message) ArrayList(java.util.ArrayList) ByteArray(org.talend.core.model.properties.ByteArray) IOException(java.io.IOException) File(java.io.File)

Example 2 with Message

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

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

the class HL7Parse method doParse.

public List<Message> doParse(String filePath, TreeViewer messageViewerStep1, List<String> msgContentList, String startChar, String endChar) {
    List<Message> messageList = new ArrayList<Message>();
    String filePathNoQuotes = TalendTextUtils.removeQuotes(filePath);
    File file = Path.fromOSString(filePathNoQuotes).toFile();
    if (file.exists()) {
        msgContentList.clear();
        ByteArray array = PropertiesFactory.eINSTANCE.createByteArray();
        try {
            array.setInnerContentFromFile(file);
            //$NON-NLS-1$
            TalendHL7Reader talendHL7Reader = new TalendHL7Reader(new java.io.FileInputStream(file), "ISO-8859-15");
            String hl7InputTem = null;
            if (startChar != null) {
                talendHL7Reader.setStartMsgChar(stringParse2Char(startChar));
            }
            if (endChar != null) {
                talendHL7Reader.setEndMsgChar(stringParse2Char(endChar));
            }
            while ((hl7InputTem = talendHL7Reader.getMessage()) != null) {
                msgContentList.add(hl7InputTem);
                Message message = getHL7MessageInput(hl7InputTem);
                messageList.add(message);
            }
            if (msgContentList == null || msgContentList.size() == 0) {
                String msgText = new String(array.getInnerContent());
                msgContentList.add(msgText);
                Message message = getHL7MessageInput(msgText);
                messageList.add(message);
            }
            messageViewerStep1.setInput(messageList.toArray());
        } catch (IOException ex) {
            ExceptionHandler.process(ex);
        }
    }
    return messageList;
}
Also used : Message(ca.uhn.hl7v2.model.Message) ArrayList(java.util.ArrayList) ByteArray(org.talend.core.model.properties.ByteArray) IOException(java.io.IOException) File(java.io.File)

Example 4 with Message

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

the class HL7PublicUtil method getFirstLevelChild.

public List getFirstLevelChild(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(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);
                            }
                        }
                    }
                }
            } catch (HL7Exception e) {
                e.printStackTrace();
            }
        }
    }
    return values;
}
Also used : Group(ca.uhn.hl7v2.model.Group) Message(ca.uhn.hl7v2.model.Message) ArrayList(java.util.ArrayList) 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) Segment(ca.uhn.hl7v2.model.Segment)

Example 5 with Message

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

the class HL7PublicUtil method getHL7TreeNodes.

public List<HL7TreeNode> getHL7TreeNodes(List<Message> messageList) {
    List<HL7TreeNode> list = new ArrayList<HL7TreeNode>();
    if (messageList == null) {
        return list;
    }
    for (Message message : messageList) {
        HL7TreeNode root = initTreeRoot(message);
        if (root instanceof Element) {
            // root = ((Element) root).getElementChildren().get(0);
            root.setParent(null);
            list.add(root);
        }
    }
    return list;
}
Also used : Message(ca.uhn.hl7v2.model.Message) Element(org.talend.designer.hl7.ui.data.Element) ArrayList(java.util.ArrayList) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode)

Aggregations

Message (ca.uhn.hl7v2.model.Message)114 Test (org.junit.Test)82 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)60 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)30 Patient (org.openmrs.Patient)24 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)22 HL7Exception (ca.uhn.hl7v2.HL7Exception)20 QRD (ca.uhn.hl7v2.model.v24.segment.QRD)19 ArrayList (java.util.ArrayList)19 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)18 ORUR01Handler (org.openmrs.hl7.handler.ORUR01Handler)15 Concept (org.openmrs.Concept)14 Obs (org.openmrs.Obs)14 Person (org.openmrs.Person)14 MSH (ca.uhn.hl7v2.model.v24.segment.MSH)13 ObsService (org.openmrs.api.ObsService)11 ADR_A19 (ca.uhn.hl7v2.model.v24.message.ADR_A19)9 MSA (ca.uhn.hl7v2.model.v24.segment.MSA)9 Encounter (org.openmrs.Encounter)9 Structure (ca.uhn.hl7v2.model.Structure)8