Skip to content

Commit

Permalink
Merge pull request #203 from MeasureAuthoringTool/feature/MAT-7004-lo…
Browse files Browse the repository at this point in the history
…gging

MAT-7004: adding extra logging and error handling to attempt to captu…
  • Loading branch information
nmorasb authored Apr 2, 2024
2 parents 90d70df + 2aa0b06 commit e64a03a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package gov.cms.madie.madiefhirservice.resources;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.api.MethodOutcome;
import gov.cms.madie.madiefhirservice.services.ExportService;
import gov.cms.madie.madiefhirservice.services.MeasureBundleService;
import gov.cms.madie.madiefhirservice.utils.BundleUtil;
import gov.cms.madie.madiefhirservice.utils.ExportFileNamesUtil;
import gov.cms.madie.models.measure.Measure;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -14,18 +12,15 @@
import org.hl7.fhir.r4.model.Bundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

@Slf4j
@Controller
Expand All @@ -50,19 +45,24 @@ public ResponseEntity<String> getMeasureBundle(
@RequestParam(required = false, defaultValue = "calculation", name = "bundleType")
String bundleType) {

Bundle bundle =
measureBundleService.createMeasureBundle(
measure, request.getUserPrincipal(), bundleType, accessToken);
try {
Bundle bundle =
measureBundleService.createMeasureBundle(
measure, request.getUserPrincipal(), bundleType, accessToken);

if (accept != null
&& accept.toUpperCase().contains(MediaType.APPLICATION_XML_VALUE.toUpperCase())) {
if (accept != null
&& accept.toUpperCase().contains(MediaType.APPLICATION_XML_VALUE.toUpperCase())) {
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_XML)
.body(fhirContext.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle));
}
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_XML)
.body(fhirContext.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle));
.contentType(MediaType.APPLICATION_JSON)
.body(fhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle));
} catch (Exception ex) {
log.error("An error occurred while creating measure bundle for measure [{}]", measure.getId(), ex);
throw ex;
}
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(fhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle));
}

@PutMapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,24 @@ public Bundle createMeasureBundle(
"Generating measure bundle of type [{}] for measure {}", bundleType, madieMeasure.getId());
madieMeasure.setCql(CqlFormatter.formatCql(madieMeasure.getCql(), principal));

log.info("CQL formatting completed successfully for measure {}", madieMeasure.getId());
org.hl7.fhir.r4.model.Measure measure =
measureTranslatorService.createFhirMeasureForMadieMeasure(madieMeasure);
Set<String> expressions = getExpressions(measure);

log.info("Mapping of MADiE measure to FHIR measure completed successfully {}", madieMeasure.getId());
// Bundle entry for Measure resource
Bundle.BundleEntryComponent measureEntryComponent =
FhirResourceHelpers.getBundleEntryComponent(measure, "Transaction");
Bundle bundle =
new Bundle().setType(Bundle.BundleType.TRANSACTION).addEntry(measureEntryComponent);
log.info("Measure bundle entry created successfully {}", madieMeasure.getId());
// Bundle entries for all the library resources of a MADiE Measure
List<Bundle.BundleEntryComponent> libraryEntryComponents =
createBundleComponentsForLibrariesOfMadieMeasure(
expressions, madieMeasure, bundleType, accessToken);
libraryEntryComponents.forEach(bundle::addEntry);
log.info("Included library components created successfully {}", madieMeasure.getId());

if (BundleUtil.MEASURE_BUNDLE_TYPE_EXPORT.equals(bundleType)) {
CqlLibraryDetails libraryDetails =
Expand Down

0 comments on commit e64a03a

Please sign in to comment.