@ SuppressWarnings ( "unchecked" ) public static < T extends IBaseResource > List < T > toListOfResourcesOfType ( FhirContext theContext , IBaseBundle theBundle , Class < T > theTypeToInclude ) { Objects . requireNonNull ( theTypeToInclude , "ResourceType must not be null" ) ; 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 . isAssignableFrom ( next . getClass ( ) ) ) { retVal . add ( ( T ) next ) ; } } } return retVal ; }
Extract all of the resources of a given type from a given bundle