Search in sources :

Example 6 with ValidateCodeRequest

use of com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest in project snow-owl by b2ihealthcare.

the class ValidateFhirCodeRestTest method validCodePostTest.

@Test
public void validCodePostTest() throws Exception {
    ValidateCodeRequest request = ValidateCodeRequest.builder().code("login").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("Parameters")).body("parameter[0].name", equalTo("result")).body("parameter[0].valueBoolean", equalTo(true)).statusCode(200);
}
Also used : 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 7 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
 * @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 = "/$validate-code", consumes = AbstractFhirController.APPLICATION_FHIR_JSON)
public Promise<Parameters.Fhir> validateCode(@Parameter(description = "The validate-code request parameters") @RequestBody Parameters.Fhir body) {
    final ValidateCodeRequest request = toRequest(body, ValidateCodeRequest.class);
    request.validate();
    return FhirRequests.codeSystems().prepareValidateCode().setRequest(request).buildAsync().execute(getBus()).then(this::toResponse);
}
Also used : ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 8 with ValidateCodeRequest

use of com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest in project snow-owl by b2ihealthcare.

the class ValidateCodeSystemCodeRequestTest method fullCircleTest.

@Test
public void fullCircleTest() throws Exception {
    Coding coding = Coding.builder().system("http://hl7.org/fhir/issue-severity").code("fatal").build();
    ValidateCodeRequest request = ValidateCodeRequest.builder().url("http://hl7.org/fhir/issue-severity").coding(coding).isAbstract(true).build();
    Json json1 = new Parameters.Json(request);
    System.out.println("JSON params:" + json1);
    Fhir fhir = new Parameters.Fhir(json1.parameters());
    String fhirJson = objectMapper.writeValueAsString(fhir);
    System.out.println("This is the JSON request from the client: " + fhirJson);
    System.out.println("This is happening in the server-side...");
    Fhir parameters = objectMapper.readValue(fhirJson, Parameters.Fhir.class);
    System.out.println("Deserialized into FHIR parameters..." + parameters.getParameters());
    System.out.println("Back to Domain JSON...");
    Json json = new Parameters.Json(parameters);
    ValidateCodeRequest validateRequest = objectMapper.convertValue(json, ValidateCodeRequest.class);
    System.out.println("... and back to the object representation we started from:" + validateRequest);
}
Also used : Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) Json(com.b2international.snowowl.fhir.core.model.dt.Parameters.Json) ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 9 with ValidateCodeRequest

use of com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest in project snow-owl by b2ihealthcare.

the class ValidateCodeSystemCodeRequestTest method testDeserialization.

@Test
public void testDeserialization() {
    Coding coding = Coding.builder().system("http://hl7.org/fhir/issue-severity").code("fatal").build();
    ValidateCodeRequest request = ValidateCodeRequest.builder().url("http://hl7.org/fhir/issue-severity").coding(coding).isAbstract(true).build();
    Fhir fhirParameters = new Parameters.Fhir(request);
    Optional<Parameter> findFirst = fhirParameters.getParameters().stream().filter(p -> {
        Uri uri = (Uri) p.getValue();
        return uri.getUriValue().equals("http://hl7.org/fhir/issue-severity");
    }).findFirst();
    assertTrue(findFirst.isPresent());
}
Also used : OperationOutcomeCode(com.b2international.snowowl.fhir.core.codesystems.OperationOutcomeCode) ValidationException(com.b2international.snowowl.fhir.core.exceptions.ValidationException) IssueSeverity(com.b2international.snowowl.fhir.core.codesystems.IssueSeverity) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) Assert.assertTrue(org.junit.Assert.assertTrue) com.b2international.snowowl.fhir.core.model.dt(com.b2international.snowowl.fhir.core.model.dt) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) Test(org.junit.Test) IssueType(com.b2international.snowowl.fhir.core.codesystems.IssueType) Json(com.b2international.snowowl.fhir.core.model.dt.Parameters.Json) Issue(com.b2international.snowowl.fhir.core.model.Issue) Optional(java.util.Optional) Builder(com.b2international.snowowl.fhir.core.model.Issue.Builder) FhirExceptionIssueMatcher(com.b2international.snowowl.fhir.tests.FhirExceptionIssueMatcher) Assert.assertEquals(org.junit.Assert.assertEquals) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 10 with ValidateCodeRequest

use of com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest in project snow-owl by b2ihealthcare.

the class ValidateCodeSystemCodeRequestTest method onlyCodeSpecifiedTest.

@Test
public void onlyCodeSpecifiedTest() {
    // This is valid as the code system can also be provided as a path parameter
    ValidateCodeRequest request = ValidateCodeRequest.builder().code("A").build();
    assertEquals("A", request.getCode());
}
Also used : ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) 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