Package ca.uhn.hl7v2.model

Examples of ca.uhn.hl7v2.model.Group


        StructureDefinition retVal = new StructureDefinition();
        retVal.setName(theStructure.getName());

        if (theStructure instanceof Group) {
            retVal.setSegment(false);
            Group group = (Group) theStructure;
            int index = 0;
            for (String nextName : group.getNames()) {
                Structure nextChild = group.get(nextName);
                StructureDefinition structureDefinition = createStructureDefinition(nextChild, thePreviousLeaf);
                structureDefinition.setNameAsItAppearsInParent(nextName);
                structureDefinition.setRepeating(group.isRepeating(nextName));
                structureDefinition.setRequired(group.isRequired(nextName));
                structureDefinition.setPosition(index++);
                structureDefinition.setParent(retVal);
                retVal.addChild(structureDefinition);
            }
        } else {
View Full Code Here


    private void addNonStandardSegmentAtCurrentPosition() throws Error {
      log.debug("Creating non standard segment {} on group: {}",
          myDirection, getCurrentPosition().getStructureDefinition().getParent().getName());
        List<Position> parentDefinitionPath = new ArrayList<Position>(myCurrentDefinitionPath.subList(0, myCurrentDefinitionPath.size() - 1));
        Group parentStructure = (Group) navigateToStructure(parentDefinitionPath);

        // Current position within parent
        Position currentPosition = getCurrentPosition();
    String nameAsItAppearsInParent = currentPosition.getStructureDefinition().getNameAsItAppearsInParent();

    int index = Arrays.asList(parentStructure.getNames()).indexOf(nameAsItAppearsInParent) + 1;
   
        String newSegmentName;
   
    // Check if the structure already has a non-standard segment in the appropriate
    // position
    String[] currentNames = parentStructure.getNames();
    if (index < currentNames.length && currentNames[index].startsWith(myDirection)) {
      newSegmentName = currentNames[index];
    } else {
          try {
              newSegmentName = parentStructure.addNonstandardSegment(myDirection, index);
          } catch (HL7Exception e) {
              throw new Error("Unable to add nonstandard segment " + myDirection + ": ", e);
          }
      }
   
View Full Code Here

            if (currentStructure == null) {
                currentStructure = myMessage;
            } else {
                try {
                    IStructureDefinition structureDefinition = next.getStructureDefinition();
                    Group currentStructureGroup = (Group) currentStructure;
                    String nextStructureName = structureDefinition.getNameAsItAppearsInParent();
                    currentStructure = currentStructureGroup.get(nextStructureName, next.getRepNumber());
                } catch (HL7Exception e) {
                    throw new Error("Failed to retrieve structure: ", e);
                }
            }
        }
View Full Code Here

  private void addNonStandardSegmentAtCurrentPosition() throws Error {
      log.debug("Creating non standard segment {} on group: {}",
          myDirection, getCurrentPosition().getStructureDefinition().getParent().getName());
       
      List<Position> parentDefinitionPath;
        Group parentStructure;
       
        switch (myMessage.getParser().getParserConfiguration().getUnexpectedSegmentBehaviour()) {
        case ADD_INLINE:
        default:
          parentDefinitionPath = new ArrayList<Position>(myCurrentDefinitionPath.subList(0, myCurrentDefinitionPath.size() - 1));
          parentStructure = (Group) navigateToStructure(parentDefinitionPath);
          break;
        case DROP_TO_ROOT:
          parentDefinitionPath = new ArrayList<Position>(myCurrentDefinitionPath.subList(0, 1));
          parentStructure = myMessage;
          myCurrentDefinitionPath = myCurrentDefinitionPath.subList(0, 2);
          break;
        case THROW_HL7_EXCEPTION:
          throw new Error(new HL7Exception("Found unknown segment: " + myDirection));
        }
       
       
        // Current position within parent
        Position currentPosition = getCurrentPosition();
    String nameAsItAppearsInParent = currentPosition.getStructureDefinition().getNameAsItAppearsInParent();

    int index = Arrays.asList(parentStructure.getNames()).indexOf(nameAsItAppearsInParent) + 1;
   
        String newSegmentName;
   
    // Check if the structure already has a non-standard segment in the appropriate
    // position
    String[] currentNames = parentStructure.getNames();
    if (index < currentNames.length && currentNames[index].startsWith(myDirection)) {
      newSegmentName = currentNames[index];
    } else {
          try {
              newSegmentName = parentStructure.addNonstandardSegment(myDirection, index);
          } catch (HL7Exception e) {
              throw new Error("Unable to add nonstandard segment " + myDirection + ": ", e);
          }
      }
   
View Full Code Here

            if (currentStructure == null) {
                currentStructure = myMessage;
            } else {
                try {
                    IStructureDefinition structureDefinition = next.getStructureDefinition();
                    Group currentStructureGroup = (Group) currentStructure;
                    String nextStructureName = structureDefinition.getNameAsItAppearsInParent();
                    currentStructure = currentStructureGroup.get(nextStructureName, next.getRepNumber());
                } catch (HL7Exception e) {
                    throw new Error("Failed to retrieve structure: ", e);
                }
            }
        }
View Full Code Here

        boolean has = true;
        if (next == null) {
            if (Group.class.isAssignableFrom(currentStructure.getClass())) {
                groupNext((Group) currentStructure);
            } else {
                Group parent = currentStructure.getParent();
                Index i = getIndex(parent, currentStructure);
                Position currentPosition = new Position(parent, i);
               
                try {                   
                    if (parent.isRepeating(i.name) && currentStructure.getName().equals(direction)) {
                        nextRep(currentPosition);
                    } else {
                        has = nextPosition(currentPosition, this.direction, this.handleUnexpectedSegments);
                    }
                } catch (HL7Exception e) {
View Full Code Here

        // i.e. trying to avoid calling matchExistsAfterCurrentPosition
       
        if (!makeNewSegmentIfNeeded && Message.class.isAssignableFrom(currPos.parent.getClass())) {
            nextExists = false;
        } else if (!makeNewSegmentIfNeeded || matchExistsAfterPosition(currPos, direction, false, true)) {    
            Group grandparent = currPos.parent.getParent();
            Index parentIndex = getIndex(grandparent, currPos.parent);
            Position parentPos = new Position(grandparent, parentIndex);
           
            try {
                boolean parentRepeats = parentPos.parent.isRepeating(parentPos.index.name);               
View Full Code Here

            }
        }
       
        //recurse to parent (if parent is not message root)
        if (!matchExists && !Message.class.isAssignableFrom(pos.parent.getClass())) {
            Group grandparent = pos.parent.getParent();
            Position parentPos = new Position(grandparent, getIndex(grandparent, pos.parent));
            matchExists = matchExistsAfterPosition(parentPos, name, firstDescendentsOnly, upToFirstRequired);
        }
        log.debug("Match exists after position {} for {}? {}", new Object[] {pos, name, matchExists});
        return matchExists;
View Full Code Here

    public static boolean contains(Structure s, String name, boolean firstDescendentsOnly, boolean upToFirstRequired) {
        boolean contains = false;
        if (Segment.class.isAssignableFrom(s.getClass())) {
            if (s.getName().equals(name)) contains = true;           
        } else {
            Group g = (Group) s;
            String[] names = g.getNames();
            for (int i = 0; i < names.length && !contains; i++) {
                try {
                    contains = contains(g.get(names[i], 0), name, firstDescendentsOnly, upToFirstRequired);               
                    if (firstDescendentsOnly) break;
                    if (upToFirstRequired && g.isRequired(names[i])) break;
                } catch (HL7Exception e) {
                    throw new Error("HL7Exception due to bad index: " + e.getMessage());
                }
            }
        }
View Full Code Here

    StructureDefinition retVal = new StructureDefinition();
    retVal.setName(theStructure.getName());

    if (theStructure instanceof Group) {
      retVal.setSegment(false);
      Group group = (Group) theStructure;
      int index = 0;
      List<String> childNames = Arrays.asList(group.getNames());
     
      /*
       * For SuperStructures, which can hold more than one type of structure,
       * we only actually bring in the child names that are actually a part
       * of the structure we are trying to parse
       */
      if (theStructure instanceof SuperStructure) {
        String struct = theStructureName;
        Map<String, String> evtMap = new DefaultModelClassFactory().getEventMapForVersion(Version.versionOf(theStructure.getMessage().getVersion()));
        if (evtMap.containsKey(struct)) {
          struct = evtMap.get(struct);
        }
        childNames = ((SuperStructure) theStructure).getChildNamesForStructure(struct);
      }
     
      for (String nextName : childNames) {
        Structure nextChild = group.get(nextName);
        StructureDefinition structureDefinition = createStructureDefinition(nextChild, thePreviousLeaf, theStructureName);
        structureDefinition.setNameAsItAppearsInParent(nextName);
        structureDefinition.setRepeating(group.isRepeating(nextName));
        structureDefinition.setRequired(group.isRequired(nextName));
        structureDefinition.setChoiceElement(group.isChoiceElement(nextName));
        structureDefinition.setPosition(index++);
        structureDefinition.setParent(retVal);
        retVal.addChild(structureDefinition);
      }
    } else {
View Full Code Here

TOP

Related Classes of ca.uhn.hl7v2.model.Group

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.