private BaseRuntimeChildDefinition getDefinition(BaseRuntimeElementCompositeDefinition<?> theCurrentDef, List<String> theSubList) { BaseRuntimeChildDefinition nextDef = theCurrentDef.getChildByNameOrThrowDataFormatException(theSubList.get(0)); if (theSubList.size() == 1) { return nextDef; } BaseRuntimeElementCompositeDefinition<?> cmp = (BaseRuntimeElementCompositeDefinition<?>) nextDef.getChildByName(theSubList.get(0)); return getDefinition(cmp, theSubList.subList(1, theSubList.size())); }
/** * Add a paratemer value to a Parameters resource * * @param theContext The FhirContext * @param theParameters The Parameters resource * @param theName The parametr name * @param theValue The parameter value (can be a {@link IBaseResource resource} or a {@link IBaseDatatype datatype}) */ public static void addParameterToParameters(FhirContext theContext, IBaseParameters theParameters, String theName, Object theValue) { RuntimeResourceDefinition def = theContext.getResourceDefinition(theParameters); BaseRuntimeChildDefinition paramChild = def.getChildByName("parameter"); BaseRuntimeElementCompositeDefinition<?> paramChildElem = (BaseRuntimeElementCompositeDefinition<?>) paramChild.getChildByName("parameter"); addClientParameter(theContext, theValue, theParameters, paramChild, paramChildElem, theName); }
/** * Extract all of the resources of a given type from a given bundle */ @SuppressWarnings("unchecked") public static <T extends IBaseResource> List<T> toListOfResourcesOfType(FhirContext theContext, IBaseBundle theBundle, Class<T> theTypeToInclude) { List<T> retVal = new ArrayList<>(); RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle); BaseRuntimeChildDefinition entryChild = def.getChildByName("entry"); List<IBase> entries = entryChild.getAccessor().getValues(theBundle); BaseRuntimeElementCompositeDefinition<?> entryChildElem = (BaseRuntimeElementCompositeDefinition<?>) entryChild.getChildByName("entry"); BaseRuntimeChildDefinition resourceChild = entryChildElem.getChildByName("resource"); for (IBase nextEntry : entries) { for (IBase next : resourceChild.getAccessor().getValues(nextEntry)) { if (theTypeToInclude != null && !theTypeToInclude.isAssignableFrom(next.getClass())) { continue; } retVal.add((T) next); } } return retVal; }
b.append(" - Valid types: "); for (Iterator<String> iter = new TreeSet<String>(nextChild.getValidChildNames()).iterator(); iter.hasNext(); ) { BaseRuntimeElementDefinition<?> childByName = nextChild.getChildByName(iter.next()); b.append(childByName.getImplementingClass().getSimpleName()); if (iter.hasNext()) {
private static IBase createIssue(FhirContext theCtx, IBaseResource theOutcome) { RuntimeResourceDefinition ooDef = theCtx.getResourceDefinition(theOutcome); BaseRuntimeChildDefinition issueChild = ooDef.getChildByName("issue"); BaseRuntimeElementCompositeDefinition<?> issueElement = (BaseRuntimeElementCompositeDefinition<?>) issueChild.getChildByName("issue"); IBase issue = issueElement.newInstance(); issueChild.getMutator().addValue(theOutcome, issue); return issue; }
IBase value = nextDef.getChildByName(name).newInstance(); nextDef.getMutator().addValue(theCurrentObj, value); List<IBase> list = new ArrayList<>();
BaseRuntimeElementCompositeDefinition<?> paramChildElem = (BaseRuntimeElementCompositeDefinition<?>) paramChild.getChildByName("parameter");
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); }
@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; }
List<IBase> entries = entryChild.getAccessor().getValues(theBundle); BaseRuntimeElementCompositeDefinition<?> entryChildElem = (BaseRuntimeElementCompositeDefinition<?>) entryChild.getChildByName("entry"); BaseRuntimeChildDefinition resourceChild = entryChildElem.getChildByName("resource"); BaseRuntimeElementCompositeDefinition<?> requestDef = (BaseRuntimeElementCompositeDefinition<?>) requestChild.getChildByName("request");
BaseRuntimeElementCompositeDefinition<?> entryDef = (BaseRuntimeElementCompositeDefinition<?>) entryChildDef.getChildByName("entry");
BaseRuntimeElementCompositeDefinition<?> entryDef = (BaseRuntimeElementCompositeDefinition<?>) entryChildDef.getChildByName("entry");
BaseRuntimeElementCompositeDefinition<?> entryDef = (BaseRuntimeElementCompositeDefinition<?>) entryChildDef.getChildByName("entry");
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); } }
@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); } }
BaseRuntimeElementDefinition<?> metaChild = theMetaChildUncast.getChildByName("meta"); if (IBaseMetaType.class.isAssignableFrom(metaChild.getImplementingClass())) { IBaseMetaType newType = (IBaseMetaType) metaChild.newInstance();
List<IBase> entries = entryChild.getAccessor().getValues(theBundle); BaseRuntimeElementCompositeDefinition<?> entryChildElem = (BaseRuntimeElementCompositeDefinition<?>) entryChild.getChildByName("entry"); BaseRuntimeElementCompositeDefinition<?> requestElem = (BaseRuntimeElementCompositeDefinition<?>) requestChild.getChildByName("request"); BaseRuntimeChildDefinition urlChild = requestElem.getChildByName("url"); BaseRuntimeChildDefinition methodChild = requestElem.getChildByName("method");
BaseRuntimeElementCompositeDefinition<?> paramChildElem = (BaseRuntimeElementCompositeDefinition<?>) paramChild.getChildByName("parameter"); IBase parameter = paramChildElem.newInstance(); paramChild.getMutator().addValue(parameters, parameter);
@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()); } }
BaseRuntimeElementCompositeDefinition<?> entryDef = (BaseRuntimeElementCompositeDefinition<?>) entryChild.getChildByName("entry"); List<IBase> entries = entryChild.getAccessor().getValues(retVal); if (entries != null) {