-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #768 from MeasureAuthoringTool/MAT-7964_FixingVers…
…ioningTranslatorVersionProblem MAT-7964: Fixing issue where ELMJson translator wasn't updated on Ver…
- Loading branch information
Showing
8 changed files
with
190 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/cms/gov/madie/measure/services/ElmToJsonService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cms.gov.madie.measure.services; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
import cms.gov.madie.measure.exceptions.CqlElmTranslationErrorException; | ||
import cms.gov.madie.measure.exceptions.InvalidResourceStateException; | ||
import gov.cms.madie.models.measure.ElmJson; | ||
import gov.cms.madie.models.measure.Measure; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@AllArgsConstructor | ||
@Service | ||
public class ElmToJsonService { | ||
private final ElmTranslatorClient elmTranslatorClient; | ||
|
||
protected void retrieveElmJson(Measure measure, String accessToken) { | ||
if (StringUtils.isBlank(measure.getCql())) { | ||
throw new InvalidResourceStateException( | ||
"Measure", measure.getId(), "since there is no associated CQL."); | ||
} | ||
|
||
if (measure.isCqlErrors()) { | ||
throw new InvalidResourceStateException( | ||
"Measure", measure.getId(), "since CQL errors exist."); | ||
} | ||
|
||
if (CollectionUtils.isEmpty(measure.getGroups())) { | ||
throw new InvalidResourceStateException( | ||
"Measure", measure.getId(), "since there are no associated population criteria."); | ||
} | ||
|
||
final ElmJson elmJson = | ||
elmTranslatorClient.getElmJson(measure.getCql(), measure.getModel(), accessToken); | ||
if (elmTranslatorClient.hasErrors(elmJson)) { | ||
throw new CqlElmTranslationErrorException(measure.getMeasureName()); | ||
} | ||
measure.setElmJson(elmJson.getJson()); | ||
measure.setElmXml(elmJson.getXml()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/test/java/cms/gov/madie/measure/services/ElmToJsonServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package cms.gov.madie.measure.services; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
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.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import cms.gov.madie.measure.exceptions.CqlElmTranslationServiceException; | ||
import cms.gov.madie.measure.exceptions.InvalidResourceStateException; | ||
import cms.gov.madie.measure.utils.ResourceUtil; | ||
import gov.cms.madie.models.common.ModelType; | ||
import gov.cms.madie.models.common.Version; | ||
import gov.cms.madie.models.measure.Group; | ||
import gov.cms.madie.models.measure.Measure; | ||
import gov.cms.madie.models.measure.MeasureGroupTypes; | ||
import gov.cms.madie.models.measure.MeasureMetaData; | ||
import gov.cms.madie.models.measure.Population; | ||
import gov.cms.madie.models.measure.PopulationType; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ElmToJsonServiceTest implements ResourceUtil { | ||
|
||
@Mock private ElmTranslatorClient elmTranslatorClient; | ||
|
||
@InjectMocks private ElmToJsonService elmToJsonService; | ||
|
||
private Measure measure; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
Group group = | ||
Group.builder() | ||
.id("xyz-p12r-12ert") | ||
.populationBasis("Encounter") | ||
.measureGroupTypes(List.of(MeasureGroupTypes.PROCESS)) | ||
.populations( | ||
List.of( | ||
new Population( | ||
"id-1", PopulationType.INITIAL_POPULATION, "FactorialOfFive", null, null))) | ||
.groupDescription("Description") | ||
.scoringUnit("test-scoring-unit") | ||
.build(); | ||
|
||
List<Group> groups = new ArrayList<>(); | ||
groups.add(group); | ||
String elmJson = getData("/test_elm.json"); | ||
MeasureMetaData metaData = MeasureMetaData.builder().draft(true).build(); | ||
measure = | ||
Measure.builder() | ||
.active(true) | ||
.id("xyz-p13r-13ert") | ||
.cql("test cql") | ||
.model(ModelType.QDM_5_6.getValue()) | ||
.cqlErrors(false) | ||
.elmJson(elmJson) | ||
.measureSetId("IDIDID") | ||
.measureName("MSR01") | ||
.version(new Version(0, 0, 1)) | ||
.groups(groups) | ||
.measureMetaData(metaData) | ||
.createdAt(Instant.now()) | ||
.createdBy("test user") | ||
.lastModifiedAt(Instant.now()) | ||
.lastModifiedBy("test user") | ||
.build(); | ||
} | ||
|
||
@Test | ||
void testBundleMeasureThrowsCqlElmTranslationServiceException() { | ||
|
||
when(elmTranslatorClient.getElmJson(anyString(), anyString(), anyString())) | ||
.thenThrow( | ||
new CqlElmTranslationServiceException( | ||
"There was an error calling CQL-ELM translation service", new Exception())); | ||
assertThrows( | ||
CqlElmTranslationServiceException.class, | ||
() -> elmToJsonService.retrieveElmJson(measure, "calculation")); | ||
} | ||
|
||
@Test | ||
void testBundleMeasureWhenThereAreCqlErrors() { | ||
measure.setCqlErrors(true); | ||
assertThrows( | ||
InvalidResourceStateException.class, | ||
() -> elmToJsonService.retrieveElmJson(measure, "calculation")); | ||
} | ||
|
||
@Test | ||
void testBundleMeasureWhenThereIsNoCql() { | ||
measure.setCql(null); | ||
assertThrows( | ||
InvalidResourceStateException.class, | ||
() -> elmToJsonService.retrieveElmJson(measure, "calculation")); | ||
} | ||
} |
Oops, something went wrong.