diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderDate.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderDate.java index a04c8a674f5..eebf0f2987f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderDate.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderDate.java @@ -176,15 +176,15 @@ public class PredicateBuilderDate extends BasePredicateBuilder implements IPredi lb = theBuilder.greaterThan(theFrom.get("myValueHigh"), upperBoundInstant); } } else if (operation == SearchFilterParser.CompareOperation.ge) { - if (lowerBoundInstant == null) { - throw new InvalidRequestException("lowerBound value not correctly specified for compare operation"); - } - if (isOrdinalComparison) { - lb = theBuilder.greaterThanOrEqualTo(theFrom.get("myValueLowDateOrdinal"), theRange.getLowerBoundAsDateInteger()); - } else { - lb = theBuilder.greaterThanOrEqualTo(theFrom.get("myValueLow"), lowerBoundInstant); - } - } else if (operation == SearchFilterParser.CompareOperation.ne) { + if (lowerBoundInstant == null) { + throw new InvalidRequestException("lowerBound value not correctly specified for compare operation"); + } + if (isOrdinalComparison) { + lb = theBuilder.greaterThanOrEqualTo(theFrom.get("myValueLowDateOrdinal"), theRange.getLowerBoundAsDateInteger()); + } else { + lb = theBuilder.greaterThanOrEqualTo(theFrom.get("myValueLow"), lowerBoundInstant); + } + } else if (operation == SearchFilterParser.CompareOperation.ne) { if ((lowerBoundInstant == null) || (upperBoundInstant == null)) { throw new InvalidRequestException("lowerBound and/or upperBound value not correctly specified for compare operation"); @@ -224,6 +224,7 @@ public class PredicateBuilderDate extends BasePredicateBuilder implements IPredi gt = theBuilder.lessThanOrEqualTo(theFrom.get("myValueLow"), upperBoundInstant); lt = theBuilder.lessThanOrEqualTo(theFrom.get("myValueHigh"), upperBoundInstant); } + if (theRange.getUpperBound().getPrefix() == ParamPrefixEnum.ENDS_BEFORE || theRange.getUpperBound().getPrefix() == ParamPrefixEnum.EQUAL) { ub = lt; } else { diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java index 7731f589210..22ee5267be5 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java @@ -68,6 +68,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { version.onTable("HFJ_RES_VER").dropColumn("20200218.2", "FORCED_ID_PID"); version.onTable("HFJ_RES_VER").addForeignKey("20200218.3", "FK_RESOURCE_HISTORY_RESOURCE").toColumn("RES_ID").references("HFJ_RESOURCE", "RES_ID"); version.onTable("HFJ_RES_VER").modifyColumn("20200220.1", "RES_ID").nonNullable().failureAllowed().withType(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + // } protected void init420() { // 20191015 - 20200217 diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamDate.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamDate.java index e355cce822b..eb5e6097c6b 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamDate.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamDate.java @@ -29,12 +29,10 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -import org.apache.commons.lang3.time.DateUtils; import org.hibernate.search.annotations.Field; import org.hl7.fhir.r4.model.DateTimeType; import javax.persistence.*; -import java.util.Calendar; import java.util.Date; @Embeddable @@ -57,10 +55,15 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar @Field public Date myValueLow; + /** + * Field which stores an integer representation of YYYYMDD as calculated by Calendar + * e.g. 2019-01-20 -> 2019020 + * (note that the month is 0 since calendar month counting starts at 0. + */ @Column(name="SP_VALUE_LOW_DATE_ORDINAL") - public int myValueLowDateOrdinal; + public Integer myValueLowDateOrdinal; @Column(name="SP_VALUE_HIGH_DATE_ORDINAL") - public int myValueHighDateOrdinal; + public Integer myValueHighDateOrdinal; @Transient private transient String myOriginalValue; @@ -99,13 +102,7 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar this.myValueHighDateOrdinal = generateOrdinalDateInteger(theHigh); } private int generateOrdinalDateInteger(Date theDate) { - Calendar calendar = DateUtils.toCalendar(theDate); - String ordinalDateString = new StringBuilder() - .append(calendar.get(Calendar.YEAR)) - .append(calendar.get(Calendar.MONTH)) - .append(calendar.get(Calendar.DAY_OF_MONTH)) - .toString(); - return Integer.parseInt(ordinalDateString); + return ca.uhn.fhir.util.DateUtils.convertDatetoDayInteger(theDate); } private void computeValueLowDateOrdinal(Date theLow) {