Package ca.uhn.hl7v2

Examples of ca.uhn.hl7v2.HL7Exception


        String msh = message.substring(startMSH, endMSH);
        String fieldSep = null;
        if (msh.length() > 3) {
            fieldSep = String.valueOf(msh.charAt(3));
        } else {
            throw new HL7Exception("Can't find field separator in MSH: " + msh, HL7Exception.UNSUPPORTED_VERSION_ID);
        }

        String[] fields = split(msh, fieldSep);

        String compSep = null;
        if (fields.length >= 2 && fields[1] != null && fields[1].length() == 4) {
            compSep = String.valueOf(fields[1].charAt(0)); // get component
                                                           // separator as 1st
                                                           // encoding char
        } else {
            throw new HL7Exception("Invalid or incomplete encoding characters - MSH-2 is " + fields[1], HL7Exception.REQUIRED_FIELD_MISSING);
        }

        String version = null;
        if (fields.length >= 12) {
            String[] comp = split(fields[11], compSep);
            if (comp.length >= 1) {
                version = comp[0];
            } else {
                throw new HL7Exception("Can't find version ID - MSH.12 is " + fields[11], HL7Exception.REQUIRED_FIELD_MISSING);
            }
        } else {
            throw new HL7Exception("Can't find version ID - MSH has only " + fields.length + " fields.", HL7Exception.REQUIRED_FIELD_MISSING);
        }
        return version;
    }
View Full Code Here


        MessageIterator messageIter = new MessageIterator(message, structureDef, "MSH", true);

        String[] segments = split(string, segDelim);

        if (segments.length == 0) {
          throw new HL7Exception("Invalid message content: \"" + string + "\"");
        }
       
        if (segments[0] == null || segments[0].length() < 4) {
          throw new HL7Exception("Invalid message content: \"" + string + "\"");
        }

        char delim = '|';
        for (int i = 0; i < segments.length; i++) {

            // get rid of any leading whitespace characters ...
            if (segments[i] != null && segments[i].length() > 0 && Character.isWhitespace(segments[i].charAt(0)))
                segments[i] = stripLeadingWhitespace(segments[i]);

            // sometimes people put extra segment delimiters at end of msg ...
            if (segments[i] != null && segments[i].length() >= 3) {
             
                final String name;
                if (i == 0) {
                    if (segments[i].length() < 4) {
                      throw new HL7Exception("Invalid message content: \"" + string + "\"");
                    }
                    name = segments[i].substring(0, 3);
                    delim = segments[i].charAt(3);
                } else {
                    if (segments[i].indexOf(delim) >= 0) {
View Full Code Here

   * This package should have the packages datatype, segment, group, and message
   * under it. The path ends in with a slash.
   */
  public static String getVersionPackagePath(String ver) throws HL7Exception {
      if (Parser.validVersion(ver) == false) {
          throw new HL7Exception("The HL7 version " + ver + " is not recognized", HL7Exception.UNSUPPORTED_VERSION_ID);
      }
      StringBuffer path = new StringBuffer("ca/uhn/hl7v2/model/v");
      char[] versionChars = new char[ver.length()];
      ver.getChars(0, ver.length(), versionChars, 0);
      for (int i = 0; i < versionChars.length; i++) {
View Full Code Here

     * @param version the HL7 version
     * @param type 'message', 'group', 'segment', or 'datatype
     */
    private static Class<?> findClass(String name, String version, String type) throws HL7Exception {
        if (Parser.validVersion(version) == false) {
            throw new HL7Exception(
                "The HL7 version " + version + " is not recognized",
                HL7Exception.UNSUPPORTED_VERSION_ID);
        }

        //get list of packages to search for the corresponding message class
        String[] packageList = packageList(version);

        if (packageList == null) {
          return null;
        }
       
        //get subpackage for component type
        String types = "message|group|segment|datatype";
        if (types.indexOf(type) < 0)
            throw new HL7Exception("Can't find " + name + " for version " + version
                        + " -- type must be " + types + " but is " + type);
        String subpackage = type;
       
        //try to load class from each package
        Class<?> compClass = null;
View Full Code Here

        }
        else if (encoding.equalsIgnoreCase("XML")) {
            appropriateParser = xmlParser;
        }
        else {
            throw new HL7Exception(
                "Can't find appropriate parser - encoding not recognized",
                HL7Exception.APPLICATION_INTERNAL_ERROR);
        }
        return appropriateParser;
    }
View Full Code Here

                if (comps.length < 3) {
                    buf.append(" HINT: there are only ");
                    buf.append(comps.length);
                    buf.append(" of 3 components present");
                }
                throw new HL7Exception(buf.toString(), HL7Exception.UNSUPPORTED_MESSAGE_TYPE);
            }           
        }
        catch (IndexOutOfBoundsException e) {
            throw new HL7Exception(
            "Can't find message structure (MSH-9-3): " + e.getMessage(),
            HL7Exception.UNSUPPORTED_MESSAGE_TYPE);
        }
       
        return new MessageStructure(messageStructure, explicityDefined);
View Full Code Here

        //get encoding characters ...
        Segment msh = (Segment) source.get("MSH");
        String fieldSepString = Terser.get(msh, 1, 0, 1, 1);
       
        if (fieldSepString == null)
            throw new HL7Exception("Can't encode message: MSH-1 (field separator) is missing");
       
        char fieldSep = '|';
        if (fieldSepString != null && fieldSepString.length() > 0)
            fieldSep = fieldSepString.charAt(0);
       
        String encCharString = Terser.get(msh, 2, 0, 1, 1);
       
        if (encCharString == null)
            throw new HL7Exception("Can't encode message: MSH-2 (encoding characters) is missing");
               
        if (encCharString.length() != 4)
            throw new HL7Exception(
            "Encoding characters '" + encCharString + "' invalid -- must be 4 characters",
            HL7Exception.DATA_TYPE_ERROR);
        EncodingCharacters en = new EncodingCharacters(fieldSep, encCharString);
       
        //pass down to group encoding method which will operate recursively on children ...
View Full Code Here

     */
    public Segment getCriticalResponseData(String message) throws HL7Exception {
        //try to get MSH segment
        int locStartMSH = message.indexOf("MSH");
        if (locStartMSH < 0)
            throw new HL7Exception(
            "Couldn't find MSH segment in message: " + message,
            HL7Exception.SEGMENT_SEQUENCE_ERROR);
        int locEndMSH = message.indexOf('\r', locStartMSH + 1);
        if (locEndMSH < 0)
            locEndMSH = message.length();
        String mshString = message.substring(locStartMSH, locEndMSH);
       
        //find out what the field separator is
        char fieldSep = mshString.charAt(3);
       
        //get field array
        String[] fields = split(mshString, String.valueOf(fieldSep));
       
        Segment msh = null;
        try {
            //parse required fields
            String encChars = fields[1];
            char compSep = encChars.charAt(0);
            String messControlID = fields[9];
            String[] procIDComps = split(fields[10], String.valueOf(compSep));
           
            //fill MSH segment
            String version = "2.4"; //default
            try {
                version = this.getVersion(message);
            }
            catch (Exception e) { /* use the default */
            }
           
            msh = Parser.makeControlMSH(version, getFactory());
            Terser.set(msh, 1, 0, 1, 1, String.valueOf(fieldSep));
            Terser.set(msh, 2, 0, 1, 1, encChars);
            Terser.set(msh, 10, 0, 1, 1, messControlID);
            Terser.set(msh, 11, 0, 1, 1, procIDComps[0]);
            Terser.set(msh, 12, 0, 1, 1, version);
           
            }
        catch (Exception e) {
            throw new HL7Exception(
            "Can't parse critical fields from MSH segment ("
            + e.getClass().getName()
            + ": "
            + e.getMessage()
            + "): "
View Full Code Here

        String fieldSep = null;
        if (msh.length() > 3) {
            fieldSep = String.valueOf(msh.charAt(3));
        }
        else {
            throw new HL7Exception("Can't find field separator in MSH: " + msh, HL7Exception.UNSUPPORTED_VERSION_ID);
        }
       
        String[] fields = split(msh, fieldSep);
       
        String compSep = null;
        if (fields.length >= 2 && fields[1] != null && fields[1].length() == 4) {
            compSep = String.valueOf(fields[1].charAt(0)); //get component separator as 1st encoding char
        }
        else {
            throw new HL7Exception("Invalid or incomplete encoding characters - MSH-2 is " + fields[1]
                    HL7Exception.REQUIRED_FIELD_MISSING);
        }
       
        String version = null;
        if (fields.length >= 12) {
          String[] comp = split(fields[11], compSep);
          if (comp.length >= 1) {
            version = comp[0];
          } else {
            throw new HL7Exception("Can't find version ID - MSH.12 is " + fields[11],
                HL7Exception.REQUIRED_FIELD_MISSING);
          }
        }
        else {
            throw new HL7Exception(
            "Can't find version ID - MSH has only " + fields.length + " fields.",
            HL7Exception.REQUIRED_FIELD_MISSING);
        }
        return version;
    }
View Full Code Here

                }
               
                if (response != null && isError(response)) {
                    String[] errMsgPath = {"MSA-3"};
                    String[] errMsg = PreParser.getFields(response.getMessage(), errMsgPath);                   
                    throw new HL7Exception("Error message received: " + errMsg[0]);
                }
               
            } while (response == null && ++retries <= maxRetries);
        }
    }
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.