From ebf84296db6d529c6cc697ab0f82afab0f3ddd26 Mon Sep 17 00:00:00 2001 From: Joseph Kotanchik Date: Wed, 4 Dec 2024 14:08:13 -0500 Subject: [PATCH] MAT-7966: Use the DataRequirementsProcessor to prepare the set of Data Requirements for Included Libraries. --- .../service/EffectiveDataRequirementService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/gov/cms/mat/cql_elm_translation/service/EffectiveDataRequirementService.java b/src/main/java/gov/cms/mat/cql_elm_translation/service/EffectiveDataRequirementService.java index 59340b1..f5a8a4f 100644 --- a/src/main/java/gov/cms/mat/cql_elm_translation/service/EffectiveDataRequirementService.java +++ b/src/main/java/gov/cms/mat/cql_elm_translation/service/EffectiveDataRequirementService.java @@ -7,15 +7,19 @@ import gov.cms.madie.cql_elm_translator.utils.cql.data.RequestData; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.cqframework.cql.cql2elm.CqlCompilerOptions; import org.cqframework.cql.cql2elm.CqlTranslator; import org.cqframework.cql.cql2elm.LibraryBuilder; import org.cqframework.cql.cql2elm.LibraryManager; import org.cqframework.cql.cql2elm.model.CompiledLibrary; import org.cqframework.cql.elm.requirements.fhir.DataRequirementsProcessor; +import org.hl7.elm.r1.ExpressionDef; import org.springframework.stereotype.Service; import gov.cms.madie.cql_elm_translator.service.CqlLibraryService; +import java.util.stream.Collectors; + @Slf4j @Service @RequiredArgsConstructor @@ -64,6 +68,15 @@ public org.hl7.fhir.r5.model.Library getEffectiveDataRequirements( options.setCollapseDataRequirements(true); // removing duplicate data requirements options.setSignatureLevel(LibraryBuilder.SignatureLevel.Overloads); + // null indicates Included Library, pass all CQL Definitions to DataRequirementsProcessor + if (libraryDetails.getExpressions() == null) { + libraryDetails.setExpressions( + translatedLibrary.getLibrary().getStatements().getDef().stream() + .map(ExpressionDef::getName) + .filter(defName -> !StringUtils.equalsIgnoreCase(defName, "patient")) + .collect(Collectors.toSet())); + } + org.hl7.fhir.r5.model.Library effectiveDataRequirements = dqReqTrans.gatherDataRequirements( libraryManager,