private static void addSegments(final Group group, final Map<String, Segment> segments, final Map<String, Integer> segmentIndexes) throws HL7Exception { if (!isEmpty(group)) { for (final String name : group.getNames()) { for (final Structure structure : group.getAll(name)) { if (group.isGroup(name) && structure instanceof Group) { addSegments((Group) structure, segments, segmentIndexes); } else if (structure instanceof Segment) { addSegments((Segment) structure, segments, segmentIndexes); } } segmentIndexes.put(name, segmentIndexes.getOrDefault(name, 1) + 1); } } }
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); } } } }
Group group = (Group) structure; String[] names = group.getNames();
/** * 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); }
/** Resets the location to the beginning of the tree (the root) */ public void reset() { this.ancestors = new Stack<GroupContext>(); this.currentGroup = root; this.currentChild = -1; this.childNames = currentGroup.getNames(); }
/** * 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); }
/** Resets the location to the beginning of the tree (the root) */ public void reset() { this.ancestors = new Stack<GroupContext>(); this.currentGroup = root; this.currentChild = -1; this.childNames = currentGroup.getNames(); }
/** * Sets next to the first child of the given group (iteration * always proceeds from group to first child). */ private void groupNext(Group current) { next = new Position(current, current.getNames()[0], 0); }
/** * Sets next to the first child of the given group (iteration * always proceeds from group to first child). */ private void groupNext(Group current) { next = new Position(current, current.getNames()[0], 0); }
/** * Sets the next location to the next sibling of the given * index. */ private void nextSibling(Position pos) { String[] names = pos.parent.getNames(); int i = 0; for (; i < names.length && !names[i].equals(pos.index.name); i++) {} String nextName = names[i+1]; this.next = new Position(pos.parent, nextName, 0); }
/** * 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); }
/** * 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); }
/** * Sets the next location to the next sibling of the given * index. */ private void nextSibling(Position pos) { String[] names = pos.parent.getNames(); int i = 0; for (; i < names.length && !names[i].equals(pos.index.name); i++) {} String nextName = names[i+1]; this.next = new Position(pos.parent, nextName, 0); }
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."); } } }
public String[] getNames() { return getDelegate().getNames(); }
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."); } } }
public String[] getNames() { return getDelegate().getNames(); }
/** * Checks a group's children against a list of allowed structures for the group (ie those * mentioned in the profile with usage other than X). Returns a list of exceptions representing * structures that appear in the message but are not supposed to. */ protected List<ValidationException> checkForExtraStructures(Group group, List<String> allowedStructures) { List<ValidationException> exList = new ArrayList<>(); for (String childName : group.getNames()) { if (!allowedStructures.contains(childName)) { try { for (Structure rep : group.getAll(childName)) { profileViolatedWhen(!isEmpty(rep), exList, STRUCTURE_NOT_DEFINED_IN_PROFILE, childName); } } catch (HL7Exception he) { exList.add(new ValidationException("Problem checking profile:" + he.getMessage())); } } } return exList; }
private Structure getStructure(String namePattern, int rep) throws HL7Exception { Structure s = null; if (getCurrentStructure(0).equals(this.getRoot())) drillDown(0); String[] names = getCurrentStructure(0).getParent().getNames(); for (int i = 0; i < names.length && s == null; i++) { if (matches(namePattern, names[i])) { toChild(i); s = getCurrentStructure(rep); } } if (s == null) throw new HL7Exception("Can't find " + namePattern + " as a direct child"); return s; }
private Structure getStructure(String namePattern, int rep) throws HL7Exception { Structure s = null; if (getCurrentStructure(0).equals(this.getRoot())) drillDown(0); String[] names = getCurrentStructure(0).getParent().getNames(); for (int i = 0; i < names.length && s == null; i++) { if (matches(namePattern, names[i])) { toChild(i); s = getCurrentStructure(rep); } } if (s == null) throw new HL7Exception("Can't find " + namePattern + " as a direct child"); return s; }