FHIR Chat · aggregation operators · cql

Stream: cql

Topic: aggregation operators


view this post on Zulip Georg Fette (Mar 08 2019 at 10:29):

Hello, I have a CQL problem using the aggregation operators. The documentation says that "If a path is specified, the count returns the number of elements that have a value for the property specified by the path.". What happens if the path traverses array fields ? Do all elements in this array have to have a value for the rest of the path, or only one ?
Another problem I have with the semantics of the aggregation operators is the scope of the aggregation. Taking as example the CQL query "[Patient] A where Count(A.name.given) > 1 return A". The query could either return all patients with more than one name that has at least one given name, or all patient with at least one name having more than one given name. It could be assumed that the scope gets set by default to the source given in the operator. How would a query look like that defines as scope a part of the path (A.name) and not the source (A) ?

view this post on Zulip Chris Moesel (Mar 08 2019 at 20:33):

Hi @Georg Fette. I'm not entirely sure I understand your question, but in regard to your example:

[Patient] A where Count(A.name.given) > 1 return A

I agree that due to the path-traversal approach that was added for fhirpath, this could be "all patients with more than one name that has at least one given name, or all patient with at least one name having more than one given name."

If you want to be more specific, I think you'll need to do so via more complex queries. For example:

// all patients with more than one name that has at least one given name
[Patient] A where Count((A.name) N where Count(N.given) > 0) > 1

and

// all patients with at least one name having more than one given name
[Patient] A where exists((A.name) N where Count(N.given) > 1)

I didn't compile and test the CQL above, but I think it portrays the point. Does that help? Or did I miss the intent of the question?

view this post on Zulip Georg Fette (Mar 08 2019 at 20:40):

ah, those two alternatives would solve the ambiguity. Thank you.


Last updated: Apr 12 2022 at 19:14 UTC