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

Drc data criteria #101

Merged
merged 6 commits into from
Oct 11, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public class SourceDataCriteria {
private String description;
private String type;
private boolean drc;
// MAT-6210: codeId used for drc
private String codeId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private SourceDataCriteria buildSourceDataCriteriaForCode(CQLCode code, Set<Stri
.description(dataType + ": " + name)
.type(buildCriteriaType(dataType))
.drc(true)
.codeId(code.getId())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public org.hl7.fhir.r5.model.Library getEffectiveDataRequirements(
Set<String> expressionList = getExpressions(r5Measure);
var dqReqTrans = new DataRequirementsProcessor();
CqlTranslatorOptions options = CqlTranslatorOptions.defaultOptions();
options.setCollapseDataRequirements(true); //removing duplicate data requirements
options.setCollapseDataRequirements(true); // removing duplicate data requirements

org.hl7.fhir.r5.model.Library effectiveDataRequirements =
dqReqTrans.gatherDataRequirements(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public CQLTools(
/**
* The CQL Filter Entry Point.
*
* <p>This function will find all of the used CQL expressions, create a valueset - datatype map
* and code - datatype map, and find return types for each expression.
* <p>This function will find all the used CQL expressions, create a valueset - datatype map and
* code - datatype map, and find return types for each expression.
*
* @throws IOException
*/
Expand Down Expand Up @@ -142,6 +142,7 @@ public void generate() throws IOException {
new HashMap<>(listener.getValueSetDataTypeMap());
Map<String, Map<String, Set<String>>> codeMap = new HashMap<>(listener.getCodeDataTypeMap());
Map<String, String> valueSetOids = new HashMap<>(listener.getValueSetOids());
Map<String, CQLCode> drcs = new HashMap<>(listener.getDrcs());

collectUsedExpressions(
graph,
Expand All @@ -154,10 +155,10 @@ public void generate() throws IOException {
functionsSet);
collectValueSetCodeDataType(valuesetMap, codeMap);
collectReturnTypeMap();
collectDataCriteria(valueSetOids);
collectDataCriteria(valueSetOids, drcs);
}

private void collectDataCriteria(Map<String, String> valueSetOids) {
private void collectDataCriteria(Map<String, String> valueSetOids, Map<String, CQLCode> drcs) {
valuesetDataTypeMap
.keySet()
.forEach(
Expand All @@ -174,15 +175,7 @@ private void collectDataCriteria(Map<String, String> valueSetOids) {
code ->
dataCriteria
.getDataCriteriaWithCodes()
.put(
CQLCode.builder()
.codeName(code)
// TODO lookup code & code system details
.codeOID("shrug")
.codeSystemName("shrug")
.codeSystemOID("shrug")
.build(),
codeDataTypeMap.get(code)));
.put(drcs.get(code), codeDataTypeMap.get(code)));
}

private void collectUsedExpressions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.nio.charset.StandardCharsets;
import java.util.*;

import gov.cms.mat.cql_elm_translation.utils.cql.parsing.model.CQLCode;
import gov.cms.mat.cql_elm_translation.utils.cql.parsing.model.CQLGraph;
import lombok.Getter;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.misc.NotNull;
Expand Down Expand Up @@ -45,7 +47,7 @@
* The identifier of the current library, relative to the library that brought us here. Will be in
* the form of libraryName|alias
*/
private String libraryIdentifier;
private final String libraryIdentifier;

/**
* The include def object which we are current parsing, relative to the library that brought us
Expand All @@ -54,28 +56,29 @@
IncludeDef libraryAccessor = null;

/** The current library object from the parser */
private CompiledLibrary library;
private final CompiledLibrary library;

/** The map of the other libraries in the current library */
Map<String, CompiledLibrary> translatedLibraryMap;

/** The current context, aka which expression are we currently in. */
private String currentContext;

private Set<String> libraries = new HashSet<>();
private Set<String> valuesets = new HashSet<>();
private Set<String> codes = new HashSet<>();
private Set<String> codesystems = new HashSet<>();
private Set<String> parameters = new HashSet<>();
private Set<String> definitions = new HashSet<>();
private Set<String> functions = new HashSet<>();
private HashMap<String, String> valueSetOids = new HashMap<>();
private Map<String, Map<String, Set<String>>> valueSetDataTypeMap = new HashMap<>();
private Map<String, Map<String, Set<String>>> codeDataTypeMap = new HashMap<>();
@Getter private final Set<String> libraries = new HashSet<>();
@Getter private final Set<String> valuesets = new HashSet<>();
@Getter private final Set<String> codes = new HashSet<>();
@Getter private final Set<String> codesystems = new HashSet<>();
@Getter private final Set<String> parameters = new HashSet<>();
@Getter private final Set<String> definitions = new HashSet<>();
@Getter private final Set<String> functions = new HashSet<>();
@Getter private final HashMap<String, String> valueSetOids = new HashMap<>();
@Getter private final HashMap<String, CQLCode> drcs = new HashMap<>();
@Getter private final Map<String, Map<String, Set<String>>> valueSetDataTypeMap = new HashMap<>();
@Getter private final Map<String, Map<String, Set<String>>> codeDataTypeMap = new HashMap<>();

private Stack<String> namespace = new Stack<>();
private final Stack<String> namespace = new Stack<>();

private CQLGraph graph;
@Getter private final CQLGraph graph;

Check warning on line 81 in src/main/java/gov/cms/mat/cql_elm_translation/utils/cql/parsing/Cql2ElmListener.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/gov/cms/mat/cql_elm_translation/utils/cql/parsing/Cql2ElmListener.java#L81

Added line #L81 was not covered by tests

public Cql2ElmListener(
CQLGraph graph,
Expand Down Expand Up @@ -130,7 +133,7 @@
String qualifier = "";

if (shouldResolve(identifier)) {
// a qualified identifier can take on the form (qualifier) '.')* identifier. If there is only
// a qualified identifier can take on the form (qualifier '.')* identifier. If there is only
// one qualifier,
// then that could be a library. Resolve the qualifier to check if it's a library.
if (CollectionUtils.isNotEmpty(ctx.qualifierExpression())
Expand Down Expand Up @@ -269,6 +272,7 @@
current.get(formattedIdentifier).add(dataType);
valueSetOids.putIfAbsent(
formattedIdentifier, ((ValueSetDef) element).getId().substring("urn:oid:".length()));

} else if (element instanceof CodeDef) {
Map<String, Set<String>> current = codeDataTypeMap.get(currentContext);
if (current == null) {
Expand All @@ -283,6 +287,13 @@
}

current.get(formattedIdentifier).add(dataType);
drcs.putIfAbsent(
formattedIdentifier,
CQLCode.builder()
.id(((CodeDef) element).getId())
.codeName(formattedIdentifier)
.codeSystemName(((CodeDef) element).getCodeSystem().getName())
.build());
}
}

Expand Down Expand Up @@ -507,49 +518,6 @@
valueSetDataTypeMap.putAll(listener.getValueSetDataTypeMap());
codeDataTypeMap.putAll(listener.getCodeDataTypeMap());
valueSetOids.putAll(listener.getValueSetOids());
}

public Set<String> getLibraries() {
return libraries;
}

public Set<String> getValuesets() {
return valuesets;
}

public Set<String> getCodes() {
return codes;
}

public Set<String> getCodesystems() {
return codesystems;
}

public Set<String> getParameters() {
return parameters;
}

public Set<String> getDefinitions() {
return definitions;
}

public Set<String> getFunctions() {
return functions;
}

public Map<String, Map<String, Set<String>>> getValueSetDataTypeMap() {
return valueSetDataTypeMap;
}

public Map<String, Map<String, Set<String>>> getCodeDataTypeMap() {
return codeDataTypeMap;
}

public Map<String, String> getValueSetOids() {
return valueSetOids;
}

public CQLGraph getGraph() {
return graph;
drcs.putAll(listener.getDrcs());

Check warning on line 521 in src/main/java/gov/cms/mat/cql_elm_translation/utils/cql/parsing/Cql2ElmListener.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/gov/cms/mat/cql_elm_translation/utils/cql/parsing/Cql2ElmListener.java#L521

Added line #L521 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ public boolean isPath(String source, String destination) {
public String toString() {
StringBuilder builder = new StringBuilder();
for (String node : graph.keySet()) {
builder.append(node + " ---> " + graph.get(node) + "\n");
builder.append(node).append(" ---> ").append(graph.get(node)).append("\n");
}

return builder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ void testGetSourceDataCriteria() {
assertThat(
sourceDataCriteria.get(2).getDescription(),
is(equalTo("Encounter, Performed: Clinical Examples")));

// MAT-6210 only setCodeId for direct reference code
assertThat(sourceDataCriteria.get(0).getCodeId(), is(equalTo(null)));
assertThat(sourceDataCriteria.get(1).getCodeId(), is(equalTo(null)));
assertThat(sourceDataCriteria.get(2).getCodeId(), is(equalTo("1021859")));
}

@Test
Expand Down
Loading