Package ca.uhn.hl7v2

Examples of ca.uhn.hl7v2.HL7Exception


     */
    public static EncodingCharacters getInstance(Message message) throws HL7Exception {

        final String encodingCharactersValue = message.getEncodingCharactersValue();
        if (encodingCharactersValue == null || encodingCharactersValue.length() == 0) {
            throw new HL7Exception("encoding characters not populated");
        }

        final Character fieldSeparatorValue = message.getFieldSeparatorValue();
        if (fieldSeparatorValue == null) {
            throw new HL7Exception("Field separator not populated");
        }

        return new EncodingCharacters(fieldSeparatorValue, encodingCharactersValue);
    }
View Full Code Here


     * in future HAPI versions these will be parsed as well.
     * @param message an XML or ER7 encoded message string
     * @return null if it parses correctly, an HL7Exception otherwise
     */
    public static HL7Exception parsesCorrectly(String context, String message) {
        HL7Exception problem = null;
        try {
            Message m = parser.parse(message);
            String encoding = parser.getEncoding(message);
            String result = parser.encode(m, encoding);
            if (!EncodedMessageComparator.equivalent(message, result)) {
                problem = new HL7Exception(context + ": Original differs semantically from parsed/encoded message.\r\n-----Original:------------\r\n"
                    + message + " \r\n------ Parsed/Encoded: ----------\r\n" + result + " \r\n-----Original Standardized: ---------\r\n"
                    + EncodedMessageComparator.standardize(message) + " \r\n---------------------\r\n");
            }           
        } catch (Exception e) {
            problem = new HL7Exception(context + ": " + e.getMessage() + " in message: \r\n-------------\r\n" + message + "\r\n-------------");;
        }
        return problem;
    }
View Full Code Here

    public HL7Exception[] testAll() throws IOException {
      List<HL7Exception> list = new ArrayList<HL7Exception>();

        String message = null;
        while ((message = getNextMessage()).length() > 0) {
            HL7Exception e = parsesCorrectly(this.context, message);
            if (e != null) list.add(e);
        }
       
        return list.toArray(new HL7Exception[0]);
    }
View Full Code Here

                doc = parser.getDocument();
            }
            m = parseDocument(doc, version);
        }
        catch (SAXException e) {
            throw new HL7Exception("SAXException parsing XML", HL7Exception.APPLICATION_INTERNAL_ERROR, e);
        }
        catch (IOException e) {
            throw new HL7Exception("IOException parsing XML", HL7Exception.APPLICATION_INTERNAL_ERROR, e);
        }

        return m;
    }
View Full Code Here

     * @throws HL7Exception if the data fields in the message do not permit encoding
     *      (e.g. required fields are null)
     */
    protected String doEncode(Message source) throws HL7Exception {
        if (source instanceof GenericMessage) {
            throw new HL7Exception("Can't XML-encode a GenericMessage.  Message must have a recognized structure.");
        }
       
        Document doc = encodeDocument(source);
        Element documentElement = doc.getDocumentElement();
    documentElement.setAttribute("xmlns", "urn:hl7-org:v2xml");
       
        StringWriter out = new StringWriter();

        OutputFormat outputFormat = new OutputFormat("", null, true);
        outputFormat.setLineWidth(0);
       
        if (textEncoding != null) {
          outputFormat.setEncoding(textEncoding);
        }
       
        XMLSerializer ser = new XMLSerializer(out, outputFormat); //default output format
        try {
            ser.serialize(doc);
        }
        catch (IOException e) {
            throw new HL7Exception(
                "IOException serializing XML document to string",
                HL7Exception.APPLICATION_INTERNAL_ERROR,
                e);
        }
        return out.toString();
View Full Code Here

                if (componentHasValue) {
                    try {
                        segmentElement.appendChild(newNode);
                    }
                    catch (DOMException e) {
                        throw new HL7Exception(
                            "DOMException encoding Segment: ",
                            HL7Exception.APPLICATION_INTERNAL_ERROR,
                            e);
                    }
                    hasValue = true;
View Full Code Here

        if (tagStart >= 0 && valEnd >= valStart) {
            value = message.substring(valStart, valEnd);
        }
        else {
            throw new HL7Exception(
                "Couldn't find "
                    + tagName
                    + " in message beginning: "
                    + message.substring(0, Math.min(150, message.length())),
                HL7Exception.REQUIRED_FIELD_MISSING);
View Full Code Here

        Terser t = new Terser(message);
       
        //check msg type, event type, msg struct ID
        String msgType = t.get("/MSH-9-1");
        if (!msgType.equals(profile.getMsgType())) {
            HL7Exception e =
                new ProfileNotFollowedException("Message type " + msgType + " doesn't match profile type of " + profile.getMsgType());
            exList.add(e);
        }
       
        String evType = t.get("/MSH-9-2");
        if (!evType.equals(profile.getEventType()) && !profile.getEventType().equalsIgnoreCase("ALL")) {
            HL7Exception e =
                new ProfileNotFollowedException("Event type " + evType + " doesn't match profile type of " + profile.getEventType());
            exList.add(e);
        }
       
        String msgStruct = t.get("/MSH-9-3");
        if (msgStruct == null || !msgStruct.equals(profile.getMsgStructID())) {
            HL7Exception e =
                new ProfileNotFollowedException("Message structure " + msgStruct + " doesn't match profile type of " + profile.getMsgStructID());
            exList.add(e);
        }
       
        if (validateChildren) {
View Full Code Here

                    ArrayList<Structure> instancesWithContent = new ArrayList<Structure>(10);
                    for (int j = 0; j < instances.length; j++) {
                        if (hasContent(instances[j])) instancesWithContent.add(instances[j]);
                    }
                   
                    HL7Exception ce = testCardinality(instancesWithContent.size(),
                    struct.getMin(), struct.getMax(), struct.getUsage(), struct.getName());
                    if (ce != null) exList.add(ce);
                   
                    //test children on instances with content
                    if (validateChildren) {
View Full Code Here

            if (!allowedStructures.contains(childNames[i])) {
                try {
                    Structure[] reps = group.getAll(childNames[i]);
                    for (int j = 0; j < reps.length; j++) {
                        if (hasContent(reps[j])) {
                            HL7Exception e =
                                new XElementPresentException("The structure "
                                    + childNames[i]
                                    + " appears in the message but not in the profile");
                            exList.add(e);
                        }
View Full Code Here

TOP

Related Classes of ca.uhn.hl7v2.HL7Exception

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.