use of com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest in project snow-owl by b2ihealthcare.
the class ValidateFhirCodeRestTest method validCodingTestWithPostTest.
@Test
public void validCodingTestWithPostTest() throws Exception {
String system = "http://hl7.org/fhir/issue-severity";
Coding coding = Coding.builder().system(system).code("fatal").build();
ValidateCodeRequest request = ValidateCodeRequest.builder().url(system).coding(coding).build();
Fhir fhirParameters = new Parameters.Fhir(request);
String jsonBody = objectMapper.writeValueAsString(fhirParameters);
givenAuthenticatedRequest(FHIR_ROOT_CONTEXT).contentType(APPLICATION_FHIR_JSON).body(jsonBody).when().post("/CodeSystem/$validate-code").then().body("resourceType", equalTo("Parameters")).body("parameter[0].name", equalTo("result")).body("parameter[0].valueBoolean", equalTo(true)).statusCode(200);
}
use of com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest in project snow-owl by b2ihealthcare.
the class ValidateFhirCodeRestTest method validCodeableConceptTestWithPostTest.
@Test
public void validCodeableConceptTestWithPostTest() throws Exception {
String system = "http://hl7.org/fhir/issue-severity";
Coding coding = Coding.builder().system(system).code("fatal").build();
CodeableConcept codeableConcept = CodeableConcept.builder().addCoding(coding).build();
ValidateCodeRequest request = ValidateCodeRequest.builder().url(system).codeableConcept(codeableConcept).build();
Fhir fhirParameters = new Parameters.Fhir(request);
String jsonBody = objectMapper.writeValueAsString(fhirParameters);
givenAuthenticatedRequest(FHIR_ROOT_CONTEXT).contentType(APPLICATION_FHIR_JSON).body(jsonBody).when().post("/CodeSystem/$validate-code").then().body("resourceType", equalTo("Parameters")).body("parameter[0].name", equalTo("result")).body("parameter[0].valueBoolean", equalTo(true)).statusCode(200);
}
use of com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest in project snow-owl by b2ihealthcare.
the class ValidateFhirCodeRestTest method invalidParametersOnInstancePostTest.
@Test
public void invalidParametersOnInstancePostTest() throws Exception {
// URL
ValidateCodeRequest request = ValidateCodeRequest.builder().url(// should not be specified on the instance level
"fhir/issue-severity").code("fatal").build();
Fhir fhirParameters = new Parameters.Fhir(request);
String jsonBody = objectMapper.writeValueAsString(fhirParameters);
givenAuthenticatedRequest(FHIR_ROOT_CONTEXT).contentType(APPLICATION_FHIR_JSON).pathParam("id", FHIR_ISSUE_TYPE_CODESYSTEM_ID).body(jsonBody).when().post("/CodeSystem/{id}/$validate-code").then().body("resourceType", equalTo("OperationOutcome")).body("issue.severity", hasItem("error")).body("issue.code", hasItem("invalid")).body("issue.diagnostics", hasItem("Parameter 'url' cannot be specified when the code system ID is set.")).body("issue.details.text", hasItem("Parameter 'ValidateCodeRequest.url' content is invalid")).statusCode(400);
// Coding
request = ValidateCodeRequest.builder().coding(// should not be specified on the instance level
Coding.builder().system("http://hl7.org/fhir/issue-severity").code("fatal").build()).build();
fhirParameters = new Parameters.Fhir(request);
jsonBody = objectMapper.writeValueAsString(fhirParameters);
givenAuthenticatedRequest(FHIR_ROOT_CONTEXT).contentType(APPLICATION_FHIR_JSON).pathParam("id", FHIR_ISSUE_TYPE_CODESYSTEM_ID).body(jsonBody).when().post("/CodeSystem/{id}/$validate-code").then().body("resourceType", equalTo("OperationOutcome")).body("issue.severity", hasItem("error")).body("issue.code", hasItem("invalid")).body("issue.diagnostics", hasItem("Parameter 'coding' cannot be specified when the code system ID is set.")).body("issue.details.text", hasItem("Parameter 'ValidateCodeRequest.coding' content is invalid")).statusCode(400);
// CodeableConcept
request = ValidateCodeRequest.builder().codeableConcept(// should not be specified on the instance level
CodeableConcept.builder().addCoding(Coding.builder().system("http://hl7.org/fhir/issue-severity").code("fatal").build()).build()).build();
fhirParameters = new Parameters.Fhir(request);
jsonBody = objectMapper.writeValueAsString(fhirParameters);
givenAuthenticatedRequest(FHIR_ROOT_CONTEXT).contentType(APPLICATION_FHIR_JSON).pathParam("id", FHIR_ISSUE_TYPE_CODESYSTEM_ID).body(jsonBody).when().post("/CodeSystem/{id}/$validate-code").then().body("resourceType", equalTo("OperationOutcome")).body("issue.severity", hasItem("error")).body("issue.code", hasItem("invalid")).body("issue.diagnostics", hasItem("Parameter 'codeableConcept' cannot be specified when the code system ID is set.")).body("issue.details.text", hasItem("Parameter 'ValidateCodeRequest.codeableConcept' content is invalid")).statusCode(400);
}
use of com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest in project snow-owl by b2ihealthcare.
the class FhirCodeSystemValidateCodeOperationController method validateCode.
/**
* POST-based $validate-code end-point.
* All parameters are in the request body, except the codeSystemId
* @param body - FHIR parameters
* @return out - FHIR parameters
*/
@Operation(summary = "Validate a code in a code system", description = "Validate that a coded value is in a code system.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "400", description = "Bad request") })
@PostMapping(value = "/{codeSystemId:**}/$validate-code", consumes = AbstractFhirController.APPLICATION_FHIR_JSON)
public Promise<Parameters.Fhir> validateCode(@Parameter(description = "The id of the code system to validate against") @PathVariable("codeSystemId") String codeSystemId, @Parameter(description = "The validate-code request parameters") @RequestBody Parameters.Fhir body) {
final ValidateCodeRequest request = toRequest(body, ValidateCodeRequest.class);
// Validate for parameters that are not allowed on the instance level
if (request.getUrl() != null) {
throw new BadRequestException("Parameter 'url' cannot be specified when the code system ID is set.", "ValidateCodeRequest.url");
}
if (request.getCoding() != null) {
throw new BadRequestException("Parameter 'coding' cannot be specified when the code system ID is set.", "ValidateCodeRequest.coding");
}
if (request.getCodeableConcept() != null) {
throw new BadRequestException("Parameter 'codeableConcept' cannot be specified when the code system ID is set.", "ValidateCodeRequest.codeableConcept");
}
if (request.getCodeSystem() != null) {
throw new BadRequestException("Validation against external code systems is not supported", "ValidateCodeRequest.codeSystem");
}
// before execution set the codesystem to the path variable
request.setUrl(new Uri(codeSystemId));
return FhirRequests.codeSystems().prepareValidateCode().setRequest(request).buildAsync().execute(getBus()).then(this::toResponse);
}
use of com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest in project snow-owl by b2ihealthcare.
the class FhirCodeSystemValidateCodeOperationTest method POST_CodeSystem_$validate_code_Existing.
@Test
public void POST_CodeSystem_$validate_code_Existing() throws Exception {
ValidateCodeRequest request = ValidateCodeRequest.builder().url(SNOMEDCT_URL).coding(Coding.of(SNOMEDCT_URL, Concepts.ROOT_CONCEPT)).build();
givenAuthenticatedRequest(FHIR_ROOT_CONTEXT).contentType(APPLICATION_FHIR_JSON).body(toFhirParameters(request)).when().post(CODESYSTEM_VALIDATE_CODE).then().assertThat().statusCode(200).body("parameter[0].name", equalTo("result")).body("parameter[0].valueBoolean", equalTo(true)).body("parameter[1]", nullValue());
}
Aggregations