diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateParam.java index 41d05aa45c5..f35dcae17f6 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateParam.java @@ -23,21 +23,23 @@ package ca.uhn.fhir.rest.param; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IQueryParameterOr; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; +import ca.uhn.fhir.model.api.annotation.SimpleSetter; import ca.uhn.fhir.model.primitive.BaseDateTimeDt; import ca.uhn.fhir.model.primitive.DateDt; import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.InstantDt; +import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.rest.api.QualifiedParamList; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.util.ObjectUtil; import ca.uhn.fhir.util.ValidateUtil; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.commons.lang3.time.DateUtils; import org.hl7.fhir.instance.model.api.IPrimitiveType; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -222,7 +224,7 @@ public class DateParam extends BaseParamWithPrefix implements /*IQuer if (theParameters.size() == 1) { setValueAsString(theParameters.get(0)); } else if (theParameters.size() > 1) { - throw new InvalidRequestException("This server does not support multi-valued dates for this paramater: " + theParameters); + throw new InvalidRequestException("This server does not support multi-valued dates for this parameter: " + theParameters); } } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java index 434f7664e3e..a63d72988dc 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java @@ -2,15 +2,14 @@ package ca.uhn.fhir.rest.param; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IQueryParameterAnd; +import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.rest.api.QualifiedParamList; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import org.apache.commons.lang3.time.DateUtils; import org.hl7.fhir.instance.model.api.IPrimitiveType; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; import static ca.uhn.fhir.rest.param.ParamPrefixEnum.*; import static java.lang.String.format; @@ -260,6 +259,14 @@ public class DateRangeParam implements IQueryParameterAnd { return null; } Date retVal = myLowerBound.getValue(); + + if (myLowerBound.getPrecision().ordinal() <= TemporalPrecisionEnum.DAY.ordinal()) { + Calendar cal = DateUtils.toCalendar(retVal); + cal.setTimeZone(TimeZone.getTimeZone("GMT-11:30")); + cal = DateUtils.truncate(cal, Calendar.DATE); + retVal = cal.getTime(); + } + if (myLowerBound.getPrefix() != null) { switch (myLowerBound.getPrefix()) { case GREATERTHAN: @@ -306,7 +313,16 @@ public class DateRangeParam implements IQueryParameterAnd { if (myUpperBound == null) { return null; } + Date retVal = myUpperBound.getValue(); + + if (myLowerBound.getPrecision().ordinal() <= TemporalPrecisionEnum.DAY.ordinal()) { + Calendar cal = DateUtils.toCalendar(retVal); + cal.setTimeZone(TimeZone.getTimeZone("GMT+11:30")); + cal = DateUtils.truncate(cal, Calendar.DATE); + retVal = cal.getTime(); + } + if (myUpperBound.getPrefix() != null) { switch (myUpperBound.getPrefix()) { case LESSTHAN: diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java index caf57c079ea..2e5d8aadde9 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java @@ -87,7 +87,7 @@ public class ParametersUtil { addClientParameter(theContext, next, theTargetResource, paramChild, paramChildElem, theName); } } else { - throw new IllegalArgumentException("Don't know how to handle value of type " + theValue.getClass() + " for paramater " + theName); + throw new IllegalArgumentException("Don't know how to handle value of type " + theValue.getClass() + " for parameter " + theName); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java index 5cf4bd44de3..706f4d1bdd9 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.config; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java index 31377f9aaca..6cc035be6ae 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java @@ -22,9 +22,9 @@ import java.util.*; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoRegistry.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoRegistry.java index abee9e15ded..5eb2fd01f6b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoRegistry.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoRegistry.java @@ -1,7 +1,28 @@ package ca.uhn.fhir.jpa.dao; +/*- + * #%L + * HAPI FHIR JPA Server + * %% + * Copyright (C) 2014 - 2018 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeResourceDefinition; +import ca.uhn.fhir.rest.param.HasAndListParam; import org.apache.commons.lang3.Validate; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; @@ -17,27 +38,32 @@ public class DaoRegistry implements ApplicationContextAware { @Autowired private FhirContext myCtx; - private Map> myResourceNameToResourceDao = new HashMap<>(); + private volatile Map> myResourceNameToResourceDao = new HashMap<>(); @Override public void setApplicationContext(ApplicationContext theApplicationContext) throws BeansException { myAppCtx = theApplicationContext; } - @PostConstruct - public void start() { - Map resourceDaos = myAppCtx.getBeansOfType(IFhirResourceDao.class); - for (IFhirResourceDao nextResourceDao : resourceDaos.values()) { - RuntimeResourceDefinition nextResourceDef = myCtx.getResourceDefinition(nextResourceDao.getResourceType()); - myResourceNameToResourceDao.put(nextResourceDef.getName(), nextResourceDao); - } - } - public IFhirResourceDao getResourceDao(String theResourceName) { - IFhirResourceDao retVal = myResourceNameToResourceDao.get(theResourceName); + IFhirResourceDao retVal = getResourceNameToResourceDao().get(theResourceName); Validate.notNull(retVal, "No DAO exists for resource type %s", theResourceName); return retVal; } + private Map> getResourceNameToResourceDao() { + Map> retVal = myResourceNameToResourceDao; + if (retVal == null) { + retVal = new HashMap<>(); + Map resourceDaos = myAppCtx.getBeansOfType(IFhirResourceDao.class); + for (IFhirResourceDao nextResourceDao : resourceDaos.values()) { + RuntimeResourceDefinition nextResourceDef = myCtx.getResourceDefinition(nextResourceDao.getResourceType()); + retVal.put(nextResourceDef.getName(), nextResourceDao); + } + myResourceNameToResourceDao = retVal; + } + return retVal; + } + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IResultIterator.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IResultIterator.java index 7e375fa5734..b479a2fa1ae 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IResultIterator.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IResultIterator.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jpa.dao; +/*- + * #%L + * HAPI FHIR JPA Server + * %% + * Copyright (C) 2014 - 2018 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.util.Iterator; public interface IResultIterator extends Iterator { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/ISearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/ISearchBuilder.java index ff6c0c6be0c..06281a3e022 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/ISearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/ISearchBuilder.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.dao; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java index 0dcafde5661..c209d5e5b2b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java @@ -997,6 +997,8 @@ public class SearchBuilder implements ISearchBuilder { } } + ourLog.trace("Date range is {} - {}", lowerBound, upperBound); + if (lb != null && ub != null) { return (theBuilder.and(lb, ub)); } else if (lb != null) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java index 8bcf3b93d42..a525889b905 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java @@ -31,9 +31,9 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/Search.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/Search.java index d6ecad30f29..ef8846df1ab 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/Search.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/Search.java @@ -24,9 +24,9 @@ import static org.apache.commons.lang3.StringUtils.left; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/SearchStatusEnum.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/SearchStatusEnum.java index 2d70f39ce9b..cc8419df6c1 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/SearchStatusEnum.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/SearchStatusEnum.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.entity; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/SubscriptionRetriggeringProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/SubscriptionRetriggeringProvider.java index da7b7843fe5..736df36f37e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/SubscriptionRetriggeringProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/SubscriptionRetriggeringProvider.java @@ -29,16 +29,15 @@ import ca.uhn.fhir.jpa.util.JpaConstants; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; -import ca.uhn.fhir.rest.annotation.RequiredParam; import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.server.IResourceProvider; -import ca.uhn.fhir.util.OperationOutcomeUtil; +import ca.uhn.fhir.util.ParametersUtil; import ca.uhn.fhir.util.ValidateUtil; -import org.hl7.fhir.dstu3.model.UriType; import org.hl7.fhir.instance.model.IdType; -import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; +import org.hl7.fhir.instance.model.api.IBaseParameters; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; @@ -54,7 +53,7 @@ public class SubscriptionRetriggeringProvider implements IResourceProvider { private List> mySubscriptionInterceptorList; @Operation(name= JpaConstants.OPERATION_RETRIGGER_SUBSCRIPTION) - public IBaseOperationOutcome reTriggerSubscription( + public IBaseParameters reTriggerSubscription( @IdParam IIdType theSubscriptionId, @OperationParam(name= RESOURCE_ID) UriParam theResourceId) { @@ -77,8 +76,10 @@ public class SubscriptionRetriggeringProvider implements IResourceProvider { next.submitResourceModified(msg); } - IBaseOperationOutcome retVal = OperationOutcomeUtil.newInstance(myFhirContext); - OperationOutcomeUtil.addIssue(myFhirContext, retVal, "information", "Triggered resource " + theResourceId.getValue() + " for subscription", null, null); + IBaseParameters retVal = ParametersUtil.newInstance(myFhirContext); + IPrimitiveType value = (IPrimitiveType) myFhirContext.getElementDefinition("string").newInstance(); + value.setValueAsString("Triggered resource " + theResourceId.getValue() + " for subscription"); + ParametersUtil.addParameterToParameters(myFhirContext, retVal, "information", value); return retVal; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java index 59e362241e9..7f9fa948bfb 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.search; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/StaleSearchDeletingSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/StaleSearchDeletingSvcImpl.java index 356c697f173..5e90ad0dd27 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/StaleSearchDeletingSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/StaleSearchDeletingSvcImpl.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.search; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java index 5557e57e067..943fc6b0451 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java @@ -105,7 +105,7 @@ public class TestR4Config extends BaseJavaConfigR4 { DataSource dataSource = ProxyDataSourceBuilder .create(retVal) - .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL") +// .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL") .logSlowQueryBySlf4j(10, TimeUnit.SECONDS) .countQuery(new ThreadQueryCountHolder()) .build(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java index e62a5e8bd47..9ae77a3b429 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java @@ -38,10 +38,7 @@ import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; -import java.util.Date; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; @@ -3227,6 +3224,79 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { } + @Test + public void testDateSearchParametersShouldBeTimezoneIndependent() { + + createObservationWithEffective("NO1", "2011-01-02T23:00:00-11:30"); + createObservationWithEffective("NO2", "2011-01-03T00:00:00+01:00"); + + createObservationWithEffective("YES01", "2011-01-02T00:00:00-11:30"); + createObservationWithEffective("YES02", "2011-01-02T00:00:00-10:00"); + createObservationWithEffective("YES03", "2011-01-02T00:00:00-09:00"); + createObservationWithEffective("YES04", "2011-01-02T00:00:00-08:00"); + createObservationWithEffective("YES05", "2011-01-02T00:00:00-07:00"); + createObservationWithEffective("YES06", "2011-01-02T00:00:00-06:00"); + createObservationWithEffective("YES07", "2011-01-02T00:00:00-05:00"); + createObservationWithEffective("YES08", "2011-01-02T00:00:00-04:00"); + createObservationWithEffective("YES09", "2011-01-02T00:00:00-03:00"); + createObservationWithEffective("YES10", "2011-01-02T00:00:00-02:00"); + createObservationWithEffective("YES11", "2011-01-02T00:00:00-01:00"); + createObservationWithEffective("YES12", "2011-01-02T00:00:00Z"); + createObservationWithEffective("YES13", "2011-01-02T00:00:00+01:00"); + createObservationWithEffective("YES14", "2011-01-02T00:00:00+02:00"); + createObservationWithEffective("YES15", "2011-01-02T00:00:00+03:00"); + createObservationWithEffective("YES16", "2011-01-02T00:00:00+04:00"); + createObservationWithEffective("YES17", "2011-01-02T00:00:00+05:00"); + createObservationWithEffective("YES18", "2011-01-02T00:00:00+06:00"); + createObservationWithEffective("YES19", "2011-01-02T00:00:00+07:00"); + createObservationWithEffective("YES20", "2011-01-02T00:00:00+08:00"); + createObservationWithEffective("YES21", "2011-01-02T00:00:00+09:00"); + createObservationWithEffective("YES22", "2011-01-02T00:00:00+10:00"); + createObservationWithEffective("YES23", "2011-01-02T00:00:00+11:00"); + + + SearchParameterMap map = new SearchParameterMap(); + map.setLoadSynchronous(true); + map.add(Observation.SP_DATE, new DateParam("2011-01-02")); + IBundleProvider results = myObservationDao.search(map); + List values = toUnqualifiedVersionlessIdValues(results); + Collections.sort(values); + assertThat(values.toString(), values, contains( + "Observation/YES01", + "Observation/YES02", + "Observation/YES03", + "Observation/YES04", + "Observation/YES05", + "Observation/YES06", + "Observation/YES07", + "Observation/YES08", + "Observation/YES09", + "Observation/YES10", + "Observation/YES11", + "Observation/YES12", + "Observation/YES13", + "Observation/YES14", + "Observation/YES15", + "Observation/YES16", + "Observation/YES17", + "Observation/YES18", + "Observation/YES19", + "Observation/YES20", + "Observation/YES21", + "Observation/YES22", + "Observation/YES23" + )); + } + + private void createObservationWithEffective(String theId, String theEffective) { + Observation obs = new Observation(); + obs.setId(theId); + obs.setEffective(new DateTimeType(theEffective)); + myObservationDao.update(obs); + + ourLog.info("Obs {} has time {}", theId, obs.getEffectiveDateTimeType().getValue().toString()); + } + /** * See #744 */ diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RetriggeringDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RetriggeringDstu3Test.java index f2eb11e0653..7bd2bd74391 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RetriggeringDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RetriggeringDstu3Test.java @@ -144,8 +144,8 @@ public class RetriggeringDstu3Test extends BaseResourceProviderDstu3Test { .withParameter(Parameters.class, SubscriptionRetriggeringProvider.RESOURCE_ID, new UriType(obsId.toUnqualifiedVersionless().getValue())) .execute(); - OperationOutcome oo = (OperationOutcome) response.getParameter().get(0).getResource(); - assertEquals("Triggered resource " + obsId.getValue() + " for subscription", oo.getIssue().get(0).getDiagnostics()); + String responseValue = response.getParameter().get(0).getValue().primitiveValue(); + assertEquals("Triggered resource " + obsId.getValue() + " for subscription", responseValue); waitForQueueToDrain(); waitForSize(0, ourCreatedObservations); @@ -181,8 +181,8 @@ public class RetriggeringDstu3Test extends BaseResourceProviderDstu3Test { .withParameter(Parameters.class, SubscriptionRetriggeringProvider.RESOURCE_ID, new UriType(obsId.toUnqualifiedVersionless().getValue())) .execute(); - OperationOutcome oo = (OperationOutcome) response.getParameter().get(0).getResource(); - assertEquals("Triggered resource " + obsId.getValue() + " for subscription", oo.getIssue().get(0).getDiagnostics()); + String responseValue = response.getParameter().get(0).getValue().primitiveValue(); + assertEquals("Triggered resource " + obsId.getValue() + " for subscription", responseValue); waitForQueueToDrain(); waitForSize(0, ourCreatedObservations); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java index f832ba8e22a..dce9ff20d27 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java @@ -39,6 +39,14 @@ public class DateRangeParamTest { TestUtil.clearAllStaticFieldsForUnitTest(); } + @Test + public void testGetLowerRange() { + ourLog.info("Time is {}", new Date()); + + DateRangeParam param = new DateRangeParam(new DateParam("2011-01-02")); + ourLog.info("Adjusted time is " + param.getLowerBoundAsInstant().toString()); + } + private static DateRangeParam create(String theLower, String theUpper) throws InvalidRequestException { DateRangeParam p = new DateRangeParam(); List tokens = new ArrayList(); diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 7fea779b76f..e2fd6ff55cd 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -65,6 +65,12 @@ DatConfig#setSearchPreFetchThresholds()]]> for configuration of this feature. + + When performing a JPA server using a date parameter, if a time is not specified in + the query URL, the date range is expanded slightly to include all possible + timezones where the date that could apply. This makes the search slightly more + inclusive, which errs on the side of caution. +