Skip to content

Commit

Permalink
MAT-6907 add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
adongare committed Mar 14, 2024
1 parent 6e2ee35 commit c22fce3
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 31 deletions.
4 changes: 4 additions & 0 deletions src/main/java/gov/cms/madie/dto/CQLCodeSystem.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package gov.cms.madie.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CQLCodeSystem {
private String id;
private String codeSystem;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gov/cms/madie/dto/CQLIncludeLibrary.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package gov.cms.madie.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CQLIncludeLibrary {
Expand Down
17 changes: 3 additions & 14 deletions src/main/java/gov/cms/madie/hqmf/qdm_5_6/HQMFGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
import gov.cms.madie.hqmf.dto.MeasureExport;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
* The Class CQLbasedHQMFGenerator.
*
* @author jmeyer
*/
/** The Class CQL based HQMFGenerator. */
@Slf4j
@Service
@AllArgsConstructor
Expand All @@ -23,8 +17,6 @@ public class HQMFGenerator implements Generator {
private HQMFMeasureDetailsGenerator hqmfMeasureDetailsGenerator;
private HQMFDataCriteriaGenerator hqmfDataCriteriaGenerator;

private final Logger logger = LoggerFactory.getLogger(HQMFDataCriteriaGenerator.class);

/**
* Generate hqmf for CQL Based measures (QDM version 5.6)
*
Expand All @@ -34,7 +26,7 @@ public class HQMFGenerator implements Generator {
@Override
public String generate(MeasureExport measureExport) throws Exception {
try {
// MAT 6911: Export CQL based HQMF w/ Meta Data Section
// Prepare CQL based HQMF Meta Data Section
String hqmfXML = hqmfMeasureDetailsGenerator.generate(measureExport);
// Inline comments are added after the end of last componentOf tag.
// This is removed in this method
Expand All @@ -45,12 +37,9 @@ public String generate(MeasureExport measureExport) throws Exception {

XmlProcessor hqmfProcessor = new XmlProcessor(hqmfXML);
measureExport.setHqmfXmlProcessor(hqmfProcessor);

// generateNarrative(me);
return finalCleanUp(measureExport);
} catch (Exception e) {
logger.error(
"Unable to generate HQMF for QDM v5.6. Exception Stack Strace is as followed : ");
log.error("Unable to generate HQMF for QDM v5.6. Exception Stack Strace is as followed : ");
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package gov.cms.madie.hqmf.qdm_5_6;

import gov.cms.madie.hqmf.dto.MeasureExport;
import gov.cms.madie.packaging.utils.ResourceFileUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;

@ExtendWith(MockitoExtension.class)
public class HQMFDataCriteriaGeneratorTest implements ResourceFileUtil {
@InjectMocks private HQMFDataCriteriaGenerator hqmfDataCriteriaGenerator;

@BeforeEach
void setup() {}

@Test
void testGenerateHqmfWithDataCriteria() throws Exception {
String simpleXml = getStringFromTestResource("/simplexml/BMAT1644A-v0-0-001-QDM-5-6.xml");
MeasureExport measureExport =
MeasureExport.builder().simpleXml(simpleXml).releaseVersion("1.3.1").build();
String hqmf = hqmfDataCriteriaGenerator.generate(measureExport);
assertThat(hqmf, is(notNullValue()));
assertThat(hqmf.contains("<title value=\"Data Criteria Section\"/>"), is(true));
assertThat(hqmf.contains("<title value=\"Encounter, Performed\"/>"), is(true));
assertThat(hqmf.contains("<dataCriteriaSection>"), is(true));
assertThat(hqmf.contains("<populationCriteriaSection>"), is(true));
}

@Test
void testrRemoveOccurrenceFromName() {
String testString = "Occurrence A_Encounter";
String formattedString = HQMFDataCriteriaGenerator.removeOccurrenceFromName(testString);
assertThat(formattedString, is(equalTo("Encounter")));
}

@Test
void testrRemoveOccurrenceFromNameWhenRegexNotPresent() {
String testString = "Encounter_performed";
String formattedString = HQMFDataCriteriaGenerator.removeOccurrenceFromName(testString);
assertThat(formattedString, is(equalTo(testString)));
}
}
25 changes: 22 additions & 3 deletions src/test/java/gov/cms/madie/hqmf/qdm_5_6/HQMFGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import gov.cms.madie.hqmf.dto.MeasureExport;
import gov.cms.madie.packaging.utils.ResourceFileUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -57,13 +60,29 @@ void testGenerate() throws Exception {
MeasureExport measureExport =
MeasureExport.builder().simpleXml(simpleXml).releaseVersion("1.3.1").build();
when(hqmfMeasureDetailsGenerator.generate(any(MeasureExport.class))).thenReturn(baseHqmf);
// TODO: would be handled by MAT-6785
// when(hqmfDataCriteriaGenerator.generate(any(MeasureExport.class))).thenReturn(dataCriteriaXml);
when(hqmfDataCriteriaGenerator.generate(any(MeasureExport.class))).thenReturn(dataCriteriaXml);
String hqmf = hqmfGenerator.generate(measureExport);
assertThat(hqmf, is(notNullValue()));
assertThat(
hqmf.trim().startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"),
is(true));
// assertThat(hqmf.contains("<dataCriteriaSection>"), is(true));
assertThat(hqmf.contains("<dataCriteriaSection>"), is(true));
}

@Test
void testGenerateWhenDataCriteriaGenerationFailed() throws Exception {
String simpleXml = getStringFromTestResource("/simplexml/BMAT1644A-v0-0-001-QDM-5-6.xml");
MeasureExport measureExport =
MeasureExport.builder().simpleXml(simpleXml).releaseVersion("1.3.1").build();
when(hqmfMeasureDetailsGenerator.generate(any(MeasureExport.class))).thenReturn(baseHqmf);
String errorMessage = "test";
Mockito.doThrow(new Exception(errorMessage))
.when(hqmfDataCriteriaGenerator)
.generate(any(MeasureExport.class));

Exception ex =
Assertions.assertThrows(
Exception.class, () -> hqmfGenerator.generate(measureExport), errorMessage);
assertThat(ex.getMessage(), is(equalTo(errorMessage)));
}
}
203 changes: 189 additions & 14 deletions src/test/java/gov/cms/madie/services/MeasureMapperTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package gov.cms.madie.services;

import generated.gov.cms.madie.simplexml.ClauseType;
import generated.gov.cms.madie.simplexml.DevelopersType;
import generated.gov.cms.madie.simplexml.ElementLookUpType;
import generated.gov.cms.madie.simplexml.EndorsementType;
import generated.gov.cms.madie.simplexml.FinalizedDateType;
import generated.gov.cms.madie.simplexml.GroupType;
import generated.gov.cms.madie.simplexml.MeasureDetailsType;
import generated.gov.cms.madie.simplexml.MeasureGroupingType;
import generated.gov.cms.madie.simplexml.MeasureType;
import generated.gov.cms.madie.simplexml.PeriodType;
import generated.gov.cms.madie.simplexml.QdmType;
import generated.gov.cms.madie.simplexml.ScoringType;
import generated.gov.cms.madie.simplexml.StewardType;
import generated.gov.cms.madie.simplexml.TypesType;
import generated.gov.cms.madie.simplexml.*;
import gov.cms.madie.dto.CQLCode;
import gov.cms.madie.dto.CQLCodeSystem;
import gov.cms.madie.dto.CQLDefinition;
import gov.cms.madie.dto.CQLFunctionArgument;
import gov.cms.madie.dto.CQLIncludeLibrary;
import gov.cms.madie.dto.CQLParameter;
import gov.cms.madie.dto.CQLValueSet;
import gov.cms.madie.dto.CqlLookups;
import gov.cms.madie.dto.ElementLookup;
import gov.cms.madie.models.common.ModelType;
Expand Down Expand Up @@ -847,4 +840,186 @@ void testElementLookupsToElementLookupType() {
assertThat(type2.getIsCodeSystemVersionIncluded(), is(equalTo("false")));
assertThat(type2.getTaxonomy(), is(equalTo(lookup2.getTaxonomy())));
}

@Test
void testFunctionArgumentsToArgumentsTypeForNullInput() {
assertThat(measureMapper.functionArgumentsToArgumentsType(null), is(nullValue()));
}

@Test
void testFunctionArgumentsToArgumentsTypeForEmptyInput() {
assertThat(measureMapper.functionArgumentsToArgumentsType(List.of()), is(nullValue()));
}

@Test
void testFunctionArgumentsToArgumentsType() {
CQLFunctionArgument arg1 =
CQLFunctionArgument.builder()
.id("51e3a1669fad")
.argumentName("QualifyingEncounter")
.argumentType("QDM Datatype")
.qdmDataType("Encounter, Performed")
.build();
ArgumentsType argumentsTypes = measureMapper.functionArgumentsToArgumentsType(List.of(arg1));
assertThat(argumentsTypes, is(notNullValue()));
assertThat(argumentsTypes.getArgument().size(), is(equalTo(1)));
ArgumentType argumentsType = argumentsTypes.getArgument().get(0);
assertThat(argumentsType.getType(), is(equalTo(arg1.getArgumentType())));
assertThat(argumentsType.getQdmDataType(), is(equalTo(arg1.getQdmDataType())));
}

@Test
void testCqlIncludeLibrariesToIncludeLibrariesTypeForEmptyInput() {
assertThat(measureMapper.cqlIncludeLibrariesToIncludeLibrarysType(Set.of()), is(nullValue()));
}

@Test
void testCqlIncludeLibrariesToIncludeLibrariesTypeForNullInput() {
assertThat(measureMapper.cqlIncludeLibrariesToIncludeLibrarysType(null), is(nullValue()));
}

@Test
void testCqlIncludeLibrariesToIncludeLibrariesType() {
CQLIncludeLibrary includeLibrary =
CQLIncludeLibrary.builder()
.aliasName("Commons")
.cqlLibraryName("MADiECommonFunctions")
.version("1.0.000")
.qdmVersion("5.6")
.build();
IncludeLibrarysType librariesType =
measureMapper.cqlIncludeLibrariesToIncludeLibrarysType(Set.of(includeLibrary));
assertThat(librariesType, is(notNullValue()));
IncludeLibraryType includeLibraryType = librariesType.getIncludeLibrary().get(0);
assertThat(includeLibraryType.getName(), is(equalTo(includeLibrary.getAliasName())));
assertThat(
includeLibraryType.getCqlLibRefName(), is(equalTo(includeLibrary.getCqlLibraryName())));
assertThat(includeLibraryType.getCqlLibRefId(), is(equalTo(includeLibrary.getId())));
}

@Test
void testValueSetsToValueSetsTypeForNullInput() {
assertThat(measureMapper.valueSetsToValuesetsType(null), is(nullValue()));
}

@Test
void testValueSetsToValueSetsType() {
CQLValueSet cqlValueSet =
CQLValueSet.builder()
.name("Bilateral Mastectomy")
.oid("2.16.840.1.113883.3.464.1003.198.12.1005")
.build();
ValuesetsType valueSetsType = measureMapper.valueSetsToValuesetsType(Set.of(cqlValueSet));
assertThat(valueSetsType, is(notNullValue()));
assertThat(valueSetsType.getValueset().size(), is(equalTo(1)));
ValuesetType valueSetType = valueSetsType.getValueset().get(0);
assertThat(valueSetType.getName(), is(equalTo(cqlValueSet.getName())));
assertThat(valueSetType.getOid(), is(equalTo(cqlValueSet.getOid())));
}

@Test
void testCqlCodeSystemsToCodeSystemsTypeNullInput() {
assertThat(measureMapper.cqlCodeSystemsToCodeSystemsType(null), is(nullValue()));
}

@Test
void testCqlCodeSystemsToCodeSystemsType() {
CQLCodeSystem cqlCodeSystem =
CQLCodeSystem.builder()
.codeSystem("2.16.840.1.113883.6.96")
.codeSystemName("SNOMEDCT")
.codeSystemVersion("2023-01-12")
.build();
CodeSystemsType codeSystemsType =
measureMapper.cqlCodeSystemsToCodeSystemsType(Set.of(cqlCodeSystem));
assertThat(codeSystemsType, is(notNullValue()));
assertThat(codeSystemsType.getCodeSystem().size(), is(equalTo(1)));
CodeSystemType codeSystemType = codeSystemsType.getCodeSystem().get(0);
assertThat(codeSystemType.getCodeSystem(), is(equalTo(cqlCodeSystem.getCodeSystem())));
assertThat(codeSystemType.getCodeSystemName(), is(equalTo(cqlCodeSystem.getCodeSystemName())));
assertThat(
codeSystemType.getCodeSystemVersion(), is(equalTo(cqlCodeSystem.getCodeSystemVersion())));
}

@Test
void testCqlCodesToCodesTypeForNullInput() {
assertThat(measureMapper.cqlCodesToCodesType(null), is(nullValue()));
}

@Test
void testCqlCodesToCodesType() {
CQLCode cqlCode =
CQLCode.builder().id("225337009").codeSystemOID("2.16.840.1.113883.6.96").build();
CodesType codesType = measureMapper.cqlCodesToCodesType(Set.of(cqlCode));
assertThat(codesType, is(notNullValue()));
assertThat(codesType.getCode().size(), is(equalTo(1)));
CodeType codeType = codesType.getCode().get(0);
assertThat(codeType.getCodeOID(), is(equalTo(cqlCode.getId())));
assertThat(codeType.getCodeSystemOID(), is(equalTo(cqlCode.getCodeSystemOID())));
assertThat(codeType.getIsCodeSystemVersionIncluded(), is(equalTo("false")));
}

@Test
void testParametersTypeForNullInput() {
assertThat(measureMapper.cqlParametersToParametersType(null), is(nullValue()));
}

@Test
void testParametersTypeFor() {
CQLParameter cqlParameter =
CQLParameter.builder()
.parameterName("Measurement Period")
.parameterLogic("interval<DateTime>")
.build();
ParametersType parametersType =
measureMapper.cqlParametersToParametersType(Set.of(cqlParameter));
assertThat(parametersType, is(notNullValue()));
assertThat(parametersType.getParameter().size(), is(equalTo(1)));
ParameterType parameterType = parametersType.getParameter().get(0);
assertThat(parameterType.getName(), is(equalTo(cqlParameter.getParameterName())));
assertThat(parameterType.getLogic(), is(equalTo(cqlParameter.getParameterLogic())));
}

@Test
void testCqlDefinitionsToFunctionsTypeForNullInput() {
assertThat(measureMapper.cqlDefinitionsToFunctionsType(null), is(nullValue()));
}

@Test
void testCqlDefinitionsToFunctionsType() {
CQLDefinition cqlDefinition1 =
CQLDefinition.builder()
.id(UUID.randomUUID().toString())
.uuid(UUID.randomUUID().toString())
.definitionName("Measure Population")
.isFunction(false)
.build();
CQLFunctionArgument arg1 =
CQLFunctionArgument.builder()
.id("51e3a1669fad")
.argumentName("QualifyingEncounter")
.argumentType("QDM Datatype")
.qdmDataType("Encounter, Performed")
.build();
CQLDefinition cqlDefinition2 =
CQLDefinition.builder()
.id(UUID.randomUUID().toString())
.uuid(UUID.randomUUID().toString())
.definitionName("Measure Observation")
.functionArguments(List.of(arg1))
.definitionLogic("duration in days of QualifyingEncounter.relevantPeriod")
.isFunction(true)
.build();
Set<CQLDefinition> cqlDefinitions = Set.of(cqlDefinition1, cqlDefinition2);
FunctionsType functionsType = measureMapper.cqlDefinitionsToFunctionsType(cqlDefinitions);
assertThat(functionsType, is(notNullValue()));
assertThat(functionsType.getFunction().size(), is(equalTo(1)));
FunctionType functionType = functionsType.getFunction().get(0);
assertThat(functionType.getName(), is(equalTo(cqlDefinition2.getDefinitionName())));
assertThat(functionType.getLogic(), is(equalTo(cqlDefinition2.getDefinitionLogic())));
assertThat(functionType.getArguments().getArgument().size(), is(equalTo(1)));
List<ArgumentType> argumentTypes = functionType.getArguments().getArgument();
assertThat(argumentTypes.get(0).getQdmDataType(), is(equalTo(arg1.getQdmDataType())));
assertThat(argumentTypes.get(0).getArgumentName(), is(equalTo(arg1.getArgumentName())));
}
}

0 comments on commit c22fce3

Please sign in to comment.