diff --git a/src/main/java/gov/cms/madie/services/PackagingService.java b/src/main/java/gov/cms/madie/services/PackagingService.java index b8b4959..c590290 100644 --- a/src/main/java/gov/cms/madie/services/PackagingService.java +++ b/src/main/java/gov/cms/madie/services/PackagingService.java @@ -79,8 +79,16 @@ public byte[] createQRDA(QrdaRequestDTO qrdaRequestDTO, String accessToken) { 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()); + if (qrda.getQrda() == null) { + log.warn("QRDA export for Measure [{}], testcase filename [{}] is missing QRDA", measure.getId(), qrda.getFilename()); + } else { + entries.put(qrdaDir + qrda.getFilename() + ".xml", qrda.getQrda().getBytes()); + } + if (qrda.getReport() == null) { + log.warn("QRDA export for Measure [{}], testcase filename [{}] is missing HTML", measure.getId(), qrda.getFilename()); + } else { + entries.put(htmlDir + qrda.getFilename() + ".html", qrda.getReport().getBytes()); + } } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); return new ZipUtility().zipEntries(entries, outputStream); diff --git a/src/test/java/gov/cms/madie/services/PackagingServiceTest.java b/src/test/java/gov/cms/madie/services/PackagingServiceTest.java index 52be902..061fa73 100644 --- a/src/test/java/gov/cms/madie/services/PackagingServiceTest.java +++ b/src/test/java/gov/cms/madie/services/PackagingServiceTest.java @@ -176,4 +176,62 @@ void testCreateQRDA() { assertThat(new String(qrda), containsString("html/")); assertThat(new String(qrda), containsString("1_test.html")); } + + @Test + void testCreateQrdaHandlesNullQrdaEntry() { + when(qrdaService.generateQrda(any(QrdaRequestDTO.class), any(String.class))) + .thenReturn( + QrdaExportResponseDto.builder() + .summaryReport("summaryReport") + .individualReports( + List.of( + QrdaReportDTO.builder() + .qrda(null) + .filename("1_test") + .report("report1") + .build(), + QrdaReportDTO.builder() + .qrda("qrda2") + .filename("2_test") + .report("report2") + .build())) + .build()); + byte[] qrda = + packagingService.createQRDA(QrdaRequestDTO.builder().measure(measure).build(), TOKEN); + assertThat(new String(qrda), containsString("qrda/")); + assertThat(new String(qrda), containsString("2_test.xml")); + + assertThat(new String(qrda), containsString("html/")); + assertThat(new String(qrda), containsString("1_test.html")); + assertThat(new String(qrda), containsString("2_test.html")); + } + + @Test + void testCreateQrdaHandlesNullHtmlEntry() { + when(qrdaService.generateQrda(any(QrdaRequestDTO.class), any(String.class))) + .thenReturn( + QrdaExportResponseDto.builder() + .summaryReport("summaryReport") + .individualReports( + List.of( + QrdaReportDTO.builder() + .qrda("qrda1") + .filename("1_test") + .report(null) + .build(), + QrdaReportDTO.builder() + .qrda("qrda2") + .filename("2_test") + .report("report2") + .build())) + .build()); + byte[] qrda = + packagingService.createQRDA(QrdaRequestDTO.builder().measure(measure).build(), TOKEN); + assertThat(new String(qrda), containsString("qrda/")); + assertThat(new String(qrda), containsString("1_test.xml")); + assertThat(new String(qrda), containsString("2_test.xml")); + + assertThat(new String(qrda), containsString("html/")); + assertThat(new String(qrda), containsString("2_test.html")); + } }