I am working with the HAPI HL7 Libraries, and I am attempting to find out how to get the count for how many times a segment or field repeats in the original message.
The terser path assumes 0 if the field/segment repeats and no index is given, but I don't see any way to simple ask on the message, or the terser, to get the count of how many times something repeats.
Is there some way to find out how many times a field/segement repeats using the Hapi Libraries?
Yes, each of the types have explicit getXXXReps methods, but I am processing all sorts of messages, I don't know what they may or may not be... writing a generic count for things, regardless of the type of message it is.
I wound up getting what I needed by the following, where S is the Message:
try {
AbstractGroup m2 = (AbstractGroup) s;
result = m2.currentReps(part);
} catch (HL7Exception | ClassCastException e) {
if (s.getClass().getSuperclass().getName().matches("ca.uhn.hl7v2.model.AbstractSegment")) {
AbstractSegment m3 = (AbstractSegment) s;
Type[] t = m3.getField(Integer.parseInt(part));
result = t.length;
} else {
result = 1; // Should NEVER be able to be reached, BUT, adding it just to be safe
}