Skip to content

Commit

Permalink
MAT-7653 facilitate the measure resources in QI Core exports
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-prateekkeerthi committed Sep 3, 2024
1 parent c5a6f0f commit 4a920f0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>gov.cms.madie.packaging</groupId>
<artifactId>packaging-utility</artifactId>
<version>0.2.3</version>
<version>0.2.4</version>

<name>packaging-utility</name>
<description>A simple packaging-utility.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import gov.cms.madie.packaging.utils.PackagingUtility;
import gov.cms.madie.packaging.utils.ZipUtility;
import lombok.extern.slf4j.Slf4j;
import org.hl7.fhir.r4.model.Measure;

@Slf4j
public class PackagingUtilityImpl implements PackagingUtility {
Expand Down Expand Up @@ -138,12 +139,25 @@ private byte[] zipEntries(
CQL_DIRECTORY + library.getCqlLibraryName() + "-" + library.getVersion() + ".cql";
entries.put(filePath, library.getCql().getBytes());
}

// add Measure Resource to Export
List<Measure> measure = getMeasureResource(bundle);
for (Measure measure1 : measure) {
String json = jsonParser.setPrettyPrint(true).encodeResourceToString(measure1);
String xml = xmlParser.setPrettyPrint(true).encodeResourceToString(measure1);
String fileName =
RESOURCES_DIRECTORY + "measure-" + measure1.getName() + "-" + measure1.getVersion();
entries.put(fileName + ".json", json.getBytes());
entries.put(fileName + ".xml", xml.getBytes());
}

// add Library Resources to Export
List<Library> libraries = getLibraryResources(bundle);
for (Library library1 : libraries) {
String json = jsonParser.setPrettyPrint(true).encodeResourceToString(library1);
String xml = xmlParser.setPrettyPrint(true).encodeResourceToString(library1);
String fileName = RESOURCES_DIRECTORY + library1.getName() + "-" + library1.getVersion();
String fileName =
RESOURCES_DIRECTORY + "library-" + library1.getName() + "-" + library1.getVersion();
entries.put(fileName + ".json", json.getBytes());
entries.put(fileName + ".xml", xml.getBytes());
}
Expand Down Expand Up @@ -185,4 +199,12 @@ private List<Library> getLibraryResources(Bundle measureBundle) {
.map(entry -> (Library) entry.getResource())
.toList();
}

private List<Measure> getMeasureResource(Bundle measureBundle) {
return measureBundle.getEntry().stream()
.filter(
entry -> StringUtils.equals("Measure", entry.getResource().getResourceType().name()))
.map(entry -> (Measure) entry.getResource())
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ void testGetZipBundleWithLibraries() throws IOException {
zipContents.get("widget.xml").startsWith("<Bundle xmlns=\"http://hl7.org/fhir\">"),
is(true));

assertThat(zipContents.containsKey("TestCreateNewLibrary-1.0.000.xml"), is(true));
assertThat(zipContents.containsKey("library-TestCreateNewLibrary-1.0.000.xml"), is(true));
assertThat(
zipContents
.get("TestCreateNewLibrary-1.0.000.xml")
.get("library-TestCreateNewLibrary-1.0.000.xml")
.startsWith("<Library xmlns=\"http://hl7.org/fhir\">"),
is(true));

Expand All @@ -100,12 +100,26 @@ void testGetZipBundleWithLibraries() throws IOException {
.startsWith("library TestCreateNewLibrary version '1.0.000'"),
is(true));

assertThat(zipContents.containsKey("TestCreateNewLibrary-1.0.000.json"), is(true));
assertThat(zipContents.containsKey("library-TestCreateNewLibrary-1.0.000.json"), is(true));
assertThat(
zipContents
.get("TestCreateNewLibrary-1.0.000.json")
.get("library-TestCreateNewLibrary-1.0.000.json")
.startsWith("{\n \"resourceType\": \"Library\","),
is(true));

assertThat(zipContents.containsKey("measure-TestCreateNewLibrary-1.0.000.json"), is(true));
assertThat(
zipContents
.get("measure-TestCreateNewLibrary-1.0.000.json")
.startsWith("{\n \"resourceType\": \"Measure\","),
is(true));

assertThat(zipContents.containsKey("measure-TestCreateNewLibrary-1.0.000.xml"), is(true));
assertThat(
zipContents
.get("measure-TestCreateNewLibrary-1.0.000.xml")
.startsWith("<Measure xmlns=\"http://hl7.org/fhir\">"),
is(true));
}

@Test
Expand Down

0 comments on commit 4a920f0

Please sign in to comment.