Skip to content

Commit

Permalink
Merge pull request #14 from MeasureAuthoringTool/MAT-6710_addQRDAExpo…
Browse files Browse the repository at this point in the history
…rtButton

MAT-6710 export QRDA
  • Loading branch information
sb-cecilialiu authored Mar 8, 2024
2 parents d94cd5d + ed3c08e commit 0797806
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/gov/cms/madie/resources/PackageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,21 @@ public ResponseEntity<String> generateHqmf(
"Unsupported model type: "
+ (measure == null || measure.getModel() == null ? "NONE" : measure.getModel()));
}

@PutMapping(
value = "/package/qrda",
produces = {
MediaType.APPLICATION_OCTET_STREAM_VALUE,
},
consumes = {MediaType.APPLICATION_JSON_VALUE})
public byte[] getQRDA(
@RequestBody @Validated(Measure.ValidationSequence.class) Measure measure,
@RequestHeader("Authorization") String accessToken) {
log.info("export QRDA for measure [{}] ", measure.getId());
// generate QRDA if the model type is QDM
if (measure.getModel() != null && measure.getModel().contains("QDM")) {
return packagingService.createQRDA(measure, accessToken);
}
throw new UnsupportedModelException("Unsupported model type: " + measure.getModel());
}
}
6 changes: 6 additions & 0 deletions src/main/java/gov/cms/madie/services/PackagingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ public byte[] createMeasurePackage(Measure measure, String accessToken) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
return new ZipUtility().zipEntries(entries, outputStream);
}

public byte[] createQRDA(Measure measure, String accessToken) {
log.info("Creating QRDA for measure [{}]", measure.getId());
// to be implemented: calling back end QRDA Service
return "test qrda".getBytes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,42 @@ void testGetMeasureHqmfForUnsupportedModel() throws Exception {
mockResult.getResolvedException().getMessage(),
is(equalTo("Unsupported model type: QI-Core v4.1.1")));
}

@Test
void testGetQRDASuccess() throws Exception {
String measureJson = getStringFromTestResource("/measures/qdm-test-measure.json");
Mockito.when(packagingService.createQRDA(new Measure(), TOKEN))
.thenReturn("measure package".getBytes());
mockMvc
.perform(
MockMvcRequestBuilders.put("/qdm/measures/package/qrda")
.with(user(TEST_USER_ID))
.with(csrf())
.header(HttpHeaders.AUTHORIZATION, TOKEN)
.content(measureJson)
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk())
.andReturn();

verify(packagingService, times(1)).createQRDA(any(Measure.class), anyString());
}

@Test
void testGetQRDAUnsupportedModel() throws Exception {
String measureJson = getStringFromTestResource("/measures/qicore-test-measure.json");
MvcResult mockResult =
mockMvc
.perform(
MockMvcRequestBuilders.put("/qdm/measures/package/qrda")
.with(user(TEST_USER_ID))
.with(csrf())
.header(HttpHeaders.AUTHORIZATION, TOKEN)
.content(measureJson)
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isBadRequest())
.andReturn();
assertThat(
mockResult.getResolvedException().getMessage(),
is(equalTo("Unsupported model type: QI-Core v4.1.1")));
}
}
32 changes: 32 additions & 0 deletions src/test/java/gov/cms/madie/resources/PackageControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,36 @@ void testGenerateHqmfReturnsHqmf() throws Exception {
String hqmf = packageController.generateHqmf(measure, TOKEN).getBody();
assertThat(hqmf, is(equalTo("<QualityMeasureDocument></QualityMeasureDocument>")));
}

@Test
void testGetQRDASuccess() {
String qrda = "test QRDA";
when(packagingService.createQRDA(measure, TOKEN)).thenReturn(qrda.getBytes());
byte[] result = packageController.getQRDA(measure, TOKEN);
assertThat(new String(result), is(equalTo(qrda)));
}

@Test
void testGetQRDAIfModelIsNull() {
measure.setModel(null);
String errorMessage = "Unsupported model type: " + measure.getModel();
Exception ex =
Assertions.assertThrows(
UnsupportedModelException.class,
() -> packageController.getQRDA(measure, TOKEN),
errorMessage);
assertThat(ex.getMessage(), is(equalTo(errorMessage)));
}

@Test
void testGetQRDAForUnsupportedModel() {
measure.setModel(String.valueOf(ModelType.QI_CORE));
String errorMessage = "Unsupported model type: " + measure.getModel();
Exception ex =
Assertions.assertThrows(
UnsupportedModelException.class,
() -> packageController.getQRDA(measure, TOKEN),
errorMessage);
assertThat(ex.getMessage(), is(equalTo(errorMessage)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,10 @@ void testCreateMeasurePackageWhenTranslationFailed() {
msg);
assertThat(exception.getMessage(), containsString(msg));
}

@Test
void testCreateQRDA() {
byte[] qrda = packagingService.createQRDA(measure, TOKEN);
assertThat(new String(qrda), is(equalTo("test qrda")));
}
}

0 comments on commit 0797806

Please sign in to comment.