Skip to content

Commit fa04ad6

Browse files
authored
Attempt fix for npe (#6213)
* wip * wip * wip * remove whitespace * Add test * changelog
1 parent 9e0efca commit fa04ad6

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IAnyResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public interface IAnyResource extends IBaseResource {
5656
@SearchParamDefinition(
5757
name = SP_RES_LAST_UPDATED,
5858
path = "Resource.meta.lastUpdated",
59-
description = "The last updated date of the resource",
59+
description = "Only return resources which were last updated as specified by the given range",
6060
type = "date")
6161

6262
/**
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
type: fix
3+
issue: 6208
4+
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"

hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import ca.uhn.fhir.model.primitive.UriDt;
3030
import ca.uhn.fhir.parser.IParser;
3131
import ca.uhn.fhir.parser.StrictErrorHandler;
32+
import ca.uhn.fhir.rest.api.CacheControlDirective;
3233
import ca.uhn.fhir.rest.api.Constants;
3334
import ca.uhn.fhir.rest.api.MethodOutcome;
3435
import ca.uhn.fhir.rest.api.PreferReturnEnum;
@@ -1112,6 +1113,34 @@ public void testCountParam() {
11121113

11131114
}
11141115

1116+
@Test
1117+
public void testSearchByUrl() {
1118+
// setup
1119+
DateType dt = new DateType(new Date());
1120+
String nowStr = dt.getValueAsString();
1121+
1122+
boolean storeResourceInHSearch = myStorageSettings.isStoreResourceInHSearchIndex();
1123+
boolean advancedHSearch = myStorageSettings.isAdvancedHSearchIndexing();
1124+
1125+
try {
1126+
// use full text search
1127+
myStorageSettings.setStoreResourceInHSearchIndex(true);
1128+
myStorageSettings.setAdvancedHSearchIndexing(true);
1129+
1130+
// test
1131+
Bundle b = myClient.search()
1132+
.byUrl("Patient?_lastUpdated=" + nowStr)
1133+
.returnBundle(Bundle.class)
1134+
.cacheControl(CacheControlDirective.noCache())
1135+
.execute();
1136+
1137+
assertNotNull(b);
1138+
} finally {
1139+
// reset back to previous
1140+
myStorageSettings.setAdvancedHSearchIndexing(advancedHSearch);
1141+
myStorageSettings.setStoreResourceInHSearchIndex(storeResourceInHSearch);
1142+
}
1143+
}
11151144
@Test
11161145
public void testCreateConditionalWithPreferRepresentation() {
11171146
Patient p = new Patient();

hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,12 @@ public class ${className}ResourceProvider extends
121121
@RawParam
122122
Map<String, List<String>> theAdditionalRawParams,
123123

124+
##DSTU2 is not an IAnyResource, yet supports LastUpdated, so we keep the magic SP in this case.
125+
#if ( $version == 'dstu2' )
124126
@Description(shortDefinition="Only return resources which were last updated as specified by the given range")
125127
@OptionalParam(name="_lastUpdated")
126-
DateRangeParam theLastUpdated,
128+
DateRangeParam the_lastUpdated,
129+
#end
127130

128131
@IncludeParam
129132
Set<Include> theIncludes,
@@ -161,12 +164,19 @@ public class ${className}ResourceProvider extends
161164
paramMap.add(ca.uhn.fhir.rest.api.Constants.PARAM_LANGUAGE, theResourceLanguage);
162165

163166
paramMap.add("_has", theHas);
164-
#foreach ( $param in $searchParams )
165-
paramMap.add("${param.name}", the${param.nameCapitalized});
167+
#foreach ( $param in $searchParams )
168+
#if( ${param.name} == "_lastUpdated")
169+
## Skip Last Updated since its handled by param defined below.
170+
#else
171+
paramMap.add("${param.name}", the${param.nameCapitalized});
172+
#end
166173
#end
167174
#if ( $version != 'dstu' )
168-
paramMap.setRevIncludes(theRevIncludes);
169-
paramMap.setLastUpdated(theLastUpdated);
175+
paramMap.setRevIncludes(theRevIncludes);
176+
## Note that since we have added an SearchParamDefinition on IAnyResource for this, we had to remove
177+
## the magic _lastUpdated that was previously hardcoded as an OperationParam. However, we still need to populate
178+
## This special variable in the SP map.
179+
paramMap.setLastUpdated(the_lastUpdated);
170180
#end
171181
paramMap.setIncludes(theIncludes);
172182
paramMap.setSort(theSort);

0 commit comments

Comments
 (0)