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); } } } }
/** * Returns the array of structures at the current location. * Throws an exception if pointer is at root. */ public Structure[] getCurrentChildReps() throws HL7Exception { if (this.currentGroup == this.root && this.currentChild == -1) throw new HL7Exception("Pointer is at root of navigator: there is no current child"); String childName = this.childNames[this.currentChild]; return this.currentGroup.getAll(childName); }
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; }
/** * Returns the array of structures at the current location. * Throws an exception if pointer is at root. */ public Structure[] getCurrentChildReps() throws HL7Exception { if (this.currentGroup == this.root && this.currentChild == -1) throw new HL7Exception("Pointer is at root of navigator: there is no current child"); String childName = this.childNames[this.currentChild]; return this.currentGroup.getAll(childName); }
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; }
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 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."); } } }
/** * Returns given group serialized as a pipe-encoded string - this method is called * by encode(Message source, String encoding). */ public static String encode(Group source, EncodingCharacters encodingChars) throws HL7Exception { StringBuffer result = new StringBuffer(); String[] names = source.getNames(); for (int i = 0; i < names.length; i++) { Structure[] reps = source.getAll(names[i]); for (int rep = 0; rep < reps.length; rep++) { if (reps[rep] instanceof Group) { result.append(encode((Group) reps[rep], encodingChars)); } else { String segString = encode((Segment) reps[rep], encodingChars); if (segString.length() >= 4) { result.append(segString); result.append('\r'); } } } } return result.toString(); }
/** * Returns given group serialized as a pipe-encoded string - this method is called * by encode(Message source, String encoding). */ public static String encode(Group source, EncodingCharacters encodingChars) throws HL7Exception { StringBuffer result = new StringBuffer(); String[] names = source.getNames(); for (int i = 0; i < names.length; i++) { Structure[] reps = source.getAll(names[i]); for (int rep = 0; rep < reps.length; rep++) { if (reps[rep] instanceof Group) { result.append(encode((Group) reps[rep], encodingChars)); } else { String segString = encode((Segment) reps[rep], encodingChars); if (segString.length() >= 4) { result.append(segString); result.append('\r'); } } } } return result.toString(); }
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())); } }
/** * Returns the index of the given structure as a child of the * given parent. Returns null if the child isn't found. */ public static Index getIndex(Group parent, Structure child) { Index index = null; String[] names = parent.getNames(); findChild : for (int i = 0; i < names.length; i++) { if (names[i].startsWith(child.getName())) { try { Structure[] reps = parent.getAll(names[i]); for (int j = 0; j < reps.length; j++) { if (child.equals(reps[j])) { index = new Index(names[i], j); break findChild; } } } catch (HL7Exception e) { log.error(e.getMessage(), e); throw new Error("Internal HL7Exception finding structure index: " + e.getMessage()); } } } return index; }
/** * 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 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())); } }
/** * 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 void checkForExtraStructures(Group group, List<String> allowedStructures, List<HL7Exception> exList) throws ProfileException { for (String childName : group.getNames()) { if (!allowedStructures.contains(childName)) { try { for (Structure rep : group.getAll(childName)) { if (!rep.isEmpty()) { HL7Exception e = new XElementPresentException("The structure " + childName + " appears in the message but not in the profile"); exList.add(e); } } } catch (HL7Exception he) { throw new ProfileException("Problem checking profile", he); } } } }
/** * 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 void checkForExtraStructures(Group group, List<String> allowedStructures, List<HL7Exception> exList) throws ProfileException { for (String childName : group.getNames()) { if (!allowedStructures.contains(childName)) { try { for (Structure rep : group.getAll(childName)) { if (!rep.isEmpty()) { HL7Exception e = new XElementPresentException("The structure " + childName + " appears in the message but not in the profile"); exList.add(e); } } } catch (HL7Exception he) { throw new ProfileException("Problem checking profile", he); } } } }
/** * Returns the index of the given structure as a child of the * given parent. Returns null if the child isn't found. */ public static Index getIndex(Group parent, Structure child) { Index index = null; String[] names = parent.getNames(); findChild : for (int i = 0; i < names.length; i++) { if (names[i].startsWith(child.getName())) { try { Structure[] reps = parent.getAll(names[i]); for (int j = 0; j < reps.length; j++) { if (child.equals(reps[j])) { index = new Index(names[i], j); break findChild; } } } catch (HL7Exception e) { log.error(e.getMessage(), e); throw new Error("Internal HL7Exception finding structure index: " + e.getMessage()); } } } return index; }
Structure[] reps = groupObject.getAll(name); for (Structure rep : reps) { String elementName = makeGroupElementName(messageName, name);
for (Structure instance : group.getAll(struct.getName())) { if (!instance.isEmpty()) instancesWithContent.add(instance);
for (Structure instance : group.getAll(struct.getName())) { if (!instance.isEmpty()) instancesWithContent.add(instance);