Skip to content

Commit

Permalink
Merge pull request #18 from MeasureAuthoringTool/MAT-7627_FHIRHelpers…
Browse files Browse the repository at this point in the history
…MissingErrorMsg

MAT-7627 FHIRHelper missing error msg
  • Loading branch information
sb-cecilialiu authored Aug 28, 2024
2 parents 49a4dcf + a2a9044 commit ae581d6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import gov.cms.madie.cql_elm_translator.utils.cql.data.RequestData;
import gov.cms.madie.cql_elm_translator.service.CqlLibraryService;
import gov.cms.madie.cql_elm_translator.exceptions.InternalServerException;
import gov.cms.mat.cql_elm_translation.exceptions.MissingLibraryCqlCompilerException;
import gov.cms.mat.cql_elm_translation.service.filters.AnnotationErrorFilter;
import gov.cms.mat.cql_elm_translation.service.filters.CqlTranslatorExceptionFilter;
import gov.cms.mat.cql_elm_translation.service.support.CqlExceptionErrorProcessor;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.minidev.json.JSONArray;

import org.apache.commons.lang3.StringUtils;
import org.cqframework.cql.cql2elm.CqlCompilerException;
import org.cqframework.cql.cql2elm.CqlTranslator;
import org.cqframework.cql.cql2elm.LibraryContentType;
Expand Down Expand Up @@ -51,6 +54,9 @@ public CqlConversionPayload processCqlDataWithErrors(RequestData requestData) {
// Gets the translator results
CqlTranslator cqlTranslator = processCqlData(requestData);

// QI-Core measures require FHIRHelpers...enforce this validation only for measure CQL
processForMissingFhirHelpersLibrary(cqlTranslator, requestData.getCqlData());

List<CqlCompilerException> cqlTranslatorExceptions =
processErrors(
requestData.getCqlData(), requestData.isShowWarnings(), cqlTranslator.getExceptions());
Expand Down Expand Up @@ -86,6 +92,35 @@ public CqlConversionPayload processCqlDataWithErrors(RequestData requestData) {
return CqlConversionPayload.builder().json(jsonWithErrors).xml(cqlTranslator.toXml()).build();
}

/**
* MODIFIES INPUT PARAMETER Checks for FHIRHelpers library and adds an exception on the
* CqlTranslator object if missing. Exception is not added if the CQL is for the FHIRHelpers
* library itself.
*
* @param cqlTranslator
* @param cql
*/
public void processForMissingFhirHelpersLibrary(CqlTranslator cqlTranslator, String cql) {
VersionedIdentifier identifier =
cqlTranslator.getTranslatedLibrary().getLibrary().getIdentifier();
if (StringUtils.isNotBlank(cql)
&& identifier != null
&& !identifier.getId().contains("FHIRHelpers")) {
Library.Includes includes = cqlTranslator.getTranslatedLibrary().getLibrary().getIncludes();
if (includes == null
|| includes.getDef() == null
|| includes.getDef().isEmpty()
|| !includes.getDef().stream()
.anyMatch(includeDef -> includeDef.getPath().contains("FHIRHelpers"))) {
cqlTranslator
.getExceptions()
.add(
new MissingLibraryCqlCompilerException(
"FHIRHelpers", cqlTranslator.getTranslatedLibrary().getIdentifier(), 1));
}
}
}

public TranslatedLibrary buildTranslatedLibrary(
CompiledLibrary compiledLibrary, Map<String, String> cqlMap) {
if (compiledLibrary == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,16 @@ void testProcessCqlDataWithErrors() {
try {
JsonNode jsonNode = objectMapper.readTree(resultJson);
assertNotNull(jsonNode);
JsonNode libraryNode = jsonNode.at("/errorExceptions");
assertNotNull(libraryNode);
assertTrue(libraryNode.isMissingNode());

JsonNode libraryNodeEx = jsonNode.at("/errorExceptions");
assertNotNull(libraryNodeEx);
assertFalse(libraryNodeEx.isMissingNode());
assertThat(libraryNodeEx.isArray(), is(true));
assertThat(
libraryNodeEx.get(0).get("message").textValue(),
is(
equalTo(
"FHIRHelpers is required as an included library for QI-Core. Please add the appropriate version of FHIRHelpers to your CQL.")));
} catch (JsonProcessingException e) {
fail(e.getMessage());
}
Expand Down Expand Up @@ -134,9 +141,17 @@ void testProcessCqlDataWithErrorsQICore() {
try {
JsonNode jsonNode = objectMapper.readTree(resultJson);
assertNotNull(jsonNode);
JsonNode libraryNode = jsonNode.at("/errorExceptions");
assertNotNull(libraryNode);
assertTrue(libraryNode.isMissingNode());

JsonNode libraryNodeEx = jsonNode.at("/errorExceptions");
assertNotNull(libraryNodeEx);
assertFalse(libraryNodeEx.isMissingNode());
assertThat(libraryNodeEx.isArray(), is(true));
assertThat(
libraryNodeEx.get(0).get("message").textValue(),
is(
equalTo(
"FHIRHelpers is required as an included library for QI-Core. Please add the appropriate version of FHIRHelpers to your CQL.")));

} catch (JsonProcessingException e) {
fail(e.getMessage());
}
Expand Down

0 comments on commit ae581d6

Please sign in to comment.