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); }
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; }
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; }
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; }
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; }
public String getValue() { return getDelegate().getValue(); }
public String getValue() { return getDelegate().getValue(); }
/** * Sets the data contained by this instance of Varies. If a data object already exists, * then its values are copied to the incoming data object before the old one is replaced. * For example, if getData() returns an ST with the value "19901012" and you call * setData(new DT()), then subsequent calls to getData() will return the same DT, with the value * set to "19901012". * * @param data the data to be set for this Varies instance * @throws DataTypeException if the data could not be set */ public void setData(Type data) throws DataTypeException { if (this.data != null) { if (!(this.data instanceof Primitive) || ((Primitive) this.data).getValue() != null) { ca.uhn.hl7v2.util.DeepCopy.copy(this.data, data); } } this.data = data; }
/** * Sets the data contained by this instance of Varies. If a data object already exists, * then its values are copied to the incoming data object before the old one is replaced. * For example, if getData() returns an ST with the value "19901012" and you call * setData(new DT()), then subsequent calls to getData() will return the same DT, with the value * set to "19901012". * * @param data the data to be set for this Varies instance * @throws DataTypeException if the data could not be set */ public void setData(Type data) throws DataTypeException { if (this.data != null) { if (!(this.data instanceof Primitive) || ((Primitive) this.data).getValue() != null) { ca.uhn.hl7v2.util.DeepCopy.copy(this.data, data); } } this.data = data; }
@Override public boolean visit(Primitive primitive, Location location) throws HL7Exception { if (inComposite) { compositeObject.addProperty(Integer.toString(location.getComponent()), primitive.getValue()); } else { String fieldComponent = String.format("%d_%d", location.getField(), location.getComponent()); if (location.getComponent() < 0) { fieldComponent = String.format("%d", location.getField()); } segmentObject.addProperty(fieldComponent, primitive.getValue()); } return true; } }
/** * {@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); }
/** * Tests table values for ID, IS, and CE types. An empty list is returned for all other types or * if the table name or number is missing. */ protected void testTypeAgainstTable(Type type, AbstractComponent<?> profile, String profileID, List<HL7Exception> exList) { if (profile.getTable() != null && (type.getName().equals("IS") || type.getName().equals("ID"))) { String codeSystem = String.format("HL7%1$4s", profile.getTable()).replace(" ", "0"); String value = ((Primitive) type).getValue(); addTableTestResult(profileID, codeSystem, value, exList); } else if (type.getName().equals("CE")) { String value = Terser.getPrimitive(type, 1, 1).getValue(); String codeSystem = Terser.getPrimitive(type, 3, 1).getValue(); addTableTestResult(profileID, codeSystem, value, exList); value = Terser.getPrimitive(type, 4, 1).getValue(); codeSystem = Terser.getPrimitive(type, 6, 1).getValue(); addTableTestResult(profileID, codeSystem, value, exList); } }
/** * Tests table values for ID, IS, and CE types. An empty list is returned for all other types or * if the table name or number is missing. */ protected void testTypeAgainstTable(Type type, AbstractComponent<?> profile, String profileID, List<HL7Exception> exList) { if (profile.getTable() != null && (type.getName().equals("IS") || type.getName().equals("ID"))) { String codeSystem = String.format("HL7%1$4s", profile.getTable()).replace(" ", "0"); String value = ((Primitive) type).getValue(); addTableTestResult(profileID, codeSystem, value, exList); } else if (type.getName().equals("CE")) { String value = Terser.getPrimitive(type, 1, 1).getValue(); String codeSystem = Terser.getPrimitive(type, 3, 1).getValue(); addTableTestResult(profileID, codeSystem, value, exList); value = Terser.getPrimitive(type, 4, 1).getValue(); codeSystem = Terser.getPrimitive(type, 6, 1).getValue(); addTableTestResult(profileID, codeSystem, value, exList); } }
/** * {@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(); }
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); } } }
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); } } }
/** * 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); } } }
/** * 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); } } }