private void addExtensionMetadata(RuntimeResourceDefinition theResDef, IBaseResource theResource, boolean theContainedResource, boolean theSubResource, List<Map.Entry<ResourceMetadataKeyEnum<?>, Object>> extensionMetadataKeys, RuntimeResourceDefinition resDef, JsonLikeWriter theEventWriter) throws IOException { if (extensionMetadataKeys.isEmpty()) { return; } ExtensionDt metaResource = new ExtensionDt(); for (Map.Entry<ResourceMetadataKeyEnum<?>, Object> entry : extensionMetadataKeys) { metaResource.addUndeclaredExtension((ExtensionDt) entry.getValue()); } encodeCompositeElementToStreamWriter(theResDef, theResource, metaResource, theEventWriter, theContainedResource, theSubResource, new CompositeChildElement(resDef, theSubResource)); }
@Override public void addValue(Object theTarget, IBase theValue) { ExtensionDt target = (ExtensionDt) theTarget; if (theValue instanceof IDatatype) { target.setValue((IDatatype) theTarget); } else { target.getUndeclaredExtensions().add((ExtensionDt) theValue); } }
@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; } };
item.setText("Hello"); ExtensionDt extension = new ExtensionDt(false, "http://hl7.org/fhir/StructureDefinition/translation"); item.getTextElement().addUndeclaredExtension(extension); extension.addUndeclaredExtension(new ExtensionDt(false, "lang", new CodeDt("es"))); extension.addUndeclaredExtension(new ExtensionDt(false, "cont", new StringDt("hola"))); ExtensionDt ext = new ExtensionDt(); ext.setModifier(false); ext.setUrl("http://example.com/extensions#someext"); ext.setValue(new DateTimeDt("2011-01-02T11:13:15")); ExtensionDt givenExt = new ExtensionDt(false, "http://examples.com#moreext", new StringDt("Hello")); given.addUndeclaredExtension(givenExt);
@SuppressWarnings("unchecked") private ExtensionDt createEmptyExtensionDt(IBaseExtension theBaseExtension, boolean theIsModifier, String theUrl) { ExtensionDt retVal = new ExtensionDt(theIsModifier, theUrl); theBaseExtension.getExtension().add(retVal); return retVal; }
String userInfoEndpoint = null; for (ExtensionDt extensionDt : extensions) { if(extensionDt.getUrl().equalsIgnoreCase(URIS_ENDPOINT_EXTENSION)){ List<ExtensionDt> urisExtensions = extensionDt.getUndeclaredExtensions(); for (ExtensionDt uriExtensionDt : urisExtensions) { if (uriExtensionDt.getUrl().equalsIgnoreCase("authorize")){ authEndpoint = uriExtensionDt.getValueAsPrimitive().getValueAsString(); else if(uriExtensionDt.getUrl().equalsIgnoreCase("token")){ tokenEndpoint = uriExtensionDt.getValueAsPrimitive().getValueAsString(); userInfoEndpoint = tokenEndpoint.replaceFirst("token", "userinfo");
/** * Retained for backward compatibility * * @see ExtensionDt#getUrl() */ public String getUrlAsString() { return getUrl(); }
String userInfoEndpoint = null; for (ExtensionDt extension : extensions) { if (extension.getUrl().equalsIgnoreCase(URIS_ENDPOINT_EXTENSION)) { List<ExtensionDt> urisExtensions = extension.getExtension(); for (ExtensionDt uriExtensionDt : urisExtensions) { if (uriExtensionDt.getUrl().equalsIgnoreCase("authorize")) { authEndpoint = uriExtensionDt.getValueAsPrimitive().getValueAsString(); } else if (uriExtensionDt.getUrl().equalsIgnoreCase("token")) { tokenEndpoint = uriExtensionDt.getValueAsPrimitive().getValueAsString(); userInfoEndpoint = tokenEndpoint.replaceFirst("token", "userinfo");
/** * 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(); }
@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"); }
IPrimitiveType<?> uniqueExtsValuePrimitive = uniqueExts.get(0).getValueAsPrimitive(); if (uniqueExtsValuePrimitive != null) { if ("true".equalsIgnoreCase(uniqueExtsValuePrimitive.getValueAsString())) {
@Override public List<ExtensionDt> getUndeclaredExtensionsByUrl(String theUrl) { org.apache.commons.lang3.Validate.notNull(theUrl, "URL can not be null"); ArrayList<ExtensionDt> retVal = new ArrayList<ExtensionDt>(); for (ExtensionDt next : getAllUndeclaredExtensions()) { if (theUrl.equals(next.getUrlAsString())) { retVal.add(next); } } return Collections.unmodifiableList(retVal); }
ExtensionDt ext = new ExtensionDt(); ext.setModifier(false); ext.setUrl("http://example.com/extensions#someext"); ext.setValue(new DateTimeDt("2011-01-02T11:13:15")); StringDt given = name.addGiven(); given.setValue("Joe"); ExtensionDt ext2 = new ExtensionDt(false, "http://examples.com#moreext", new StringDt("Hello")); given.addUndeclaredExtension(ext2);
@Override public ExtensionDt addUndeclaredExtension(boolean theIsModifier, String theUrl, IBaseDatatype theValue) { Validate.notEmpty(theUrl, "URL must be populated"); Validate.notNull(theValue, "Value must not be null"); ExtensionDt retVal = new ExtensionDt(theIsModifier, theUrl, theValue); if (theIsModifier) { getUndeclaredModifierExtensions(); myUndeclaredModifierExtensions.add(retVal); } else { getUndeclaredExtensions(); myUndeclaredExtensions.add(retVal); } return retVal; }
private Map<String, String> convertChannelExtensionsDstu2(ca.uhn.fhir.model.dstu2.resource.Subscription theSubscription) { Map<String, String> retval = new HashMap<>(); for (ExtensionDt extension : theSubscription.getChannel().getUndeclaredExtensions()) { String url = extension.getUrl(); if (isNotBlank(url)) { String value = extractExtension(theSubscription, url); if (isNotBlank(value)) { retval.put(url, value); } } } return retval; }
@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; } };
@Override public List<ExtensionDt> getUndeclaredExtensionsByUrl(String theUrl) { org.apache.commons.lang3.Validate.notNull(theUrl, "URL can not be null"); ArrayList<ExtensionDt> retVal = new ArrayList<ExtensionDt>(); for (ExtensionDt next : getAllUndeclaredExtensions()) { if (theUrl.equals(next.getUrlAsString())) { retVal.add(next); } } return Collections.unmodifiableList(retVal); }
public void foo() { //START SNIPPET: subExtension Patient patient = new Patient(); ExtensionDt parent = new ExtensionDt(false, "http://example.com#parent"); patient.addUndeclaredExtension(parent); ExtensionDt child1 = new ExtensionDt(false, "http://example.com#childOne", new StringDt("value1")); parent.addUndeclaredExtension(child1); ExtensionDt child2 = new ExtensionDt(false, "http://example.com#childTwo", new StringDt("value1")); parent.addUndeclaredExtension(child2); //END SNIPPET: subExtension }