Skip to content

Commit

Permalink
MAT-7243: Expose getter methods that wrap the Measure Narrative text …
Browse files Browse the repository at this point in the history
…in CSS, aka human readable, and return the result as a String so that it can be accessed independently of the Bundle.
  • Loading branch information
jkotanchik-SB committed Jan 8, 2025
1 parent 59ec709 commit 7cd8c56
Show file tree
Hide file tree
Showing 5 changed files with 460 additions and 340 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.5</version>
<version>0.2.6</version>

<name>packaging-utility</name>
<description>A simple packaging-utility.</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package gov.cms.madie.packaging.utils;

import gov.cms.madie.packaging.exceptions.InternalServerException;
import org.hl7.fhir.r4.model.Bundle;

public interface PackagingUtility {

byte[] getZipBundle(Object export, String exportFileName) throws InternalServerException;

String getHumanReadableWithCSS(Bundle measureBundle);

String getHumanReadableWithCSS(String measureBundleJson);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.r4.model.Attachment;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Library;
import org.hl7.fhir.r4.model.*;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.IParser;
Expand All @@ -22,7 +20,6 @@
import gov.cms.madie.packaging.utils.ZipUtility;
import gov.cms.madie.packaging.utils.qicore.ResourceUtils;
import lombok.extern.slf4j.Slf4j;
import org.hl7.fhir.r4.model.Measure;

@Slf4j
public class PackagingUtilityImpl implements PackagingUtility {
Expand Down Expand Up @@ -68,11 +65,7 @@ private byte[] getZipBundle(Bundle bundle, String exportFileName) throws Interna
if (ResourceUtils.isMeasureBundle(bundle)) {
org.hl7.fhir.r4.model.DomainResource measure =
(org.hl7.fhir.r4.model.DomainResource) ResourceUtils.getResource(bundle, "Measure");
String humanReadable = measure.getText().getDivAsString();

String template = ResourceUtils.getData("/templates/HumanReadable.liquid");
String humanReadableWithCSS =
template.replace("human_readable_content_holder", humanReadable);
String humanReadableWithCSS = getHumanReadableWithCSS(measure);

return zipEntries(exportFileName, jsonParser, xmlParser, bundle, humanReadableWithCSS);
} else if (ResourceUtils.isPatientBundle(bundle)) {
Expand All @@ -82,6 +75,47 @@ private byte[] getZipBundle(Bundle bundle, String exportFileName) throws Interna
}
}

/**
* Retrieve the Measure's Narrative text (aka the Human Readable) from the provided Bundle and
* wrap with CSS.
*
* @param measureBundleJson String of the Measure Bundle JSON with a Measure entry containing one
* Narrative.
* @return String representation of the Human Readable with CSS.
*/
public String getHumanReadableWithCSS(String measureBundleJson) {
IParser jsonParser = context.newJsonParser();
Bundle bundle =
(Bundle) jsonParser.parseResource(measureBundleJson);
return getHumanReadableWithCSS(bundle);
}

/**
* Retrieve the Measure's Narrative text (aka the Human Readable) from the provided Bundle and
* wrap with CSS.
*
* @param measureBundle Measure Bundle with a Measure entry containing one Narrative.
* @return String representation of the Human Readable with CSS.
*/
public String getHumanReadableWithCSS(Bundle measureBundle) {
if (measureBundle == null) {
return null;
}
if (ResourceUtils.isMeasureBundle(measureBundle)) {
DomainResource measure =
(DomainResource)
ResourceUtils.getResource(measureBundle, "Measure");
return getHumanReadableWithCSS(measure);
}
throw new InternalServerException("Unable to parse Measure Bundle");
}

private String getHumanReadableWithCSS(DomainResource measure) {
String humanReadableNarrative = measure.getText().getDivAsString();
String template = ResourceUtils.getData("/templates/HumanReadable.liquid");
return template.replace("human_readable_content_holder", humanReadableNarrative);
}

private byte[] getTestCaseZipBundle(Map<String, Bundle> exportBundles)
throws InternalServerException {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package gov.cms.madie.packaging.utils.qicore6;

/**
* QI-Core 6.0.0 matches packaging requirements of QICore v4.1.1
*/
/** QI-Core 6.0.0 matches packaging requirements of QICore v4.1.1 */
public class PackagingUtilityImpl
extends gov.cms.madie.packaging.utils.qicore411.PackagingUtilityImpl {}
Loading

0 comments on commit 7cd8c56

Please sign in to comment.