fix bugs in calculating ordinal date
This commit is contained in:
parent
df9e86ec66
commit
165f5fd808
|
@ -171,15 +171,19 @@ public final class DateUtils {
|
||||||
return cal.getTime();
|
return cal.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static int convertDatetoDayInteger(final Date theDateValue) {
|
public static int convertDatetoDayInteger(final Date theDateValue) {
|
||||||
notNull(theDateValue, "Date value");
|
notNull(theDateValue, "Date value");
|
||||||
Calendar cal = org.apache.commons.lang3.time.DateUtils.toCalendar(theDateValue);
|
|
||||||
SimpleDateFormat format = new SimpleDateFormat(PATTERN_INTEGER_DATE);
|
SimpleDateFormat format = new SimpleDateFormat(PATTERN_INTEGER_DATE);
|
||||||
String theDateString = format.format(theDateValue);
|
String theDateString = format.format(theDateValue);
|
||||||
return Integer.parseInt(theDateString);
|
return Integer.parseInt(theDateString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String convertDateToIso8601String(final Date theDateValue){
|
||||||
|
notNull(theDateValue, "Date value");
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
||||||
|
return format.format(theDateValue);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the given date according to the RFC 1123 pattern.
|
* Formats the given date according to the RFC 1123 pattern.
|
||||||
*
|
*
|
||||||
|
|
|
@ -26,6 +26,7 @@ import ca.uhn.fhir.model.primitive.InstantDt;
|
||||||
import ca.uhn.fhir.rest.param.DateParam;
|
import ca.uhn.fhir.rest.param.DateParam;
|
||||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||||
import ca.uhn.fhir.util.DateUtils;
|
import ca.uhn.fhir.util.DateUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
@ -34,6 +35,7 @@ import org.hibernate.search.annotations.Field;
|
||||||
import org.hl7.fhir.r4.model.DateTimeType;
|
import org.hl7.fhir.r4.model.DateTimeType;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Embeddable
|
@Embeddable
|
||||||
|
@ -93,14 +95,22 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar
|
||||||
setParamName(theParamName);
|
setParamName(theParamName);
|
||||||
setValueLow(theLow);
|
setValueLow(theLow);
|
||||||
setValueHigh(theHigh);
|
setValueHigh(theHigh);
|
||||||
|
if (theHigh != null && theHighString == null) {
|
||||||
|
theHighString = DateUtils.convertDateToIso8601String(theHigh);
|
||||||
|
}
|
||||||
|
if (theLow != null && theLowString == null) {
|
||||||
|
theLowString = DateUtils.convertDateToIso8601String(theLow);
|
||||||
|
}
|
||||||
computeValueHighDateOrdinal(theHighString);
|
computeValueHighDateOrdinal(theHighString);
|
||||||
computeValueLowDateOrdinal(theLowString);
|
computeValueLowDateOrdinal(theLowString);
|
||||||
myOriginalValue = theOriginalValue;
|
myOriginalValue = theOriginalValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void computeValueHighDateOrdinal(String theHigh) {
|
private void computeValueHighDateOrdinal(String theHigh) {
|
||||||
|
if (!StringUtils.isBlank(theHigh)) {
|
||||||
this.myValueHighDateOrdinal = generateOrdinalDateInteger(theHigh);
|
this.myValueHighDateOrdinal = generateOrdinalDateInteger(theHigh);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private int generateOrdinalDateInteger(String theDateString){
|
private int generateOrdinalDateInteger(String theDateString){
|
||||||
if (theDateString.contains("T")) {
|
if (theDateString.contains("T")) {
|
||||||
theDateString = theDateString.substring(0, theDateString.indexOf("T"));
|
theDateString = theDateString.substring(0, theDateString.indexOf("T"));
|
||||||
|
@ -110,8 +120,10 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar
|
||||||
}
|
}
|
||||||
|
|
||||||
private void computeValueLowDateOrdinal(String theLow) {
|
private void computeValueLowDateOrdinal(String theLow) {
|
||||||
|
if (StringUtils.isNotBlank(theLow)) {
|
||||||
this.myValueLowDateOrdinal = generateOrdinalDateInteger(theLow);
|
this.myValueLowDateOrdinal = generateOrdinalDateInteger(theLow);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getValueLowDateOrdinal() {
|
public Integer getValueLowDateOrdinal() {
|
||||||
return myValueLowDateOrdinal;
|
return myValueLowDateOrdinal;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -45,8 +46,8 @@ public class ResourceIndexedSearchParamDateTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsIsTrueForMatchingDates() {
|
public void equalsIsTrueForMatchingDates() {
|
||||||
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date1A, date1A.toString(), date2A, date2A.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date1A, null, date2A, null, "SomeValue");
|
||||||
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date1B, date1B.toString(), date2B, date2B.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date1B, null, date2B, null, "SomeValue");
|
||||||
|
|
||||||
assertTrue(param.equals(param2));
|
assertTrue(param.equals(param2));
|
||||||
assertTrue(param2.equals(param));
|
assertTrue(param2.equals(param));
|
||||||
|
@ -55,8 +56,8 @@ public class ResourceIndexedSearchParamDateTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsIsTrueForMatchingTimeStampsThatMatch() {
|
public void equalsIsTrueForMatchingTimeStampsThatMatch() {
|
||||||
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", timestamp1A, timestamp1A.toString(), timestamp2A, timestamp2A.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", timestamp1A, null, timestamp2A, null, "SomeValue");
|
||||||
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", timestamp1B, timestamp1B.toString(), timestamp2B, timestamp2B.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", timestamp1B, null, timestamp2B, null, "SomeValue");
|
||||||
|
|
||||||
assertTrue(param.equals(param2));
|
assertTrue(param.equals(param2));
|
||||||
assertTrue(param2.equals(param));
|
assertTrue(param2.equals(param));
|
||||||
|
@ -67,8 +68,8 @@ public class ResourceIndexedSearchParamDateTest {
|
||||||
// other will be equivalent but will be a java.sql.Timestamp. Equals should work in both directions.
|
// other will be equivalent but will be a java.sql.Timestamp. Equals should work in both directions.
|
||||||
@Test
|
@Test
|
||||||
public void equalsIsTrueForMixedTimestampsAndDates() {
|
public void equalsIsTrueForMixedTimestampsAndDates() {
|
||||||
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date1A, date1A.toString(), date2A, date2A.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date1A, null, date2A, null, "SomeValue");
|
||||||
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", timestamp1A, timestamp1A.toString(), timestamp2A, timestamp2A.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", timestamp1A, null, timestamp2A, null, "SomeValue");
|
||||||
|
|
||||||
assertTrue(param.equals(param2));
|
assertTrue(param.equals(param2));
|
||||||
assertTrue(param2.equals(param));
|
assertTrue(param2.equals(param));
|
||||||
|
@ -77,8 +78,8 @@ public class ResourceIndexedSearchParamDateTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsIsFalseForNonMatchingDates() {
|
public void equalsIsFalseForNonMatchingDates() {
|
||||||
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date1A, date1A.toString(), date2A, date2A.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date1A, null, date2A, null, "SomeValue");
|
||||||
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date2A, date2A.toString(), date1A, date1A.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date2A, null, date1A, null, "SomeValue");
|
||||||
|
|
||||||
assertFalse(param.equals(param2));
|
assertFalse(param.equals(param2));
|
||||||
assertFalse(param2.equals(param));
|
assertFalse(param2.equals(param));
|
||||||
|
@ -87,7 +88,7 @@ public class ResourceIndexedSearchParamDateTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsIsFalseForNonMatchingDatesNullCase() {
|
public void equalsIsFalseForNonMatchingDatesNullCase() {
|
||||||
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date1A, date1A.toString(), date2A, date2A.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date1A, null, date2A, null, "SomeValue");
|
||||||
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", null, null, null, null, "SomeValue");
|
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", null, null, null, null, "SomeValue");
|
||||||
|
|
||||||
assertFalse(param.equals(param2));
|
assertFalse(param.equals(param2));
|
||||||
|
@ -97,8 +98,8 @@ public class ResourceIndexedSearchParamDateTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsIsFalseForNonMatchingTimeStamps() {
|
public void equalsIsFalseForNonMatchingTimeStamps() {
|
||||||
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", timestamp1A, timestamp1A.toString(), timestamp2A, timestamp2A.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", timestamp1A, null, timestamp2A, null, "SomeValue");
|
||||||
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", timestamp2A, timestamp2A.toString(), timestamp1A, timestamp1A.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", timestamp2A, null, timestamp1A, null, "SomeValue");
|
||||||
|
|
||||||
assertFalse(param.equals(param2));
|
assertFalse(param.equals(param2));
|
||||||
assertFalse(param2.equals(param));
|
assertFalse(param2.equals(param));
|
||||||
|
@ -107,8 +108,8 @@ public class ResourceIndexedSearchParamDateTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsIsFalseForMixedTimestampsAndDatesThatDoNotMatch() {
|
public void equalsIsFalseForMixedTimestampsAndDatesThatDoNotMatch() {
|
||||||
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date1A, date1A.toString(), date2A, date2A.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate("Patient", "SomeResource", date1A, null, date2A, null, "SomeValue");
|
||||||
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", timestamp2A, timestamp2A.toString(), timestamp1A, timestamp1A.toString(), "SomeValue");
|
ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate("Patient", "SomeResource", timestamp2A, null, timestamp1A, null, "SomeValue");
|
||||||
|
|
||||||
assertFalse(param.equals(param2));
|
assertFalse(param.equals(param2));
|
||||||
assertFalse(param2.equals(param));
|
assertFalse(param2.equals(param));
|
||||||
|
|
Loading…
Reference in New Issue