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

#1202: Fixed collapsing data requirements not fixing up references to… #1262

Merged
merged 1 commit into from
Oct 26, 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 @@ -3871,6 +3871,9 @@ public Expression resolveFunctionOrQualifiedFunction(String identifier, cqlParse
return systemMethodResolver.resolveMethod((Expression)target, identifier, paramListCtx, true);
}

if (!isMethodInvocationEnabled()) {
throw new CqlCompilerException(String.format("The identifier %s could not be resolved as an invocation because method-style invocation is disabled.", identifier), CqlCompilerException.ErrorSeverity.Error);
}
throw new IllegalArgumentException(String.format("Invalid invocation target: %s", target.getClass().getName()));
}
finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package org.cqframework.cql.elm.requirements;

import org.hl7.elm.r1.IncludeElement;
import org.hl7.elm.r1.Retrieve;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CollapsedElmRequirements {

private List<ElmRequirement> uniqueRequirements = new ArrayList<ElmRequirement>();

private Map<String, String> requirementIdMap = new HashMap<>();
public Iterable<ElmRequirement> getUniqueRequirements() {
return uniqueRequirements;
}
Expand All @@ -17,10 +24,22 @@ public void add(ElmRequirement requirement) {
}
else {
uniqueRequirements.remove(existing);
ElmRequirement newRequirement = ComparableElmRequirement.mergeRequirements(existing, requirement);
mapRequirementId(requirement, newRequirement);
uniqueRequirements.add(ComparableElmRequirement.mergeRequirements(existing, requirement));
}
}

public Map<String, String> getRequirementIdMap() {
return requirementIdMap;
}

private void mapRequirementId(ElmRequirement oldRequirement, ElmRequirement newRequirement) {
if (oldRequirement.getElement().getLocalId() != null) {
requirementIdMap.put(oldRequirement.getElement().getLocalId(), newRequirement.getElement().getLocalId());
}
}

public ElmRequirement getEquivalent(ElmRequirement requirement) {
for (ElmRequirement existing : uniqueRequirements) {
if (ComparableElmRequirement.requirementsEquivalent(existing, requirement)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,18 +296,46 @@ public ElmRequirements collapse(ElmRequirementsContext context) {
// Has the same context, type/profile, code path and date path
// If two retrieves are "equivalent" they can be merged
// TODO: code/date-range consolidation
Map<String, String> requirementIdMap = new HashMap<>();
for (Map.Entry<String, List<ElmRequirement>> entry : retrievesByType.entrySet()) {
// Determine unique set per type/profile
CollapsedElmRequirements collapsedRetrieves = new CollapsedElmRequirements();
for (ElmRequirement requirement : entry.getValue()) {
collapsedRetrieves.add(requirement);
}

// Collect target mappings
for (Map.Entry<String, String> idMapEntry : collapsedRetrieves.getRequirementIdMap().entrySet()) {
requirementIdMap.put(idMapEntry.getKey(), idMapEntry.getValue());
}

for (ElmRequirement r : collapsedRetrieves.getUniqueRequirements()) {
result.reportRequirement(r);
}
}

// Fixup references in the resulting requirements
for (ElmRequirement requirement : result.getRequirements()) {
if (requirement.getElement() instanceof Retrieve) {
Retrieve r = ((Retrieve)requirement.getElement());
if (r.getIncludedIn() != null) {
String mappedId = requirementIdMap.get(r.getIncludedIn());
if (mappedId != null) {
r.setIncludedIn(mappedId);
}
}

for (IncludeElement includeElement : r.getInclude()) {
if (includeElement.getIncludeFrom() != null) {
String mappedId = requirementIdMap.get(includeElement.getIncludeFrom());
if (mappedId != null) {
includeElement.setIncludeFrom(mappedId);
}
}
}
}
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,17 @@ public void TestCMS645() throws IOException {
//outputModuleDefinitionLibrary(moduleDefinitionLibrary);
}

@Test
public void TestPCSBMI() throws IOException {
CqlCompilerOptions compilerOptions = CqlCompilerOptions.defaultOptions();
var manager = setupDataRequirementsAnalysis("PCSBMI/PCSBMIScreenAndFollowUpFHIR.cql", compilerOptions);
org.hl7.fhir.r5.model.Library moduleDefinitionLibrary = getModuleDefinitionLibrary(manager, compilerOptions, new HashMap<String, Object>(), ZonedDateTime.of(2023, 1, 16, 0, 0, 0, 0, ZoneId.of("UTC")));
assertNotNull(moduleDefinitionLibrary);
assertEqualToExpectedModuleDefinitionLibrary(moduleDefinitionLibrary, "PCSBMI/PCSBMI-ModuleDefinitionLibrary.json");

//outputModuleDefinitionLibrary(moduleDefinitionLibrary);
}

@Test
public void TestCMS143() throws IOException {
CqlCompilerOptions compilerOptions = CqlCompilerOptions.defaultOptions();
Expand Down
Loading