FirelyTeam / firely-cql-sdk

BSD 3-Clause "New" or "Revised" License
30 stars 17 forks source link

Produced Library resources contain named expressions as parameters instead as data requirements #102

Open alexzautke opened 12 months ago

alexzautke commented 12 months ago

Describe the bug Take the following CQL expressions:

define "Qualifying Encounters":
  (
                    [Encounter: "Office Visit"]
                        union [Encounter: "Annual Wellness Visit"]
                        union [Encounter: "Preventive Care Services - Established Office Visit, 18 and Up"]
                        union [Encounter: "Preventive Care Services-Initial Office Visit, 18 and Up"]
                        union [Encounter: "Home Healthcare Services"]
                  ) ValidEncounter
                        where ValidEncounter.status  = 'finished'
                        and Global."Normalize Interval"(ValidEncounter.period) during "Measurement Period"

The SDK will produce a library resource based on this where "Qualifying Encounters" is mentioned as a parameter. However according to it should show up as a data requirement in the Library resource. Additionally, the "type" element in the "parameter" element of the Library is set to "List". Make sure to use the correct resource type.

Expected behavior Only parameters declared as parameters should be in the parameters section of the Library.

Version used: 1.0.0-rc2

EvanMachusak commented 11 months ago

CQL defines are included in the Library resource as parameters whose use is out. That is intended behavior.

The return type of the CQL in your snippet would be a List<Encounter>. Which value of FHIRAllTypes do you think it should be? When we use the CPG Library Evaluate operation, we return a Parameters resource. In this case, this definition would be expressed as a FHIR List resource containing the Encounters it returned.

EvanMachusak commented 11 months ago

We could set the type to Encounter and use the cardinality (max: "*") and then repeat the parameter name multiple times in the outputted Parameters resource. That would obviate the need for an extension that qualifies that the parameter's type is List and further that its element type is Encounter. But it runs the risk of losing ordering. CQL could do: define "Example"{1, 2, 3} and the Parameters output where the name Example is repeated 3 times with values 1, 2, and 3 could be the same as the output from define "Example": { 3,2,1 }. It's unclear to me how much, if at all, that matters.

baseTwo commented 2 months ago

@richfirely do you know if this ticket should be included in the September WGM milestone? I see it in the current sprint, but it is not assigned to that milestone yet. If not, I will move it to the backlog