@Override public String getName() { return segment.getName(); }
private static void addSegments(final Segment segment, final Map<String, Segment> segments, final Map<String, Integer> segmentIndexes) throws HL7Exception { if (!isEmpty(segment)) { final String segmentName = segment.getName(); final StringBuilder sb = new StringBuilder().append(segmentName); if (isRepeating(segment)) { final int segmentIndex = segmentIndexes.getOrDefault(segmentName, 1); sb.append("_").append(segmentIndex); } final String segmentKey = sb.toString(); segments.put(segmentKey, segment); } }
/** Returns the expected XML element name for the given child of the given Segment */ private String makeElementName(Segment s, int child) { return s.getName() + "." + child; }
/** Returns the expected XML element name for the given child of the given Segment */ private String makeElementName(Segment s, int child) { return s.getName() + "." + child; }
@Override public boolean end(Segment segment, Location location) throws HL7Exception { if (!segments.has(segment.getName())) { segments.add(segment.getName(), segmentObject); } else { Object object = segments.get(segment.getName()); if (!(object instanceof JsonArray)) { JsonObject o = (JsonObject) segments.get(segment.getName()); JsonArray a = new JsonArray(); a.add(o); a.add(segmentObject); segments.add(segment.getName(), a); } } return true; }
public static void fixMFE4(Segment segment, ModelClassFactory factory, ParserConfiguration parserConfiguration) throws HL7Exception { if (!(segment.getName().contains("MFE")) && Version.versionOf(segment.getMessage().getVersion()).isGreaterThan(Version.V23)) { throw new IllegalArgumentException("Expected MFE segment, but was: " + segment.getName()); } fix(segment, 5, 4, null, null, factory, parserConfiguration); }
public static void fixMFE4(Segment segment, ModelClassFactory factory, ParserConfiguration parserConfiguration) throws HL7Exception { if (!(segment.getName().contains("MFE")) && Version.versionOf(segment.getMessage().getVersion()).isGreaterThan(Version.V23)) { throw new IllegalArgumentException("Expected MFE segment, but was: " + segment.getName()); } fix(segment, 5, 4, null, null, factory, parserConfiguration); }
/** * Sets the string value of the field specified. See class docs for location spec syntax. * * @param spec primitive path specification * @param value value to be set * @throws HL7Exception if the primitive does not exist */ public void set(String spec, String value) throws HL7Exception { StringTokenizer tok = new StringTokenizer(spec, "-", false); Segment segment = getSegment(tok.nextToken()); int[] ind = getIndices(spec); log.trace("Setting {} seg: {} ind: {} {} {} {}", new Object[] { spec, segment.getName(), ind[0], ind[1], ind[2], ind[3] }); set(segment, ind[0], ind[1], ind[2], ind[3], value); }
/** * Sets the string value of the field specified. See class docs for location spec syntax. * * @param spec primitive path specification * @param value value to be set * @throws HL7Exception if the primitive does not exist */ public void set(String spec, String value) throws HL7Exception { StringTokenizer tok = new StringTokenizer(spec, "-", false); Segment segment = getSegment(tok.nextToken()); int[] ind = getIndices(spec); log.trace("Setting {} seg: {} ind: {} {} {} {}", new Object[] { spec, segment.getName(), ind[0], ind[1], ind[2], ind[3] }); set(segment, ind[0], ind[1], ind[2], ind[3], value); }
public static String encode(Segment source, EncodingCharacters encodingChars) { StringBuffer result = new StringBuffer(); result.append(source.getName()); result.append(encodingChars.getFieldSeparator()); if (isDelimDefSegment(source.getName())) startAt = 2; String fieldText = encode(reps[j], encodingChars); if (isDelimDefSegment(source.getName()) && i == 2) fieldText = Escape.unescape(fieldText, encodingChars); result.append(fieldText);
public Location getLocation(Message msg) throws HL7Exception { Terser t = new Terser(msg); StringTokenizer tok = new StringTokenizer(expression, "-", false); Segment segment = t.getSegment(tok.nextToken()); Location location = new Location() .withSegmentName(segment.getName()) .withFieldIndizes(Terser.getIndices(expression)); return location; }
public static String encode(Segment source, EncodingCharacters encodingChars) { StringBuffer result = new StringBuffer(); result.append(source.getName()); result.append(encodingChars.getFieldSeparator()); if (isDelimDefSegment(source.getName())) startAt = 2; String fieldText = encode(reps[j], encodingChars); if (isDelimDefSegment(source.getName()) && i == 2) fieldText = Escape.unescape(fieldText, encodingChars); result.append(fieldText);
public Location getLocation(Message msg) throws HL7Exception { Terser t = new Terser(msg); StringTokenizer tok = new StringTokenizer(expression, "-", false); Segment segment = t.getSegment(tok.nextToken()); Location location = new Location() .withSegmentName(segment.getName()) .withFieldIndizes(Terser.getIndices(expression)); return location; }
/** * Checks a segment against a list of allowed fields (ie those mentioned in the profile with * usage other than X). Returns a list of exceptions representing field that appear but are not * supposed to. * * @param allowedFields an array of Integers containing field #s of allowed fields */ protected List<ValidationException> checkForExtraFields(Segment segment, List<Integer> allowedFields) { ArrayList<ValidationException> exList = new ArrayList<>(); for (int i = 1; i <= segment.numFields(); i++) { if (!allowedFields.contains(i)) { try { Type[] reps = segment.getField(i); for (Type rep : reps) { profileViolatedWhen(!isEmpty(rep), exList, FIELD_NOT_DEFINED_IN_PROFILE, i, segment.getName()); } } catch (HL7Exception he) { exList.add(new ValidationException("Problem testing against profile: " + he.getMessage())); } } } return exList; }
/** * Checks a segment against a list of allowed fields (ie those mentioned in the profile with * usage other than X). Returns a list of exceptions representing field that appear but are not * supposed to. * * @param allowedFields an array of Integers containing field #s of allowed fields */ protected void checkForExtraFields(Segment segment, List<Integer> allowedFields, List<HL7Exception> exList) throws ProfileException { for (int i = 1; i <= segment.numFields(); i++) { if (!allowedFields.contains(i)) { try { Type[] reps = segment.getField(i); for (Type rep : reps) { if (!rep.isEmpty()) { HL7Exception e = new XElementPresentException("Field " + i + " in " + segment.getName() + " appears in the message but not in the profile"); exList.add(e); } } } catch (HL7Exception he) { throw new ProfileException("Problem testing against profile", he); } } } }
/** * Checks a segment against a list of allowed fields (ie those mentioned in the profile with * usage other than X). Returns a list of exceptions representing field that appear but are not * supposed to. * * @param allowedFields an array of Integers containing field #s of allowed fields */ protected void checkForExtraFields(Segment segment, List<Integer> allowedFields, List<HL7Exception> exList) throws ProfileException { for (int i = 1; i <= segment.numFields(); i++) { if (!allowedFields.contains(i)) { try { Type[] reps = segment.getField(i); for (Type rep : reps) { if (!rep.isEmpty()) { HL7Exception e = new XElementPresentException("Field " + i + " in " + segment.getName() + " appears in the message but not in the profile"); exList.add(e); } } } catch (HL7Exception he) { throw new ProfileException("Problem testing against profile", he); } } } }
private void testPrimitiveRules(Message message, ValidationExceptionHandler<R> handler) throws HL7Exception { LOG.debug("Validating message against primitive type rules"); for (Iterator<Structure> iter = ReadOnlyMessageIterator .createPopulatedSegmentIterator(message); iter.hasNext();) { Segment s = (Segment) iter.next(); for (int field = 1; field <= s.numFields(); field++) { Type[] t = s.getField(field); for (int rep = 0; rep < t.length; rep++) { Location location = new Location(); location .withSegmentName(s.getName()) .withField(field) .withFieldRepetition(rep); testType(t[rep], handler, location); } } } }
private void testPrimitiveRules(Message message, ValidationExceptionHandler<R> handler) throws HL7Exception { LOG.debug("Validating message against primitive type rules"); for (Iterator<Structure> iter = ReadOnlyMessageIterator .createPopulatedSegmentIterator(message); iter.hasNext();) { Segment s = (Segment) iter.next(); for (int field = 1; field <= s.numFields(); field++) { Type[] t = s.getField(field); for (int rep = 0; rep < t.length; rep++) { Location location = new Location(); location .withSegmentName(s.getName()) .withField(field) .withFieldRepetition(rep); testType(t[rep], handler, location); } } } }