diff --git a/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/BaseFhirTypeConverter.java b/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/BaseFhirTypeConverter.java index abc3a1828..599b6ad5c 100644 --- a/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/BaseFhirTypeConverter.java +++ b/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/BaseFhirTypeConverter.java @@ -87,6 +87,8 @@ public IBase toFhirType(Object value) { return toFhirBoolean((Boolean) value); case "Integer": return toFhirInteger((Integer) value); + case "Long": + return toFhirInteger64((Long) value); case "BigDecimal": return toFhirDecimal((BigDecimal) value); case "Date": @@ -245,25 +247,19 @@ public ICompositeType toFhirInterval(Interval value) { } @Override - public Boolean isCqlType(Object value) { + public boolean isCqlType(Object value) { Objects.requireNonNull(value, "value can not be null"); if (value instanceof Iterable) { throw new IllegalArgumentException("isCqlType can not be used for Iterables"); } - if (value instanceof CqlType) { - return true; - } - - if (value instanceof BigDecimal + return value instanceof BigDecimal || value instanceof String || value instanceof Integer - || value instanceof Boolean) { - return true; - } - - return false; + || value instanceof Boolean + || value instanceof Long + || value instanceof CqlType; } @Override @@ -277,7 +273,7 @@ public Iterable toCqlTypes(Iterable values) { } else if (isCqlType(value)) { converted.add(value); } else if (isFhirType(value)) { - converted.add(toCqlType((IBase) value)); + converted.add(toCqlType(value)); } else { throw new IllegalArgumentException(String.format( "Unknown type encountered during conversion %s", @@ -316,6 +312,8 @@ public Object toCqlType(Object value) { return toCqlBoolean((IPrimitiveType) value); case "IntegerType": return toCqlInteger((IPrimitiveType) value); + case "Integer64Type": + return toCqlLong((IPrimitiveType) value); case "DecimalType": return toCqlDecimal((IPrimitiveType) value); case "DateType": @@ -373,6 +371,15 @@ public Integer toCqlInteger(IPrimitiveType value) { return value.getValue(); } + @Override + public Long toCqlLong(IPrimitiveType value) { + if (value == null) { + return null; + } + + return value.getValue(); + } + @Override public BigDecimal toCqlDecimal(IPrimitiveType value) { if (value == null) { diff --git a/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu2FhirTypeConverter.java b/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu2FhirTypeConverter.java index b5813fbea..fcc8706e1 100644 --- a/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu2FhirTypeConverter.java +++ b/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu2FhirTypeConverter.java @@ -44,6 +44,11 @@ public IPrimitiveType toFhirInteger(Integer value) { return new IntegerType(value); } + @Override + public IPrimitiveType toFhirInteger64(Long value) { + throw new IllegalArgumentException("FHIR DSTU2 does not support Long/Integer64 values"); + } + @Override public IPrimitiveType toFhirDecimal(BigDecimal value) { if (value == null) { diff --git a/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu3FhirTypeConverter.java b/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu3FhirTypeConverter.java index d58927482..cf934fce7 100644 --- a/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu3FhirTypeConverter.java +++ b/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu3FhirTypeConverter.java @@ -43,6 +43,11 @@ public IPrimitiveType toFhirInteger(Integer value) { return new IntegerType(value); } + @Override + public IPrimitiveType toFhirInteger64(Long value) { + throw new IllegalArgumentException("FHIR DSTU3 does not support Long/Integer64 values"); + } + @Override public IPrimitiveType toFhirDecimal(BigDecimal value) { if (value == null) { diff --git a/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/FhirTypeConverter.java b/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/FhirTypeConverter.java index c81c3e48f..d8aca1be0 100644 --- a/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/FhirTypeConverter.java +++ b/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/FhirTypeConverter.java @@ -88,6 +88,13 @@ public interface FhirTypeConverter { */ public IPrimitiveType toFhirInteger(Integer value); + /** + * Converts a Long to a FHIR Integer64 + * @param value the value to convert + * @return a FHIR Integer64 + */ + public IPrimitiveType toFhirInteger64(Long value); + /** * Converts a BigDecimal to a FHIR Decimal * @@ -233,7 +240,7 @@ public interface FhirTypeConverter { * @return true if value is a CQL type, false otherwise * @throws NullPointerException if value is null */ - public Boolean isCqlType(Object value); + public boolean isCqlType(Object value); /** * Converts an Object to a CQL type. @@ -278,6 +285,13 @@ public interface FhirTypeConverter { */ public Integer toCqlInteger(IPrimitiveType value); + /** + * Converts a FHIR Integer64 to a CQL Long + * @param value the value to convert + * @return a Long + */ + public Long toCqlLong(IPrimitiveType value); + /** * Converts a FHIR Decimal to a CQL Decimal * diff --git a/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/R4FhirTypeConverter.java b/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/R4FhirTypeConverter.java index b69f1f8d6..ec09ee67d 100644 --- a/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/R4FhirTypeConverter.java +++ b/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/R4FhirTypeConverter.java @@ -44,6 +44,11 @@ public IPrimitiveType toFhirInteger(Integer value) { return new IntegerType(value); } + @Override + public IPrimitiveType toFhirInteger64(Long value) { + throw new IllegalArgumentException("FHIR R4 does not support Long/Integer64 values"); + } + @Override public IPrimitiveType toFhirDecimal(BigDecimal value) { if (value == null) { diff --git a/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/R5FhirTypeConverter.java b/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/R5FhirTypeConverter.java index c8c53194e..ce89a5dc3 100644 --- a/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/R5FhirTypeConverter.java +++ b/Src/java/engine-fhir/src/main/java/org/opencds/cqf/cql/engine/fhir/converter/R5FhirTypeConverter.java @@ -44,6 +44,15 @@ public IPrimitiveType toFhirInteger(Integer value) { return new IntegerType(value); } + @Override + public IPrimitiveType toFhirInteger64(Long value) { + if (value == null) { + return null; + } + + return new Integer64Type(value); + } + @Override public IPrimitiveType toFhirDecimal(BigDecimal value) { if (value == null) { @@ -367,7 +376,7 @@ public Concept toCqlConcept(ICompositeType value) { return new Concept() .withDisplay(codeableConcept.getText()) .withCodes(codeableConcept.getCoding().stream() - .map(x -> toCqlCode(x)) + .map(this::toCqlCode) .collect(Collectors.toList())); } diff --git a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu2TypeConverterTests.java b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu2TypeConverterTests.java index e35315c88..7739bcd94 100644 --- a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu2TypeConverterTests.java +++ b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu2TypeConverterTests.java @@ -133,17 +133,13 @@ void isFhirType() { @Test void nullIsFhirType() { - assertThrows(NullPointerException.class, () -> { - typeConverter.isFhirType(null); - }); + assertThrows(NullPointerException.class, () -> typeConverter.isFhirType(null)); } @Test void iterableIsFhirType() { var value = new ArrayList<>(); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.isFhirType(value); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.isFhirType(value)); } @Test @@ -158,23 +154,19 @@ void toFhirType() { assertThat(actual, instanceOf(IdType.class)); actual = typeConverter.toFhirType(null); - assertNull(null); + assertNull(actual); } @Test void toFhirTypeIterable() { var value = new ArrayList<>(); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirType(value); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirType(value)); } @Test void toFhirTypeNotCql() { var offset = ZoneOffset.ofHours(3); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirType(offset); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirType(offset)); } @Test @@ -233,8 +225,8 @@ void primitiveCqlTypeToFhirType() { expectedString = typeConverter.toFhirString(null); assertNull(expectedString); - IPrimitiveType expectedDecimal = new DecimalType(new BigDecimal(2.0)); - IPrimitiveType actualDecimal = typeConverter.toFhirDecimal(new BigDecimal(2.0)); + IPrimitiveType expectedDecimal = new DecimalType(new BigDecimal("2.0")); + IPrimitiveType actualDecimal = typeConverter.toFhirDecimal(new BigDecimal("2.0")); assertEquals(expectedDecimal.getValue(), actualDecimal.getValue()); expectedDecimal = typeConverter.toFhirDecimal(null); @@ -338,9 +330,7 @@ void nullToFhirAny() { @Test void objectToFhirAny() { - assertThrows(NotImplementedException.class, () -> { - typeConverter.toFhirAny("Huh"); - }); + assertThrows(NotImplementedException.class, () -> typeConverter.toFhirAny("Huh")); } @Test @@ -454,9 +444,7 @@ void intervalToFhirPeriodNull() { @Test void invalidIntervalToFhirPeriod() { var interval = new Interval(5, true, 6, true); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirPeriod(interval); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirPeriod(interval)); } @Test @@ -478,15 +466,13 @@ void intervalToFhirRange() { assertTrue(expected.equalsDeep(actual)); actual = (Range) typeConverter.toFhirRange(null); - assertNull(null); + assertNull(actual); } @Test void invalidIntervalToFhirRange() { var interval = new Interval(5, true, 6, true); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirRange(interval); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirRange(interval)); } @Test @@ -522,9 +508,7 @@ void intervalToFhirInterval() { void invalidIntervalToFhirInterval() { var interval = new Interval(5, true, 6, true); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirInterval(interval); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirInterval(interval)); } private static List getPartsByName(ParametersParameterComponent ppc, String name) { @@ -710,22 +694,19 @@ void toCqlType() { assertThat(actual, instanceOf(Interval.class)); actual = typeConverter.toCqlType(null); - assertNull(null); + assertNull(actual); } @Test void toCqlTypeIterable() { - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toCqlType(new ArrayList<>()); - }); + var list = new ArrayList<>(); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toCqlType(list)); } @Test void toCqlTypeNotCql() { var offset = ZoneOffset.ofHours(3); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toCqlType(offset); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toCqlType(offset)); } @Test @@ -764,33 +745,33 @@ void stringToCqlId() { @Test void primitiveFhirTypeToCqlType() { - Boolean expectedBoolean = false; - Boolean actualBoolean = typeConverter.toCqlBoolean(new BooleanType(false)); - assertEquals(expectedBoolean, actualBoolean); + Boolean actualBoolean = typeConverter.toCqlBoolean(new org.hl7.fhir.r5.model.BooleanType(false)); + assertFalse(actualBoolean); - expectedBoolean = typeConverter.toCqlBoolean(null); - assertNull(expectedBoolean); + actualBoolean = typeConverter.toCqlBoolean(null); + assertNull(actualBoolean); Integer expectedInteger = 5; - Integer actualInteger = typeConverter.toCqlInteger(new IntegerType(5)); + Integer actualInteger = typeConverter.toCqlInteger(new org.hl7.fhir.r5.model.IntegerType(5)); assertEquals(expectedInteger, actualInteger); expectedInteger = typeConverter.toCqlInteger(null); assertNull(expectedInteger); String expectedString = "5"; - String actualString = typeConverter.toCqlString(new StringType("5")); + String actualString = typeConverter.toCqlString(new org.hl7.fhir.r5.model.StringType("5")); assertEquals(expectedString, actualString); - expectedString = typeConverter.toCqlString(null); - assertNull(expectedString); + actualString = typeConverter.toCqlString(null); + assertNull(actualString); - BigDecimal expectedDecimal = new BigDecimal(2.0); - BigDecimal actualDecimal = typeConverter.toCqlDecimal(new DecimalType(new BigDecimal(2.0))); + BigDecimal expectedDecimal = new BigDecimal("2.0"); + BigDecimal actualDecimal = + typeConverter.toCqlDecimal(new org.hl7.fhir.r5.model.DecimalType(new BigDecimal("2.0"))); assertEquals(expectedDecimal, actualDecimal); - expectedDecimal = typeConverter.toCqlDecimal(null); - assertNull(expectedDecimal); + actualDecimal = typeConverter.toCqlDecimal(null); + assertNull(actualDecimal); } @Test @@ -861,9 +842,7 @@ void nullToCqlType() { @Test void objectToCqlType() { var id = new IdType(); - assertThrows(NotImplementedException.class, () -> { - typeConverter.toCqlAny(id); - }); + assertThrows(NotImplementedException.class, () -> typeConverter.toCqlAny(id)); } @Test @@ -930,7 +909,7 @@ void periodToCqlInterval() { assertTrue(expected.equal(actual)); actual = typeConverter.toCqlInterval(null); - assertNull(null); + assertNull(actual); } @Test @@ -952,15 +931,13 @@ void rangeToCqlInterval() { assertTrue(expected.equal(actual)); actual = typeConverter.toCqlInterval(null); - assertNull(null); + assertNull(actual); } @Test void invalidTypeToCqlInterval() { var attachment = new Attachment(); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toCqlInterval(attachment); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toCqlInterval(attachment)); } @Test @@ -969,8 +946,18 @@ void tupleToCqlTuple() { assertNull(expected); var p = new Patient(); - assertThrows(NotImplementedException.class, () -> { - typeConverter.toCqlTuple(p); - }); + assertThrows(NotImplementedException.class, () -> typeConverter.toCqlTuple(p)); + } + + @Test + void longToCqlLong() { + Long expected = 5L; + var actual = typeConverter.toCqlType(expected); + assertEquals(expected, actual); + } + + @Test + void longToFhirInteger64() { + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirInteger64(5L)); } } diff --git a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu3TypeConverterTests.java b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu3TypeConverterTests.java index 38a75bce3..7accdfe05 100644 --- a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu3TypeConverterTests.java +++ b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/Dstu3TypeConverterTests.java @@ -133,17 +133,13 @@ void isFhirType() { @Test void nullIsFhirType() { - assertThrows(NullPointerException.class, () -> { - typeConverter.isFhirType(null); - }); + assertThrows(NullPointerException.class, () -> typeConverter.isFhirType(null)); } @Test void iterableIsFhirType() { var value = new ArrayList<>(); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.isFhirType(value); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.isFhirType(value)); } @Test @@ -158,23 +154,19 @@ void toFhirType() { assertThat(actual, instanceOf(IdType.class)); actual = typeConverter.toFhirType(null); - assertNull(null); + assertNull(actual); } @Test void toFhirTypeIterable() { var value = new ArrayList<>(); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirType(value); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirType(value)); } @Test void toFhirTypeNotCql() { var offset = ZoneOffset.ofHours(3); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirType(offset); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirType(offset)); } @Test @@ -233,8 +225,8 @@ void primitiveCqlTypeToFhirType() { expectedString = typeConverter.toFhirString(null); assertNull(expectedString); - IPrimitiveType expectedDecimal = new DecimalType(new BigDecimal(2.0)); - IPrimitiveType actualDecimal = typeConverter.toFhirDecimal(new BigDecimal(2.0)); + IPrimitiveType expectedDecimal = new DecimalType(new BigDecimal("2.0")); + IPrimitiveType actualDecimal = typeConverter.toFhirDecimal(new BigDecimal("2.0")); assertEquals(expectedDecimal.getValue(), actualDecimal.getValue()); expectedDecimal = typeConverter.toFhirDecimal(null); @@ -338,9 +330,7 @@ void nullToFhirAny() { @Test void objectToFhirAny() { - assertThrows(NotImplementedException.class, () -> { - typeConverter.toFhirAny("Huh"); - }); + assertThrows(NotImplementedException.class, () -> typeConverter.toFhirAny("Huh")); } @Test @@ -454,9 +444,7 @@ void intervalToFhirPeriodNull() { @Test void invalidIntervalToFhirPeriod() { var interval = new Interval(5, true, 6, true); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirPeriod(interval); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirPeriod(interval)); } @Test @@ -480,15 +468,13 @@ void intervalToFhirRange() { assertTrue(expected.equalsDeep(actual)); actual = (Range) typeConverter.toFhirRange(null); - assertNull(null); + assertNull(actual); } @Test void invalidIntervalToFhirRange() { var interval = new Interval(5, true, 6, true); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirRange(interval); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirRange(interval)); } @Test @@ -526,9 +512,7 @@ void intervalToFhirInterval() { void invalidIntervalToFhirInterval() { var interval = new Interval(5, true, 6, true); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirInterval(interval); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirInterval(interval)); } private static List getPartsByName(ParametersParameterComponent ppc, String name) { @@ -714,22 +698,19 @@ void toCqlType() { assertThat(actual, instanceOf(Interval.class)); actual = typeConverter.toCqlType(null); - assertNull(null); + assertNull(actual); } @Test void toCqlTypeIterable() { - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toCqlType(new ArrayList<>()); - }); + var list = new ArrayList<>(); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toCqlType(list)); } @Test void toCqlTypeNotCql() { var offset = ZoneOffset.ofHours(3); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toCqlType(offset); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toCqlType(offset)); } @Test @@ -768,33 +749,33 @@ void stringToCqlId() { @Test void primitiveFhirTypeToCqlType() { - Boolean expectedBoolean = false; - Boolean actualBoolean = typeConverter.toCqlBoolean(new BooleanType(false)); - assertEquals(expectedBoolean, actualBoolean); + Boolean actualBoolean = typeConverter.toCqlBoolean(new org.hl7.fhir.r5.model.BooleanType(false)); + assertFalse(actualBoolean); - expectedBoolean = typeConverter.toCqlBoolean(null); - assertNull(expectedBoolean); + actualBoolean = typeConverter.toCqlBoolean(null); + assertNull(actualBoolean); Integer expectedInteger = 5; - Integer actualInteger = typeConverter.toCqlInteger(new IntegerType(5)); + Integer actualInteger = typeConverter.toCqlInteger(new org.hl7.fhir.r5.model.IntegerType(5)); assertEquals(expectedInteger, actualInteger); expectedInteger = typeConverter.toCqlInteger(null); assertNull(expectedInteger); String expectedString = "5"; - String actualString = typeConverter.toCqlString(new StringType("5")); + String actualString = typeConverter.toCqlString(new org.hl7.fhir.r5.model.StringType("5")); assertEquals(expectedString, actualString); - expectedString = typeConverter.toCqlString(null); - assertNull(expectedString); + actualString = typeConverter.toCqlString(null); + assertNull(actualString); - BigDecimal expectedDecimal = new BigDecimal(2.0); - BigDecimal actualDecimal = typeConverter.toCqlDecimal(new DecimalType(new BigDecimal(2.0))); + BigDecimal expectedDecimal = new BigDecimal("2.0"); + BigDecimal actualDecimal = + typeConverter.toCqlDecimal(new org.hl7.fhir.r5.model.DecimalType(new BigDecimal("2.0"))); assertEquals(expectedDecimal, actualDecimal); - expectedDecimal = typeConverter.toCqlDecimal(null); - assertNull(expectedDecimal); + actualDecimal = typeConverter.toCqlDecimal(null); + assertNull(actualDecimal); } @Test @@ -865,9 +846,7 @@ void nullToCqlType() { @Test void objectToCqlType() { var id = new IdType(); - assertThrows(NotImplementedException.class, () -> { - typeConverter.toCqlAny(id); - }); + assertThrows(NotImplementedException.class, () -> typeConverter.toCqlAny(id)); } @Test @@ -934,7 +913,7 @@ void periodToCqlInterval() { assertTrue(expected.equal(actual)); actual = typeConverter.toCqlInterval(null); - assertNull(null); + assertNull(actual); } @Test @@ -956,15 +935,13 @@ void rangeToCqlInterval() { assertTrue(expected.equal(actual)); actual = typeConverter.toCqlInterval(null); - assertNull(null); + assertNull(actual); } @Test void invalidTypeToCqlInterval() { var attachment = new Attachment(); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toCqlInterval(attachment); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toCqlInterval(attachment)); } @Test @@ -973,8 +950,18 @@ void tupleToCqlTuple() { assertNull(expected); var p = new Patient(); - assertThrows(NotImplementedException.class, () -> { - typeConverter.toCqlTuple(p); - }); + assertThrows(NotImplementedException.class, () -> typeConverter.toCqlTuple(p)); + } + + @Test + void longToCqlLong() { + Long expected = 5L; + var actual = typeConverter.toCqlType(expected); + assertEquals(expected, actual); + } + + @Test + void longToFhirInteger64() { + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirInteger64(5L)); } } diff --git a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/R4TypeConverterTests.java b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/R4TypeConverterTests.java index 0e446722c..a974a9eee 100644 --- a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/R4TypeConverterTests.java +++ b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/R4TypeConverterTests.java @@ -133,17 +133,13 @@ void isFhirType() { @Test void nullIsFhirType() { - assertThrows(NullPointerException.class, () -> { - typeConverter.isFhirType(null); - }); + assertThrows(NullPointerException.class, () -> typeConverter.isFhirType(null)); } @Test void iterableIsFhirType() { var value = new ArrayList<>(); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.isFhirType(value); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.isFhirType(value)); } @Test @@ -158,23 +154,19 @@ void toFhirType() { assertThat(actual, instanceOf(IdType.class)); actual = typeConverter.toFhirType(null); - assertNull(null); + assertNull(actual); } @Test void toFhirTypeIterable() { var value = new ArrayList<>(); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirType(value); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirType(value)); } @Test void toFhirTypeNotCql() { var offset = ZoneOffset.ofHours(3); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirType(offset); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirType(offset)); } @Test @@ -233,8 +225,8 @@ void primitiveCqlTypeToFhirType() { expectedString = typeConverter.toFhirString(null); assertNull(expectedString); - IPrimitiveType expectedDecimal = new DecimalType(new BigDecimal(2.0)); - IPrimitiveType actualDecimal = typeConverter.toFhirDecimal(new BigDecimal(2.0)); + IPrimitiveType expectedDecimal = new DecimalType(new BigDecimal("2.0")); + IPrimitiveType actualDecimal = typeConverter.toFhirDecimal(new BigDecimal("2.0")); assertEquals(expectedDecimal.getValue(), actualDecimal.getValue()); expectedDecimal = typeConverter.toFhirDecimal(null); @@ -338,9 +330,7 @@ void nullToFhirAny() { @Test void objectToFhirAny() { - assertThrows(NotImplementedException.class, () -> { - typeConverter.toFhirAny("Huh"); - }); + assertThrows(NotImplementedException.class, () -> typeConverter.toFhirAny("Huh")); } @Test @@ -454,9 +444,7 @@ void intervalToFhirPeriodNull() { @Test void invalidIntervalToFhirPeriod() { var interval = new Interval(5, true, 6, true); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirPeriod(interval); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirPeriod(interval)); } @Test @@ -480,15 +468,13 @@ void intervalToFhirRange() { assertTrue(expected.equalsDeep(actual)); actual = (Range) typeConverter.toFhirRange(null); - assertNull(null); + assertNull(actual); } @Test void invalidIntervalToFhirRange() { var interval = new Interval(5, true, 6, true); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirRange(interval); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirRange(interval)); } @Test @@ -526,9 +512,7 @@ void intervalToFhirInterval() { void invalidIntervalToFhirInterval() { var interval = new Interval(5, true, 6, true); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirInterval(interval); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirInterval(interval)); } private static List getPartsByName(ParametersParameterComponent ppc, String name) { @@ -714,22 +698,19 @@ void toCqlType() { assertThat(actual, instanceOf(Interval.class)); actual = typeConverter.toCqlType(null); - assertNull(null); + assertNull(actual); } @Test void toCqlTypeIterable() { - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toCqlType(new ArrayList<>()); - }); + var list = new ArrayList<>(); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toCqlType(list)); } @Test void toCqlTypeNotCql() { var offset = ZoneOffset.ofHours(3); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toCqlType(offset); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toCqlType(offset)); } @Test @@ -768,33 +749,33 @@ void stringToCqlId() { @Test void primitiveFhirTypeToCqlType() { - Boolean expectedBoolean = false; - Boolean actualBoolean = typeConverter.toCqlBoolean(new BooleanType(false)); - assertEquals(expectedBoolean, actualBoolean); + Boolean actualBoolean = typeConverter.toCqlBoolean(new org.hl7.fhir.r5.model.BooleanType(false)); + assertFalse(actualBoolean); - expectedBoolean = typeConverter.toCqlBoolean(null); - assertNull(expectedBoolean); + actualBoolean = typeConverter.toCqlBoolean(null); + assertNull(actualBoolean); Integer expectedInteger = 5; - Integer actualInteger = typeConverter.toCqlInteger(new IntegerType(5)); + Integer actualInteger = typeConverter.toCqlInteger(new org.hl7.fhir.r5.model.IntegerType(5)); assertEquals(expectedInteger, actualInteger); expectedInteger = typeConverter.toCqlInteger(null); assertNull(expectedInteger); String expectedString = "5"; - String actualString = typeConverter.toCqlString(new StringType("5")); + String actualString = typeConverter.toCqlString(new org.hl7.fhir.r5.model.StringType("5")); assertEquals(expectedString, actualString); - expectedString = typeConverter.toCqlString(null); - assertNull(expectedString); + actualString = typeConverter.toCqlString(null); + assertNull(actualString); - BigDecimal expectedDecimal = new BigDecimal(2.0); - BigDecimal actualDecimal = typeConverter.toCqlDecimal(new DecimalType(new BigDecimal(2.0))); + BigDecimal expectedDecimal = new BigDecimal("2.0"); + BigDecimal actualDecimal = + typeConverter.toCqlDecimal(new org.hl7.fhir.r5.model.DecimalType(new BigDecimal("2.0"))); assertEquals(expectedDecimal, actualDecimal); - expectedDecimal = typeConverter.toCqlDecimal(null); - assertNull(expectedDecimal); + actualDecimal = typeConverter.toCqlDecimal(null); + assertNull(actualDecimal); } @Test @@ -865,9 +846,7 @@ void nullToCqlType() { @Test void objectToCqlType() { var id = new IdType(); - assertThrows(NotImplementedException.class, () -> { - typeConverter.toCqlAny(id); - }); + assertThrows(NotImplementedException.class, () -> typeConverter.toCqlAny(id)); } @Test @@ -934,7 +913,7 @@ void periodToCqlInterval() { assertTrue(expected.equal(actual)); actual = typeConverter.toCqlInterval(null); - assertNull(null); + assertNull(actual); } @Test @@ -956,15 +935,13 @@ void rangeToCqlInterval() { assertTrue(expected.equal(actual)); actual = typeConverter.toCqlInterval(null); - assertNull(null); + assertNull(actual); } @Test void invalidTypeToCqlInterval() { var attachment = new Attachment(); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toCqlInterval(attachment); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toCqlInterval(attachment)); } @Test @@ -973,8 +950,18 @@ void tupleToCqlTuple() { assertNull(expected); var p = new Patient(); - assertThrows(NotImplementedException.class, () -> { - typeConverter.toCqlTuple(p); - }); + assertThrows(NotImplementedException.class, () -> typeConverter.toCqlTuple(p)); + } + + @Test + void longToCqlLong() { + Long expected = 5L; + var actual = typeConverter.toCqlType(expected); + assertEquals(expected, actual); + } + + @Test + void longToFhirInteger64() { + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirInteger64(5L)); } } diff --git a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/R5TypeConverterTests.java b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/R5TypeConverterTests.java index b80bfb695..34788ffa9 100644 --- a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/R5TypeConverterTests.java +++ b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/converter/R5TypeConverterTests.java @@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.instanceOf; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -36,6 +37,7 @@ import org.hl7.fhir.r5.model.Encounter; import org.hl7.fhir.r5.model.IdType; import org.hl7.fhir.r5.model.InstantType; +import org.hl7.fhir.r5.model.Integer64Type; import org.hl7.fhir.r5.model.IntegerType; import org.hl7.fhir.r5.model.Parameters; import org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent; @@ -133,17 +135,13 @@ void isFhirType() { @Test void nullIsFhirType() { - assertThrows(NullPointerException.class, () -> { - typeConverter.isFhirType(null); - }); + assertThrows(NullPointerException.class, () -> typeConverter.isFhirType(null)); } @Test void iterableIsFhirType() { var value = new ArrayList<>(); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.isFhirType(value); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.isFhirType(value)); } @Test @@ -158,23 +156,19 @@ void toFhirType() { assertThat(actual, instanceOf(IdType.class)); actual = typeConverter.toFhirType(null); - assertNull(null); + assertNull(actual); } @Test void toFhirTypeIterable() { var value = new ArrayList<>(); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirType(value); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirType(value)); } @Test void toFhirTypeNotCql() { var offset = ZoneOffset.ofHours(3); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirType(offset); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirType(offset)); } @Test @@ -233,8 +227,8 @@ void primitiveCqlTypeToFhirType() { expectedString = typeConverter.toFhirString(null); assertNull(expectedString); - IPrimitiveType expectedDecimal = new DecimalType(new BigDecimal(2.0)); - IPrimitiveType actualDecimal = typeConverter.toFhirDecimal(new BigDecimal(2.0)); + IPrimitiveType expectedDecimal = new DecimalType(new BigDecimal("2.0")); + IPrimitiveType actualDecimal = typeConverter.toFhirDecimal(new BigDecimal("2.0")); assertEquals(expectedDecimal.getValue(), actualDecimal.getValue()); expectedDecimal = typeConverter.toFhirDecimal(null); @@ -338,9 +332,7 @@ void nullToFhirAny() { @Test void objectToFhirAny() { - assertThrows(NotImplementedException.class, () -> { - typeConverter.toFhirAny("Huh"); - }); + assertThrows(NotImplementedException.class, () -> typeConverter.toFhirAny("Huh")); } @Test @@ -454,9 +446,7 @@ void intervalToFhirPeriodNull() { @Test void invalidIntervalToFhirPeriod() { var interval = new Interval(5, true, 6, true); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirPeriod(interval); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirPeriod(interval)); } @Test @@ -480,15 +470,13 @@ void intervalToFhirRange() { assertTrue(expected.equalsDeep(actual)); actual = (Range) typeConverter.toFhirRange(null); - assertNull(null); + assertNull(actual); } @Test void invalidIntervalToFhirRange() { var interval = new Interval(5, true, 6, true); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirRange(interval); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirRange(interval)); } @Test @@ -526,9 +514,7 @@ void intervalToFhirInterval() { void invalidIntervalToFhirInterval() { var interval = new Interval(5, true, 6, true); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toFhirInterval(interval); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toFhirInterval(interval)); } private static List getPartsByName(ParametersParameterComponent ppc, String name) { @@ -714,22 +700,19 @@ void toCqlType() { assertThat(actual, instanceOf(Interval.class)); actual = typeConverter.toCqlType(null); - assertNull(null); + assertNull(actual); } @Test void toCqlTypeIterable() { - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toCqlType(new ArrayList<>()); - }); + var list = new ArrayList<>(); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toCqlType(list)); } @Test void toCqlTypeNotCql() { var offset = ZoneOffset.ofHours(3); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toCqlType(offset); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toCqlType(offset)); } @Test @@ -768,12 +751,11 @@ void stringToCqlId() { @Test void primitiveFhirTypeToCqlType() { - Boolean expectedBoolean = false; Boolean actualBoolean = typeConverter.toCqlBoolean(new BooleanType(false)); - assertEquals(expectedBoolean, actualBoolean); + assertFalse(actualBoolean); - expectedBoolean = typeConverter.toCqlBoolean(null); - assertNull(expectedBoolean); + actualBoolean = typeConverter.toCqlBoolean(null); + assertNull(actualBoolean); Integer expectedInteger = 5; Integer actualInteger = typeConverter.toCqlInteger(new IntegerType(5)); @@ -786,15 +768,15 @@ void primitiveFhirTypeToCqlType() { String actualString = typeConverter.toCqlString(new StringType("5")); assertEquals(expectedString, actualString); - expectedString = typeConverter.toCqlString(null); - assertNull(expectedString); + actualString = typeConverter.toCqlString(null); + assertNull(actualString); - BigDecimal expectedDecimal = new BigDecimal(2.0); - BigDecimal actualDecimal = typeConverter.toCqlDecimal(new DecimalType(new BigDecimal(2.0))); + BigDecimal expectedDecimal = new BigDecimal("2.0"); + BigDecimal actualDecimal = typeConverter.toCqlDecimal(new DecimalType(new BigDecimal("2.0"))); assertEquals(expectedDecimal, actualDecimal); - expectedDecimal = typeConverter.toCqlDecimal(null); - assertNull(expectedDecimal); + actualDecimal = typeConverter.toCqlDecimal(null); + assertNull(actualDecimal); } @Test @@ -865,9 +847,7 @@ void nullToCqlType() { @Test void objectToCqlType() { var id = new IdType(); - assertThrows(NotImplementedException.class, () -> { - typeConverter.toCqlAny(id); - }); + assertThrows(NotImplementedException.class, () -> typeConverter.toCqlAny(id)); } @Test @@ -934,7 +914,7 @@ void periodToCqlInterval() { assertTrue(expected.equal(actual)); actual = typeConverter.toCqlInterval(null); - assertNull(null); + assertNull(actual); } @Test @@ -956,15 +936,13 @@ void rangeToCqlInterval() { assertTrue(expected.equal(actual)); actual = typeConverter.toCqlInterval(null); - assertNull(null); + assertNull(actual); } @Test void invalidTypeToCqlInterval() { var attachment = new Attachment(); - assertThrows(IllegalArgumentException.class, () -> { - typeConverter.toCqlInterval(attachment); - }); + assertThrows(IllegalArgumentException.class, () -> typeConverter.toCqlInterval(attachment)); } @Test @@ -973,8 +951,40 @@ void tupleToCqlTuple() { assertNull(expected); var p = new Patient(); - assertThrows(NotImplementedException.class, () -> { - typeConverter.toCqlTuple(p); - }); + assertThrows(NotImplementedException.class, () -> typeConverter.toCqlTuple(p)); + } + + @Test + void longToCqlLong() { + Long expected = 5L; + var actual = typeConverter.toCqlType(expected); + assertEquals(expected, actual); + } + + @Test + void nullToCqlLong() { + var actual = typeConverter.toCqlLong(null); + assertNull(actual); + } + + @Test + void fhirToCqlLong() { + var fhirType = new Integer64Type(5L); + var actual = typeConverter.toCqlLong(fhirType); + assertEquals(5L, actual); + } + + @Test + void fhirToFhirInteger64() { + var expected = new Integer64Type(5L); + var actual = typeConverter.toFhirInteger64(5L); + assertEquals(expected.getValue(), actual.getValue()); + } + + @Test + void longToFhirType() { + var actual = typeConverter.toFhirType(5L); + assertInstanceOf(Integer64Type.class, actual); + assertEquals(5L, ((Integer64Type) actual).getValue()); } }