Search in sources :

Example 1 with ValidateCodeRequest

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);
}
Also used : Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) Test(org.junit.Test) FhirRestTest(com.b2international.snowowl.fhir.tests.FhirRestTest)

Example 2 with ValidateCodeRequest

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);
}
Also used : Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) CodeableConcept(com.b2international.snowowl.fhir.core.model.dt.CodeableConcept) Test(org.junit.Test) FhirRestTest(com.b2international.snowowl.fhir.tests.FhirRestTest)

Example 3 with ValidateCodeRequest

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);
}
Also used : Parameters(com.b2international.snowowl.fhir.core.model.dt.Parameters) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) Test(org.junit.Test) FhirRestTest(com.b2international.snowowl.fhir.tests.FhirRestTest)

Example 4 with ValidateCodeRequest

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);
}
Also used : BadRequestException(com.b2international.snowowl.fhir.core.exceptions.BadRequestException) ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) Uri(com.b2international.snowowl.fhir.core.model.dt.Uri) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 5 with ValidateCodeRequest

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());
}
Also used : ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) FhirRestTest(com.b2international.snowowl.fhir.tests.FhirRestTest) Test(org.junit.Test)

Aggregations

ValidateCodeRequest (com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest)10 Test (org.junit.Test)8 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)6 FhirRestTest (com.b2international.snowowl.fhir.tests.FhirRestTest)5 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)3 Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)2 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)2 Operation (io.swagger.v3.oas.annotations.Operation)2 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)2 IssueSeverity (com.b2international.snowowl.fhir.core.codesystems.IssueSeverity)1 IssueType (com.b2international.snowowl.fhir.core.codesystems.IssueType)1 OperationOutcomeCode (com.b2international.snowowl.fhir.core.codesystems.OperationOutcomeCode)1 BadRequestException (com.b2international.snowowl.fhir.core.exceptions.BadRequestException)1 ValidationException (com.b2international.snowowl.fhir.core.exceptions.ValidationException)1 Issue (com.b2international.snowowl.fhir.core.model.Issue)1 Builder (com.b2international.snowowl.fhir.core.model.Issue.Builder)1 com.b2international.snowowl.fhir.core.model.dt (com.b2international.snowowl.fhir.core.model.dt)1 CodeableConcept (com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)1 Parameters (com.b2international.snowowl.fhir.core.model.dt.Parameters)1 Uri (com.b2international.snowowl.fhir.core.model.dt.Uri)1