cqframework / cql-engine

Clinical Quality Language Evaluation Engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make external function interface validate result is a CQL Any value

duncand opened this issue · comments

This issue is a followup to issue #52.

The CQL Engine needs to validate the outputs of any external functions that it invokes by way of the CQL external function interface. To be specific, it needs to validate that the Java "Object" that the function returns is a member of the CQL "Any" type, that it is a member of one of the Java types used by the CQL Engine to represent any of the CQL types.

That means for example the result is allowed to be a Java null, a Java Integer, a Java BigDecimal, or a value of Engine-defined classes like Quantity, Interval, Tuple, DateTime, Time, and so on.

In contrast, other data types that an external function might try to return but that don't actually work include a Java Date. It has already been seen for example in actual use that if a Date is passed back by an external function then the Engine will silently accept it and store it, but that operations such as Equivalent() will return null when given it, or a collection with it as an element, as an argument.

The primary deliverable of this issue is that SystemExternalFunctionProvider.evaluate() will throw an exception if the result of the function it calls isn't a valid CQL Any value.

The secondary deliverable of this issue are making that validation into a reusable Java utility function such as "Boolean javaObjectIsCqlAny(Object value)" which said evaluate() just calls and can also be used for validation elsewhere in the Engine as desired.

The tertiary deliverable is to add any useful missing data conversion utility functions that can be invoked by external functions to aid in their meeting the output constraints. A specific useful example (which I have a sample implementation of) is a variant on DateTime.fromJavaDate() that produces a CQL DateTime with day precision rather than millisecond precision, so an input that is what one normally considers a "date" compares with a CQL date correctly.

Validation that the external function result is a member of a specific CQL type rather than its Any type is outside the scope of this issue.

This task should be reasonably straightforward and simple and quick to implement for someone savvy with the Engine.