From 6e0b6d2a3ea13fdff3159b40121830ab41c62c0a Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Fri, 31 Jan 2025 14:35:59 -0500 Subject: [PATCH 01/13] added test for '-delt-add' in hapi --- .../r4/TerminologyUploaderProviderR4Test.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java index 99180105bde9..5f12915e7478 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java @@ -356,6 +356,40 @@ public void testApplyDeltaAdd_UsingCodeSystem() { ); } + @Test + public void testApplyDeltaAdd_UsingCodeSystemWithElasticSearch() { + //Given: Advance HSearch indexing is enabled + myStorageSettings.setHibernateSearchIndexFullText(true); + myStorageSettings.setHibernateSearchIndexSearchParams(true); + myStorageSettings.setStoreResourceInHSearchIndex(true); + //Given: We have an existing NOT_PRESENT code system + CodeSystem codeSystem = new CodeSystem(); + codeSystem.setUrl("http://example.com/cs"); + codeSystem.setContent(CodeSystem.CodeSystemContentMode.NOTPRESENT); + myClient.create().resource(codeSystem).execute(); + CodeSystem.ConceptDefinitionComponent chem = codeSystem.addConcept().setCode("CHEM").setDisplay("Chemistry"); + chem.addConcept().setCode("HB").setDisplay("Hemoglobin"); + chem.addConcept().setCode("NEUT").setDisplay("Neutrophils"); + CodeSystem.ConceptDefinitionComponent micro = codeSystem.addConcept().setCode("MICRO").setDisplay("Microbiology"); + micro.addConcept().setCode("C&S").setDisplay("Culture And Sensitivity"); + //Execute + Parameters outcome = myClient + .operation() + .onType(CodeSystem.class) + .named(JpaConstants.OPERATION_APPLY_CODESYSTEM_DELTA_ADD) + .withParameter(Parameters.class, TerminologyUploaderProvider.PARAM_SYSTEM, new UriType("http://example.com/cs")) + .andParameter(TerminologyUploaderProvider.PARAM_CODESYSTEM, codeSystem) + .prettyPrint() + .execute(); + //Validate + IntegerType conceptCount = (IntegerType) outcome.getParameter("conceptCount").getValue(); + assertThat(conceptCount.getValue()).isEqualTo(5); + //Teardown + myStorageSettings.setHibernateSearchIndexFullText(false); + myStorageSettings.setHibernateSearchIndexSearchParams(false); + myStorageSettings.setStoreResourceInHSearchIndex(false); + } + @Test public void testApplyDeltaAdd_UsingCodeSystemWithConceptProprieties() { CodeSystem codeSystem = new CodeSystem(); From 5802286ef66d2f97a45bb442f9604725f37068bf Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Fri, 31 Jan 2025 14:49:39 -0500 Subject: [PATCH 02/13] fixed an issue with the _lastUpdated search param not being recognized as a valid sort spec with Hsearch enabled in CDR --- .../jpa/dao/search/HSearchSortHelperImpl.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java index 4fbcd65c927c..8554b7fdeffc 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java @@ -22,6 +22,7 @@ import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortSpec; @@ -46,6 +47,7 @@ import static ca.uhn.fhir.jpa.model.search.HSearchIndexWriter.QTY_VALUE_NORM; import static ca.uhn.fhir.jpa.model.search.HSearchIndexWriter.SEARCH_PARAM_ROOT; import static ca.uhn.fhir.jpa.model.search.HSearchIndexWriter.URI_VALUE; +import static ca.uhn.fhir.rest.api.Constants.PARAM_LASTUPDATED; /** * Used to build HSearch sort clauses. @@ -152,15 +154,28 @@ Optional getSortClause(SearchSortFactory theF, SortSpec theSortSp @VisibleForTesting Optional getParamType(String theResourceTypeName, String theParamName) { ResourceSearchParams activeSearchParams = mySearchParamRegistry.getActiveSearchParams( - theResourceTypeName, ISearchParamRegistry.SearchParamLookupContextEnum.SEARCH); + theResourceTypeName, ISearchParamRegistry.SearchParamLookupContextEnum.SEARCH); RuntimeSearchParam searchParam = activeSearchParams.get(theParamName); if (searchParam == null) { - return Optional.empty(); + RestSearchParameterTypeEnum paramType = this.getParamTypeOfSortingParams(theParamName); + return paramType != null ? Optional.of(paramType) : Optional.empty(); } return Optional.of(searchParam.getParamType()); } + private RestSearchParameterTypeEnum getParamTypeOfSortingParams(String paramName) { + Map paramNameToParamType = + Map.of( + Constants.PARAM_LASTUPDATED, RestSearchParameterTypeEnum.DATE, + Constants.PARAM_ID, RestSearchParameterTypeEnum.TOKEN, + Constants.PARAM_TAG, RestSearchParameterTypeEnum.TOKEN, + Constants.PARAM_SECURITY, RestSearchParameterTypeEnum.TOKEN, + Constants.PARAM_SOURCE, RestSearchParameterTypeEnum.TOKEN + ); + return paramNameToParamType.get(paramName); + } + /** * Retrieves the generic property names (* instead of parameter name) from the configured map and * replaces the '*' segment by theParamName before returning the final property name list From dba6493c0903b6580fbcdb8ba12897cdcf9f796b Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Fri, 31 Jan 2025 20:14:25 -0500 Subject: [PATCH 03/13] added null check --- .../fhir/jpa/term/TermCodeSystemStorageSvcImpl.java | 2 +- .../FhirResourceDaoR4SearchWithElasticSearchIT.java | 12 ++++++++++++ .../r4/TerminologyUploaderProviderR4Test.java | 4 +--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java index 567d92e324a1..c0e46faa16c2 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java @@ -165,7 +165,7 @@ public UploadStatistics applyDeltaCodeSystemsAdd(String theSystem, CustomTermino Validate.notNull(csv); CodeSystem codeSystem = myTerminologySvc.fetchCanonicalCodeSystemFromCompleteContext(theSystem); - if (codeSystem.getContent() != CodeSystem.CodeSystemContentMode.NOTPRESENT) { + if (codeSystem != null && codeSystem.getContent() != CodeSystem.CodeSystemContentMode.NOTPRESENT) { throw new InvalidRequestException( Msg.code(844) + "CodeSystem with url[" + Constants.codeSystemWithDefaultDescription(theSystem) + "] can not apply a delta - wrong content mode: " + codeSystem.getContent()); diff --git a/hapi-fhir-jpaserver-elastic-test-utilities/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java b/hapi-fhir-jpaserver-elastic-test-utilities/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java index 0662fbc1dc83..4f4249d6912e 100644 --- a/hapi-fhir-jpaserver-elastic-test-utilities/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java +++ b/hapi-fhir-jpaserver-elastic-test-utilities/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java @@ -26,6 +26,7 @@ import ca.uhn.fhir.jpa.rp.r4.PatientResourceProvider; import ca.uhn.fhir.jpa.search.BaseSourceSearchParameterTestCases; import ca.uhn.fhir.jpa.search.CompositeSearchParameterTestCases; +import ca.uhn.fhir.jpa.search.IIdSearchTestTemplate; import ca.uhn.fhir.jpa.search.QuantitySearchParameterTestCases; import ca.uhn.fhir.jpa.search.builder.SearchBuilder; import ca.uhn.fhir.jpa.search.lastn.ElasticsearchRestClientFactory; @@ -2616,5 +2617,16 @@ protected void beforeOrAfterTestClass(TestContext testContext, DirtiesContext.Cl } } + @Nested + class IdTestCases implements IIdSearchTestTemplate { + @Override + public TestDaoSearch getSearch() { + return myTestDaoSearch; + } + @Override + public ITestDataBuilder getBuilder() { + return myTestDataBuilder; + } + } } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java index 5f12915e7478..7ca298ac6067 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java @@ -362,10 +362,8 @@ public void testApplyDeltaAdd_UsingCodeSystemWithElasticSearch() { myStorageSettings.setHibernateSearchIndexFullText(true); myStorageSettings.setHibernateSearchIndexSearchParams(true); myStorageSettings.setStoreResourceInHSearchIndex(true); - //Given: We have an existing NOT_PRESENT code system + //Given: We have a non-existent code system CodeSystem codeSystem = new CodeSystem(); - codeSystem.setUrl("http://example.com/cs"); - codeSystem.setContent(CodeSystem.CodeSystemContentMode.NOTPRESENT); myClient.create().resource(codeSystem).execute(); CodeSystem.ConceptDefinitionComponent chem = codeSystem.addConcept().setCode("CHEM").setDisplay("Chemistry"); chem.addConcept().setCode("HB").setDisplay("Hemoglobin"); From 19862397a4cd8cdaf06bb123c380b164eb6ff543 Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Sat, 1 Feb 2025 11:37:10 -0500 Subject: [PATCH 04/13] added tests --- .../jpa/dao/search/HSearchSortHelperImpl.java | 9 ++--- .../dao/search/HSearchSortHelperImplTest.java | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java index 8554b7fdeffc..1425524852e3 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java @@ -47,7 +47,6 @@ import static ca.uhn.fhir.jpa.model.search.HSearchIndexWriter.QTY_VALUE_NORM; import static ca.uhn.fhir.jpa.model.search.HSearchIndexWriter.SEARCH_PARAM_ROOT; import static ca.uhn.fhir.jpa.model.search.HSearchIndexWriter.URI_VALUE; -import static ca.uhn.fhir.rest.api.Constants.PARAM_LASTUPDATED; /** * Used to build HSearch sort clauses. @@ -154,7 +153,7 @@ Optional getSortClause(SearchSortFactory theF, SortSpec theSortSp @VisibleForTesting Optional getParamType(String theResourceTypeName, String theParamName) { ResourceSearchParams activeSearchParams = mySearchParamRegistry.getActiveSearchParams( - theResourceTypeName, ISearchParamRegistry.SearchParamLookupContextEnum.SEARCH); + theResourceTypeName, ISearchParamRegistry.SearchParamLookupContextEnum.SEARCH); RuntimeSearchParam searchParam = activeSearchParams.get(theParamName); if (searchParam == null) { RestSearchParameterTypeEnum paramType = this.getParamTypeOfSortingParams(theParamName); @@ -165,14 +164,12 @@ Optional getParamType(String theResourceTypeName, S } private RestSearchParameterTypeEnum getParamTypeOfSortingParams(String paramName) { - Map paramNameToParamType = - Map.of( + Map paramNameToParamType = Map.of( Constants.PARAM_LASTUPDATED, RestSearchParameterTypeEnum.DATE, Constants.PARAM_ID, RestSearchParameterTypeEnum.TOKEN, Constants.PARAM_TAG, RestSearchParameterTypeEnum.TOKEN, Constants.PARAM_SECURITY, RestSearchParameterTypeEnum.TOKEN, - Constants.PARAM_SOURCE, RestSearchParameterTypeEnum.TOKEN - ); + Constants.PARAM_SOURCE, RestSearchParameterTypeEnum.TOKEN); return paramNameToParamType.get(paramName); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java index 313381c6be5f..d93f0ab88388 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.dao.search; import ca.uhn.fhir.context.RuntimeSearchParam; +import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortSpec; @@ -80,6 +81,38 @@ void testGetParamType() { verify(mockResourceSearchParams, times(1)).get("the-param-name"); assertFalse(paramType.isEmpty()); } + /** + * In CDR, when HSearch is enabled, a lot of search params are missing. + * Validates that _id, _lastUpdated, _tag, _security and _source returns a type when absent from + * the search param registry. + */ + @Test + void testGetParamTypeWhenParamNameIsNotInSearchParamRegistry() { + //Given that we have + String resourceType = "CodeSystem"; + SortSpec [] sortSpecs = { + new SortSpec(Constants.PARAM_LASTUPDATED), + new SortSpec(Constants.PARAM_ID), + new SortSpec(Constants.PARAM_TAG), + new SortSpec(Constants.PARAM_SECURITY), + new SortSpec(Constants.PARAM_SOURCE) + }; + RestSearchParameterTypeEnum [] expectedSearchParamTypes = { + RestSearchParameterTypeEnum.DATE, + RestSearchParameterTypeEnum.TOKEN, + RestSearchParameterTypeEnum.TOKEN, + RestSearchParameterTypeEnum.TOKEN, + RestSearchParameterTypeEnum.TOKEN + }; + when(mockSearchParamRegistry.getActiveSearchParams(eq(resourceType), any())).thenReturn(mockResourceSearchParams); + for (int i=0; i < 5; i++) { + String absentSearchParam = sortSpecs[i].getParamName(); + Optional expectedSearchParamType = Optional.of(expectedSearchParamTypes[i]); + when(mockResourceSearchParams.get(absentSearchParam)).thenReturn(null); + Optional paramType = tested.getParamType(resourceType, absentSearchParam); + assertThat(paramType).isEqualTo(expectedSearchParamType); + } + } @Test void testGetSortClause() { From 211a2a946a27d68b942506b6fac328b5281b674e Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Sat, 1 Feb 2025 11:45:46 -0500 Subject: [PATCH 05/13] added comments --- .../ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java index d93f0ab88388..954a18aa415f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java @@ -88,7 +88,7 @@ void testGetParamType() { */ @Test void testGetParamTypeWhenParamNameIsNotInSearchParamRegistry() { - //Given that we have + //Given that we have params absent from the SearchParamsRegistry String resourceType = "CodeSystem"; SortSpec [] sortSpecs = { new SortSpec(Constants.PARAM_LASTUPDATED), @@ -105,11 +105,13 @@ void testGetParamTypeWhenParamNameIsNotInSearchParamRegistry() { RestSearchParameterTypeEnum.TOKEN }; when(mockSearchParamRegistry.getActiveSearchParams(eq(resourceType), any())).thenReturn(mockResourceSearchParams); + //Execute for (int i=0; i < 5; i++) { String absentSearchParam = sortSpecs[i].getParamName(); Optional expectedSearchParamType = Optional.of(expectedSearchParamTypes[i]); when(mockResourceSearchParams.get(absentSearchParam)).thenReturn(null); Optional paramType = tested.getParamType(resourceType, absentSearchParam); + //Validate assertThat(paramType).isEqualTo(expectedSearchParamType); } } From da6fa3ac911517c3344b07a8d359985d64790036 Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Tue, 4 Feb 2025 12:25:13 -0500 Subject: [PATCH 06/13] addressed comments --- .../jpa/dao/search/HSearchSortHelperImpl.java | 21 +++----- .../dao/search/HSearchSortHelperImplTest.java | 51 +++++++++---------- .../r4/TerminologyUploaderProviderR4Test.java | 4 ++ 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java index 1425524852e3..026fe8dc7173 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java @@ -53,6 +53,12 @@ */ public class HSearchSortHelperImpl implements IHSearchSortHelper { private static final Logger ourLog = LoggerFactory.getLogger(HSearchSortHelperImpl.class); + private static final Map sortingParamNameToParamType = Map.of( + Constants.PARAM_LASTUPDATED, RestSearchParameterTypeEnum.DATE, + Constants.PARAM_ID, RestSearchParameterTypeEnum.TOKEN, + Constants.PARAM_TAG, RestSearchParameterTypeEnum.TOKEN, + Constants.PARAM_SECURITY, RestSearchParameterTypeEnum.TOKEN, + Constants.PARAM_SOURCE, RestSearchParameterTypeEnum.TOKEN); /** Indicates which HSearch properties must be sorted for each RestSearchParameterTypeEnum **/ private Map> mySortPropertyListMap = Map.of( @@ -156,23 +162,12 @@ Optional getParamType(String theResourceTypeName, S theResourceTypeName, ISearchParamRegistry.SearchParamLookupContextEnum.SEARCH); RuntimeSearchParam searchParam = activeSearchParams.get(theParamName); if (searchParam == null) { - RestSearchParameterTypeEnum paramType = this.getParamTypeOfSortingParams(theParamName); - return paramType != null ? Optional.of(paramType) : Optional.empty(); + RestSearchParameterTypeEnum paramType = sortingParamNameToParamType.get(theParamName); + return Optional.ofNullable(paramType); } - return Optional.of(searchParam.getParamType()); } - private RestSearchParameterTypeEnum getParamTypeOfSortingParams(String paramName) { - Map paramNameToParamType = Map.of( - Constants.PARAM_LASTUPDATED, RestSearchParameterTypeEnum.DATE, - Constants.PARAM_ID, RestSearchParameterTypeEnum.TOKEN, - Constants.PARAM_TAG, RestSearchParameterTypeEnum.TOKEN, - Constants.PARAM_SECURITY, RestSearchParameterTypeEnum.TOKEN, - Constants.PARAM_SOURCE, RestSearchParameterTypeEnum.TOKEN); - return paramNameToParamType.get(paramName); - } - /** * Retrieves the generic property names (* instead of parameter name) from the configured map and * replaces the '*' segment by theParamName before returning the final property name list diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java index 954a18aa415f..f0e20e90a361 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java @@ -14,6 +14,9 @@ import org.hibernate.search.engine.search.sort.dsl.SortFinalStep; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; @@ -21,6 +24,7 @@ import java.util.List; import java.util.Optional; +import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -81,39 +85,34 @@ void testGetParamType() { verify(mockResourceSearchParams, times(1)).get("the-param-name"); assertFalse(paramType.isEmpty()); } + + private static Stream provideArgumentsForGetParamType() { + return Stream.of( + Arguments.of(new SortSpec(Constants.PARAM_LASTUPDATED), Optional.of(RestSearchParameterTypeEnum.DATE)), + Arguments.of(new SortSpec(Constants.PARAM_ID), Optional.of(RestSearchParameterTypeEnum.TOKEN)), + Arguments.of(new SortSpec(Constants.PARAM_TAG), Optional.of(RestSearchParameterTypeEnum.TOKEN)), + Arguments.of(new SortSpec(Constants.PARAM_SECURITY), Optional.of(RestSearchParameterTypeEnum.TOKEN)), + Arguments.of(new SortSpec(Constants.PARAM_SOURCE), Optional.of(RestSearchParameterTypeEnum.TOKEN)) + ); + } /** - * In CDR, when HSearch is enabled, a lot of search params are missing. - * Validates that _id, _lastUpdated, _tag, _security and _source returns a type when absent from + * Validates that getParamType() returns a param type when _id, _lastUpdated, _tag, _security and _source are absent from * the search param registry. */ - @Test - void testGetParamTypeWhenParamNameIsNotInSearchParamRegistry() { + @ParameterizedTest + @MethodSource("provideArgumentsForGetParamType") + void testGetParamTypeWhenParamNameIsNotInSearchParamRegistry(SortSpec sortSpec, Optional expectedSearchParamType) { //Given that we have params absent from the SearchParamsRegistry String resourceType = "CodeSystem"; - SortSpec [] sortSpecs = { - new SortSpec(Constants.PARAM_LASTUPDATED), - new SortSpec(Constants.PARAM_ID), - new SortSpec(Constants.PARAM_TAG), - new SortSpec(Constants.PARAM_SECURITY), - new SortSpec(Constants.PARAM_SOURCE) - }; - RestSearchParameterTypeEnum [] expectedSearchParamTypes = { - RestSearchParameterTypeEnum.DATE, - RestSearchParameterTypeEnum.TOKEN, - RestSearchParameterTypeEnum.TOKEN, - RestSearchParameterTypeEnum.TOKEN, - RestSearchParameterTypeEnum.TOKEN - }; + String absentSearchParam = sortSpec.getParamName(); when(mockSearchParamRegistry.getActiveSearchParams(eq(resourceType), any())).thenReturn(mockResourceSearchParams); + when(mockResourceSearchParams.get(absentSearchParam)).thenReturn(null); + //Execute - for (int i=0; i < 5; i++) { - String absentSearchParam = sortSpecs[i].getParamName(); - Optional expectedSearchParamType = Optional.of(expectedSearchParamTypes[i]); - when(mockResourceSearchParams.get(absentSearchParam)).thenReturn(null); - Optional paramType = tested.getParamType(resourceType, absentSearchParam); - //Validate - assertThat(paramType).isEqualTo(expectedSearchParamType); - } + Optional paramType = tested.getParamType(resourceType, absentSearchParam); + + //Validate + assertThat(paramType).isEqualTo(expectedSearchParamType); } @Test diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java index 7ca298ac6067..d38138fed0b0 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java @@ -362,6 +362,7 @@ public void testApplyDeltaAdd_UsingCodeSystemWithElasticSearch() { myStorageSettings.setHibernateSearchIndexFullText(true); myStorageSettings.setHibernateSearchIndexSearchParams(true); myStorageSettings.setStoreResourceInHSearchIndex(true); + //Given: We have a non-existent code system CodeSystem codeSystem = new CodeSystem(); myClient.create().resource(codeSystem).execute(); @@ -370,6 +371,7 @@ public void testApplyDeltaAdd_UsingCodeSystemWithElasticSearch() { chem.addConcept().setCode("NEUT").setDisplay("Neutrophils"); CodeSystem.ConceptDefinitionComponent micro = codeSystem.addConcept().setCode("MICRO").setDisplay("Microbiology"); micro.addConcept().setCode("C&S").setDisplay("Culture And Sensitivity"); + //Execute Parameters outcome = myClient .operation() @@ -379,9 +381,11 @@ public void testApplyDeltaAdd_UsingCodeSystemWithElasticSearch() { .andParameter(TerminologyUploaderProvider.PARAM_CODESYSTEM, codeSystem) .prettyPrint() .execute(); + //Validate IntegerType conceptCount = (IntegerType) outcome.getParameter("conceptCount").getValue(); assertThat(conceptCount.getValue()).isEqualTo(5); + //Teardown myStorageSettings.setHibernateSearchIndexFullText(false); myStorageSettings.setHibernateSearchIndexSearchParams(false); From 00b903802234e046a57ffeced08388d8ce674a11 Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Fri, 7 Feb 2025 10:35:24 -0500 Subject: [PATCH 07/13] updated static class property name --- .../ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java index 026fe8dc7173..45fda1c218de 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java @@ -53,7 +53,7 @@ */ public class HSearchSortHelperImpl implements IHSearchSortHelper { private static final Logger ourLog = LoggerFactory.getLogger(HSearchSortHelperImpl.class); - private static final Map sortingParamNameToParamType = Map.of( + private static final Map ourSortingParamNameToParamType = Map.of( Constants.PARAM_LASTUPDATED, RestSearchParameterTypeEnum.DATE, Constants.PARAM_ID, RestSearchParameterTypeEnum.TOKEN, Constants.PARAM_TAG, RestSearchParameterTypeEnum.TOKEN, @@ -162,7 +162,7 @@ Optional getParamType(String theResourceTypeName, S theResourceTypeName, ISearchParamRegistry.SearchParamLookupContextEnum.SEARCH); RuntimeSearchParam searchParam = activeSearchParams.get(theParamName); if (searchParam == null) { - RestSearchParameterTypeEnum paramType = sortingParamNameToParamType.get(theParamName); + RestSearchParameterTypeEnum paramType = ourSortingParamNameToParamType.get(theParamName); return Optional.ofNullable(paramType); } return Optional.of(searchParam.getParamType()); From 546004a9750a38f7445ab92f72feb5847cdfbae5 Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Fri, 7 Feb 2025 14:29:00 -0500 Subject: [PATCH 08/13] modified test --- .../jpa/dao/search/HSearchSortHelperImpl.java | 2 +- .../jpa/dao/search/HSearchSortHelperImplTest.java | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java index 45fda1c218de..9bd9c50fb44d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java @@ -53,7 +53,7 @@ */ public class HSearchSortHelperImpl implements IHSearchSortHelper { private static final Logger ourLog = LoggerFactory.getLogger(HSearchSortHelperImpl.class); - private static final Map ourSortingParamNameToParamType = Map.of( + public static final Map ourSortingParamNameToParamType = Map.of( Constants.PARAM_LASTUPDATED, RestSearchParameterTypeEnum.DATE, Constants.PARAM_ID, RestSearchParameterTypeEnum.TOKEN, Constants.PARAM_TAG, RestSearchParameterTypeEnum.TOKEN, diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java index f0e20e90a361..55a19dbd55fe 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java @@ -87,13 +87,14 @@ void testGetParamType() { } private static Stream provideArgumentsForGetParamType() { - return Stream.of( - Arguments.of(new SortSpec(Constants.PARAM_LASTUPDATED), Optional.of(RestSearchParameterTypeEnum.DATE)), - Arguments.of(new SortSpec(Constants.PARAM_ID), Optional.of(RestSearchParameterTypeEnum.TOKEN)), - Arguments.of(new SortSpec(Constants.PARAM_TAG), Optional.of(RestSearchParameterTypeEnum.TOKEN)), - Arguments.of(new SortSpec(Constants.PARAM_SECURITY), Optional.of(RestSearchParameterTypeEnum.TOKEN)), - Arguments.of(new SortSpec(Constants.PARAM_SOURCE), Optional.of(RestSearchParameterTypeEnum.TOKEN)) - ); + Stream.Builder retVal = Stream.builder(); + HSearchSortHelperImpl.ourSortingParamNameToParamType.forEach((theSortSpecName, theRestSearchParameterTypeEnum) -> + { + SortSpec sortSpec = new SortSpec(theSortSpecName); + retVal.add(Arguments.of(sortSpec, Optional.of(theRestSearchParameterTypeEnum))); + }); + + return retVal.build(); } /** * Validates that getParamType() returns a param type when _id, _lastUpdated, _tag, _security and _source are absent from From 82462e96961e2d5790dcc01881096b4de9ecc2b1 Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Mon, 10 Feb 2025 10:47:52 -0500 Subject: [PATCH 09/13] added changelog and addressed more comments --- .../6697-missing-search-params-with-hsearch-enabled.yaml | 4 ++++ .../ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java | 4 ++++ .../uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java | 1 - .../jpa/provider/r4/TerminologyUploaderProviderR4Test.java | 5 ----- 4 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6697-missing-search-params-with-hsearch-enabled.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6697-missing-search-params-with-hsearch-enabled.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6697-missing-search-params-with-hsearch-enabled.yaml new file mode 100644 index 000000000000..90b604357804 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6697-missing-search-params-with-hsearch-enabled.yaml @@ -0,0 +1,4 @@ +--- +type: fix +issue: 6697 +title: "Previously, using the $apply-codesystem-delta-add operation with hibernate search enabled and automatic support of default search params turned off resulted in an invalid sort specification error. This has been fixed." diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java index 9bd9c50fb44d..41a0964fb152 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java @@ -47,6 +47,7 @@ import static ca.uhn.fhir.jpa.model.search.HSearchIndexWriter.QTY_VALUE_NORM; import static ca.uhn.fhir.jpa.model.search.HSearchIndexWriter.SEARCH_PARAM_ROOT; import static ca.uhn.fhir.jpa.model.search.HSearchIndexWriter.URI_VALUE; +import static java.util.Objects.isNull; /** * Used to build HSearch sort clauses. @@ -158,6 +159,9 @@ Optional getSortClause(SearchSortFactory theF, SortSpec theSortSp */ @VisibleForTesting Optional getParamType(String theResourceTypeName, String theParamName) { + if (isNull(theParamName)){ + return Optional.empty(); + } ResourceSearchParams activeSearchParams = mySearchParamRegistry.getActiveSearchParams( theResourceTypeName, ISearchParamRegistry.SearchParamLookupContextEnum.SEARCH); RuntimeSearchParam searchParam = activeSearchParams.get(theParamName); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java index 55a19dbd55fe..cb87e70d2a55 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java @@ -93,7 +93,6 @@ private static Stream provideArgumentsForGetParamType() { SortSpec sortSpec = new SortSpec(theSortSpecName); retVal.add(Arguments.of(sortSpec, Optional.of(theRestSearchParameterTypeEnum))); }); - return retVal.build(); } /** diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java index d38138fed0b0..36a122d3bc64 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java @@ -385,11 +385,6 @@ public void testApplyDeltaAdd_UsingCodeSystemWithElasticSearch() { //Validate IntegerType conceptCount = (IntegerType) outcome.getParameter("conceptCount").getValue(); assertThat(conceptCount.getValue()).isEqualTo(5); - - //Teardown - myStorageSettings.setHibernateSearchIndexFullText(false); - myStorageSettings.setHibernateSearchIndexSearchParams(false); - myStorageSettings.setStoreResourceInHSearchIndex(false); } @Test From 424159f71a7576729cf229346627be643de8dff5 Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Mon, 10 Feb 2025 10:51:54 -0500 Subject: [PATCH 10/13] ran mvn spotless --- .../java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java index 41a0964fb152..bbdb151af9d2 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java @@ -159,7 +159,7 @@ Optional getSortClause(SearchSortFactory theF, SortSpec theSortSp */ @VisibleForTesting Optional getParamType(String theResourceTypeName, String theParamName) { - if (isNull(theParamName)){ + if (isNull(theParamName)) { return Optional.empty(); } ResourceSearchParams activeSearchParams = mySearchParamRegistry.getActiveSearchParams( From e0977b044b866b19fe3986a69e7d9a1be879a040 Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Mon, 10 Feb 2025 12:39:09 -0500 Subject: [PATCH 11/13] addressed comments --- .../6697-missing-search-params-with-hsearch-enabled.yaml | 2 +- .../ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java | 5 +---- .../uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java | 1 + 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6697-missing-search-params-with-hsearch-enabled.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6697-missing-search-params-with-hsearch-enabled.yaml index 90b604357804..6275acddcb4a 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6697-missing-search-params-with-hsearch-enabled.yaml +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_8_0/6697-missing-search-params-with-hsearch-enabled.yaml @@ -1,4 +1,4 @@ --- type: fix issue: 6697 -title: "Previously, using the $apply-codesystem-delta-add operation with hibernate search enabled and automatic support of default search params turned off resulted in an invalid sort specification error. This has been fixed." +title: "Previously, operation $apply-codesystem-delta-add issued with Hibernate Search enabled and default search params option turned off resulted in an invalid sort specification error. This has been fixed." diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java index bbdb151af9d2..2d950a5ae28a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java @@ -159,14 +159,11 @@ Optional getSortClause(SearchSortFactory theF, SortSpec theSortSp */ @VisibleForTesting Optional getParamType(String theResourceTypeName, String theParamName) { - if (isNull(theParamName)) { - return Optional.empty(); - } ResourceSearchParams activeSearchParams = mySearchParamRegistry.getActiveSearchParams( theResourceTypeName, ISearchParamRegistry.SearchParamLookupContextEnum.SEARCH); RuntimeSearchParam searchParam = activeSearchParams.get(theParamName); if (searchParam == null) { - RestSearchParameterTypeEnum paramType = ourSortingParamNameToParamType.get(theParamName); + RestSearchParameterTypeEnum paramType = isNull(theParamName) ? null : ourSortingParamNameToParamType.get(theParamName); return Optional.ofNullable(paramType); } return Optional.of(searchParam.getParamType()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java index cb87e70d2a55..55a19dbd55fe 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImplTest.java @@ -93,6 +93,7 @@ private static Stream provideArgumentsForGetParamType() { SortSpec sortSpec = new SortSpec(theSortSpecName); retVal.add(Arguments.of(sortSpec, Optional.of(theRestSearchParameterTypeEnum))); }); + return retVal.build(); } /** From d6dbc6e258f4b628f14a165095428d2fc5662ad0 Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Mon, 10 Feb 2025 12:43:31 -0500 Subject: [PATCH 12/13] ran mvn spotless --- .../java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java index 2d950a5ae28a..7b4f7ee432a4 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java @@ -163,7 +163,8 @@ Optional getParamType(String theResourceTypeName, S theResourceTypeName, ISearchParamRegistry.SearchParamLookupContextEnum.SEARCH); RuntimeSearchParam searchParam = activeSearchParams.get(theParamName); if (searchParam == null) { - RestSearchParameterTypeEnum paramType = isNull(theParamName) ? null : ourSortingParamNameToParamType.get(theParamName); + RestSearchParameterTypeEnum paramType = + isNull(theParamName) ? null : ourSortingParamNameToParamType.get(theParamName); return Optional.ofNullable(paramType); } return Optional.of(searchParam.getParamType()); From 6e07c43dfb667672e684009017dfcc58612688a6 Mon Sep 17 00:00:00 2001 From: Abayomi Adebowale Date: Mon, 10 Feb 2025 13:36:01 -0500 Subject: [PATCH 13/13] addressed comments --- .../fhir/jpa/dao/search/HSearchSortHelperImpl.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java index 7b4f7ee432a4..232b8ab1ccc1 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/HSearchSortHelperImpl.java @@ -159,15 +159,20 @@ Optional getSortClause(SearchSortFactory theF, SortSpec theSortSp */ @VisibleForTesting Optional getParamType(String theResourceTypeName, String theParamName) { + RestSearchParameterTypeEnum value; + ResourceSearchParams activeSearchParams = mySearchParamRegistry.getActiveSearchParams( theResourceTypeName, ISearchParamRegistry.SearchParamLookupContextEnum.SEARCH); RuntimeSearchParam searchParam = activeSearchParams.get(theParamName); + if (searchParam == null) { - RestSearchParameterTypeEnum paramType = - isNull(theParamName) ? null : ourSortingParamNameToParamType.get(theParamName); - return Optional.ofNullable(paramType); + value = isNull(theParamName) ? null : ourSortingParamNameToParamType.get(theParamName); + + } else { + value = searchParam.getParamType(); } - return Optional.of(searchParam.getParamType()); + + return Optional.ofNullable(value); } /**