Skip to content

Commit

Permalink
Add support for CQL Longs (#1459)
Browse files Browse the repository at this point in the history
* Add support for CQL Longs

* Add more tests

* Fix formatting

* More tests

* Fix Sonar issues
  • Loading branch information
JPercival authored Dec 2, 2024
1 parent 5e6b939 commit 30f8159
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand All @@ -277,7 +273,7 @@ public Iterable<Object> 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",
Expand Down Expand Up @@ -316,6 +312,8 @@ public Object toCqlType(Object value) {
return toCqlBoolean((IPrimitiveType<Boolean>) value);
case "IntegerType":
return toCqlInteger((IPrimitiveType<Integer>) value);
case "Integer64Type":
return toCqlLong((IPrimitiveType<Long>) value);
case "DecimalType":
return toCqlDecimal((IPrimitiveType<BigDecimal>) value);
case "DateType":
Expand Down Expand Up @@ -373,6 +371,15 @@ public Integer toCqlInteger(IPrimitiveType<Integer> value) {
return value.getValue();
}

@Override
public Long toCqlLong(IPrimitiveType<Long> value) {
if (value == null) {
return null;
}

return value.getValue();
}

@Override
public BigDecimal toCqlDecimal(IPrimitiveType<BigDecimal> value) {
if (value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public IPrimitiveType<Integer> toFhirInteger(Integer value) {
return new IntegerType(value);
}

@Override
public IPrimitiveType<Long> toFhirInteger64(Long value) {
throw new IllegalArgumentException("FHIR DSTU2 does not support Long/Integer64 values");
}

@Override
public IPrimitiveType<BigDecimal> toFhirDecimal(BigDecimal value) {
if (value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public IPrimitiveType<Integer> toFhirInteger(Integer value) {
return new IntegerType(value);
}

@Override
public IPrimitiveType<Long> toFhirInteger64(Long value) {
throw new IllegalArgumentException("FHIR DSTU3 does not support Long/Integer64 values");
}

@Override
public IPrimitiveType<BigDecimal> toFhirDecimal(BigDecimal value) {
if (value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ public interface FhirTypeConverter {
*/
public IPrimitiveType<Integer> toFhirInteger(Integer value);

/**
* Converts a Long to a FHIR Integer64
* @param value the value to convert
* @return a FHIR Integer64
*/
public IPrimitiveType<Long> toFhirInteger64(Long value);

/**
* Converts a BigDecimal to a FHIR Decimal
*
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -278,6 +285,13 @@ public interface FhirTypeConverter {
*/
public Integer toCqlInteger(IPrimitiveType<Integer> value);

/**
* Converts a FHIR Integer64 to a CQL Long
* @param value the value to convert
* @return a Long
*/
public Long toCqlLong(IPrimitiveType<Long> value);

/**
* Converts a FHIR Decimal to a CQL Decimal
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public IPrimitiveType<Integer> toFhirInteger(Integer value) {
return new IntegerType(value);
}

@Override
public IPrimitiveType<Long> toFhirInteger64(Long value) {
throw new IllegalArgumentException("FHIR R4 does not support Long/Integer64 values");
}

@Override
public IPrimitiveType<BigDecimal> toFhirDecimal(BigDecimal value) {
if (value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public IPrimitiveType<Integer> toFhirInteger(Integer value) {
return new IntegerType(value);
}

@Override
public IPrimitiveType<Long> toFhirInteger64(Long value) {
if (value == null) {
return null;
}

return new Integer64Type(value);
}

@Override
public IPrimitiveType<BigDecimal> toFhirDecimal(BigDecimal value) {
if (value == null) {
Expand Down Expand Up @@ -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()));
}

Expand Down
Loading

0 comments on commit 30f8159

Please sign in to comment.