public HapiSegment(final Segment segment) throws HL7Exception { this.segment = segment; final List<HL7Field> fieldList = new ArrayList<>(); for (int i = 1; i <= segment.numFields(); i++) { final Type[] types = segment.getField(i); if (types == null || types.length == 0) { fieldList.add(new EmptyField()); continue; } for (final Type type : types) { fieldList.add(new HapiField(type)); } } this.fields = Collections.unmodifiableList(fieldList); }
private static Map<String, Type> getAllFields(final String segmentKey, final Segment segment, final boolean useNames) throws HL7Exception { final Map<String, Type> fields = new TreeMap<>(); final String[] segmentNames = segment.getNames(); for (int i = 1; i <= segment.numFields(); i++) { final Type field = segment.getField(i, 0); if (!isEmpty(field)) { final String fieldName; if (useNames) { fieldName = WordUtils.capitalize(segmentNames[i-1]).replaceAll("\\W+", ""); } else { fieldName = String.valueOf(i); } final String fieldKey = new StringBuilder() .append(segmentKey) .append(".") .append(fieldName) .toString(); fields.put(fieldKey, field); } } return fields; }
String[] names = segment.getNames(); for ( int n = 1; n <= segment.numFields(); n++ ) { Type[] types = segment.getField( n ); for ( int t = 0; t < types.length; t++ ) {
public int numFields() { return getDelegate().numFields(); }
public int numFields() { return getDelegate().numFields(); }
int n = segmentObject.numFields(); for (int i = 1; i <= n; i++) { String name = makeElementName(segmentObject, i);
int n = segmentObject.numFields(); for (int i = 1; i <= n; i++) { String name = makeElementName(segmentObject, i);
/** * Copies contents from the source segment to the destination segment. This * method calls copy(Type, Type) on each repetition of each field (see additional * behavioural description there). An attempt is made to copy each repetition of * each field in the source segment, regardless of whether the corresponding * destination field is repeating or even exists. * * @param from the segment from which data are copied * @param to the segment into which data are copied * @throws HL7Exception if an error occurred while copying */ public static void copy(Segment from, Segment to) throws HL7Exception { int n = from.numFields(); for (int i = 1; i <= n; i++) { Type[] reps = from.getField(i); for (int j = 0; j < reps.length; j++) { copy(reps[j], to.getField(i, j)); } } } }
/** * Copies contents from the source segment to the destination segment. This * method calls copy(Type, Type) on each repetition of each field (see additional * behavioural description there). An attempt is made to copy each repetition of * each field in the source segment, regardless of whether the corresponding * destination field is repeating or even exists. * * @param from the segment from which data are copied * @param to the segment into which data are copied * @throws HL7Exception if an error occurred while copying */ public static void copy(Segment from, Segment to) throws HL7Exception { int n = from.numFields(); for (int i = 1; i <= n; i++) { Type[] reps = from.getField(i); for (int j = 0; j < reps.length; j++) { copy(reps[j], to.getField(i, j)); } } } }
/** * 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); } } } }
int numFields = source.numFields(); for (int i = startAt; i <= numFields; i++) { try {
int numFields = source.numFields(); for (int i = startAt; i <= numFields; i++) { try {
int numFields = source.numFields();
int numFields = source.numFields();