Skip to content

Commit

Permalink
Merge pull request #650 from FirelyTeam/458-upgrade-java-tooling-and-…
Browse files Browse the repository at this point in the history
…cms-measures-to-latest

458 upgrade java tooling
  • Loading branch information
baseTwo authored Dec 6, 2024
2 parents e8807d3 + f2964f7 commit 8315c1a
Show file tree
Hide file tree
Showing 11 changed files with 430 additions and 44 deletions.
19 changes: 13 additions & 6 deletions Cql-Sdk-All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Measures.Demo", "Demo\Measu
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CLI", "Demo\CLI\CLI.csproj", "{12BB22FD-E576-44A9-AE74-A5A673715870}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{7D787B73-D44A-4B65-B83F-4AF4A752F26C}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "30 Samples", "30 Samples", "{7D787B73-D44A-4B65-B83F-4AF4A752F26C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Cql", "Cql", "{4B5D75F5-E2FC-4CCB-90EF-6DC4A0193032}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -74,7 +74,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreTests", "Cql\CoreTests\
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "50 Tests", "50 Tests", "{314A4A1E-1671-4F4C-BA1F-DEE73D584677}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{DEA0937C-6F6B-4B25-8F9B-0ABE82978321}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "20 Tests", "20 Tests", "{DEA0937C-6F6B-4B25-8F9B-0ABE82978321}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.Measures.Demo", "Demo\Test.Measures.Demo\Test.Measures.Demo.csproj", "{95F35BF6-1FF1-4A5F-8725-A8EA4F1D43CD}"
ProjectSection(ProjectDependencies) = postProject
Expand Down Expand Up @@ -124,6 +124,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ncqa.HT.MeasuresTests", "su
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "Cql\Benchmarks\Benchmarks.csproj", "{B4C6C534-15E6-4364-A68C-286EB0EFAD50}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "00 MSBuild Tooling", "00 MSBuild Tooling", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "10 Demo Projects", "10 Demo Projects", "{85401759-2C64-414D-9882-4DB1EA41C2ED}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "10 Demo Projects", "10 Demo Projects", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -418,11 +424,11 @@ Global
{8FF55BB5-6004-4461-B8EA-19E9F41B970B} = {39731466-DC8C-4FB2-A4D3-C4212A87700A}
{50590B39-F376-4E96-92CF-67F84C149E86} = {97D67019-21A7-4591-A216-1B76BD0E68A4}
{FEF0C134-505D-4206-8630-569A6762F787} = {97D67019-21A7-4591-A216-1B76BD0E68A4}
{1C19BCFA-9965-49EC-952B-DBC753E219A2} = {B00E560D-AE0C-48E1-9013-57115AF05F41}
{A7111722-6C8F-42AA-8CDD-732D34FB678A} = {B00E560D-AE0C-48E1-9013-57115AF05F41}
{1C19BCFA-9965-49EC-952B-DBC753E219A2} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{A7111722-6C8F-42AA-8CDD-732D34FB678A} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{12BB22FD-E576-44A9-AE74-A5A673715870} = {7D787B73-D44A-4B65-B83F-4AF4A752F26C}
{7D787B73-D44A-4B65-B83F-4AF4A752F26C} = {B00E560D-AE0C-48E1-9013-57115AF05F41}
{B1161915-FFB0-412A-9C65-2F4E046FA9B8} = {B00E560D-AE0C-48E1-9013-57115AF05F41}
{B1161915-FFB0-412A-9C65-2F4E046FA9B8} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{ED703B53-BF12-4F55-B35A-F8290F542E16} = {314A4A1E-1671-4F4C-BA1F-DEE73D584677}
{314A4A1E-1671-4F4C-BA1F-DEE73D584677} = {4B5D75F5-E2FC-4CCB-90EF-6DC4A0193032}
{DEA0937C-6F6B-4B25-8F9B-0ABE82978321} = {B00E560D-AE0C-48E1-9013-57115AF05F41}
Expand All @@ -431,7 +437,7 @@ Global
{D0F1B9D3-DD8C-4F25-B7AF-0C2EB4E17AC3} = {4B5D75F5-E2FC-4CCB-90EF-6DC4A0193032}
{97D67019-21A7-4591-A216-1B76BD0E68A4} = {4B5D75F5-E2FC-4CCB-90EF-6DC4A0193032}
{B574B177-48B2-455B-BEF8-B7D6DB5C3015} = {97D67019-21A7-4591-A216-1B76BD0E68A4}
{C5C0F7CF-D0A4-41F5-B426-D99F40EC0379} = {B00E560D-AE0C-48E1-9013-57115AF05F41}
{C5C0F7CF-D0A4-41F5-B426-D99F40EC0379} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{A2259B13-A115-4EA3-9DFB-5411DB88EA6F} = {4B5D75F5-E2FC-4CCB-90EF-6DC4A0193032}
{AF223BDF-576D-45FD-9A33-483BAFE1BB75} = {A2259B13-A115-4EA3-9DFB-5411DB88EA6F}
{BF2C14B3-EF9B-4BE9-A843-EAA05368BD5A} = {A2259B13-A115-4EA3-9DFB-5411DB88EA6F}
Expand All @@ -444,6 +450,7 @@ Global
{C573B0CB-733A-4E22-9693-4581E683109C} = {1AF2E4B2-99C5-4678-B926-D224CC83A8F7}
{584116D7-4E88-401E-8089-BAA6A35DB591} = {1AF2E4B2-99C5-4678-B926-D224CC83A8F7}
{B4C6C534-15E6-4364-A68C-286EB0EFAD50} = {314A4A1E-1671-4F4C-BA1F-DEE73D584677}
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {B00E560D-AE0C-48E1-9013-57115AF05F41}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {366252DE-C2FB-4EAC-96EE-22210BD43DE2}
Expand Down
6 changes: 6 additions & 0 deletions Cql/CoreTests/Packaging/ResourceFileNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public void Parse_ValidString_ShouldReturnResourceFileName()
[TestMethod]
public void Parse_InvalidString_ShouldThrowFormatException()
{
if (ResourceFileName.AllowUnderscores)
return;

Action act = () => ResourceFileName.Parse("Invalid-Str_ing", null);
act.Should().Throw<FormatException>();
}
Expand Down Expand Up @@ -100,6 +103,9 @@ public void TryParse_ValidString_ShouldReturnTrueAndResourceFileName()
[TestMethod]
public void TryParse_InvalidString_ShouldReturnFalse()
{
if (ResourceFileName.AllowUnderscores)
return;

var result = ResourceFileName.TryParse("Invalid-Str_ing", null, out var resourceFileName);
result.Should().BeFalse();
resourceFileName.Should().Be(default(ResourceFileName));
Expand Down
56 changes: 26 additions & 30 deletions Cql/Cql.Compiler/ExpressionBuilderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -945,13 +945,15 @@ protected Expression Property(Property op)
using (PushElement(op))
{
if (string.IsNullOrWhiteSpace(op.path))
throw this.NewExpressionBuildingException("path cannot be null or empty");
throw this.NewExpressionBuildingException("Property expression cannot have null or empty path");
var path = op.path;

Type? expectedType;

if (!string.IsNullOrWhiteSpace(op.scope))
{
var scopeExpression = GetScopeExpression(op.scope!);
var expectedType = TypeFor(op) ?? typeof(object);
expectedType = TypeFor(op) ?? typeof(object);
var pathMemberInfo = _typeResolver.GetProperty(scopeExpression.Type, path!) ??
_typeResolver.GetProperty(scopeExpression.Type, op.path);
if (pathMemberInfo == null)
Expand All @@ -970,41 +972,35 @@ protected Expression Property(Property op)
return propogate;
}

if (op.source != null)
if (op.source == null)
throw this.NewExpressionBuildingException("Property expression cannot have an empty source when scope is empty");

var source = TranslateArg(op.source);
var parts = path.Split('.');
if (parts.Length > 1)
{
var source = TranslateArg(op.source);
var parts = path.Split('.');
if (parts.Length > 1)
// support paths like birthDate.value on Patient
for (int i = 0; i < parts.Length; i++)
{
// support paths like birthDate.value on Patient
for (int i = 0; i < parts.Length; i++)
var pathPart = parts[i];
var pathMemberInfo = _typeResolver.GetProperty(source.Type, pathPart);
if (pathMemberInfo != null)
{
var pathPart = parts[i];
var pathMemberInfo = _typeResolver.GetProperty(source.Type, pathPart);
if (pathMemberInfo != null)
{
var propertyAccess = PropagateNull(source, pathMemberInfo);
source = propertyAccess;
}
var propertyAccess = PropagateNull(source, pathMemberInfo);
source = propertyAccess;
}
return source;
}

var expectedType = TypeFor(op, throwIfNotFound: false);

// If we cannot determine the type from the ELM, let's try
// if the POCO model can help us.
if (expectedType == null)
{
expectedType = _typeResolver.GetProperty(source.Type, path)?.PropertyType
?? throw this.NewExpressionBuildingException("Cannot resolve type for expression");
}

var result = PropertyHelper(source, path, expectedType);
return result;
return source;
}

throw new NotImplementedException().WithContext(this);
// If we cannot determine the type from the ELM, let's try
// if the POCO model can help us.
expectedType = TypeFor(op, throwIfNotFound: false)
?? _typeResolver.GetProperty(source.Type, path)?.PropertyType
?? throw this.NewExpressionBuildingException("Cannot resolve type for expression");

var result = PropertyHelper(source, path, expectedType);
return result;
}
}

Expand Down
15 changes: 12 additions & 3 deletions Cql/Cql.Packaging/ResourceFileName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ namespace Hl7.Cql.Packaging;
// Should not contain underscores - https://build.fhir.org/ig/HL7/cql-ig/conformance.html#library-name-and-url
// Should not contain hyphens - Used as delimiter between parts of the file name

private static readonly ArgValidator<string> ValidateType = Arg.IsRequired().And(Arg.ShouldNotContain('-', '_'));
private static readonly ArgValidator<string> ValidateIdentifier = Arg.IsRequired().And(Arg.ShouldNotContain('-', '_'));
private static readonly ArgValidator<string?> ValidateVersion = Arg.ShouldNotContain('-', '_');
internal const bool AllowUnderscores = true; // Allowed for now, since NCQA cql files use underscores

#pragma warning disable CS0162 // Unreachable code detected
private static readonly char[] InvalidChars =
AllowUnderscores
? (char[])['-'/*, '_'*/]
: (char[])['-', '_'];
#pragma warning restore CS0162 // Unreachable code detected

private static readonly ArgValidator<string> ValidateType = Arg.IsRequired().And(Arg.ShouldNotContain(InvalidChars));
private static readonly ArgValidator<string> ValidateIdentifier = Arg.IsRequired().And(Arg.ShouldNotContain(InvalidChars));
private static readonly ArgValidator<string?> ValidateVersion = Arg.ShouldNotContain(InvalidChars);

private ResourceFileName(
string type,
Expand Down
7 changes: 6 additions & 1 deletion Demo/Cql/Build/CqlToElm.Targets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
</ItemGroup>

<PropertyGroup>

<!-- For certain Java tooling version use on or the other -->
<JavaCommand>java</JavaCommand>
<!-- <JavaCommand>java -Djakarta.xml.bind.JAXBContextFactory=org.eclipse.persistence.jaxb.XMLBindingContextFactory</JavaCommand> -->

<ClassPath>-classpath $(TargetDependencies)/* org.cqframework.cql.cql2elm.cli.Main</ClassPath>
<JavaOutputFile>$(MSBuildProjectDirectory)/elm-build.log</JavaOutputFile>
<JavaArgs>-input $(CqlDirectory) -f JSON -output $(ElmDirectory) -locators true -result-types true -signatures All</JavaArgs>
<JavaCLI>java -Djakarta.xml.bind.JAXBContextFactory=org.eclipse.persistence.jaxb.XMLBindingContextFactory $(ClassPath) $(JavaArgs)</JavaCLI>
<JavaCLI>$(JavaCommand) $(ClassPath) $(JavaArgs)</JavaCLI>
</PropertyGroup>

<Target Name="GenerateElmFiles"
Expand Down
8 changes: 6 additions & 2 deletions Demo/Cql/Build/Mvn.Targets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
<!-- Download MVN Dependencies -->
<PropertyGroup>
<!--
If you change the version here, you also need to update it in the pom.xml file
If you change the version here, you also need to update it in the pom.xml and Mvn.Targets.xml files
The latest version number can be found under the releases tab of the CQL to ELM CLI repository
see: https://github.com/cqframework/clinical_quality_language/releases
The Java tooling is cached in the target/dependency folder and must be manually removed if the version is changed
After that, build the Cql project in Visual Studio, which will download the tooling again into target/dependency.
-->
<CqlToElmCliVersion>3.18.0</CqlToElmCliVersion>
<CqlToElmCliVersion>3.1.0</CqlToElmCliVersion>
<TargetDependencies>$(MSBuildThisFileDirectory)target/dependency</TargetDependencies>
<PomXmlPath>$(MSBuildThisFileDirectory)pom.xml</PomXmlPath>
<Today>$([System.DateTime]::Now.ToString('yyyy-MM-dd-HH-mm-ss-fff'))</Today>
Expand Down
11 changes: 10 additions & 1 deletion Demo/Cql/Build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@
<artifactId>demo</artifactId>
<version>1.0</version>
<properties>
<cql.version>3.18.0</cql.version>
<!--
If you change the version here, you also need to update it in the pom.xml and Mvn.Targets.xml files
The latest version number can be found under the releases tab of the CQL to ELM CLI repository
see: https://github.com/cqframework/clinical_quality_language/releases
The Java tooling is cached in the target/dependency folder and must be manually removed if the version is changed
After that, build the Cql project in Visual Studio, which will download the tooling again into target/dependency.
-->
<cql.version>3.1.0</cql.version>
</properties>
<repositories>
<repository>
Expand Down
87 changes: 87 additions & 0 deletions Demo/Measures.Demo/CSharp/MeasureExample-0.0.1.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using System.Linq;
using System.Collections.Generic;
using Hl7.Cql.Runtime;
using Hl7.Cql.Primitives;
using Hl7.Cql.Abstractions;
using Hl7.Cql.ValueSets;
using Hl7.Cql.Iso8601;
using System.Reflection;
using Hl7.Cql.Operators;
using Hl7.Fhir.Model;
using Range = Hl7.Fhir.Model.Range;
using Task = Hl7.Fhir.Model.Task;

[System.CodeDom.Compiler.GeneratedCode(".NET Code Generation", "2.0.8.0")]
[CqlLibrary("MeasureExample", "0.0.1")]
public partial class MeasureExample_0_0_1 : ILibrary, ISingleton<MeasureExample_0_0_1>
{
private MeasureExample_0_0_1() {}

public static MeasureExample_0_0_1 Instance { get; } = new();

#region Library Members
public string Name => "MeasureExample";
public string Version => "0.0.1";
public ILibrary[] Dependencies => [];
#endregion Library Members

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

return b_;
}


[CqlDeclaration("Initial population")]
[CqlTag("measure", "Measure Resource Example")]
[CqlTag("year", "2024")]
[CqlTag("domain", "Testing Measures")]
[CqlTag("group", "1")]
[CqlTag("group", "2")]
[CqlTag("population", "initial-population")]
[CqlTag("description", "Patients in the IP")]
public bool? Initial_population(CqlContext context) =>
true;


[CqlDeclaration("Exclusion")]
[CqlTag("group", "1")]
[CqlTag("group", "2")]
[CqlTag("population", "denominator-exclusion")]
public bool? Exclusion(CqlContext context) =>
false;


[CqlDeclaration("Denominator")]
[CqlTag("group", "1")]
[CqlTag("group", "2")]
[CqlTag("population", "denominator")]
public bool? Denominator(CqlContext context)
{
bool? a_ = this.Initial_population(context);
bool? b_ = this.Exclusion(context);
bool? c_ = context.Operators.Not(b_);
bool? d_ = context.Operators.And(a_, c_);

return d_;
}


[CqlDeclaration("Numerator 1")]
[CqlTag("group", "1")]
[CqlTag("population", "numerator")]
public bool? Numerator_1(CqlContext context) =>
true;


[CqlDeclaration("Numerator 2")]
[CqlTag("group", "2")]
[CqlTag("population", "numerator")]
public bool? Numerator_2(CqlContext context) =>
false;

}
51 changes: 51 additions & 0 deletions LibrarySets/Demo/Cql/MeasureExample.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
library MeasureExample version'0.0.1'

using FHIR version '4.0.1'

context Patient

/**
* @measure: Measure Resource Example
* @year: 2024
* @domain: Testing Measures
*/

/*
* @group: 1
* @group: 2
* @population: initial-population
* @description: Patients in the IP
*/
define "Initial population":
true

/*
* @group: 1
* @group: 2
* @population: denominator
*/
define "Denominator":
"Initial population"
and not "Exclusion"

/*
* @group: 1
* @group: 2
* @population: denominator-exclusion
*/
define "Exclusion":
false

/*
* @group: 1
* @population: numerator
*/
define "Numerator 1":
true

/*
* @group: 2
* @population: numerator
*/
define "Numerator 2":
false
Loading

0 comments on commit 8315c1a

Please sign in to comment.