Skip to content

Commit 79b699a

Browse files
#1475: Fixed mapping expansions for profile-informed authoring not re… (#1476)
#1475: Fixed mapping expansions for profile-informed authoring not respecting signature level Co-authored-by: JP <[email protected]>
1 parent 10af73a commit 79b699a

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/LibraryBuilder.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,6 +2743,22 @@ public Expression applyTargetMap(Expression source, String targetMap) {
27432743
String functionArgument = targetMap.substring(invocationStart + 1, targetMap.lastIndexOf(')'));
27442744
Expression argumentSource =
27452745
functionArgument.equals("%value") ? source : applyTargetMap(source, functionArgument);
2746+
2747+
// NOTE: This is needed to work around the mapping for ToInterval
2748+
// FHIRHelpers defines multiple overloads of ToInterval, but the type mapping
2749+
// does not have the type of the source data type.
2750+
// All the mappings for ToInterval use FHIR.Period, so this is safe to assume
2751+
// In addition, no other FHIRHelpers functions use overloads (except ToString and ToDateTime,
2752+
// but those mappings expand the value element directly, rather than invoking the FHIRHelpers function)
2753+
TypeSpecifier argumentSignature = null;
2754+
if (this.options.getSignatureLevel() != SignatureLevel.None) {
2755+
if (qualifiedFunctionName.equals("FHIRHelpers.ToInterval")) {
2756+
NamedTypeSpecifier namedTypeSpecifier =
2757+
new NamedTypeSpecifier().withName(dataTypeToQName(resolveTypeName("FHIR", "Period")));
2758+
argumentSignature = namedTypeSpecifier;
2759+
}
2760+
}
2761+
27462762
if (argumentSource.getResultType() instanceof ListType) {
27472763
Query query = of.createQuery()
27482764
.withSource(of.createAliasedQuerySource()
@@ -2752,6 +2768,11 @@ public Expression applyTargetMap(Expression source, String targetMap) {
27522768
.withLibraryName(libraryName)
27532769
.withName(functionName)
27542770
.withOperand(of.createAliasRef().withName("$this"));
2771+
2772+
if (argumentSignature != null) {
2773+
fr.getSignature().add(argumentSignature);
2774+
}
2775+
27552776
// This doesn't quite work because the US.Core types aren't subtypes of FHIR types.
27562777
// resolveCall(libraryName, functionName, new FunctionRefInvocation(fr), false, false);
27572778
query.setReturn(of.createReturnClause().withDistinct(false).withExpression(fr));
@@ -2763,6 +2784,11 @@ public Expression applyTargetMap(Expression source, String targetMap) {
27632784
.withName(functionName)
27642785
.withOperand(argumentSource);
27652786
fr.setResultType(source.getResultType());
2787+
2788+
if (argumentSignature != null) {
2789+
fr.getSignature().add(argumentSignature);
2790+
}
2791+
27662792
return fr;
27672793
// This doesn't quite work because the US.Core types aren't subtypes of FHIR types,
27682794
// or they are defined as System types and not FHIR types

Src/java/cql-to-elm/src/test/java/org/cqframework/cql/cql2elm/TranslationTests.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,38 @@ void abstractClassNotRetrievable() throws IOException {
467467
errors.stream().map(Throwable::getMessage).collect(Collectors.toList());
468468
assertThat(errorMessages, contains("Specified data type DomainResource does not support retrieval."));
469469
}
470+
471+
@Test
472+
void mappingExpansionsRespectSignatureLevel() throws IOException {
473+
// See: https://github.com/cqframework/clinical_quality_language/issues/1475
474+
final CqlTranslator translator = TestUtils.runSemanticTest(
475+
"MappingExpansionsRespectSignatureLevel.cql", 0, LibraryBuilder.SignatureLevel.Overloads);
476+
/*
477+
ExpressionDef: EncounterPeriod
478+
expression is Query
479+
return
480+
expression is FunctionRef
481+
name FHIRHelpers.ToInterval
482+
signature is NamedTypeSpecifier FHIR.Period
483+
*/
484+
485+
Library compiledLibrary = translator.getTranslatedLibrary().getLibrary();
486+
List<ExpressionDef> statements = compiledLibrary.getStatements().getDef();
487+
488+
assertThat(statements.size(), is(2));
489+
ExpressionDef encounterPeriod = statements.get(1);
490+
assertThat(encounterPeriod.getName(), is("EncounterPeriod"));
491+
assertThat(encounterPeriod.getExpression(), instanceOf(Query.class));
492+
Query query = (Query) encounterPeriod.getExpression();
493+
assertThat(query.getReturn().getExpression(), instanceOf(FunctionRef.class));
494+
FunctionRef functionRef = (FunctionRef) query.getReturn().getExpression();
495+
assertThat(functionRef.getLibraryName(), is("FHIRHelpers"));
496+
assertThat(functionRef.getName(), is("ToInterval"));
497+
assertThat(functionRef.getSignature(), notNullValue());
498+
assertThat(functionRef.getSignature().size(), is(1));
499+
assertThat(functionRef.getSignature().get(0), instanceOf(NamedTypeSpecifier.class));
500+
NamedTypeSpecifier namedTypeSpecifier =
501+
(NamedTypeSpecifier) functionRef.getSignature().get(0);
502+
assertThat(namedTypeSpecifier.getName().getLocalPart(), is("Period"));
503+
}
470504
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
library MappingExpansionsRespectSignatureLevel
2+
3+
// https://github.com/cqframework/clinical_quality_language/issues/1475
4+
5+
using QICore version '4.1.1'
6+
7+
include FHIRHelpers version '4.0.1'
8+
9+
parameter "Measurement Period" Interval<DateTime> default Interval[@2024-01-01T00:00:00.0Z, @2025-01-01T00:00:00.0Z)
10+
11+
context Patient
12+
13+
define EncounterPeriod:
14+
[Encounter] E
15+
return E.period

0 commit comments

Comments
 (0)