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

Make sure a Library includes the dataRequirements from its dependencies #623

Open
wants to merge 5 commits into
base: develop-2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cql/CoreTests/CSharp/TestRetrieve-1.0.1.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,26 @@ public Patient Patient(CqlContext context)
return b_;
}


[CqlDeclaration("InDemographic")]
public IEnumerable<Patient> InDemographic(CqlContext context)
{
IEnumerable<Patient> a_ = context.Operators.Retrieve<Patient>(new RetrieveParameters(default, default, default, "http://hl7.org/fhir/StructureDefinition/Patient"));

return a_;
}


[CqlDeclaration("SexuallyActive")]
public bool? SexuallyActive(CqlContext context)
{
IEnumerable<Condition> a_ = context.Operators.Retrieve<Condition>(new RetrieveParameters(default, default, default, "http://hl7.org/fhir/StructureDefinition/Condition"));
bool? b_ = context.Operators.Exists<Condition>(a_);
IEnumerable<ServiceRequest> c_ = context.Operators.Retrieve<ServiceRequest>(new RetrieveParameters(default, default, default, "http://hl7.org/fhir/StructureDefinition/ServiceRequest"));
bool? d_ = context.Operators.Exists<ServiceRequest>(c_);
bool? e_ = context.Operators.Or(b_, d_);

return e_;
}

}
9 changes: 9 additions & 0 deletions Cql/CoreTests/CSharp/TestRetrieveInclude-1.0.1.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,13 @@ public CqlValueSet Inflammatory_Diseases_of_Female_Reproductive_Organs(CqlContex
public CqlValueSet Chlamydia(CqlContext context) =>
new CqlValueSet("2.16.840.1.113883.3.464.1003.112.12.1003", default);


[CqlDeclaration("InDemographic")]
public IEnumerable<Observation> InDemographic(CqlContext context)
{
IEnumerable<Observation> a_ = context.Operators.Retrieve<Observation>(new RetrieveParameters(default, default, default, "http://hl7.org/fhir/StructureDefinition/Observation"));

return a_;
}

}
4 changes: 3 additions & 1 deletion Cql/CoreTests/Elm/TestDataRequirementsAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public void ConvertRetrievesToDataRequirements()

// Assert
var actual = dataRequirements.Select(dr => dr.Type).Distinct().ToArray();
actual.Should().BeEquivalentTo([FHIRAllTypes.Patient]);

// Condition+Patient+ServiceRequest is from TestRetrieve, Observation is from TestRetrieveInclude
actual.Should().BeEquivalentTo([FHIRAllTypes.Patient, FHIRAllTypes.ServiceRequest, FHIRAllTypes.Condition, FHIRAllTypes.Observation]);
}
}
18 changes: 2 additions & 16 deletions Cql/CoreTests/Input/ELM/HL7/TestRetrieve.cql
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,7 @@ parameter MeasurementPeriod default Interval[DateTime(2013, 1, 1, 0, 0, 0, 0), D

context Patient

define "InDemographic":
AgeInYearsAt(start of MeasurementPeriod) >= 16 and AgeInYearsAt(start of MeasurementPeriod) < 24
and "Patient"."gender" in test."Female Administrative Sex"
define "InDemographic": ["Patient"]

define "SexuallyActive":
exists (["Condition": test."Other Female Reproductive Conditions"] C where Interval[C.onset, C.abatement] overlaps MeasurementPeriod)
or exists (["Condition": test."Genital Herpes"] C where Interval[C.onset, C.abatement] overlaps MeasurementPeriod)
or exists (["Condition": onset = 'HIV'] C where Interval[C.onset, C.abatement] overlaps MeasurementPeriod)
or exists (["ServiceRequest": status in {'a','b'}] O where O.authoredOn during MeasurementPeriod)

define "InInitialPopulation":
"InDemographic" and "SexuallyActive"

define "InDenominator":
true

define "InNumerator":
exists (["DiagnosticReport": "Chlamydia Screening"] R where R.effective during MeasurementPeriod and R."result" is not null)
exists (["Condition"]) or exists (["ServiceRequest"])
92 changes: 92 additions & 0 deletions Cql/CoreTests/Input/ELM/HL7/TestRetrieve.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,98 @@
"type" : "Retrieve"
}
}
}, {
"locator" : "30:1-30:35",
"name" : "InDemographic",
"context" : "Patient",
"accessLevel" : "Public",
"resultTypeSpecifier" : {
"type" : "ListTypeSpecifier",
"elementType" : {
"name" : "{http://hl7.org/fhir}Patient",
"type" : "NamedTypeSpecifier"
}
},
"expression" : {
"locator" : "30:25-30:35",
"dataType" : "{http://hl7.org/fhir}Patient",
"templateId" : "http://hl7.org/fhir/StructureDefinition/Patient",
"type" : "Retrieve",
"resultTypeSpecifier" : {
"type" : "ListTypeSpecifier",
"elementType" : {
"name" : "{http://hl7.org/fhir}Patient",
"type" : "NamedTypeSpecifier"
}
}
}
}, {
"locator" : "32:1-33:57",
"resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean",
"name" : "SexuallyActive",
"context" : "Patient",
"accessLevel" : "Public",
"expression" : {
"locator" : "33:5-33:57",
"resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean",
"type" : "Or",
"signature" : [ {
"name" : "{urn:hl7-org:elm-types:r1}Boolean",
"type" : "NamedTypeSpecifier"
}, {
"name" : "{urn:hl7-org:elm-types:r1}Boolean",
"type" : "NamedTypeSpecifier"
} ],
"operand" : [ {
"locator" : "33:5-33:26",
"resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean",
"type" : "Exists",
"signature" : [ {
"type" : "ListTypeSpecifier",
"elementType" : {
"name" : "{http://hl7.org/fhir}Condition",
"type" : "NamedTypeSpecifier"
}
} ],
"operand" : {
"locator" : "33:12-33:26",
"dataType" : "{http://hl7.org/fhir}Condition",
"templateId" : "http://hl7.org/fhir/StructureDefinition/Condition",
"type" : "Retrieve",
"resultTypeSpecifier" : {
"type" : "ListTypeSpecifier",
"elementType" : {
"name" : "{http://hl7.org/fhir}Condition",
"type" : "NamedTypeSpecifier"
}
}
}
}, {
"locator" : "33:31-33:57",
"resultTypeName" : "{urn:hl7-org:elm-types:r1}Boolean",
"type" : "Exists",
"signature" : [ {
"type" : "ListTypeSpecifier",
"elementType" : {
"name" : "{http://hl7.org/fhir}ServiceRequest",
"type" : "NamedTypeSpecifier"
}
} ],
"operand" : {
"locator" : "33:38-33:57",
"dataType" : "{http://hl7.org/fhir}ServiceRequest",
"templateId" : "http://hl7.org/fhir/StructureDefinition/ServiceRequest",
"type" : "Retrieve",
"resultTypeSpecifier" : {
"type" : "ListTypeSpecifier",
"elementType" : {
"name" : "{http://hl7.org/fhir}ServiceRequest",
"type" : "NamedTypeSpecifier"
}
}
}
} ]
}
} ]
}
}
Expand Down
4 changes: 4 additions & 0 deletions Cql/CoreTests/Input/ELM/HL7/TestRetrieveInclude.cql
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
library TestRetrieveInclude version '1.0.1'

using FHIR version '4.0.1'

valueset "Female Administrative Sex": '2.16.840.1.113883.3.560.100.2'
valueset "Other Female Reproductive Conditions": '2.16.840.1.113883.3.464.1003.111.12.1006'
valueset "Genital Herpes": '2.16.840.1.113883.3.464.1003.110.12.1049'
valueset "Genococcal Infections and Venereal Diseases": '2.16.840.1.113883.3.464.1003.112.12.1001'
valueset "Inflammatory Diseases of Female Reproductive Organs": '2.16.840.1.113883.3.464.1003.112.12.1004'
valueset "Chlamydia": '2.16.840.1.113883.3.464.1003.112.12.1003'

define "InDemographic": ["Observation"]
45 changes: 39 additions & 6 deletions Cql/CoreTests/Input/ELM/HL7/TestRetrieveInclude.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,79 @@
"def" : [ {
"localIdentifier" : "System",
"uri" : "urn:hl7-org:elm-types:r1"
}, {
"locator" : "3:1-3:26",
"localIdentifier" : "FHIR",
"uri" : "http://hl7.org/fhir",
"version" : "4.0.1"
} ]
},
"valueSets" : {
"def" : [ {
"locator" : "3:1-3:69",
"locator" : "5:1-5:69",
"resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet",
"name" : "Female Administrative Sex",
"id" : "2.16.840.1.113883.3.560.100.2",
"accessLevel" : "Public"
}, {
"locator" : "4:1-4:91",
"locator" : "6:1-6:91",
"resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet",
"name" : "Other Female Reproductive Conditions",
"id" : "2.16.840.1.113883.3.464.1003.111.12.1006",
"accessLevel" : "Public"
}, {
"locator" : "5:1-5:69",
"locator" : "7:1-7:69",
"resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet",
"name" : "Genital Herpes",
"id" : "2.16.840.1.113883.3.464.1003.110.12.1049",
"accessLevel" : "Public"
}, {
"locator" : "6:1-6:98",
"locator" : "8:1-8:98",
"resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet",
"name" : "Genococcal Infections and Venereal Diseases",
"id" : "2.16.840.1.113883.3.464.1003.112.12.1001",
"accessLevel" : "Public"
}, {
"locator" : "7:1-7:106",
"locator" : "9:1-9:106",
"resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet",
"name" : "Inflammatory Diseases of Female Reproductive Organs",
"id" : "2.16.840.1.113883.3.464.1003.112.12.1004",
"accessLevel" : "Public"
}, {
"locator" : "8:1-8:64",
"locator" : "10:1-10:64",
"resultTypeName" : "{urn:hl7-org:elm-types:r1}ValueSet",
"name" : "Chlamydia",
"id" : "2.16.840.1.113883.3.464.1003.112.12.1003",
"accessLevel" : "Public"
} ]
},
"statements" : {
"def" : [ {
"locator" : "12:1-12:39",
"name" : "InDemographic",
"context" : "Patient",
"accessLevel" : "Public",
"resultTypeSpecifier" : {
"type" : "ListTypeSpecifier",
"elementType" : {
"name" : "{http://hl7.org/fhir}Observation",
"type" : "NamedTypeSpecifier"
}
},
"expression" : {
"locator" : "12:25-12:39",
"dataType" : "{http://hl7.org/fhir}Observation",
"templateId" : "http://hl7.org/fhir/StructureDefinition/Observation",
"type" : "Retrieve",
"resultTypeSpecifier" : {
"type" : "ListTypeSpecifier",
"elementType" : {
"name" : "{http://hl7.org/fhir}Observation",
"type" : "NamedTypeSpecifier"
}
}
}
} ]
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion Cql/Cql.Compiler/LibrarySet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class LibrarySet : IReadOnlyCollection<Library>//, IReadOnlyDictionary<st
/// </summary>
public string Name { get; }

private readonly Dictionary<string, (Library library, LibraryByVersionedIdentifierHashSet dependencies)> _libraryInfosByVersionedIdentifier;
private readonly Dictionary<string, (Library library, LibraryByVersionedIdentifierHashSet dependencies)> _libraryInfosByVersionedIdentifier;

private (IReadOnlySet<Library> RootLibraries, IReadOnlyCollection<Library> TopologicallySortedLibraries) _calculatedState;

Expand Down Expand Up @@ -101,6 +101,16 @@ private bool TryGetLibraryInfoByVersionedIdentifier(
public IReadOnlySet<Library> GetLibraryDependencies(string? versionedIdentifier, bool throwError = true) =>
TryGetLibraryInfoByVersionedIdentifier(versionedIdentifier, throwError, out var info) ? info.dependencies : EmptySet<Library>.Instance;

/// <summary>
/// Gets the dependencies of a library.
/// </summary>
/// <param name="parent">The library to retrieve the dependencies for.</param>
/// <param name="throwError">Indicates whether to throw an exception if the library is not found.</param>
/// <returns>The dependencies of the parent library, or an empty list if the library is not part of this <see cref="LibrarySet"/>.</returns>
/// <exception cref="KeyNotFoundError">If the library is not part of the LibrarySet and if throwError is set to <c>true</c>.</exception>
public IReadOnlySet<Library> GetLibraryDependencies(Library parent, bool throwError = true) =>
GetLibraryDependencies(parent.GetVersionedIdentifier(), throwError);

/// <summary>
/// Loads the libraries from the specified collection of files.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Cql/Cql.Compiler/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Hl7.Cql.Compiler.LibrarySet.AddLibraries(System.Collections.Generic.IEnumerable<
Hl7.Cql.Compiler.LibrarySet.Count.get -> int
Hl7.Cql.Compiler.LibrarySet.GetEnumerator() -> System.Collections.Generic.IEnumerator<Hl7.Cql.Elm.Library!>!
Hl7.Cql.Compiler.LibrarySet.GetLibrary(string! versionedIdentifier, bool throwError = true) -> Hl7.Cql.Elm.Library?
Hl7.Cql.Compiler.LibrarySet.GetLibraryDependencies(Hl7.Cql.Elm.Library! parent, bool throwError = true) -> System.Collections.Generic.IReadOnlySet<Hl7.Cql.Elm.Library!>!
Hl7.Cql.Compiler.LibrarySet.GetLibraryDependencies(string? versionedIdentifier, bool throwError = true) -> System.Collections.Generic.IReadOnlySet<Hl7.Cql.Elm.Library!>!
Hl7.Cql.Compiler.LibrarySet.LibrarySet(string! name = "", params Hl7.Cql.Elm.Library![]! libraries) -> void
Hl7.Cql.Compiler.LibrarySet.LoadLibraries(System.Collections.Generic.IReadOnlyCollection<System.IO.FileInfo!>! files) -> System.Collections.Generic.IReadOnlyCollection<Hl7.Cql.Elm.Library!>!
Expand Down
Loading