diff --git a/hapi-fhir-jpaserver-searchparam/pom.xml b/hapi-fhir-jpaserver-searchparam/pom.xml index 0c6bebff682..8fd32350fa2 100755 --- a/hapi-fhir-jpaserver-searchparam/pom.xml +++ b/hapi-fhir-jpaserver-searchparam/pom.xml @@ -107,6 +107,16 @@ logback-classic test + + org.springframework + spring-test + test + + + org.springframework.boot + spring-boot-test + test + diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcher.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcher.java index f09bdabcc53..6eb2e98d19a 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcher.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcher.java @@ -190,6 +190,7 @@ public class InMemoryResourceMatcher { return theAndOrParams.stream().flatMap(List::stream).anyMatch(param -> param.getQueryParameterQualifier() != null); } + // FIXME KHS change to hasUnsupportedPrefixes private boolean hasPrefixes(List> theAndOrParams) { Predicate hasPrefixPredicate = param -> param instanceof BaseParamWithPrefix && ((BaseParamWithPrefix) param).getPrefix() != null; diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherTest.java new file mode 100644 index 00000000000..bb9115b017c --- /dev/null +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherTest.java @@ -0,0 +1,65 @@ +package ca.uhn.fhir.jpa.searchparam.matcher; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.RuntimeSearchParam; +import ca.uhn.fhir.jpa.searchparam.MatchUrlService; +import ca.uhn.fhir.jpa.searchparam.extractor.ResourceIndexedSearchParams; +import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; +import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; +import org.hl7.fhir.r5.model.DateTimeType; +import org.hl7.fhir.r5.model.Observation; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@RunWith(SpringRunner.class) +public class InMemoryResourceMatcherTest { + @Autowired + InMemoryResourceMatcher myInMemoryResourceMatcher; + + @MockBean + ISearchParamRegistry mySearchParamRegistry; + + @Configuration + public static class SpringConfig { + @Bean + InMemoryResourceMatcher inMemoryResourceMatcher() { + return new InMemoryResourceMatcher(); + } + + @Bean + MatchUrlService matchUrlService() { + return new MatchUrlService(); + } + + @Bean + FhirContext fhirContext() { + return FhirContext.forR5(); + } + } + + @Before + public void before() { + RuntimeSearchParam searchParams = new RuntimeSearchParam(null, null, null, null, "Observation.effective", RestSearchParameterTypeEnum.DATE, null, null, null, RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE); + when(mySearchParamRegistry.getSearchParamByName(any(), any())).thenReturn(searchParams); + } + + @Test + public void testDateGe() { + Observation observation = new Observation(); + observation.setEffective(new DateTimeType("1970-01-01")); + ResourceIndexedSearchParams searchParams = new ResourceIndexedSearchParams(); + InMemoryMatchResult result = myInMemoryResourceMatcher.match("date=ge1965-08-09", observation, searchParams); + assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.matched()); + } +}