Skip to content

Commit

Permalink
Merge pull request #15 from MeasureAuthoringTool/feature/mat-7821-use…
Browse files Browse the repository at this point in the history
…-latest-translator

[MAT-7821] Bump CQL-ELM Translator to 3.18.0
  • Loading branch information
jkotanchik-SB authored Nov 11, 2024
2 parents 6dbbcdc + 91750aa commit cc60c6c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 34 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# madie-translator-commons
# madie-translator-commons

#### CQL-ELM Translator Support

| translator-commons | CQL-ELM Translator |
|--------------------|-------------------------|
| 1.x.y | \>= 3.3.2 and <= 3.14.0 |
| 2.x.y | \>= 3.15.0 |
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
<modelVersion>4.0.0</modelVersion>
<groupId>gov.cms.madie</groupId>
<artifactId>madie-translator-commons</artifactId>
<version>1.0.0</version>
<version>2.0.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<mockito.version>5.12.0</mockito.version>
<slf4j.version>2.0.13</slf4j.version>
<cqframework.version>3.14.0</cqframework.version>
<cqframework.version>3.18.0</cqframework.version>
<spotify.fmt.version>2.21.1</spotify.fmt.version>
<lombok.version>1.18.24</lombok.version>
<lombok.version>1.18.30</lombok.version>
<madie.rest.commons.version>0.0.7-SNAPSHOT</madie.rest.commons.version>
<hamcrest.version>3.0-rc1</hamcrest.version>
<jaxb.api.version>2.3.1</jaxb.api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.cqframework.cql.cql2elm.LibraryBuilder;
import org.cqframework.cql.cql2elm.model.CompiledLibrary;
import org.cqframework.cql.cql2elm.model.ResolvedIdentifierContext;
import org.cqframework.cql.cql2elm.preprocessor.CqlPreprocessorElmCommonVisitor;
import org.cqframework.cql.elm.IdObjectFactory;
import org.cqframework.cql.gen.cqlBaseListener;
Expand All @@ -43,7 +44,6 @@
import org.cqframework.cql.gen.cqlParser.WithoutClauseContext;
import org.hl7.elm.r1.CodeDef;
import org.hl7.elm.r1.CodeSystemDef;
import org.hl7.elm.r1.Element;
import org.hl7.elm.r1.ExpressionDef;
import org.hl7.elm.r1.IncludeDef;
import org.hl7.elm.r1.ParameterDef;
Expand Down Expand Up @@ -160,15 +160,21 @@ private CompiledLibrary getCurrentLibraryContext() {
public void enterCodesystemDefinition(cqlParser.CodesystemDefinitionContext ctx) {
String identifier = parseString(ctx.identifier().getText());

if (library.resolve(identifier) instanceof CodeSystemDef csDef) {
CQLCodeSystem codeSystem = new CQLCodeSystem();
codeSystem.setId(csDef.getId());
codeSystem.setOID(csDef.getId());
// MAT-6935 extracting the version from the url
codeSystem.setCodeSystemVersion(getParsedVersion(csDef.getVersion()));
library
.resolve(identifier)
.getExactMatchElement()
.ifPresent(
element -> {
if (element instanceof CodeSystemDef csDef) {
CQLCodeSystem codeSystem = new CQLCodeSystem();
codeSystem.setId(csDef.getId());
codeSystem.setOID(csDef.getId());
// MAT-6935 extracting the version from the url
codeSystem.setCodeSystemVersion(getParsedVersion(csDef.getVersion()));

codeSystemMap.putIfAbsent(identifier, codeSystem);
}
codeSystemMap.putIfAbsent(identifier, codeSystem);
}
});
}

private String getParsedVersion(String version) {
Expand Down Expand Up @@ -391,12 +397,11 @@ public void enterRetrieve(@NotNull cqlParser.RetrieveContext ctx) {
String formattedIdentifier = formatIdentifier(identifier);

// we need to resolve based on the identifier since it will be looking in the proper library but
// we need
// to put the formatted identifier into the maps since this is the format MAT is looking for
// we need to put the formatted identifier into the maps.
String dataType =
parseString(ctx.namedTypeSpecifier().referentialOrTypeNameIdentifier().getText());
Element element = resolve(identifier, getCurrentLibraryContext());
if (element instanceof ValueSetDef) {

if (getCurrentLibraryContext().resolveValueSetRef(identifier) != null) {
Map<String, Set<String>> current = valueSetDataTypeMap.get(currentContext);
if (current == null) {
valueSetDataTypeMap.put(currentContext, new HashMap<>());
Expand All @@ -411,9 +416,11 @@ public void enterRetrieve(@NotNull cqlParser.RetrieveContext ctx) {

current.get(formattedIdentifier).add(dataType);
valueSetOids.putIfAbsent(
formattedIdentifier, ((ValueSetDef) element).getId().substring("urn:oid:".length()));

} else if (element instanceof CodeDef codeDef) {
formattedIdentifier,
(getCurrentLibraryContext().resolveValueSetRef(identifier))
.getId()
.substring("urn:oid:".length()));
} else if (getCurrentLibraryContext().resolveCodeRef(identifier) != null) {
Map<String, Set<String>> current = codeDataTypeMap.get(currentContext);
if (current == null) {
codeDataTypeMap.put(currentContext, new HashMap<>());
Expand All @@ -427,6 +434,7 @@ public void enterRetrieve(@NotNull cqlParser.RetrieveContext ctx) {
}

current.get(formattedIdentifier).add(dataType);
CodeDef codeDef = getCurrentLibraryContext().resolveCodeRef(identifier);
drcs.putIfAbsent(
formattedIdentifier,
CQLCode.builder()
Expand Down Expand Up @@ -569,14 +577,16 @@ private String formatIdentifier(String identifier) {
return formattedIdentifier;
}

private Element resolve(String identifier, CompiledLibrary library) {
Element element = library.resolve(identifier);
private void resolve(String identifier, CompiledLibrary library) {
ResolvedIdentifierContext resolvedIdentifierContext = library.resolve(identifier);
String formattedIdentifier = formatIdentifier(identifier);
libraryAccessor =
null; // we've done all we need to do with the accessor, so set it equal to null so it can
// be
// updated again if need be.
if (element instanceof IncludeDef def) {
// we've done all we need to do with the accessor,
// so set it equal to null so it can be updated again if need be.
libraryAccessor = null;

if (resolvedIdentifierContext.getElementOfType(IncludeDef.class).isPresent()) {
IncludeDef def = resolvedIdentifierContext.getElementOfType(IncludeDef.class).get();

graph.addEdge(
currentContext, def.getPath() + "-" + def.getVersion() + "|" + def.getLocalIdentifier());
libraryAccessor = def;
Expand Down Expand Up @@ -606,7 +616,8 @@ private Element resolve(String identifier, CompiledLibrary library) {
"IOException while parsing child library [{}] " + e.getMessage(),
def.getPath() + "-" + def.getVersion());
}
} else if (element instanceof CodeDef codeDef) {
} else if (resolvedIdentifierContext.getElementOfType(CodeDef.class).isPresent()) {
CodeDef codeDef = resolvedIdentifierContext.getElementOfType(CodeDef.class).get();
codes.add(formattedIdentifier);
CQLCodeSystem cqlCodeSystem = codeSystemMap.get(codeDef.getCodeSystem().getName());
CQLCode declaredCode =
Expand All @@ -622,10 +633,11 @@ private Element resolve(String identifier, CompiledLibrary library) {
.build();
declaredCodes.add(declaredCode);
graph.addEdge(currentContext, formattedIdentifier);
} else if (element instanceof CodeSystemDef) {
} else if (resolvedIdentifierContext.getElementOfType(CodeSystemDef.class).isPresent()) {
codesystems.add(identifier);
graph.addEdge(currentContext, formattedIdentifier);
} else if (element instanceof ValueSetDef vsDef) {
} else if (resolvedIdentifierContext.getElementOfType(ValueSetDef.class).isPresent()) {
ValueSetDef vsDef = resolvedIdentifierContext.getElementOfType(ValueSetDef.class).get();
valuesets.add(formattedIdentifier);
graph.addEdge(currentContext, formattedIdentifier);

Expand All @@ -638,15 +650,17 @@ private Element resolve(String identifier, CompiledLibrary library) {
.build();
cqlValuesets.add(declaredValueSet);

} else if (element instanceof ParameterDef parameterDef) {
} else if (resolvedIdentifierContext.getElementOfType(ParameterDef.class).isPresent()) {
ParameterDef parameterDef =
resolvedIdentifierContext.getElementOfType(ParameterDef.class).get();
CQLParameter parameter =
CQLParameter.builder()
.parameterName(formattedIdentifier)
.parameterLogic(parameterDef.getResultType().toString())
.build();
parameters.add(parameter);
graph.addEdge(currentContext, formattedIdentifier);
} else if (element instanceof ExpressionDef) {
} else if (resolvedIdentifierContext.getElementOfType(ExpressionDef.class).isPresent()) {
definitions.add(formattedIdentifier);
graph.addEdge(currentContext, formattedIdentifier);
} else {
Expand All @@ -663,8 +677,6 @@ private Element resolve(String identifier, CompiledLibrary library) {
}
});
}

return element;
}

private void parseChildLibraries(IncludeDef def) throws IOException {
Expand Down

0 comments on commit cc60c6c

Please sign in to comment.