Skip to content

Commit

Permalink
Attempt fix for npe (#6213)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip

* remove whitespace

* Add test

* changelog
  • Loading branch information
tadgh authored Aug 13, 2024
1 parent 9e0efca commit fa04ad6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -1112,6 +1113,34 @@ public void testCountParam() {

}

@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();
Expand Down
20 changes: 15 additions & 5 deletions hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -161,12 +164,19 @@ public class ${className}ResourceProvider extends
paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_LANGUAGE, theResourceLanguage);

paramMap.add("_has", theHas);
#foreach ( $param in $searchParams )
paramMap.add("${param.name}", the${param.nameCapitalized});
#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);
paramMap.setRevIncludes(theRevIncludes);
## 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);
Expand Down

0 comments on commit fa04ad6

Please sign in to comment.