Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CQL Union operator appears to be broken. #1441

Open
dand9959 opened this issue Nov 12, 2024 · 1 comment
Open

CQL Union operator appears to be broken. #1441

dand9959 opened this issue Nov 12, 2024 · 1 comment
Labels
Milestone

Comments

@dand9959
Copy link

There appears to be an issue with how Union works...

The scenario below was created in VSCode using the CQL Extension v0.6.0 (The latest version of the extension doesn't work on my environment, so someone needs to try to reproduce in v0.7.3, and/or also outside of VSCode to determine if this behavior is because of the CQL extension or is in the language itself. )

The measure and test case used are arbitrary, but should have a single Procedure resource that can be referenced by the selector as such:

["Procedure"]

Below are two defines, one that selects Procedures and one that selects Observations. In this scenario, there
is a single Procedure resource and no Observation resources. Also note the define that is a simple a Union of those two define results:

define "ORIG-Proc1":
  ["Procedure"] 

define "ORIG-Assess1":
  ["Observation"] 
  
define "ORIG-UnionOfProc1AndAssess1":
  "ORIG-Proc1"
  union "ORIG-Assess1"

and here is the output when doing 'Execute CQL' on the measure cql file:

ORIG-Proc1=[Procedure(id=Procedure-1)]
ORIG-Assess1=[]
ORIG-UnionOfProc1AndAssess1=null

The result of the union returns null, even though it should be a list of the single procedure.

Now here is a "fixed" version of those same defines. The ONLY difference is that the procedure and observation selects bind
their results to a local variable (notp and nota, respectively).

        define "FIXED-Proc1":
	  ["Procedure"] notp 

	define "FIXED-Assess1":
	  ["Observation"] nota 
	  
	define "FIXED-UnionOfProc1AndAssess1":
	  "FIXED-Proc1"
	  union "FIXED-Assess1"

Here is the output:

        FIXED-Proc1=[Procedure(id=Procedure-1)]
	FIXED-Assess1=[]
	FIXED-UnionOfProc1AndAssess1=[Procedure(id=Procedure-1)]

Here, the above Union operation returns a list with the procedure, as expected.

But things are not as fixed, as they seem. The Procedure returned in the union operation is malformed.

Consider the following define that uses the above "fixed" union result to get the Procedure and returns a tuple of that procedure's elements:

define MalformedProcedure:
  (singleton from "FIXED-UnionOfProc1AndAssess1") theProcedure
  return  Tuple {
	  resource: theProcedure,
	  id: theProcedure.id,
	  code: theProcedure.code,
	  performed:theProcedure.performed
	}

Here is the output:

MalformedProcedure=Tuple {
	"resource": org.hl7.fhir.r4.model.Procedure@41ef649
	"id": null
	"code": null
	"performed": null
}

Now consider the following, similar, define that instead of accessing the "Procedure" from the Union result, accesses the Procedure resource directly from the ["Procedure"] selector:

      define WellFormedProcedure:
	  ["Procedure" ] theProcedure
	 return  Tuple {
		  resource: theProcedure,
		  id: theProcedure.id,
		  code: theProcedure.code,
		  performed:theProcedure.performed
		}

and note the output:

        WellFormedProcedure=[Tuple {
		"resource": org.hl7.fhir.r4.model.Procedure@41ef649
		"id": Procedure-1
		"code": Concept {
		Code { code: 112943005, system: http://snomed.info/sct, version: null, display: Epidural injection of anesthetic substance, diagnostic, caudal, continuous }
	}
		"performed": Interval[2026-04-11T08:00:00, 2026-04-11T10:15:00]
	}]

The Procedure resources selected from both of the defines above are the same (note the internal "resource" identifier), but the first version is malformed, the latter is correct.

Note: it doesn't matter what resource type(s) we are selecting. In the above scenario we are selecting "Procedure" resources. But you could use "Patient", or "Encounter" or whatever.

@antvaset
Copy link
Contributor

I have v0.7.3 of the extension and can reproduce the issue with union. E.g. this

define x:
  [Observation] a
    union [Procedure] b

evaluates to

x=[Observation(id=obs-1), Procedure(id=proc-1)]

while this

define x:
  [Observation]
    union [Procedure]

gives

x=[]

However I can successfully create a Tuple with the elements from the procedure from the union. E.g.

define x:
  [Observation]
    union [Procedure] b

define y:
  (singleton from x) z
    return Tuple {
      resource: z,
      id: z.id,
      code: z.code,
      performed: z.performed
    }

gives

x=[Procedure(id=proc-1)]
y=Tuple {
	"resource": org.hl7.fhir.r4.model.Procedure@172c09c5
	"id": Procedure/proc-1
	"code": org.hl7.fhir.r4.model.CodeableConcept@5bfe90b4
	"performed": org.hl7.fhir.r4.model.Period@35ab1ab4
}

@brynrhodes brynrhodes added the bug label Nov 19, 2024
@brynrhodes brynrhodes added this to the Maintenance milestone Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants