private void populateSegments(final Group group, final List<HL7Segment> segments) throws HL7Exception { for (final String structureName : group.getNames()) { final Structure[] structures = group.getAll(structureName); if (group.isGroup(structureName)) { for (final Structure structure : structures) { populateSegments((Group) structure, segments); } } else { for (final Structure structure : structures) { final Segment segment = (Segment) structure; final HapiSegment hapiSegment = new HapiSegment(segment); segments.add(hapiSegment); } } } }
new HL7Value( message.getVersion(), rootGroup.getName(), group.getName(), structure.getName(), structureNumber, names[n - 1], coordinates, types[t].getName(), description, string ); values.add( value ); Group group = (Group) structure; String[] names = group.getNames(); Structure subStructure = group.get( name ); parseStructure( values, message, terser, subStructure, structureNumber + "." + n );
private static boolean isRepeating(final Segment segment) throws HL7Exception { if (isEmpty(segment)) { return false; } final Group parent = segment.getParent(); final Group grandparent = parent.getParent(); if (parent == grandparent) { return false; } return grandparent.isRepeating(parent.getName()); }
private void addChildren(Group theParent) { String[] names = theParent.getNames(); for (int i = names.length - 1; i >= 0; i--) { try { Structure[] reps = theParent.getAll(names[i]); for (int j = reps.length - 1; j >= 0; j--) { myRemaining.add(reps[j]); } } catch (HL7Exception e) { throw new Error("Internal error: an invalid child name was obtained from its parent."); } } }
private void apply(Group theStructure, List<ValidationException> theExceptions) { Set<String> choicesWithContent = null; for (String nextName : theStructure.getNames()) { try { boolean nextIsChoiceElement = theStructure.isChoiceElement(nextName); for (Structure nextStruct : theStructure.getAll(nextName)) { if (nextIsChoiceElement && !nextStruct.isEmpty()) { if (choicesWithContent == null) { choicesWithContent = new HashSet<String>(); } choicesWithContent.add(nextName); } if (nextStruct instanceof Group) { apply((Group) nextStruct, theExceptions); } } } catch (HL7Exception e) { throw new Error("Failed to find " + nextName + " in structure. This is probably a HAPI bug."); } } if (choicesWithContent != null && choicesWithContent.size() > 1) { theExceptions.add(new ValidationException("Structure '" + theStructure.getName() + "' must have content only in one of the following choices: " + choicesWithContent.toString())); } }
if (pos.parent.isRepeating(pos.index.name)) { Structure s = pos.parent.get(pos.index.name, pos.index.rep); matchExists = contains(s, name, firstDescendentsOnly, upToFirstRequired); String[] siblings = pos.parent.getNames(); boolean after = false; for (int i = 0; i < siblings.length && !matchExists; i++) { if (after) { matchExists = contains(pos.parent.get(siblings[i]), name, firstDescendentsOnly, upToFirstRequired); if (upToFirstRequired && pos.parent.isRequired(siblings[i])) break; Group grandparent = pos.parent.getParent(); Position parentPos = new Position(grandparent, getIndex(grandparent, pos.parent)); matchExists = matchExistsAfterPosition(parentPos, name, firstDescendentsOnly, upToFirstRequired);
StringBuilder result = new StringBuilder(); String[] names = source.getNames(); Structure[] reps = source.getAll(nextName); boolean nextNameIsRequired = source.isRequired(nextName); if (!source.isGroup(nextName)) { firstMandatorySegmentName = nextName;
/** * Tests whether the name of the given Index matches * the name of the last child of the given group. */ public static boolean isLast(Position p) { String[] names = p.parent.getNames(); return names[names.length-1].equals(p.index.name); }
Group group = (Group) theStructure; int index = 0; List<String> childNames = Arrays.asList(group.getNames()); 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);
String[] childNames = groupObject.getNames(); String messageName = groupObject.getMessage().getName(); if(groupObject.isGroup(nextChildName)) { childName = makeGroupElementName(groupObject.getMessage().getName(), nextChildName); String segIndexName = groupObject.addNonstandardSegment(segName); parseReps(groupElement, groupObject, messageName, segName, segIndexName);
String[] childNames = groupObject.getNames(); String messageName = groupObject.getMessage().getName(); Structure[] reps = groupObject.getAll(name); for (Structure rep : reps) { String elementName = makeGroupElementName(messageName, name);
/** * Sets the next position to a new segment of the given name, within the * given group. */ private void newSegment(Group parent, String name) throws HL7Exception { log.info("MessageIterator creating new segment: {}", name); parent.addNonstandardSegment(name); next = new Position(parent, parent.getNames()[parent.getNames().length-1], 0); }
} 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());
public Structure[] getAll(String name) throws HL7Exception { Structure[] structures = getDelegate().getAll(name); Structure[] unmodifiableStructures = new Structure[structures.length]; if (structures.length > 0) { for (int i = 0; i < structures.length; i++) { unmodifiableStructures[i] = unmodifiableStructure(structures[i]); } } return unmodifiableStructures; }
/** * Drills down into the group at the given index within the current * group -- ie sets the location pointer to the first structure within the child * @param childNumber the index of the group child into which to drill * @param rep the group repetition into which to drill */ public void drillDown(int childNumber, int rep) throws HL7Exception { if (childNumber != -1) { Structure s = currentGroup.get(childNames[childNumber], rep); if (!(s instanceof Group)) { throw new HL7Exception("Can't drill into segment"); } Group group = (Group) s; //stack the current group and location GroupContext gc = new GroupContext(this.currentGroup, this.currentChild); this.ancestors.push(gc); this.currentGroup = group; } this.currentChild = 0; this.childNames = this.currentGroup.getNames(); }
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); boolean parentRepeats = parentPos.parent.isRepeating(parentPos.index.name); if (parentRepeats && contains(parentPos.parent.get(parentPos.index.name, 0), direction, false, true)) { nextRep(parentPos); } else {
log.trace("# of elements matching {}: {}", groupName, reps.size()); if (groupObject.isRepeating(childIndexName)) { for (int i = 0; i < reps.size(); i++) { parseRep(reps.get(i), groupObject.get(childIndexName, i)); parseRep(reps.get(0), groupObject.get(childIndexName, 0)); for (i = 1; i < reps.size(); i++) { newIndexName = childName+(i+1); Structure st = groupObject.get(newIndexName); parseRep(reps.get(i), st); newIndexName = groupObject.addNonstandardSegment(childName); for (int j = i; j < reps.size(); j++) { parseRep(reps.get(j), groupObject.get(newIndexName, j-i));
/** * Returns the given rep of the structure at the current location. * If at root, always returns the root (the rep is ignored). */ public Structure getCurrentStructure(int rep) throws HL7Exception { if (this.currentChild != -1) { String childName = this.childNames[this.currentChild]; return this.currentGroup.get(childName, rep); } return this.currentGroup; }
public boolean isRepeating(String name) throws HL7Exception { return getDelegate().isRepeating(name); }
public String toString() { StringBuffer ret = new StringBuffer(parent.getName()); ret.append(":"); ret.append(index.name); ret.append("("); ret.append(index.rep); ret.append(")"); return ret.toString(); } }