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; }
Type[] types = segment.getField( n ); for ( int t = 0; t < types.length; t++ ) { int nrComponents = Terser.numComponents( types[t] );
/** * Returns the Primitive object at the given location. */ private static Primitive getPrimitive(Segment segment, int field, int rep, int component, int subcomponent) throws HL7Exception { Type type = segment.getField(field, rep); return getPrimitive(type, component, subcomponent); }
private void parseReps(Segment segmentObject, Element segmentElement, String fieldName, int fieldNum) throws HL7Exception { NodeList reps = segmentElement.getElementsByTagName(fieldName); for (int i = 0; i < reps.getLength(); i++) { parse(segmentObject.getField(fieldNum, i), (Element) reps.item(i)); } }
/** * Returns the Primitive object at the given location. */ private static Primitive getPrimitive(Segment segment, int field, int rep, int component, int subcomponent) throws HL7Exception { Type type = segment.getField(field, rep); return getPrimitive(type, component, subcomponent); }
private void parseReps(Segment segmentObject, Element segmentElement, String fieldName, int fieldNum) throws HL7Exception { NodeList reps = segmentElement.getElementsByTagName(fieldName); for (int i = 0; i < reps.getLength(); i++) { parse(segmentObject.getField(fieldNum, i), (Element) reps.item(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)); } } } }
/** * {@inheritDoc } */ public Character getFieldSeparatorValue() throws HL7Exception { Segment firstSegment = (Segment) get(getNames()[0]); Primitive value = (Primitive) firstSegment.getField(1, 0); String valueString = value.getValue(); if (valueString == null || valueString.length() == 0) { return null; } return valueString.charAt(0); }
/** * {@inheritDoc } */ public Character getFieldSeparatorValue() throws HL7Exception { Segment firstSegment = (Segment) get(getNames()[0]); Primitive value = (Primitive) firstSegment.getField(1, 0); String valueString = value.getValue(); if (valueString == null || valueString.length() == 0) { return null; } return valueString.charAt(0); }
public Type[] getField(int number) throws HL7Exception { if (number < 1 || number > numFields()) { throw new IllegalArgumentException(String.format("Cannot add field with index %d to unmodifiable segment %s " + " - there are currently only %d fields.", number, getName(), numFields())); } Type[] types = getDelegate().getField(number); Type[] unmodifiableTypes = new Type[types.length]; if (types.length > 0) { for (int i = 0; i < types.length; i++) { unmodifiableTypes[i] = unmodifiableType(types[i]); } } return unmodifiableTypes; }
public Type[] getField(int number) throws HL7Exception { if (number < 1 || number > numFields()) { throw new IllegalArgumentException(String.format("Cannot add field with index %d to unmodifiable segment %s " + " - there are currently only %d fields.", number, getName(), numFields())); } Type[] types = getDelegate().getField(number); Type[] unmodifiableTypes = new Type[types.length]; if (types.length > 0) { for (int i = 0; i < types.length; i++) { unmodifiableTypes[i] = unmodifiableType(types[i]); } } return unmodifiableTypes; }
/** * {@inheritDoc } */ public String getEncodingCharactersValue() throws HL7Exception { Segment firstSegment = (Segment) get(getNames()[0]); Primitive value = (Primitive) firstSegment.getField(2, 0); return value.getValue(); }
/** * {@inheritDoc } */ public String getEncodingCharactersValue() throws HL7Exception { Segment firstSegment = (Segment) get(getNames()[0]); Primitive value = (Primitive) firstSegment.getField(2, 0); return value.getValue(); }
/** * 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); } } } }