public void extractInlineReferences ( IBaseResource theResource ) { if ( ! myDaoConfig . isAllowInlineMatchUrlReferences ( ) ) { return ; } FhirTerser terser = myContext . newTerser ( ) ; List < IBaseReference > allRefs = terser . getAllPopulatedChildElementsOfType ( theResource , IBaseReference . class ) ; for ( IBaseReference nextRef : allRefs ) { IIdType nextId = nextRef . getReferenceElement ( ) ; String nextIdText = nextId . getValue ( ) ; if ( nextIdText == null ) { continue ; } int qmIndex = nextIdText . indexOf ( ' ' ) ; if ( qmIndex != - 1 ) { for ( int i = qmIndex - 1 ; i >= 0 ; i -- ) { if ( nextIdText . charAt ( i ) == ' ' ) { if ( i < nextIdText . length ( ) - 1 && nextIdText . charAt ( i + 1 ) == ' ' ) { // Just in case the URL is in the form Patient/?foo=bar continue ; } nextIdText = nextIdText . substring ( i + 1 ) ; break ; } } String resourceTypeString = nextIdText . substring ( 0 , nextIdText . indexOf ( ' ' ) ) . replace ( "/" , "" ) ; RuntimeResourceDefinition matchResourceDef = myContext . getResourceDefinition ( resourceTypeString ) ; if ( matchResourceDef == null ) { String msg = myContext . getLocalizer ( ) . getMessage ( BaseHapiFhirDao . class , "invalidMatchUrlInvalidResourceType" , nextId . getValue ( ) , resourceTypeString ) ; throw new InvalidRequestException ( msg ) ; } Class < ? extends IBaseResource > matchResourceType = matchResourceDef . getImplementingClass ( ) ; Set < Long > matches = myMatchResourceUrlService . processMatchUrl ( nextIdText , matchResourceType ) ; if ( matches . isEmpty ( ) ) { String msg = myContext . getLocalizer ( ) . getMessage ( BaseHapiFhirDao . class , "invalidMatchUrlNoMatches" , nextId . getValue ( ) ) ; throw new ResourceNotFoundException ( msg ) ; } if ( matches . size ( ) > 1 ) { String msg = myContext . getLocalizer ( ) . getMessage ( BaseHapiFhirDao . class , "invalidMatchUrlMultipleMatches" , nextId . getValue ( ) ) ; throw new PreconditionFailedException ( msg ) ; } Long next = matches . iterator ( ) . next ( ) ; String newId = myIdHelperService . translatePidIdToForcedId ( resourceTypeString , next ) ; ourLog . debug ( "Replacing inline match URL[{}] with ID[{}}" , nextId . getValue ( ) , newId ) ; nextRef . setReference ( newId ) ; } } }
Handle references within the resource that are match URLs for example references like Patient?identifier = foo . These match URLs are resolved and replaced with the ID of the matching resource .