/** * 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; }
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; }
BaseRuntimeElementCompositeDefinition<?> childDef = (BaseRuntimeElementCompositeDefinition<?>) theDefinition; for (BaseRuntimeChildDefinition nextChild : childDef.getChildrenAndExtension()) { List<? extends IBase> values = nextChild.getAccessor().getValues(theElement); if (values != null) { for (IBase nextValue : values) { childElementDef = nextChild.getChildElementDefinitionByDatatype(nextValue.getClass()); b.append(nextValue.getClass().getSimpleName()); b.append("] which is not valid for field["); b.append(nextChild.getElementName()); b.append("] in "); b.append(childDef.getName()); 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 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); }
public static IBaseReference getSecurityContext(FhirContext theCtx, IBaseBinary theBinary) { RuntimeResourceDefinition def = theCtx.getResourceDefinition("Binary"); BaseRuntimeChildDefinition child = def.getChildByName("securityContext"); IBaseReference retVal = null; if (child != null) { List<IBase> values = child.getAccessor().getValues(theBinary); if (values.size() > 0) { retVal = (IBaseReference) values.get(0); } } return retVal; }
if (nextChildElem.getDef().getElementName().equals("extension") || nextChildElem.getDef().getElementName().equals("modifierExtension") || nextChild instanceof RuntimeChildDeclaredExtensionDefinition) { if (!haveWrittenExtensions) { if (!narr.isEmpty()) { RuntimeChildNarrativeDefinition child = (RuntimeChildNarrativeDefinition) nextChild; String childName = nextChild.getChildNameByDatatype(child.getDatatype()); BaseRuntimeElementDefinition<?> type = child.getChildByName(childName); encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, narr, type, childName, theContainedResource, theSubResource, nextChildElem, false); String childName = nextChild.getValidChildNames().iterator().next(); BaseRuntimeElementDefinition<?> child = nextChild.getChildByName(childName); encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, null, child, childName, theContainedResource, theSubResource, nextChildElem, false); continue; List<? extends IBase> values = nextChild.getAccessor().getValues(theElement); values = super.preProcessValues(nextChild, theResource, values, nextChildElem); theEventWriter.endArray(); if (nextChild.getMax() > 1 || nextChild.getMax() == Child.MAX_UNLIMITED) { beginArray(theEventWriter, childName); inArray = true;
List<? extends IBase> values = nextDef.getAccessor().getValues(theCurrentObj); IBase value = nextDef.getChildByName(name).newInstance(); nextDef.getMutator().addValue(theCurrentObj, value); List<IBase> list = new ArrayList<>(); list.add(value); String childName = nextDef.getChildNameByDatatype(next.getClass()); if (theSubList.get(0).equals(childName)) { if (theWantedClass == null || theWantedClass.isAssignableFrom(next.getClass())) {
String elementName = nextChild.getElementName(); if (nextChild.getValidChildNames().size() > 1) { elementName = nextChild.getValidChildNames().iterator().next(); List<? extends IBase> sourceValues = sourceChildEquivalent.getAccessor().getValues(theSource); for (IBase nextElement : sourceValues) { boolean handled = false; nextChild.getMutator().addValue(theTarget, nextElement);
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); } }
if (nextChild.getElementName().equals("url") && theElement instanceof IBaseExtension) { String childName = nextChild.getChildNameByDatatype(child.getDatatype()); BaseRuntimeElementDefinition<?> type = child.getChildByName(childName); encodeChildElementToStreamWriter(theResource, theEventWriter, narr, childName, type, null, theContainedResource, theSubResource, nextChildElem); encodeChildElementToStreamWriter(theResource, theEventWriter, null, nextChild.getChildNameByDatatype(null), nextChild.getChildElementDefinitionByDatatype(null), null, theContainedResource, theSubResource, nextChildElem); } else { List<? extends IBase> values = nextChild.getAccessor().getValues(theElement); values = super.preProcessValues(nextChild, theResource, values, nextChildElem); String extensionUrl = getExtensionUrl(nextChild.getExtensionUrl());
for (IBase nextValue : nextChild.getAccessor().getValues(theSource)) { String elementName = nextChild.getChildNameByDatatype(nextValue.getClass()); BaseRuntimeChildDefinition targetChild = targetDef.getChildByName(elementName); if (targetChild == null) { IBase target = element.newInstance(); targetChild.getMutator().addValue(theTarget, target); cloneInto(nextValue, target, theIgnoreMissingFields);
for (BaseRuntimeChildDefinition nextChildDef : cdef.getChildren()) { List<IBase> values = nextChildDef.getAccessor().getValues(theElement); if (values == null || values.isEmpty()) { continue; String newPath = thePath + "." + nextChildDef.getElementName();
if (theValues.isEmpty() && theMetaChildUncast.getElementName().equals("meta")) { BaseRuntimeElementDefinition<?> metaChild = theMetaChildUncast.getChildByName("meta"); if (IBaseMetaType.class.isAssignableFrom(metaChild.getImplementingClass())) { IBaseMetaType newType = (IBaseMetaType) metaChild.newInstance();
for (BaseRuntimeChildDefinition nextChild : childDef.getChildrenAndExtension()) { List<?> values = nextChild.getAccessor().getValues(theElement); if (values != null) { for (Object nextValueObject : values) { childElementDef = nextChild.getChildElementDefinitionByDatatype(nextValue.getClass());
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())); }
private static IBase createParameterRepetition(FhirContext theContext, IBaseResource theTargetResource, BaseRuntimeChildDefinition paramChild, BaseRuntimeElementCompositeDefinition<?> paramChildElem, String theName) { IBase parameter = paramChildElem.newInstance(); paramChild.getMutator().addValue(theTargetResource, parameter); IPrimitiveType<?> value; value = createString(theContext, theName); paramChildElem.getChildByName("name").getMutator().addValue(parameter, value); return parameter; }
@Override public String toString() { return getClass().getSimpleName() + "[" + getElementName() + "]"; }
next.sealAndInitialize(theContext, theClassToElementDefinitions); for (BaseRuntimeChildDefinition next : myChildren) { if (next instanceof RuntimeChildChoiceDefinition) { String key = next.getElementName()+"[x]"; myNameToChild.put(key, next); for (String nextName : next.getValidChildNames()) { if (myNameToChild.containsKey(nextName)) { throw new ConfigurationException("Duplicate child name[" + nextName + "] in Element[" + getName() + "]");
if (myDef.getMin() > 0) { if (theElements.contains("*.(mandatory)")) { return true; thePathBuilder.append(myDef.getElementName()); String currentPath = thePathBuilder.toString(); boolean retVal = theElements.contains(currentPath);
@SuppressWarnings("unchecked") ChildNameAndDef getChildNameAndDef(BaseRuntimeChildDefinition theChild, IBase theValue) { Class<? extends IBase> type = theValue.getClass(); String childName = theChild.getChildNameByDatatype(type); BaseRuntimeElementDefinition<?> childDef = theChild.getChildElementDefinitionByDatatype(type); if (childDef == null) { if (elementDef.getName().equals("code")) { Class<? extends IBase> type2 = myContext.getElementDefinition("code").getImplementingClass(); childDef = theChild.getChildElementDefinitionByDatatype(type2); childName = theChild.getChildNameByDatatype(type2); BaseRuntimeElementDefinition<?> def = myContext.getElementDefinition((Class<? extends IBase>) nextSuperType); Class<?> nextChildType = def.getImplementingClass(); childDef = theChild.getChildElementDefinitionByDatatype((Class<? extends IBase>) nextChildType); childName = theChild.getChildNameByDatatype((Class<? extends IBase>) nextChildType);