Attempt fix for npe (#6213)

* wip

* wip

* wip

* remove whitespace

* Add test

* changelog
This commit is contained in:
Tadgh 2024-08-13 12:37:03 -07:00 committed by GitHub
parent 9e0efcaecb
commit fa04ad6c72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 49 additions and 6 deletions

View File

@ -56,7 +56,7 @@ public interface IAnyResource extends IBaseResource {
@SearchParamDefinition(
name = SP_RES_LAST_UPDATED,
path = "Resource.meta.lastUpdated",
description = "The last updated date of the resource",
description = "Only return resources which were last updated as specified by the given range",
type = "date")
/**

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 6208
title: "A regression was temporarily introduced which caused searches by `_lastUpdated` to fail with a NullPointerException when using Lucene as the backing search engine. This has been corrected"

View File

@ -29,6 +29,7 @@ import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.model.primitive.UriDt;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.parser.StrictErrorHandler;
import ca.uhn.fhir.rest.api.CacheControlDirective;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.PreferReturnEnum;
@ -1112,6 +1113,34 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
}
@Test
public void testSearchByUrl() {
// setup
DateType dt = new DateType(new Date());
String nowStr = dt.getValueAsString();
boolean storeResourceInHSearch = myStorageSettings.isStoreResourceInHSearchIndex();
boolean advancedHSearch = myStorageSettings.isAdvancedHSearchIndexing();
try {
// use full text search
myStorageSettings.setStoreResourceInHSearchIndex(true);
myStorageSettings.setAdvancedHSearchIndexing(true);
// test
Bundle b = myClient.search()
.byUrl("Patient?_lastUpdated=" + nowStr)
.returnBundle(Bundle.class)
.cacheControl(CacheControlDirective.noCache())
.execute();
assertNotNull(b);
} finally {
// reset back to previous
myStorageSettings.setAdvancedHSearchIndexing(advancedHSearch);
myStorageSettings.setStoreResourceInHSearchIndex(storeResourceInHSearch);
}
}
@Test
public void testCreateConditionalWithPreferRepresentation() {
Patient p = new Patient();

View File

@ -121,9 +121,12 @@ public class ${className}ResourceProvider extends
@RawParam
Map<String, List<String>> theAdditionalRawParams,
##DSTU2 is not an IAnyResource, yet supports LastUpdated, so we keep the magic SP in this case.
#if ( $version == 'dstu2' )
@Description(shortDefinition="Only return resources which were last updated as specified by the given range")
@OptionalParam(name="_lastUpdated")
DateRangeParam theLastUpdated,
DateRangeParam the_lastUpdated,
#end
@IncludeParam
Set<Include> theIncludes,
@ -162,11 +165,18 @@ public class ${className}ResourceProvider extends
paramMap.add("_has", theHas);
#foreach ( $param in $searchParams )
#if( ${param.name} == "_lastUpdated")
## Skip Last Updated since its handled by param defined below.
#else
paramMap.add("${param.name}", the${param.nameCapitalized});
#end
#end
#if ( $version != 'dstu' )
paramMap.setRevIncludes(theRevIncludes);
paramMap.setLastUpdated(theLastUpdated);
## Note that since we have added an SearchParamDefinition on IAnyResource for this, we had to remove
## the magic _lastUpdated that was previously hardcoded as an OperationParam. However, we still need to populate
## This special variable in the SP map.
paramMap.setLastUpdated(the_lastUpdated);
#end
paramMap.setIncludes(theIncludes);
paramMap.setSort(theSort);