diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/fhirpath/FHIRPathEngine.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/fhirpath/FHIRPathEngine.java index 956ee8cad..e82e02ff7 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/fhirpath/FHIRPathEngine.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/fhirpath/FHIRPathEngine.java @@ -2749,8 +2749,12 @@ public class FHIRPathEngine { } else if (l.hasType("decimal", "integer") && r.hasType("decimal", "integer")) { result.add(new DecimalType(new BigDecimal(l.primitiveValue()).add(new BigDecimal(r.primitiveValue())))); } else if ((l.isDateTime() || l.hasType("Date")) && r.hasType("Quantity")) { - DateTimeType dl = l instanceof DateTimeType ? (DateTimeType) l : new DateTimeType(l.primitiveValue()); - result.add(dateAdd(dl, (Quantity) r, false, expr)); + if (l.hasType("Date")) { + result.add(dateAdd((BaseDateTimeType) l, (Quantity) r, false, expr)); + } else { + DateTimeType dl = l instanceof DateTimeType ? (DateTimeType) l : new DateTimeType(l.primitiveValue()); + result.add(dateAdd(dl, (Quantity) r, false, expr)); + } } else { throw makeException(expr, I18nConstants.FHIRPATH_OP_INCOMPATIBLE, "+", left.get(0).fhirType(), right.get(0).fhirType()); } @@ -3014,8 +3018,12 @@ public class FHIRPathEngine { result.add(qty.copy().setValue(qty.getValue().abs())); } } else if ((l.isDateTime() || l.hasType("Date")) && r.hasType("Quantity")) { - DateTimeType dl = l instanceof DateTimeType ? (DateTimeType) l : new DateTimeType(l.primitiveValue()); - result.add(dateAdd(dl, (Quantity) r, true, expr)); + if (l.hasType("Date")) { + result.add(dateAdd((BaseDateTimeType) l, (Quantity) r, true, expr)); + } else { + DateTimeType dl = l instanceof DateTimeType ? (DateTimeType) l : new DateTimeType(l.primitiveValue()); + result.add(dateAdd(dl, (Quantity) r, true, expr)); + } } else { throw makeException(expr, I18nConstants.FHIRPATH_OP_INCOMPATIBLE, "-", left.get(0).fhirType(), right.get(0).fhirType()); }