@Override public List<IBase> getValues(Object theTarget) { ExtensionDt target = (ExtensionDt) theTarget; if (target.getValue() != null) { return Collections.singletonList((IBase) target.getValue()); } ArrayList<IBase> retVal = new ArrayList<IBase>(target.getUndeclaredExtensions()); return retVal; } };
/** * Returns the value of this extension, casted to a primitive datatype. This is a convenience method which should only be called if you are sure that the value for this particular extension will * be a primitive. * <p> * Note that if this extension contains extensions (instead of a datatype) then <b>this method will return null</b>. In that case, you must use {@link #getUndeclaredExtensions()} and * {@link #getUndeclaredModifierExtensions()} to retrieve the child extensions. * </p> * * @throws ClassCastException * If the value of this extension is not a primitive datatype */ public IPrimitiveDatatype<?> getValueAsPrimitive() { if (!(getValue() instanceof IPrimitiveDatatype)) { throw new ClassCastException("Extension with URL["+myUrl+"] can not be cast to primitive type, type is: "+ getClass().getCanonicalName()); } return (IPrimitiveDatatype<?>) getValue(); }
@Override public String toString() { ToStringBuilder retVal = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); retVal.append("url", getUrl()); retVal.append("value", getValue()); return retVal.build(); }
@Override public List<IBase> getValues(Object theTarget) { ExtensionDt target = (ExtensionDt) theTarget; if (target.getValue() != null) { return Collections.singletonList((IBase) target.getValue()); } ArrayList<IBase> retVal = new ArrayList<IBase>(target.getUndeclaredExtensions()); return retVal; } };
/** * Returns the value of this extension, casted to a primitive datatype. This is a convenience method which should only be called if you are sure that the value for this particular extension will * be a primitive. * <p> * Note that if this extension contains extensions (instead of a datatype) then <b>this method will return null</b>. In that case, you must use {@link #getUndeclaredExtensions()} and * {@link #getUndeclaredModifierExtensions()} to retrieve the child extensions. * </p> * * @throws ClassCastException * If the value of this extension is not a primitive datatype */ public IPrimitiveDatatype<?> getValueAsPrimitive() { if (!(getValue() instanceof IPrimitiveDatatype)) { throw new ClassCastException("Extension with URL["+myUrl+"] can not be cast to primitive type, type is: "+ getClass().getCanonicalName()); } return (IPrimitiveDatatype<?>) getValue(); }
@Override public String toString() { ToStringBuilder retVal = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); retVal.append("url", getUrl()); retVal.append("value", getValue()); return retVal.build(); }
@Test public void test() throws URISyntaxException { IDomainFactory<BaseResource> factory = DomainFactory.getInstance(); Patient pat1 = factory.fetchObject(Patient.class, "1"); assertNotNull(pat1); for (ExtensionDt extension : pat1.getAllUndeclaredExtensions()) { System.out.println(extension.getUrlAsString() + "=" + extension.getValue()); } List<Patient> patients = factory.fetchObjects(Patient.class, PAT_IDS); assertNotNull(patients); assertEquals(2, patients.size()); DocumentReference dr = factory.fetchObject(DocumentReference.class, "1"); assertNotNull(dr); UriDt uri = dr.getContentFirstRep().getUrlElement(); IGenericClient client = ClientUtil.getFhirClient(); Binary result = (Binary) client.read(uri); assertNotNull(result); byte[] text = result.getContent(); System.out.println(new String(text)); Condition cond = factory.fetchObject(Condition.class, "1"); assertNotNull(cond); testException(client, ROOT + "Patient/309349993439"); }