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

MAT-6491 fixed QI Core TC expected values dropped when observations exist #762

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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 @@ -334,8 +334,12 @@ public ResponseEntity<String> deleteCmsId(
@RequestParam(name = "cmsId") Integer cmsId,
@Value("${admin-api-key}") String apiKey,
Principal principal) {
log.info("User [{}] - Started admin task [deleteCmsId] and is attempting to delete " +
"CMS id [{}] from measure with measure id [{}]", principal.getName(), cmsId, measureId);
log.info(
"User [{}] - Started admin task [deleteCmsId] and is attempting to delete "
+ "CMS id [{}] from measure with measure id [{}]",
principal.getName(),
cmsId,
measureId);
return ResponseEntity.status(HttpStatus.OK)
.body(measureSetService.deleteCmsId(measureId, cmsId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,45 +155,58 @@ public String deleteCmsId(String measureId, Integer cmsId) {

if (measure.isPresent()) {
String measureSetId = measure.get().getMeasureSetId();
Optional<MeasureSet> optionalMeasureSet = measureSetRepository.findByMeasureSetId(measureSetId);
Optional<MeasureSet> optionalMeasureSet =
measureSetRepository.findByMeasureSetId(measureSetId);

if (optionalMeasureSet.isEmpty()) {
throw new ResourceNotFoundException("No measure set exists for measure with measure set id of "
+ measureSetId);
throw new ResourceNotFoundException(
"No measure set exists for measure with measure set id of " + measureSetId);
}

MeasureSet measureSet = optionalMeasureSet.get();

if (measureSet.getCmsId() == null) {
throw new ResourceNotFoundException(String.format("No CMS id of %s exists to be deleted " +
"within measure set with measure set id of %s", cmsId, measureSetId));
throw new ResourceNotFoundException(
String.format(
"No CMS id of %s exists to be deleted "
+ "within measure set with measure set id of %s",
cmsId, measureSetId));
}

if (!measureSet.getCmsId().equals(cmsId)) {
throw new InvalidIdException(
String.format("CMS id of %s passed in does not match CMS id of %s within " +
"measure set with measure set id of %s", cmsId,measureSet.getCmsId(), measureSetId));
String.format(
"CMS id of %s passed in does not match CMS id of %s within "
+ "measure set with measure set id of %s",
cmsId, measureSet.getCmsId(), measureSetId));
}

List<Measure> measures = measureRepository.findAllByMeasureSetIdAndActive(measureSetId, true);

if (measures.size() > 1) {
throw new InvalidRequestException(String.format("Measure set with measure set id of %s contains more than 1 measure. " +
"Cannot delete CMS id when measure set has more than 1 version of measure.", measureSetId));
throw new InvalidRequestException(
String.format(
"Measure set with measure set id of %s contains more than 1 measure. "
+ "Cannot delete CMS id when measure set has more than 1 version of measure.",
measureSetId));
}

measureSet.setCmsId(null);
measureSetRepository.save(measureSet);

log.info("With the measure id of [{}], successfully queried " +
"for its measure set with measure set id of [{}] and deleted CMS id " +
"of [{}] from the measure set", measureId, measureSetId, cmsId);

return String.format("CMS id of %s was deleted successfully from " +
"measure set with measure set id of %s", cmsId, measureSetId);
log.info(
"With the measure id of [{}], successfully queried "
+ "for its measure set with measure set id of [{}] and deleted CMS id "
+ "of [{}] from the measure set",
measureId,
measureSetId,
cmsId);

return String.format(
"CMS id of %s was deleted successfully from " + "measure set with measure set id of %s",
cmsId, measureSetId);
} else {
throw new ResourceNotFoundException(
"No measure exists with measure id of " + measureId);
throw new ResourceNotFoundException("No measure exists with measure id of " + measureId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,23 @@ public static List<TestCasePopulationValue> getObservationPopulations(
return null;
}

// exported test cases doesn't have criteria references
// filtering populations to get relevant criteria reference id for observations
private static String getCriteriaReferenceFromPopulations(
List<Population> populations, String observationName) {
String relevantPopulation =
PopulationType.DENOMINATOR_OBSERVATION.name().equalsIgnoreCase(observationName)
? "DENOMINATOR"
: "NUMERATOR";
Optional<String> matchedCriteriaReference =
populations.stream()
.filter(
(population) -> population.getName().name().equalsIgnoreCase(relevantPopulation))
.map(population -> population.getId())
.findFirst();
return matchedCriteriaReference.orElse(null);
}

public static List<TestCaseGroupPopulation> assignObservationIdAndCriteriaReferenceCVAndRatio(
List<TestCaseGroupPopulation> testCaseGroupPopulations, List<Group> measureGroups) {
if (isNotEmpty(measureGroups)
Expand Down Expand Up @@ -495,10 +512,16 @@ && isNotEmpty(testCaseGroupPopulations)
int number = 0;
for (TestCasePopulationValue value : denomAndNumerObservations) {
value.setId(
(number == 0 ? "denominator" : "numerator")
(PopulationType.DENOMINATOR_OBSERVATION
.name()
.equalsIgnoreCase(value.getName().name())
? "denominator"
: "numerator")
+ "Observation"
+ String.valueOf(number));
value.setCriteriaReference(observations.get(number).getCriteriaReference());
value.setCriteriaReference(
getCriteriaReferenceFromPopulations(
group.getPopulations(), value.getName().name()));
number++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,16 @@ void deleteCmsId() {
.acls(null)
.build();

String expectedBody = String.format("CMS Id of %s was deleted successfully from measure set with measure set id of %s", measureSet.getCmsId(), measureSet.getMeasureSetId());
String expectedBody =
String.format(
"CMS Id of %s was deleted successfully from measure set with measure set id of %s",
measureSet.getCmsId(), measureSet.getMeasureSetId());

when(measureSetService.deleteCmsId(anyString(), anyInt())).thenReturn(expectedBody);

ResponseEntity<String> response = controller.deleteCmsId(mockHttpServletRequest, measureId, measureSet.getCmsId(), "apiKey", principal);
ResponseEntity<String> response =
controller.deleteCmsId(
mockHttpServletRequest, measureId, measureSet.getCmsId(), "apiKey", principal);

assertThat(response.getBody(), is(notNullValue()));
assertEquals(expectedBody, response.getBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,23 +264,25 @@ public void testCreateCmsIdWhenCmsIdAlreadyExistsInMeasureSet() {
public void testDeleteCmsId() {
Integer cmsId = 1;
Measure measure =
Measure.builder()
.model(ModelType.QI_CORE.getValue())
.measureSetId("measureSetId1")
.build();
Measure.builder().model(ModelType.QI_CORE.getValue()).measureSetId("measureSetId1").build();

List<Measure> measures = Collections.singletonList(measure);
MeasureSet measureSet = MeasureSet.builder().measureSetId("1").cmsId(1).build();
String measureId = "measureId";

when(measureRepository.findById(anyString())).thenReturn(Optional.of( measure));
when(measureRepository.findById(anyString())).thenReturn(Optional.of(measure));
when(measureSetRepository.findByMeasureSetId(anyString())).thenReturn(Optional.of(measureSet));
when(measureRepository.findAllByMeasureSetIdAndActive(anyString(), anyBoolean())).thenReturn(measures);
when(measureRepository.findAllByMeasureSetIdAndActive(anyString(), anyBoolean()))
.thenReturn(measures);
when(measureSetRepository.save(any(MeasureSet.class))).thenReturn(measureSet);

String responseBody = measureSetService.deleteCmsId(measureId, cmsId);

assertEquals(responseBody, String.format("CMS id of %s was deleted successfully from measure set with measure set id of %s", cmsId, measure.getMeasureSetId()));
assertEquals(
responseBody,
String.format(
"CMS id of %s was deleted successfully from measure set with measure set id of %s",
cmsId, measure.getMeasureSetId()));
verify(measureRepository, times(1)).findById(anyString());
verify(measureSetRepository, times(1)).findByMeasureSetId(anyString());
verify(measureRepository, times(1)).findAllByMeasureSetIdAndActive(anyString(), anyBoolean());
Expand All @@ -295,8 +297,7 @@ public void testDeleteCmsIdWhenMeasureWithMeasureIdIsNotFound() {

Exception ex =
assertThrows(
ResourceNotFoundException.class,
() -> measureSetService.deleteCmsId(measureId, 1));
ResourceNotFoundException.class, () -> measureSetService.deleteCmsId(measureId, 1));

assertTrue(
ex.getMessage()
Expand All @@ -309,24 +310,23 @@ public void testDeleteCmsIdWhenMeasureWithMeasureIdIsNotFound() {
@Test
public void testDeleteCmsIdWhenMeasureSetIsNotFound() {
Measure measure =
Measure.builder()
.model(ModelType.QI_CORE.getValue())
.measureSetId("measureSetId")
.build();
Measure.builder().model(ModelType.QI_CORE.getValue()).measureSetId("measureSetId").build();

String measureId = "measureId";

when(measureRepository.findById(anyString())).thenReturn(Optional.of( measure));
when(measureRepository.findById(anyString())).thenReturn(Optional.of(measure));
when(measureSetRepository.findByMeasureSetId(anyString())).thenReturn(Optional.empty());

Exception ex =
assertThrows(
ResourceNotFoundException.class,
() -> measureSetService.deleteCmsId(measureId, 1));
ResourceNotFoundException.class, () -> measureSetService.deleteCmsId(measureId, 1));

assertTrue(
ex.getMessage()
.contains(String.format("No measure set exists for measure with measure set id of %s", measure.getMeasureSetId())));
.contains(
String.format(
"No measure set exists for measure with measure set id of %s",
measure.getMeasureSetId())));
verify(measureRepository, times(1)).findById(anyString());
verify(measureSetRepository, times(1)).findByMeasureSetId(anyString());
verify(measureSetRepository, times(0)).save(any(MeasureSet.class));
Expand All @@ -336,25 +336,24 @@ public void testDeleteCmsIdWhenMeasureSetIsNotFound() {
public void testDeleteCmsIdWhenCmsIdIsNotFoundInMeasureSet() {
Integer cmsId = 1;
Measure measure =
Measure.builder()
.model(ModelType.QI_CORE.getValue())
.measureSetId("measureSetId")
.build();
Measure.builder().model(ModelType.QI_CORE.getValue()).measureSetId("measureSetId").build();

MeasureSet measureSet = MeasureSet.builder().measureSetId("1").build();
String measureId = "measureId";

when(measureRepository.findById(anyString())).thenReturn(Optional.of( measure));
when(measureRepository.findById(anyString())).thenReturn(Optional.of(measure));
when(measureSetRepository.findByMeasureSetId(anyString())).thenReturn(Optional.of(measureSet));

Exception ex =
assertThrows(
ResourceNotFoundException.class,
() -> measureSetService.deleteCmsId(measureId, cmsId));
ResourceNotFoundException.class, () -> measureSetService.deleteCmsId(measureId, cmsId));

assertTrue(
ex.getMessage()
.contains(String.format("No CMS id of %s exists to be deleted within measure set with measure set id of %s", cmsId, measure.getMeasureSetId())));
.contains(
String.format(
"No CMS id of %s exists to be deleted within measure set with measure set id of %s",
cmsId, measure.getMeasureSetId())));
verify(measureRepository, times(1)).findById(anyString());
verify(measureSetRepository, times(1)).findByMeasureSetId(anyString());
verify(measureSetRepository, times(0)).save(any(MeasureSet.class));
Expand All @@ -364,60 +363,58 @@ public void testDeleteCmsIdWhenCmsIdIsNotFoundInMeasureSet() {
public void testDeleteCmsIdWhenCmsIdToDeleteDoesNotMatchCmsIdInMeasureSet() {
Integer cmsId = 1;
Measure measure =
Measure.builder()
.model(ModelType.QI_CORE.getValue())
.measureSetId("measureSetId")
.build();
Measure.builder().model(ModelType.QI_CORE.getValue()).measureSetId("measureSetId").build();

MeasureSet measureSet = MeasureSet.builder().measureSetId("1").cmsId(2).build();
String measureId = "measureId";

when(measureRepository.findById(anyString())).thenReturn(Optional.of( measure));
when(measureRepository.findById(anyString())).thenReturn(Optional.of(measure));
when(measureSetRepository.findByMeasureSetId(anyString())).thenReturn(Optional.of(measureSet));

Exception ex =
assertThrows(
InvalidIdException.class,
() -> measureSetService.deleteCmsId(measureId, cmsId));
InvalidIdException.class, () -> measureSetService.deleteCmsId(measureId, cmsId));

assertTrue(
ex.getMessage()
.contains(String.format("CMS id of %s passed in does not match CMS id of %s within measure set with measure set id of %s", cmsId, measureSet.getCmsId(), measure.getMeasureSetId())));
.contains(
String.format(
"CMS id of %s passed in does not match CMS id of %s within measure set with measure set id of %s",
cmsId, measureSet.getCmsId(), measure.getMeasureSetId())));
verify(measureRepository, times(1)).findById(anyString());
verify(measureSetRepository, times(1)).findByMeasureSetId(anyString());
verify(measureSetRepository, times(0)).save(any(MeasureSet.class));
}

@Test
public void testDeleteCmsIdWhenMeasureHasMultipleVersions() {
Integer cmsId = 1;
Measure measure1 =
Measure.builder()
.model(ModelType.QI_CORE.getValue())
.measureSetId("measureSetId1")
.build();
Measure.builder().model(ModelType.QI_CORE.getValue()).measureSetId("measureSetId1").build();

Measure measure2 =
Measure.builder()
.model(ModelType.QI_CORE.getValue())
.measureSetId("measureSetId2")
.build();
Measure.builder().model(ModelType.QI_CORE.getValue()).measureSetId("measureSetId2").build();

List<Measure> measures = Arrays.asList(measure1, measure2);
MeasureSet measureSet = MeasureSet.builder().measureSetId("1").cmsId(1).build();
String measureId = "measureId";

when(measureRepository.findById(anyString())).thenReturn(Optional.of( measure1));
when(measureRepository.findById(anyString())).thenReturn(Optional.of(measure1));
when(measureSetRepository.findByMeasureSetId(anyString())).thenReturn(Optional.of(measureSet));
when(measureRepository.findAllByMeasureSetIdAndActive(anyString(), anyBoolean())).thenReturn(measures);
when(measureRepository.findAllByMeasureSetIdAndActive(anyString(), anyBoolean()))
.thenReturn(measures);

Exception ex =
assertThrows(
InvalidRequestException.class,
() -> measureSetService.deleteCmsId(measureId, cmsId));
InvalidRequestException.class, () -> measureSetService.deleteCmsId(measureId, cmsId));

assertTrue(
ex.getMessage()
.contains(String.format(String.format("Measure set with measure set id of %s contains more than 1 measure. Cannot delete CMS id when measure set has more than 1 version of measure.", measure1.getMeasureSetId()))));
.contains(
String.format(
String.format(
"Measure set with measure set id of %s contains more than 1 measure. Cannot delete CMS id when measure set has more than 1 version of measure.",
measure1.getMeasureSetId()))));
verify(measureRepository, times(1)).findById(anyString());
verify(measureSetRepository, times(1)).findByMeasureSetId(anyString());
verify(measureRepository, times(1)).findAllByMeasureSetIdAndActive(anyString(), anyBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,7 @@ void testAssignObservationIdAndCriteriaReferenceRatio() {
Group.builder()
.id("group1")
.scoring(MeasureScoring.RATIO.toString())
.populations(List.of(population1, population2, population3, population4, population5))
.measureObservations(List.of(measureObservation1, measureObservation2))
.build();

Expand Down Expand Up @@ -1317,12 +1318,12 @@ void testAssignObservationIdAndCriteriaReferenceRatio() {
is(equalTo("denominatorObservation0")));
assertThat(
results.get(0).getPopulationValues().get(2).getCriteriaReference(),
is(equalTo("criteriaReference1")));
is(equalTo("Population2Id")));
assertThat(
results.get(0).getPopulationValues().get(4).getId(), is(equalTo("numeratorObservation1")));
assertThat(
results.get(0).getPopulationValues().get(4).getCriteriaReference(),
is(equalTo("criteriaReference2")));
is(equalTo("Population4Id")));
}

@Test
Expand Down
Loading