Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAT-8019: Skip Bundle validation for QICore STU6 Test Cases. #271

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading