public HapiField(final Type type) { this.value = PipeParser.encode(type, EncodingCharacters.defaultInstance()); final List<HL7Component> componentList = new ArrayList<>(); if (type instanceof Composite) { final Composite composite = (Composite) type; for (final Type component : composite.getComponents()) { componentList.add(new HapiField(component)); } } final ExtraComponents extra = type.getExtraComponents(); if (extra != null && extra.numComponents() > 0) { final String singleFieldValue; if (type instanceof Primitive) { singleFieldValue = ((Primitive) type).getValue(); } else { singleFieldValue = this.value; } componentList.add(new SingleValueField(singleFieldValue)); for (int i = 0; i < extra.numComponents(); i++) { componentList.add(new HapiField(extra.getComponent(i))); } } this.components = Collections.unmodifiableList(componentList); }
/** * Copies data from the "from" Type into the "to" Type. Either Type may be * a Primitive, Composite, or Varies. If a Varies is provided, the operation is * performed on the result of calling its getData() method. A Primitive may be * copied into a Composite, in which case the value is copied into the first * component of the Composite. A Composite may be copied into a Primitive, * in which case the first component is copied. Given Composites with different * numbers of components, the first components are copied, up to the length * of the smaller one. * * @param from type to copy from * @param to type to copy to * @throws DataTypeException if the types are not compatible */ public static void copy(Type from, Type to) throws DataTypeException { for (int i = 1; i <= Terser.numComponents(from); i++) { for (int j = 1; j <= Terser.numSubComponents(from, i); j++) { String val = Terser.getPrimitive(from, i, j).getValue(); Terser.getPrimitive(to, i, j).setValue(val); } } }
private void testPrimitive(Primitive p, ValidationExceptionHandler<R> handler, Location l) { List<PrimitiveTypeRule> rules = new ArrayList<PrimitiveTypeRule>(); Message m = p.getMessage(); if (getValidationContext() != null) { rules.addAll(getValidationContext().getPrimitiveRules(m.getVersion(), p.getName(), p)); } for (PrimitiveTypeRule rule : rules) { ValidationException[] exceptions = rule.apply(p.getValue()); for (ValidationException ve : exceptions) { ve.setLocation(l); } if (exceptions.length > 0) { handler.onExceptions(exceptions); } } }
String value = datatypeObject.getValue(); boolean hasValue = (value != null && value.length() > 0); if (hasValue) { try { EncodingCharacters ec = EncodingCharacters.getInstance(datatypeObject.getMessage()); char esc = ec.getEscapeCharacter(); int pos;
/** * Sets the string value of the Primitive at the given location. * * @param segment the segment from which to get the primitive * @param field the field number (indexed from 1) * @param rep the field repetition (indexed from 0) * @param component the component number (indexed from 1, use 1 for primitive field) * @param subcomponent the subcomponent number (indexed from 1, use 1 for primitive component) * @param value value to be set * @throws HL7Exception if the value could not be set */ public static void set(Segment segment, int field, int rep, int component, int subcomponent, String value) throws HL7Exception { if (segment == null) { throw new NullPointerException("segment may not be null"); } if (rep < 0) { throw new IllegalArgumentException("rep must not be negative"); } if (component < 1) { throw new IllegalArgumentException( "component must be 1 or more (note that this parameter is 1-indexed, not 0-indexed)"); } if (subcomponent < 1) { throw new IllegalArgumentException( "subcomponent must be 1 or more (note that this parameter is 1-indexed, not 0-indexed)"); } Primitive prim = getPrimitive(segment, field, rep, component, subcomponent); prim.setValue(value); }
assertNamespaceURI(child.getNamespaceURI()); EncodingCharacters ec = EncodingCharacters.getInstance(datatypeObject .getMessage()); Element elem = (Element) child; String attr = elem.getAttribute(ESCAPE_ATTRNAME).trim(); datatypeObject.setValue(builder.toString());
@Override public boolean visit(Primitive type, Location location) throws HL7Exception { return !type.isEmpty() && super.visit(type, location); }
/** * Copies data from the "from" Type into the "to" Type. Either Type may be * a Primitive, Composite, or Varies. If a Varies is provided, the operation is * performed on the result of calling its getData() method. A Primitive may be * copied into a Composite, in which case the value is copied into the first * component of the Composite. A Composite may be copied into a Primitive, * in which case the first component is copied. Given Composites with different * numbers of components, the first components are copied, up to the length * of the smaller one. * * @param from type to copy from * @param to type to copy to * @throws DataTypeException if the types are not compatible */ public static void copy(Type from, Type to) throws DataTypeException { for (int i = 1; i <= Terser.numComponents(from); i++) { for (int j = 1; j <= Terser.numSubComponents(from, i); j++) { String val = Terser.getPrimitive(from, i, j).getValue(); Terser.getPrimitive(to, i, j).setValue(val); } } }
private void testPrimitive(Primitive p, ValidationExceptionHandler<R> handler, Location l) { List<PrimitiveTypeRule> rules = new ArrayList<PrimitiveTypeRule>(); Message m = p.getMessage(); if (getValidationContext() != null) { rules.addAll(getValidationContext().getPrimitiveRules(m.getVersion(), p.getName(), p)); } for (PrimitiveTypeRule rule : rules) { ValidationException[] exceptions = rule.apply(p.getValue()); for (ValidationException ve : exceptions) { ve.setLocation(l); } if (exceptions.length > 0) { handler.onExceptions(exceptions); } } }
String value = datatypeObject.getValue(); boolean hasValue = (value != null && value.length() > 0); if (hasValue) { try { EncodingCharacters ec = EncodingCharacters.getInstance(datatypeObject.getMessage()); char esc = ec.getEscapeCharacter(); int pos;
/** * Sets the string value of the Primitive at the given location. * * @param segment the segment from which to get the primitive * @param field the field number (indexed from 1) * @param rep the field repetition (indexed from 0) * @param component the component number (indexed from 1, use 1 for primitive field) * @param subcomponent the subcomponent number (indexed from 1, use 1 for primitive component) * @param value value to be set * @throws HL7Exception if the value could not be set */ public static void set(Segment segment, int field, int rep, int component, int subcomponent, String value) throws HL7Exception { if (segment == null) { throw new NullPointerException("segment may not be null"); } if (rep < 0) { throw new IllegalArgumentException("rep must not be negative"); } if (component < 1) { throw new IllegalArgumentException( "component must be 1 or more (note that this parameter is 1-indexed, not 0-indexed)"); } if (subcomponent < 1) { throw new IllegalArgumentException( "subcomponent must be 1 or more (note that this parameter is 1-indexed, not 0-indexed)"); } Primitive prim = getPrimitive(segment, field, rep, component, subcomponent); prim.setValue(value); }
assertNamespaceURI(child.getNamespaceURI()); EncodingCharacters ec = EncodingCharacters.getInstance(datatypeObject .getMessage()); Element elem = (Element) child; String attr = elem.getAttribute(ESCAPE_ATTRNAME).trim(); datatypeObject.setValue(builder.toString());
@Override public boolean visit(Primitive type, Location location) throws HL7Exception { return !type.isEmpty() && super.visit(type, location); }
private static String encodePrimitive(Primitive p, Escaping escaping, EncodingCharacters encodingChars) { String val = (p).getValue(); if (val == null) { val = ""; } else { val = escaping.escape(val, encodingChars); } return val; }
for (Type rep : reps) { Varies v = (Varies)rep; if (type.getValue() == null) { if (defaultType != null) { LOG.debug("setting default {}-{} type to {}", new Object[] {segment.getName(), typeField, defaultType}); type.setValue(defaultType); if (type.getValue() == null) { if (v.getData() != null) { if (!(v.getData() instanceof Primitive) || ((Primitive) v.getData()).getValue() != null) { throw new HL7Exception(String.format( "A datatype for %s-%n must be specified in %s-%n.", segment.getName(), dataField, segment.getName(), typeField), String typeValue = type.getValue(); Class<? extends Type> c = factory.getTypeClass(typeValue, version); if (c == null) { Primitive obx1 = (Primitive) segment.getField(1, 0); HL7Exception h = new HL7Exception("\'" + type.getValue() + "\' in record " + obx1.getValue() + " is invalid for version " + version, ErrorCode.DATA_TYPE_ERROR); h.setSegmentName(segment.getName());
/** This method validates the <code>String</code> value passed in to be no greater then the * maximum allowable length for the extending class. If the <code>String</code> value is valid, this * method will set the underlying HAPI class's value. If the data passed in is invalid for the given * data type, a ConfDataException is thrown. * @throws ConformaceException * @param value the value of the Data Type */ protected void setValue(java.lang.String value) throws ConfDataException { if ((this.getMaxLength() > 0) && (value.length() > this.getMaxLength())) { throw new ConfDataException("DataType length exceeds the Maximum allowable length"); } try { this.hapiPrimitive.setValue(value); } catch (DataTypeException e) { throw new ConfDataException("Invalid Data Populated"); } }
private static String encodePrimitive(Primitive p, EncodingCharacters encodingChars) { String val = ((Primitive) p).getValue(); if (val == null) { val = ""; } else { val = Escape.escape(val, encodingChars); } return val; }
for (Type rep : reps) { Varies v = (Varies)rep; if (type.getValue() == null) { if (defaultType != null) { LOG.debug("setting default {}-{} type to {}", new Object[] {segment.getName(), typeField, defaultType}); type.setValue(defaultType); if (type.getValue() == null) { if (v.getData() != null) { if (!(v.getData() instanceof Primitive) || ((Primitive) v.getData()).getValue() != null) { throw new HL7Exception(String.format( "A datatype for %s-%n must be specified in %s-%n.", segment.getName(), dataField, segment.getName(), typeField), String typeValue = type.getValue(); Class<? extends Type> c = factory.getTypeClass(typeValue, version); if (c == null) { Primitive obx1 = (Primitive) segment.getField(1, 0); HL7Exception h = new HL7Exception("\'" + type.getValue() + "\' in record " + obx1.getValue() + " is invalid for version " + version, ErrorCode.DATA_TYPE_ERROR); h.setSegmentName(segment.getName());
/** This method validates the <code>String</code> value passed in to be no greater then the * maximum allowable length for the extending class. If the <code>String</code> value is valid, this * method will set the underlying HAPI class's value. If the data passed in is invalid for the given * data type, a ConfDataException is thrown. * @throws ConformaceException * @param value the value of the Data Type */ protected void setValue(java.lang.String value) throws ConfDataException { if ((this.getMaxLength() > 0) && (value.length() > this.getMaxLength())) { throw new ConfDataException("DataType length exceeds the Maximum allowable length"); } try { this.hapiPrimitive.setValue(value); } catch (DataTypeException e) { throw new ConfDataException("Invalid Data Populated"); } }
private static String encodePrimitive(Primitive p, EncodingCharacters encodingChars) { String val = ((Primitive) p).getValue(); if (val == null) { val = ""; } else { val = Escape.escape(val, encodingChars); } return val; }