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-7737 switch to new bundle validation endpoint, cleanup old endpoint #255

Merged
merged 1 commit into from
Oct 28, 2024
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 @@ -26,7 +26,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@Slf4j
Expand All @@ -51,10 +50,9 @@ public HapiOperationOutcome validateBundleByModel(
@PathVariable("model") String modelVersion, HttpEntity<String> request) {
final ModelType modelType = QICORE_VERSION_MODELTYPE_MAP.get(modelVersion);
FhirContext fhirContext = validatorFactory.getContextForModel(modelType);
IBaseBundle bundle;
IParser parser = validatorFactory.getJsonParserForModel(modelType);
FhirValidator fhirValidator = validatorFactory.getValidatorForModel(modelType);

IBaseBundle bundle;
try {
bundle = validatorFactory.parseForModel(modelType, request.getBody());
} catch (DataFormatException | ClassCastException ex) {
Expand Down Expand Up @@ -95,12 +93,4 @@ public HapiOperationOutcome validateBundleByModel(
throw new HapiJsonException("An error occurred processing the validation results", ex);
}
}

@PostMapping(
path = "/bundles",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public HapiOperationOutcome validateBundle(HttpEntity<String> request) {
return validateBundleByModel(QICORE_4_1_1, request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import static org.hamcrest.CoreMatchers.notNullValue;
import static gov.cms.madie.madiefhirservice.utils.ModelEndpointMap.QICORE_4_1_1;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
Expand All @@ -40,20 +41,13 @@
@ActiveProfiles("MvcTest")
class ValidationControllerMvcTest implements ResourceFileUtil {
private static final String TEST_USER_ID = "john_doe";
private static final String VALIDATION_API_URL = "/fhir/validations/qicore/%s/bundles";

@Autowired private FhirContext qicoreFhirContext;
@Autowired private FhirContext qicore6FhirContext;
@Autowired private FhirContext fhirContextForR5;

@MockBean private ResourceValidationService validationService;

@Autowired private MockMvc mockMvc;

@Autowired FhirValidator qicoreNpmFhirValidator;
@Autowired FhirValidator qicore6NpmFhirValidator;

@MockBean private ModelAwareFhirFactory validatorFactory;

private IParser r4Parser;

@BeforeEach
Expand Down Expand Up @@ -82,7 +76,7 @@ void testUnsuccessfulOutcomeReturnedForInvalidFhirJson() throws Exception {

mockMvc
.perform(
MockMvcRequestBuilders.post("/fhir/validations/bundles")
MockMvcRequestBuilders.post(String.format(VALIDATION_API_URL, QICORE_4_1_1))
.with(user(TEST_USER_ID))
.with(csrf())
.content(testCaseJson)
Expand Down Expand Up @@ -113,7 +107,7 @@ void testUnsuccessfulOutcomeReturnedForBadResourceType() throws Exception {

mockMvc
.perform(
MockMvcRequestBuilders.post("/fhir/validations/bundles")
MockMvcRequestBuilders.post(String.format(VALIDATION_API_URL, QICORE_4_1_1))
.with(user(TEST_USER_ID))
.with(csrf())
.content(testCaseJson)
Expand Down Expand Up @@ -149,7 +143,7 @@ void testUnsuccessfulOutcomeReturnedForInvalidEncounter() throws Exception {

mockMvc
.perform(
MockMvcRequestBuilders.post("/fhir/validations/bundles")
MockMvcRequestBuilders.post(String.format(VALIDATION_API_URL, QICORE_4_1_1))
.with(user(TEST_USER_ID))
.with(csrf())
.content(tc1Json)
Expand Down Expand Up @@ -190,7 +184,7 @@ void testUnsuccessfulOutcomeReturnedForMissingProfile() throws Exception {

mockMvc
.perform(
MockMvcRequestBuilders.post("/fhir/validations/bundles")
MockMvcRequestBuilders.post(String.format(VALIDATION_API_URL, QICORE_4_1_1))
.with(user(TEST_USER_ID))
.with(csrf())
.content(tc1Json)
Expand Down Expand Up @@ -229,7 +223,7 @@ void testSuccessfulOutcomeReturnedForValidTestCaseJson() throws Exception {

mockMvc
.perform(
MockMvcRequestBuilders.post("/fhir/validations/bundles")
MockMvcRequestBuilders.post(String.format(VALIDATION_API_URL, QICORE_4_1_1))
.with(user(TEST_USER_ID))
.with(csrf())
.content(tc1Json)
Expand Down Expand Up @@ -275,7 +269,7 @@ void testUnsuccessfulOutcomeReturnedForMissingProfileValidTestCaseJson() throws

mockMvc
.perform(
MockMvcRequestBuilders.post("/fhir/validations/bundles")
MockMvcRequestBuilders.post(String.format(VALIDATION_API_URL, QICORE_4_1_1))
.with(user(TEST_USER_ID))
.with(csrf())
.content(tc1Json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.HashMap;
import java.util.Map;

import static gov.cms.madie.madiefhirservice.utils.ModelEndpointMap.QICORE_4_1_1;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -89,7 +90,7 @@ void testValidationControllerReturnsOutcomeForDataFormatException() {
.build());

when(entity.getBody()).thenReturn("{\"foo\": \"foo2\" }");
HapiOperationOutcome output = validationController.validateBundle(entity);
HapiOperationOutcome output = validationController.validateBundleByModel(QICORE_4_1_1, entity);
assertThat(output, is(notNullValue()));
assertThat(output.getCode(), is(equalTo(HttpStatus.BAD_REQUEST.value())));
assertThat(output.isSuccessful(), is(false));
Expand All @@ -114,7 +115,7 @@ void testValidationControllerReturnsOutcomeForClassCastException() {
when(entity.getBody()).thenReturn("{\"foo\": \"foo2\" }");

// when
HapiOperationOutcome output = validationController.validateBundle(entity);
HapiOperationOutcome output = validationController.validateBundleByModel(QICORE_4_1_1, entity);

// then
assertThat(output, is(notNullValue()));
Expand All @@ -135,7 +136,9 @@ void testValidationControllerReturnsExceptionForProcessingError() throws JsonPro
when(entity.getBody()).thenReturn("{\"foo\": \"foo2\" }");

// when/then
assertThrows(HapiJsonException.class, () -> validationController.validateBundle(entity));
assertThrows(
HapiJsonException.class,
() -> validationController.validateBundleByModel(QICORE_4_1_1, entity));
}

@Test
Expand Down Expand Up @@ -167,7 +170,7 @@ void testValidationControllerReturnsOutcomeForMissingProfile() {
.thenReturn(false);

// when
HapiOperationOutcome output = validationController.validateBundle(entity);
HapiOperationOutcome output = validationController.validateBundleByModel(QICORE_4_1_1, entity);

// then
assertThat(output, is(notNullValue()));
Expand Down Expand Up @@ -203,7 +206,9 @@ void testValidationControllerReturnsExceptionForErrorProcessingOutput()
when(fhirValidator.validateWithResult(any(IBaseResource.class))).thenReturn(result);
when(parser.encodeResourceToString(any(OperationOutcome.class)))
.thenReturn("{ \"resourceType\": \"OperationOutcome\" }");
assertThrows(HapiJsonException.class, () -> validationController.validateBundle(entity));
assertThrows(
HapiJsonException.class,
() -> validationController.validateBundleByModel(QICORE_4_1_1, entity));
}

@Test
Expand Down Expand Up @@ -242,7 +247,7 @@ void testValidationControllerReturnsOutcomeWithIssues() throws JsonProcessingExc
when(validationService.isSuccessful(any(FhirContext.class), any(OperationOutcome.class)))
.thenReturn(false);

HapiOperationOutcome output = validationController.validateBundle(entity);
HapiOperationOutcome output = validationController.validateBundleByModel(QICORE_4_1_1, entity);
assertThat(output, is(notNullValue()));
assertThat(output.getCode(), is(equalTo(HttpStatus.OK.value())));
assertThat(output.isSuccessful(), is(false));
Expand Down Expand Up @@ -290,7 +295,7 @@ void testValidationControllerReturnsOutcomeWithUniqueIdIssues() throws JsonProce
when(validationService.isSuccessful(any(FhirContext.class), any(OperationOutcome.class)))
.thenReturn(false);

HapiOperationOutcome output = validationController.validateBundle(entity);
HapiOperationOutcome output = validationController.validateBundleByModel(QICORE_4_1_1, entity);
assertThat(output, is(notNullValue()));
assertThat(output.getCode(), is(equalTo(HttpStatus.BAD_REQUEST.value())));
assertThat(output.getOutcomeResponse() instanceof Map, is(true));
Expand Down Expand Up @@ -336,7 +341,7 @@ void testValidationControllerReturnsOutcomeWithInvalidIdIssues() throws JsonProc
when(validationService.isSuccessful(any(FhirContext.class), any(OperationOutcome.class)))
.thenReturn(false);

HapiOperationOutcome output = validationController.validateBundle(entity);
HapiOperationOutcome output = validationController.validateBundleByModel(QICORE_4_1_1, entity);
assertThat(output, is(notNullValue()));
assertThat(output.getCode(), is(equalTo(HttpStatus.BAD_REQUEST.value())));
assertThat(output.getOutcomeResponse() instanceof Map, is(true));
Expand Down Expand Up @@ -372,7 +377,7 @@ void testValidationControllerReturnsSuccessfulOutcome() {
when(fhirValidator.validateWithResult(any(IBaseResource.class))).thenReturn(result);
when(parser.encodeResourceToString(any(OperationOutcome.class)))
.thenReturn("{ \"resourceType\": \"OperationOutcome\" }");
HapiOperationOutcome output = validationController.validateBundle(entity);
HapiOperationOutcome output = validationController.validateBundleByModel(QICORE_4_1_1, entity);
assertThat(output, is(notNullValue()));
assertThat(output.getCode(), is(equalTo(HttpStatus.OK.value())));
assertThat(output.isSuccessful(), is(true));
Expand Down
Loading