public T newInstance() { return newInstance(null); }
protected IIdType fixContainedResourceId(String theValue) { IIdType retVal = (IIdType) myContext.getElementDefinition("id").newInstance(); if (StringUtils.isNotBlank(theValue) && theValue.charAt(0) == '#') { retVal.setValue(theValue.substring(1)); } else { retVal.setValue(theValue); } return retVal; }
@Override public Object outgoingClient(Object theObject) { IQueryParameterType obj = (IQueryParameterType) theObject; IPrimitiveType<?> retVal = (IPrimitiveType<?>) myContext.getElementDefinition("string").newInstance(); retVal.setValueAsString(obj.getValueAsQueryToken(myContext)); return retVal; }
@Override public Object outgoingClient(Object theObject) { IQueryParameterType obj = (IQueryParameterType) theObject; IPrimitiveType<?> retVal = (IPrimitiveType<?>) myContext.getElementDefinition("string").newInstance(); retVal.setValueAsString(obj.getValueAsQueryToken(myContext)); return retVal; }
if (targetTypeDtDef.isProfileOf(sourceType)) { FhirTerser terser = myContext.newTerser(); IBase newTarget = targetTypeDef.newInstance(); terser.cloneInto((IBase) nextValue, newTarget, true); theMatchingParamValues.add(newTarget);
IBase value = nextDef.getChildByName(name).newInstance(); nextDef.getMutator().addValue(theCurrentObj, value); List<IBase> list = new ArrayList<>();
public static IPrimitiveType<?> createString(FhirContext theContext, String theValue) { IPrimitiveType<?> value; if (theContext.getVersion().getVersion().isRi()) { value = (IPrimitiveType<?>) theContext.getElementDefinition("string").newInstance(theValue); } else { value = new StringDt(theValue); } return value; }
T newId = (T) idElement.newInstance(); newId.setValue(profile);
private static void populatePrimitiveValue(FhirContext theContext, IBaseResource theSubscription, String theChildName, String theValue) { RuntimeResourceDefinition def = theContext.getResourceDefinition(theSubscription); Validate.isTrue(def.getName().equals("Subscription"), "theResource is not a subscription"); BaseRuntimeChildDefinition statusChild = def.getChildByName(theChildName); List<IBase> entries = statusChild.getAccessor().getValues(theSubscription); IPrimitiveType<?> instance; if (entries.size() == 0) { BaseRuntimeElementDefinition<?> statusElement = statusChild.getChildByName(theChildName); instance = (IPrimitiveType<?>) statusElement.newInstance(statusChild.getInstanceConstructorArguments()); statusChild.getMutator().addValue(theSubscription, instance); } else { instance = (IPrimitiveType<?>) entries.get(0); } instance.setValueAsString(theValue); }
IBase target = element.newInstance();
public static void setSecurityContext(FhirContext theCtx, IBaseBinary theBinary, String theSecurityContext) { RuntimeResourceDefinition def = theCtx.getResourceDefinition("Binary"); BaseRuntimeChildDefinition child = def.getChildByName("securityContext"); BaseRuntimeElementDefinition<?> referenceDef = theCtx.getElementDefinition("reference"); IBaseReference reference = (IBaseReference) referenceDef.newInstance(); child.getMutator().addValue(theBinary, reference); reference.setReference(theSecurityContext); }
@SuppressWarnings("unchecked") @Override public T invokeClient(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException { EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType); if (respType == null) { throw NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseInputStream); } IParser parser = respType.newParser(myContext); RuntimeResourceDefinition type = myContext.getResourceDefinition("Parameters"); IBaseResource retVal = parser.parseResource(type.getImplementingClass(), theResponseInputStream); BaseRuntimeChildDefinition paramChild = type.getChildByName("parameter"); BaseRuntimeElementCompositeDefinition<?> paramChildElem = (BaseRuntimeElementCompositeDefinition<?>) paramChild.getChildByName("parameter"); List<IBase> parameter = paramChild.getAccessor().getValues(retVal); if (parameter == null || parameter.isEmpty()) { return (T) myContext.getElementDefinition(myType).newInstance(); } IBase param = parameter.get(0); List<IBase> meta = paramChildElem.getChildByName("value[x]").getAccessor().getValues(param); if (meta.isEmpty()) { return (T) myContext.getElementDefinition(myType).newInstance(); } return (T) meta.get(0); } }
IPrimitiveType<?> value = (IPrimitiveType<?>) myFhirContext.getElementDefinition("string").newInstance(); value.setValueAsString("Subscription triggering job submitted as JOB ID: " + jobDetails.myJobId); ParametersUtil.addParameterToParameters(myFhirContext, retVal, "information", value);
private static void populateDetails(FhirContext theCtx, IBase theIssue, String theSeverity, String theDetails, String theLocation, String theCode) { BaseRuntimeElementCompositeDefinition<?> issueElement = (BaseRuntimeElementCompositeDefinition<?>) theCtx.getElementDefinition(theIssue.getClass()); BaseRuntimeChildDefinition detailsChild; detailsChild = issueElement.getChildByName("diagnostics"); BaseRuntimeChildDefinition codeChild = issueElement.getChildByName("code"); IPrimitiveType<?> codeElem = (IPrimitiveType<?>) codeChild.getChildByName("code").newInstance(codeChild.getInstanceConstructorArguments()); codeElem.setValueAsString(theCode); codeChild.getMutator().addValue(theIssue, codeElem); BaseRuntimeElementDefinition<?> stringDef = detailsChild.getChildByName(detailsChild.getElementName()); BaseRuntimeChildDefinition severityChild = issueElement.getChildByName("severity"); BaseRuntimeChildDefinition locationChild = issueElement.getChildByName("location"); IPrimitiveType<?> severityElem = (IPrimitiveType<?>) severityChild.getChildByName("severity").newInstance(severityChild.getInstanceConstructorArguments()); severityElem.setValueAsString(theSeverity); severityChild.getMutator().addValue(theIssue, severityElem); IPrimitiveType<?> string = (IPrimitiveType<?>) stringDef.newInstance(); string.setValueAsString(theDetails); detailsChild.getMutator().setValue(theIssue, string); if (isNotBlank(theLocation)) { IPrimitiveType<?> locationElem = (IPrimitiveType<?>) locationChild.getChildByName("location").newInstance(locationChild.getInstanceConstructorArguments()); locationElem.setValueAsString(theLocation); locationChild.getMutator().addValue(theIssue, locationElem); } }
BaseRuntimeElementDefinition<?> metaChild = theMetaChildUncast.getChildByName("meta"); if (IBaseMetaType.class.isAssignableFrom(metaChild.getImplementingClass())) { IBaseMetaType newType = (IBaseMetaType) metaChild.newInstance(); theValues = Collections.singletonList(newType); retVal = new ArrayList<>(theValues); IBaseReference newRef = (IBaseReference) myContext.getElementDefinition(nextRef.getClass()).newInstance(); myContext.newTerser().cloneInto(nextRef, newRef, true); newRef.setReference(refText);
@SuppressWarnings("unchecked") private T readHtmlResponse(InputStream theResponseInputStream) { RuntimeResourceDefinition resDef = getFhirContext().getResourceDefinition(myReturnType); IBaseResource instance = resDef.newInstance(); BaseRuntimeChildDefinition textChild = resDef.getChildByName("text"); BaseRuntimeElementCompositeDefinition<?> textElement = (BaseRuntimeElementCompositeDefinition<?>) textChild.getChildByName("text"); IBase textInstance = textElement.newInstance(); textChild.getMutator().addValue(instance, textInstance); BaseRuntimeChildDefinition divChild = textElement.getChildByName("div"); BaseRuntimeElementDefinition<?> divElement = divChild.getChildByName("div"); IPrimitiveType<?> divInstance = (IPrimitiveType<?>) divElement.newInstance(); try { divInstance.setValueAsString(IOUtils.toString(theResponseInputStream, Charsets.UTF_8)); } catch (Exception e) { throw new InvalidResponseException(400, "Failed to process HTML response from server: " + e.getMessage(), e); } divChild.getMutator().addValue(textInstance, divInstance); return (T) instance; }
@SuppressWarnings("unchecked") private void addParam(String theName, IBase theValue) { BaseRuntimeChildDefinition parameterChild = myParametersDef.getChildByName("parameter"); BaseRuntimeElementCompositeDefinition<?> parameterElem = (BaseRuntimeElementCompositeDefinition<?>) parameterChild.getChildByName("parameter"); IBase parameter = parameterElem.newInstance(); parameterChild.getMutator().addValue(myParameters, parameter); IPrimitiveType<String> name = (IPrimitiveType<String>) myContext.getElementDefinition("string").newInstance(); name.setValue(theName); parameterElem.getChildByName("name").getMutator().setValue(parameter, name); if (theValue instanceof IBaseDatatype) { BaseRuntimeElementDefinition<?> datatypeDef = myContext.getElementDefinition(theValue.getClass()); if (datatypeDef instanceof IRuntimeDatatypeDefinition) { Class<? extends IBaseDatatype> profileOf = ((IRuntimeDatatypeDefinition) datatypeDef).getProfileOf(); if (profileOf != null) { datatypeDef = myContext.getElementDefinition(profileOf); } } String childElementName = "value" + StringUtils.capitalize(datatypeDef.getName()); BaseRuntimeChildDefinition childByName = parameterElem.getChildByName(childElementName); childByName.getMutator().setValue(parameter, theValue); } else if (theValue instanceof IBaseResource) { parameterElem.getChildByName("resource").getMutator().setValue(parameter, theValue); } else { throw new IllegalArgumentException("Don't know how to handle parameter of type " + theValue.getClass()); } }
@Override public Object outgoingClient(Object theObject) { IQueryParameterType obj = (IQueryParameterType) theObject; IPrimitiveType<?> retVal = (IPrimitiveType<?>) myContext.getElementDefinition("string").newInstance(); retVal.setValueAsString(obj.getValueAsQueryToken(myContext)); return retVal; }
@Override public Object outgoingClient(Object theObject) { IQueryParameterType obj = (IQueryParameterType) theObject; IPrimitiveType<?> retVal = (IPrimitiveType<?>) myContext.getElementDefinition("string").newInstance(); retVal.setValueAsString(obj.getValueAsQueryToken(myContext)); return retVal; }
public static IPrimitiveType<?> createString(FhirContext theContext, String theValue) { IPrimitiveType<?> value; if (theContext.getVersion().getVersion().isRi()) { value = (IPrimitiveType<?>) theContext.getElementDefinition("string").newInstance(theValue); } else { value = new StringDt(theValue); } return value; }