Skip to content

Commit

Permalink
MAT-7961: Trim the eCQM Abbr Title when used in an export filename.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotanchik-SB committed Dec 17, 2024
1 parent ce1733f commit 6f45d94
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
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
Expand Up @@ -41,23 +41,25 @@ public byte[] createMeasurePackage(Measure measure, String accessToken) {
Map<String, byte[]> entries = new HashMap<>();
for (TranslatedLibrary translatedLibrary : translatedLibraries) {
String entryName = translatedLibrary.getName() + "-" + translatedLibrary.getVersion();
entries.put(resourcesDir + entryName + ".json", translatedLibrary.getElmJson().getBytes());
entries.put(resourcesDir + entryName + ".xml", translatedLibrary.getElmXml().getBytes());
entries.put(cqlDir + entryName + ".cql", translatedLibrary.getCql().getBytes());
entries.put(
resourcesDir + entryName.trim() + ".json", translatedLibrary.getElmJson().getBytes());
entries.put(
resourcesDir + entryName.trim() + ".xml", translatedLibrary.getElmXml().getBytes());
entries.put(cqlDir + entryName.trim() + ".cql", translatedLibrary.getCql().getBytes());
}
CqlLookups cqlLookups = translationServiceClient.getCqlLookups(qdmMeasure, accessToken);
final String humanReadable = humanReadableService.generate(measure, cqlLookups);

if (humanReadable != null) {
entries.put(
measure.getEcqmTitle() + "-v" + measure.getVersion() + "-QDM" + ".html",
measure.getEcqmTitle().trim() + "-v" + measure.getVersion() + "-QDM" + ".html",
humanReadable.getBytes());
}
String hqmf = hqmfService.generateHqmf(qdmMeasure, cqlLookups);
entries.put(
measure.getEcqmTitle() + "-v" + measure.getVersion() + "-QDM" + ".xml", hqmf.getBytes());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
return new ZipUtility().zipEntries(entries, outputStream);
String hqmf = hqmfService.generateHqmf(qdmMeasure, cqlLookups);
entries.put(
measure.getEcqmTitle().trim() + "-v" + measure.getVersion() + "-QDM" + ".xml",
hqmf.getBytes());
return new ZipUtility().zipEntries(entries, new ByteArrayOutputStream());
}

public byte[] createQRDA(QrdaRequestDTO qrdaRequestDTO, String accessToken) {
Expand Down
39 changes: 36 additions & 3 deletions src/test/java/gov/cms/madie/services/PackagingServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ void testCreateMeasurePackageWhenHqmfGenerationFailed() {
when(humanReadableService.generate(any(Measure.class), any(CqlLookups.class)))
.thenReturn("success");

Mockito.doThrow(new PackagingException("An error occurred that caused the HQMF generation to fail"))
Mockito.doThrow(
new PackagingException("An error occurred that caused the HQMF generation to fail"))
.when(hqmfService)
.generateHqmf(any(QdmMeasure.class), any(CqlLookups.class));
Exception exception =
assertThrows(
PackagingException.class,
() -> packagingService.createMeasurePackage(measure, TOKEN));
PackagingException.class, () -> packagingService.createMeasurePackage(measure, TOKEN));
assertThat(
exception.getMessage(),
containsString("An error occurred that caused the HQMF generation to fail"));
Expand Down Expand Up @@ -234,4 +234,37 @@ void testCreateQrdaHandlesNullHtmlEntry() {
assertThat(new String(qrda), containsString("html/"));
assertThat(new String(qrda), containsString("2_test.html"));
}

@Test
void trimFileNameValues() {
QdmMeasure msr = measure.toBuilder().ecqmTitle(" test ").build();
TranslatedLibrary library1 =
TranslatedLibrary.builder()
.name("Lib one")
.version("0.0.000")
.elmJson("elm xml")
.elmXml("elm xml")
.cql("cql")
.build();
TranslatedLibrary library2 =
TranslatedLibrary.builder()
.name("Lib two")
.version("0.0.001")
.elmJson("elm xml")
.elmXml("elm xml")
.cql("cql")
.build();
CqlLookups cqlLookups = CqlLookups.builder().build();
when(translationServiceClient.getTranslatedLibraries(msr.getCql(), TOKEN))
.thenReturn(List.of(library1, library2));
when(translationServiceClient.getCqlLookups(any(QdmMeasure.class), anyString()))
.thenReturn(CqlLookups.builder().build());
when(hqmfService.generateHqmf(msr, cqlLookups)).thenReturn("<hqmf>this is a test hqmf</hqmf>");
when(humanReadableService.generate(any(Measure.class), any(CqlLookups.class)))
.thenReturn("success");
byte[] packageContents = packagingService.createMeasurePackage(msr, TOKEN);
String packageString = new String(packageContents);
assertThat(packageString, containsString("test-v1.2.003-QDM.html"));
assertThat(packageString, containsString("test-v1.2.003-QDM.xml"));
}
}

0 comments on commit 6f45d94

Please sign in to comment.