diff --git a/src/main/java/gov/cms/madie/madiefhirservice/services/HumanReadableService.java b/src/main/java/gov/cms/madie/madiefhirservice/services/HumanReadableService.java index cb39e93f..a2dc7ddb 100644 --- a/src/main/java/gov/cms/madie/madiefhirservice/services/HumanReadableService.java +++ b/src/main/java/gov/cms/madie/madiefhirservice/services/HumanReadableService.java @@ -15,6 +15,7 @@ import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Library; +import org.hl7.fhir.r5.model.Reference; import org.hl7.fhir.r4.model.Resource; import org.hl7.fhir.r5.model.Enumerations.FHIRTypes; import org.hl7.fhir.r5.model.Expression; @@ -57,6 +58,29 @@ private void escapeTopLevelProperties(org.hl7.fhir.r5.model.Measure measure) { measure.setGuidance(escapeStr(measure.getGuidance())); measure.setClinicalRecommendationStatement( escapeStr(measure.getClinicalRecommendationStatement())); + measure.setRationale(escapeStr(measure.getRationale())); + measure.setSubtitle(escapeStr(measure.getSubtitle())); + measure.setRiskAdjustment(escapeStr(measure.getRiskAdjustment())); + measure.setRateAggregation(escapeStr(measure.getRateAggregation())); + measure.setClinicalRecommendationStatement( + escapeStr(measure.getClinicalRecommendationStatement())); + } + + private void escapeIdentifiers(org.hl7.fhir.r5.model.Measure measure) { + if (CollectionUtils.isNotEmpty(measure.getIdentifier())) { + measure.setIdentifier( + measure.getIdentifier().stream() + .map( + identifier -> { + if (identifier.hasAssigner()) { + Reference ref = identifier.getAssigner(); + ref.setDisplay(escapeStr(ref.getDisplay())); + identifier.setAssigner(ref); + } + return identifier; + }) + .collect(Collectors.toList())); + } } private void escapeSupplementalProperties(org.hl7.fhir.r5.model.Measure measure) { @@ -79,6 +103,15 @@ public void escapeContainedProperties(org.hl7.fhir.r5.model.Measure measure) { contained -> { org.hl7.fhir.r5.model.Library lib = (org.hl7.fhir.r5.model.Library) contained; List relatedArtifacts = lib.getRelatedArtifact(); + if (lib.hasParameter()) { + lib.setParameter( + lib.getParameter().stream() + .map( + parameterDefinition -> + parameterDefinition.setName( + escapeStr(parameterDefinition.getName()))) + .collect(Collectors.toList())); + } lib.getExtension() .forEach( extension -> { @@ -106,6 +139,7 @@ public org.hl7.fhir.r5.model.Measure escapeMeasure(org.hl7.fhir.r5.model.Measure escapeTopLevelProperties(measure); escapeSupplementalProperties(measure); escapeContainedProperties(measure); + escapeIdentifiers(measure); // logic definitions, effective data requirements // risk factors and supplemental data guidance measure @@ -125,6 +159,13 @@ public org.hl7.fhir.r5.model.Measure escapeMeasure(org.hl7.fhir.r5.model.Measure }); // population criteria descriptions + escapePopulationCriteria(measure); + + // population criteria stratifications + return measure; + } + + private void escapePopulationCriteria(org.hl7.fhir.r5.model.Measure measure) { measure .getGroup() .forEach( @@ -140,8 +181,29 @@ public org.hl7.fhir.r5.model.Measure escapeMeasure(org.hl7.fhir.r5.model.Measure Expression criteria = population.getCriteria(); criteria.setExpression(escapeStr(criteria.getExpression())); }); + if (group.hasStratifier()) { + group.setStratifier( + group.getStratifier().stream() + .map( + measureGroupStratifierComponent -> { + measureGroupStratifierComponent.setDescription( + escapeStr(measureGroupStratifierComponent.getDescription())); + log.info("escaping stratifier: {}", measureGroupStratifierComponent); + if (measureGroupStratifierComponent.hasCriteria()) { + measureGroupStratifierComponent.setCriteria( + measureGroupStratifierComponent + .getCriteria() + .setExpression( + escapeStr( + measureGroupStratifierComponent + .getCriteria() + .getExpression()))); + } + return measureGroupStratifierComponent; + }) + .collect(Collectors.toList())); + } }); - return measure; } public String generateMeasureHumanReadable(