Skip to content

Commit

Permalink
Merge pull request #65 from MeasureAuthoringTool/feature/mat-6835-qrd…
Browse files Browse the repository at this point in the history
…a-summary-report

[MAT-6835] DTOs for QRDA Export
  • Loading branch information
jkotanchik-SB authored Jun 4, 2024
2 parents 89e481e + aaf8b77 commit e20167c
Show file tree
Hide file tree
Showing 20 changed files with 358 additions and 56 deletions.
17 changes: 17 additions & 0 deletions src/main/java/gov/cms/madie/dto/qrda/PopulationDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gov.cms.madie.dto.qrda;

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

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
public class PopulationDTO {
String name;
int expected;
int actual;
boolean pass;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gov.cms.madie.dto;
package gov.cms.madie.dto.qrda;

import gov.cms.madie.dto.SourceDataCriteria;
import gov.cms.madie.models.measure.TestCase;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -12,11 +13,12 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class QRDADto {
public class QrdaDTO {

String measure;
List<TestCase> testCases;
// TODO waiting for SME feedback
List<SourceDataCriteria> sourceDataCriteria;
Object options;
QrdaGroupDTO[] groupDTOs;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.cms.madie.dto;
package gov.cms.madie.dto.qrda;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -13,5 +13,5 @@
@AllArgsConstructor
public class QrdaExportResponseDto {
String summaryReport;
List<QrdaReportDto> individualReports;
List<QrdaReportDTO> individualReports;
}
17 changes: 17 additions & 0 deletions src/main/java/gov/cms/madie/dto/qrda/QrdaGroupDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gov.cms.madie.dto.qrda;

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

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
public class QrdaGroupDTO {
String groupId;
String groupNumber;
String coverage;
QrdaTestCaseDTO[] testCaseDTOs;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gov.cms.madie.dto.qrda;

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

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
public class QrdaGroupStratificationDTO {
String testCaseId;
String stratId;
String stratName;
StratificationDTO[] stratificationDtos;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.cms.madie.dto;
package gov.cms.madie.dto.qrda;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -9,7 +9,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class QrdaReportDto {
public class QrdaReportDTO {
String qrda;
String report;
String filename;
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/gov/cms/madie/dto/qrda/QrdaRequestDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gov.cms.madie.dto.qrda;

import gov.cms.madie.models.measure.Measure;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
public class QrdaRequestDTO {
Measure measure;
Object options;
QrdaGroupDTO[] groupDTOs;
}
18 changes: 18 additions & 0 deletions src/main/java/gov/cms/madie/dto/qrda/QrdaTestCaseDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gov.cms.madie.dto.qrda;

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

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
public class QrdaTestCaseDTO {
String testCaseId;
String lastName;
String firstName;
PopulationDTO[] populations;
QrdaGroupStratificationDTO[] stratifications;
}
18 changes: 18 additions & 0 deletions src/main/java/gov/cms/madie/dto/qrda/StratificationDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gov.cms.madie.dto.qrda;

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

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
public class StratificationDTO {
String id;
String name;
int expected;
int actual;
boolean pass;
}
6 changes: 4 additions & 2 deletions src/main/java/gov/cms/madie/resources/PackageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gov.cms.madie.Exceptions.UnsupportedModelException;
import gov.cms.madie.dto.CqlLookups;
import gov.cms.madie.dto.qrda.QrdaRequestDTO;
import gov.cms.madie.models.measure.QdmMeasure;
import gov.cms.madie.services.*;
import gov.cms.madie.models.measure.Measure;
Expand Down Expand Up @@ -103,12 +104,13 @@ public ResponseEntity<String> generateHqmf(
},
consumes = {MediaType.APPLICATION_JSON_VALUE})
public byte[] getQRDA(
@RequestBody @Validated(Measure.ValidationSequence.class) Measure measure,
@RequestBody QrdaRequestDTO qrdaRequestDTO,
@RequestHeader("Authorization") String accessToken) {
Measure measure = qrdaRequestDTO.getMeasure();
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);
return packagingService.createQRDA(qrdaRequestDTO, accessToken);
}
throw new UnsupportedModelException("Unsupported model type: " + measure.getModel());
}
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/gov/cms/madie/services/PackagingService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package gov.cms.madie.services;

import gov.cms.madie.dto.CqlLookups;
import gov.cms.madie.dto.QrdaExportResponseDto;
import gov.cms.madie.dto.QrdaReportDto;
import gov.cms.madie.dto.qrda.QrdaExportResponseDto;
import gov.cms.madie.dto.qrda.QrdaReportDTO;
import gov.cms.madie.dto.qrda.QrdaRequestDTO;
import gov.cms.madie.models.dto.TranslatedLibrary;
import gov.cms.madie.models.measure.Measure;
import gov.cms.madie.models.measure.QdmMeasure;
Expand Down Expand Up @@ -68,10 +69,12 @@ public byte[] createMeasurePackage(Measure measure, String accessToken) {
return new ZipUtility().zipEntries(entries, outputStream);
}

public byte[] createQRDA(Measure measure, String accessToken) {
public byte[] createQRDA(QrdaRequestDTO qrdaRequestDTO, String accessToken) {
QdmMeasure measure = (QdmMeasure) qrdaRequestDTO.getMeasure();
log.info("Creating QRDA for measure [{}]", measure.getId());

QrdaExportResponseDto qrdaExport = qrdaService.generateQrda((QdmMeasure) measure, accessToken);
QrdaExportResponseDto qrdaExport = qrdaService.generateQrda(qrdaRequestDTO, accessToken);

if (CollectionUtils.isEmpty(qrdaExport.getIndividualReports())) {
return new byte[0];
}
Expand All @@ -81,11 +84,10 @@ public byte[] createQRDA(Measure measure, String accessToken) {
String htmlDir = "/html/";
String qrdaDir = "/qrda/";
Map<String, byte[]> entries = new HashMap<>();
// TODO MAT-6835: Exclude top level summary until completion of this story.
// entries.put(
// "/" + measure.getEcqmTitle() + "_patients_results.html",
// qrdaExport.getSummaryReport().getBytes());
for (QrdaReportDto qrda : qrdaExport.getIndividualReports()) {
entries.put(
"/" + measure.getEcqmTitle() + "_patients_results.html",
qrdaExport.getSummaryReport().getBytes());
for (QrdaReportDTO qrda : qrdaExport.getIndividualReports()) {
entries.put(qrdaDir + qrda.getFilename() + ".xml", qrda.getQrda().getBytes());
entries.put(htmlDir + qrda.getFilename() + ".html", qrda.getReport().getBytes());
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gov/cms/madie/services/QrdaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import gov.cms.madie.Exceptions.TranslationServiceException;
import gov.cms.madie.config.QrdaClientConfig;
import gov.cms.madie.dto.QRDADto;
import gov.cms.madie.dto.QrdaExportResponseDto;
import gov.cms.madie.dto.qrda.QrdaDTO;
import gov.cms.madie.dto.qrda.QrdaExportResponseDto;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -27,7 +27,7 @@ public class QrdaClient {

@Autowired private ObjectMapper mapper;

public QrdaExportResponseDto getQRDA(QRDADto dto, String accessToken, String measureId) {
public QrdaExportResponseDto getQRDA(QrdaDTO dto, String accessToken, String measureId) {
URI uri = URI.create(qrdaClientConfig.getBaseUrl() + qrdaClientConfig.getQrda());
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.AUTHORIZATION, accessToken);
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/gov/cms/madie/services/QrdaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import gov.cms.madie.Exceptions.QrdaServiceException;
import gov.cms.madie.dto.QRDADto;
import gov.cms.madie.dto.QrdaExportResponseDto;
import gov.cms.madie.dto.qrda.QrdaDTO;
import gov.cms.madie.dto.qrda.QrdaExportResponseDto;
import gov.cms.madie.dto.qrda.QrdaRequestDTO;
import gov.cms.madie.dto.SourceDataCriteria;
import gov.cms.madie.models.dto.TranslatedLibrary;
import gov.cms.madie.models.measure.QdmMeasure;
Expand All @@ -30,7 +31,8 @@ public class QrdaService {
private final QrdaClient client;
private final ObjectMapper objectMapper;

public QrdaExportResponseDto generateQrda(QdmMeasure measure, String accessToken) {
public QrdaExportResponseDto generateQrda(QrdaRequestDTO request, String accessToken) {
QdmMeasure measure = (QdmMeasure) request.getMeasure();
// get Libraries
List<TranslatedLibrary> translatedLibraries =
translationServiceClient.getTranslatedLibraries(measure.getCql(), accessToken);
Expand All @@ -42,16 +44,16 @@ public QrdaExportResponseDto generateQrda(QdmMeasure measure, String accessToken
List<SourceDataCriteria> dataCriteria =
translationServiceClient.getRelevantDataElements(measure, accessToken);

QRDADto dto = null;
QrdaDTO dto = null;
try {

dto =
QRDADto.builder()
QrdaDTO.builder()
.measure(
objectMapper.writeValueAsString(mapper.measureToCqmMeasure(measure, elms, null)))
.testCases(measure.getTestCases())
.sourceDataCriteria(dataCriteria)
.options(buildOptions(measure))
.groupDTOs(request.getGroupDTOs())
.build();
} catch (JsonProcessingException e) {
throw new QrdaServiceException("Problem mapping the measure for QRDA generation", e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gov.cms.madie.resources;

import gov.cms.madie.dto.CqlLookups;
import gov.cms.madie.dto.qrda.QrdaRequestDTO;
import gov.cms.madie.models.measure.QdmMeasure;
import gov.cms.madie.services.*;
import gov.cms.madie.models.measure.Measure;
Expand All @@ -19,8 +20,7 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
Expand Down Expand Up @@ -164,8 +164,8 @@ void testGetMeasureHqmfForUnsupportedModel() throws Exception {

@Test
void testGetQRDASuccess() throws Exception {
String measureJson = getStringFromTestResource("/measures/qdm-test-measure.json");
Mockito.when(packagingService.createQRDA(new Measure(), TOKEN))
String measureJson = getStringFromTestResource("/measures/qrda-qdm-test.json");
Mockito.when(packagingService.createQRDA(any(), eq(TOKEN)))
.thenReturn("measure package".getBytes());
mockMvc
.perform(
Expand All @@ -178,12 +178,12 @@ void testGetQRDASuccess() throws Exception {
.andExpect(status().isOk())
.andReturn();

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

@Test
void testGetQRDAUnsupportedModel() throws Exception {
String measureJson = getStringFromTestResource("/measures/qicore-test-measure.json");
String measureJson = getStringFromTestResource("/measures/qrda-qicore-test.json");
MvcResult mockResult =
mockMvc
.perform(
Expand Down
13 changes: 9 additions & 4 deletions src/test/java/gov/cms/madie/resources/PackageControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gov.cms.madie.Exceptions.UnsupportedModelException;
import gov.cms.madie.dto.CqlLookups;
import gov.cms.madie.dto.qrda.QrdaRequestDTO;
import gov.cms.madie.models.measure.FhirMeasure;
import gov.cms.madie.models.measure.QdmMeasure;
import gov.cms.madie.services.HqmfService;
Expand Down Expand Up @@ -150,8 +151,10 @@ void testGenerateHqmfReturnsHqmf() throws Exception {
@Test
void testGetQRDASuccess() {
String qrda = "test QRDA";
when(packagingService.createQRDA(measure, TOKEN)).thenReturn(qrda.getBytes());
byte[] result = packageController.getQRDA(measure, TOKEN);
when(packagingService.createQRDA(QrdaRequestDTO.builder().measure(measure).build(), TOKEN))
.thenReturn(qrda.getBytes());
byte[] result =
packageController.getQRDA(QrdaRequestDTO.builder().measure(measure).build(), TOKEN);
assertThat(new String(result), is(equalTo(qrda)));
}

Expand All @@ -162,7 +165,8 @@ void testGetQRDAIfModelIsNull() {
Exception ex =
Assertions.assertThrows(
UnsupportedModelException.class,
() -> packageController.getQRDA(measure, TOKEN),
() ->
packageController.getQRDA(QrdaRequestDTO.builder().measure(measure).build(), TOKEN),
errorMessage);
assertThat(ex.getMessage(), is(equalTo(errorMessage)));
}
Expand All @@ -174,7 +178,8 @@ void testGetQRDAForUnsupportedModel() {
Exception ex =
Assertions.assertThrows(
UnsupportedModelException.class,
() -> packageController.getQRDA(measure, TOKEN),
() ->
packageController.getQRDA(QrdaRequestDTO.builder().measure(measure).build(), TOKEN),
errorMessage);
assertThat(ex.getMessage(), is(equalTo(errorMessage)));
}
Expand Down
Loading

0 comments on commit e20167c

Please sign in to comment.