fix date operations problem

This commit is contained in:
Grahame Grieve 2024-06-26 07:19:47 +10:00
parent e692665790
commit eb0c4d8d93
2 changed files with 7 additions and 3 deletions

View File

@ -2750,7 +2750,9 @@ public class FHIRPathEngine {
result.add(new DecimalType(new BigDecimal(l.primitiveValue()).add(new BigDecimal(r.primitiveValue()))));
} else if ((l.isDateTime() || l.hasType("Date")) && r.hasType("Quantity")) {
if (l.hasType("Date")) {
result.add(dateAdd((BaseDateTimeType) l, (Quantity) r, false, expr));
BaseDateTimeType dt = l instanceof BaseDateTimeType ? (BaseDateTimeType) l : TypeConvertor.castToDateTime(l);
Quantity qty = r instanceof Quantity ? (Quantity) r : TypeConvertor.castToQuantity(r);
result.add(dateAdd(dt, qty, false, expr));
} else {
DateTimeType dl = l instanceof DateTimeType ? (DateTimeType) l : new DateTimeType(l.primitiveValue());
result.add(dateAdd(dl, (Quantity) r, false, expr));
@ -3019,7 +3021,9 @@ public class FHIRPathEngine {
}
} else if ((l.isDateTime() || l.hasType("Date")) && r.hasType("Quantity")) {
if (l.hasType("Date")) {
result.add(dateAdd((BaseDateTimeType) l, (Quantity) r, true, expr));
BaseDateTimeType dt = l instanceof BaseDateTimeType ? (BaseDateTimeType) l : TypeConvertor.castToDateTime(l);
Quantity qty = r instanceof Quantity ? (Quantity) r : TypeConvertor.castToQuantity(r);
result.add(dateAdd(dt, qty, true, expr));
} else {
DateTimeType dl = l instanceof DateTimeType ? (DateTimeType) l : new DateTimeType(l.primitiveValue());
result.add(dateAdd(dl, (Quantity) r, true, expr));

View File

@ -161,7 +161,7 @@ public class TypeConvertor {
if (b instanceof DateTimeType)
return (DateTimeType) b;
else if (b.fhirType().equals("dateTime"))
else if (Utilities.existsInList(b.fhirType(), "dateTime", "date", "instant"))
return new DateTimeType(b.primitiveValue());
else
throw new FHIRException("Unable to convert a "+b.fhirType()+"("+b.getClass().getName()+") to a DateTime");