Skip to content

Commit

Permalink
MAT-8019: Skip Bundle validation for QICore STU6 Test Cases.
Browse files Browse the repository at this point in the history
Bundle validation is generic, check for presence of a Patient Resource to ensure passed Bundle is a Test Case. When skipping validations, return a "Nothing to see here!"-esque response with just enough content to be used by the frontend.

Control validation skip via feature flag, stu6TestCaseValidation.
  • Loading branch information
jkotanchik-SB committed Dec 13, 2024
1 parent e6ad5a6 commit 6e2b425
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

/** Feature flags relevant to the measure-service */
public enum MadieFeatureFlag {
QiCore_STU4_UPDATES("qiCoreStu4Updates");
QiCore_STU4_UPDATES("qiCoreStu4Updates"),
STU6_TEST_CASE_VALIDATION("stu6TestCaseValidation");

private final String flag;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
import ca.uhn.fhir.util.OperationOutcomeUtil;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.ValidationResult;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import gov.cms.madie.madiefhirservice.dto.MadieFeatureFlag;
import gov.cms.madie.madiefhirservice.factories.ModelAwareFhirFactory;
import gov.cms.madie.madiefhirservice.services.AppConfigService;
import gov.cms.madie.models.common.ModelType;
import gov.cms.madie.models.measure.HapiOperationOutcome;
import gov.cms.madie.madiefhirservice.exceptions.HapiJsonException;
import gov.cms.madie.madiefhirservice.services.ResourceValidationService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.r4.model.OperationOutcome;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -26,6 +31,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

import static gov.cms.madie.madiefhirservice.utils.ModelEndpointMap.QICORE_VERSION_MODELTYPE_MAP;

@Slf4j
Expand All @@ -39,6 +46,7 @@ public class ValidationController {

private ResourceValidationService validationService;
private ModelAwareFhirFactory validatorFactory;
private AppConfigService appConfigService;

private ObjectMapper mapper;

Expand All @@ -49,8 +57,17 @@ public class ValidationController {
public HapiOperationOutcome validateBundleByModel(
@PathVariable("model") String modelVersion, HttpEntity<String> request) {
final ModelType modelType = QICORE_VERSION_MODELTYPE_MAP.get(modelVersion);
FhirContext fhirContext = validatorFactory.getContextForModel(modelType);
IParser parser = validatorFactory.getJsonParserForModel(modelType);

// MAT-8019: Disable Test Case Validations for QI-Core STU 6 only.
if (ModelType.QI_CORE_6_0_0.equals(modelType)
&& !appConfigService.isFlagEnabled(MadieFeatureFlag.STU6_TEST_CASE_VALIDATION)
&& StringUtils.deleteWhitespace(Objects.requireNonNull(request.getBody()).trim())
.contains("\"resourceType\":\"Patient\"")) {
return noValidationResponse(parser);
}

FhirContext fhirContext = validatorFactory.getContextForModel(modelType);
FhirValidator fhirValidator = validatorFactory.getValidatorForModel(modelType);
IBaseBundle bundle;
try {
Expand Down Expand Up @@ -93,4 +110,17 @@ public HapiOperationOutcome validateBundleByModel(
throw new HapiJsonException("An error occurred processing the validation results", ex);
}
}

private HapiOperationOutcome noValidationResponse(IParser parser) {
try {
return HapiOperationOutcome.builder()
.code(HttpStatus.OK.value())
.successful(true)
.outcomeResponse(
mapper.readValue(parser.encodeResourceToString(new OperationOutcome()), Object.class))
.build();
} catch (JsonProcessingException e) {
throw new HapiJsonException("An error occurred processing the validation results", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ca.uhn.fhir.parser.StrictErrorHandler;
import ca.uhn.fhir.validation.FhirValidator;
import gov.cms.madie.madiefhirservice.factories.ModelAwareFhirFactory;
import gov.cms.madie.madiefhirservice.services.AppConfigService;
import gov.cms.madie.madiefhirservice.services.ResourceValidationService;
import gov.cms.madie.madiefhirservice.utils.ResourceFileUtil;
import gov.cms.madie.models.common.ModelType;
Expand Down Expand Up @@ -48,6 +49,7 @@ class ValidationControllerMvcTest implements ResourceFileUtil {
@Autowired private MockMvc mockMvc;
@Autowired FhirValidator qicoreNpmFhirValidator;
@MockBean private ModelAwareFhirFactory validatorFactory;
@MockBean private AppConfigService appConfigService;
private IParser r4Parser;

@BeforeEach
Expand Down

0 comments on commit 6e2b425

Please sign in to comment.