-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Description:
When invoking a CQL library definition that returns a list of patients and uses AgeInYears() or AgeInYearsAt(), an exception occurs: "Sequence contains more than one element."
The generated C# assembly method signature correctly accepts IEnumerable, but inside the compiled filter logic, the generated code calls this.Patient instead of using the patient from the .Where LINQ clause, causing the evaluation to fail when multiple patients are passed.
To Reproduce:
-
Create a basic CqlLibraryString with a define that gets a list of patients back and has the AgeInYearsAt() function. See the attached screenshot for the cql you can use.
-
For the FHIR Bundle, you can create any type of valid bundle.
-
Create a librarySetInvoker.
-
Call .invokeLibraryDefinition on the librarySetInvoker with the above cql, definition name and library identifier.
-
Try catch the method and view the error/exception.
Expected Behavior:
I expected this to return a list of patients that meet the criteria of the define. I.e all patients that are above a certain age are returned.
Screenshots:
cql:
library ControllingBloodPressure version '1.0.0'
using FHIR version '4.0.1'
parameter "Measurement Period" Interval<DateTime> default
Interval [@2024-01-01T00:00:00.0, @2024-12-31T23:59:59.0]
context Patient
define "Eligible Population":
[Patient] Primary
where AgeInYearsAt(start of "Measurement Period") >= 18
C# of the LibrarySetInvoker invoking and error display:
CqlToolkit cqlToolkit = new();
var cql = (CqlLibraryString) cqlBundle;
var fhirLibrary = (CqlLibraryString) File.ReadAllText("resources/FHIRHelper.cql");
LibrarySetInvoker LibrarySetInvoker = cqlToolkit.AddCqlLibraries([cql]).CreateLibrarySetInvoker();
try
{
LibrarySetInvoker.InvokeLibraryDefinition(
cqlContext: FhirCqlContext.ForBundle(fhirBundle),
LibraryIdentifier: cql.LibraryIdentifier,
definitionSignature: "Eligible Population");
} catch (Exception ex)
{
Console. WriteLine(ex. Message);
}
Version used:
- Version: 2.1.0