Package ca.uhn.hl7v2

Examples of ca.uhn.hl7v2.HL7Exception


    @SuppressWarnings("unchecked")
  protected <T extends Structure> List<T> getAllAsList(String name, Class<T> theType) throws HL7Exception {
        Class<? extends Structure> clazz = classes.get(name);
       
    if (!theType.equals(clazz)) {
          throw new HL7Exception("Structure with name \"" + name + "\" has type " + clazz.getName() + " but should be " + theType);
        }
     
      ArrayList<T> retVal = new ArrayList<T>();
        for (Structure next : getAll(name)) {
          retVal.add((T) next);
View Full Code Here


     *             if the named Structure is not part of this Group.
     */
    public Structure removeRepetition(String name, int index) throws HL7Exception {
        ArrayList<Structure> list = structures.get(name);
        if (list == null) {
            throw new HL7Exception("The structure " + name + " does not exist in the group " + this.getClass().getName(), HL7Exception.APPLICATION_INTERNAL_ERROR);
        }
        if (list.size() == 0) {
            throw new HL7Exception("Invalid index: " + index + ", structure " + name + " has no repetitions", HL7Exception.APPLICATION_INTERNAL_ERROR);
        }
        if (list.size() <= index) {
            throw new HL7Exception("Invalid index: " + index + ", structure " + name + " must be between 0 and " + (list.size() - 1), HL7Exception.APPLICATION_INTERNAL_ERROR);
        }

        return list.remove(index);
    }
View Full Code Here

        if (structure == null) {
            throw new NullPointerException("Structure may not be null");
        }

        if (structure.getMessage() != this.getMessage()) {
            throw new HL7Exception("Structure does not belong to this message", HL7Exception.APPLICATION_INTERNAL_ERROR);
        }

        ArrayList<Structure> list = structures.get(name);

        if (list == null) {
            throw new HL7Exception("The structure " + name + " does not exist in the group " + this.getClass().getName(), HL7Exception.APPLICATION_INTERNAL_ERROR);
        }
        if (list.size() < index) {
            throw new HL7Exception("Invalid index: " + index + ", structure " + name + " must be between 0 and " + (list.size()), HL7Exception.APPLICATION_INTERNAL_ERROR);
        }

        list.add(index, structure);
    }
View Full Code Here

            throw new NullPointerException("Name may not be null/empty");
        }

        Class<? extends Structure> structureClass = this.classes.get(name);
        if (structureClass == null) {
            throw new HL7Exception("Group " + this.getClass().getName() + " has no structure named " + name + ": Valid names: " + this.classes.keySet(),
                    HL7Exception.APPLICATION_INTERNAL_ERROR);
        }

        Structure rep = tryToInstantiateStructure(structureClass, name);
        insertRepetition(name, rep, index);
View Full Code Here

     * that the first child is at index 1
     */
    public int getFieldNumForName(String name) throws HL7Exception {
      int retVal = names.indexOf(name);
      if (retVal == -1) {
        throw new HL7Exception("Unknown name: " + name);
      }
      return retVal + 1;
    }
View Full Code Here

            }
            name = newName;
        }
       
        if (index > this.names.size()) {
          throw new HL7Exception("Invalid index " + index + " - Should be <= " + this.names.size());
        }
       
        this.names.add(index, name);
        this.required.put(name, new Boolean(required));
        this.repeating.put(name, new Boolean(repeating));
View Full Code Here

                } // if
               
                if (obx2.getValue() == null) {
                    if (v.getData() != null) {
                        if (!(v.getData() instanceof Primitive) || ((Primitive) v.getData()).getValue() != null) {
                            throw new HL7Exception(
                                "OBX-5 is valued, but OBX-2 is not.  A datatype for OBX-5 must be specified using OBX-2. See JavaDoc for Varies#fixOBX5(Segment, ModelClassFactory)",
                                HL7Exception.REQUIRED_FIELD_MISSING);
                        }
                    }
                }
                else {
                    //set class
                    String version = segment.getMessage().getVersion();
          String obx2Value = obx2.getValue();
          Class<? extends Type> c = factory.getTypeClass(obx2Value, version);
//                    Class c = ca.uhn.hl7v2.parser.Parser.findClass(obx2.getValue(),
//                                                    segment.getMessage().getVersion(),
//                                                    "datatype");
                    if (c == null) {
                       
                        String defaultOBX2Type = parserConfiguration.getInvalidObx2Type();
                        if (defaultOBX2Type == null) {
                          defaultOBX2Type = System.getProperty(INVALID_OBX2_TYPE_PROP);
                        }
                        if (defaultOBX2Type != null) {
                            c = factory.getTypeClass(defaultOBX2Type, version);
                        }
                       
                        if (c == null) {
                          Primitive obx1 = (Primitive) segment.getField(1, 0);
                          HL7Exception h = new HL7Exception("\'" +
                            obx2.getValue() + "\' in record " +
                            obx1.getValue() + " is invalid for version " + version +
                            ". See JavaDoc for Varies#fixOBX5(Segment, ModelClassFactory)",
                            HL7Exception.DATA_TYPE_ERROR);
                          h.setSegmentName("OBX");
                          h.setFieldPosition(2);
                          throw h;
                        }
                    }

                    Type newTypeInstance;
                    try {
                        newTypeInstance = (Type) c.getConstructor(new Class[]{Message.class}).newInstance(new Object[]{v.getMessage()});
                    } catch (NoSuchMethodException e) {
                        newTypeInstance = (Type) c.getConstructor(new Class[]{Message.class, Integer.class}).newInstance(new Object[]{v.getMessage(), 0});
                    }
                   
                    if (newTypeInstance instanceof Primitive) {
                      Type[] subComponentsInFirstField = v.getFirstComponentSubcomponentsOnlyIfMoreThanOne();
                      if (subComponentsInFirstField != null) {
                       
                        if (escapeSubcompponentDelimInPrimitive()) {
                       
                          StringBuilder firstComponentValue = new StringBuilder();
                          for (Type type : subComponentsInFirstField) {
                            if (firstComponentValue.length() != 0) {
                              char subComponentSeparator = EncodingCharacters.getInstance(segment.getMessage()).getSubcomponentSeparator();
                              firstComponentValue.append(subComponentSeparator);
                            }
                            firstComponentValue.append(type.encode());
                }
                         
                          v.setFirstComponentPrimitiveValue(firstComponentValue.toString());
                       
                        }
                       
                      }
                    }
                   
                    v.setData(newTypeInstance);
                }
               
            } // for reps
           
        }
        catch (HL7Exception e) {
            throw e;
        }
        catch (Exception e) {
            throw new HL7Exception(
                e.getClass().getName() + " trying to set data type of OBX-5",
                HL7Exception.APPLICATION_INTERNAL_ERROR,
                e);
        }
  }
View Full Code Here

            StringTokenizer tok = new StringTokenizer(thePathSpecs[i], "-", false);
            String segSpec = tok.nextToken();
            tok = new StringTokenizer(segSpec, "()", false);
            String segName = tok.nextToken();
            if (segName.length() != 3) {
                throw new HL7Exception("In field path, " + segName + " is not a valid segment name");
            }
            int segRep = 0;
            if (tok.hasMoreTokens()) {
                String rep = tok.nextToken();
                try {
                    segRep = Integer.parseInt(rep);
                } catch (NumberFormatException e) {
                    throw new HL7Exception("In field path, segment rep" + rep + " is not valid", e);
                }
            }
           
            int[] indices = Terser.getIndices(thePathSpecs[i]);
            paths[i] = new DatumPath();
View Full Code Here

     */    
    private static String[] getFields(String theMessageText, DatumPath[] thePaths) throws HL7Exception {
        String[] fields = new String[thePaths.length];
        String encoding = ourParser.getEncoding(theMessageText);
        if (encoding == null) {
            throw new HL7Exception("Message encoding is not recognized");
        }       
        Properties props = new Properties();
       
        List<DatumPath> mask = Arrays.asList(thePaths);

        boolean OK = false;
        if (encoding.equals("VB")) {
            OK = ER7.parseMessage(props, mask, theMessageText);
        } else if (encoding.equals("XML")) {
            OK = XML.parseMessage(props, theMessageText, null);
        }
       
        if (!OK) {
            throw new HL7Exception("Parse failed");
        }
       
        for (int i = 0; i < fields.length; i++) {
            fields[i] = props.getProperty(thePaths[i].toString());
        }
View Full Code Here

        Message ack = null;
        try {
            ack = ca.uhn.hl7v2.app.DefaultApplication.makeACK((Segment) in.get("MSH"));
            addProblemsToACK(ack, problems);
        } catch (java.io.IOException e) {
            throw new HL7Exception(e);
        }
        return ack;
    }
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.