Search in sources :

Example 11 with Fhir

use of com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir 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 12 with Fhir

use of com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir in project snow-owl by b2ihealthcare.

the class FhirCodeSystemValidateCodeOperationController method validateCode.

/**
 * HTTP Get request to validate that a coded value is in the code system specified by the ID param in the path.
 * The code system is identified by its Code System ID within the path - 'instance' level call
 * If the operation is not called at the instance level, one of the parameters "url" or "codeSystem" must be provided.
 * The operation returns a result (true / false), an error message, and the recommended display for the code.
 * When invoking this operation, a client SHALL provide one (and only one) of the parameters (code+system, coding, or codeableConcept).
 * Other parameters (including version and display) are optional.
 *
 * @param codeSystemId the code system to validate against
 * @param code to code to validate
 * @param version the version of the code system to validate against
 * @param date the date for which the validation should be checked
 * @param isAbstract If this parameter has a value of true, the client is stating that the validation is being performed in a context
 * 			where a concept designated as 'abstract' is appropriate/allowed.
 *
 * @return validation results as {@link OperationOutcome}
 */
@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 = "400", description = "Bad request"), @ApiResponse(responseCode = "404", description = "Code system not found") })
@GetMapping("/{codeSystemId:**}/$validate-code")
public Promise<Parameters.Fhir> validateCode(@Parameter(description = "The id of the code system to validate against") @PathVariable("codeSystemId") String codeSystemId, @Parameter(description = "The code to be validated") @RequestParam(value = "code") final String code, @Parameter(description = "The version of the code system") @RequestParam(value = "version") final Optional<String> version, @Parameter(description = "The display string of the code") @RequestParam(value = "display") final Optional<String> display, @Parameter(description = "The date stamp of the code system to validate against") @RequestParam(value = "date") final Optional<String> date, @Parameter(description = "The abstract status of the code") @RequestParam(value = "abstract") final Optional<Boolean> isAbstract) {
    ValidateCodeRequest.Builder builder = ValidateCodeRequest.builder().code(code).version(version.orElse(null)).display(display.orElse(null)).isAbstract(isAbstract.orElse(null));
    if (date.isPresent()) {
        builder.date(date.get());
    }
    // Convert to FHIR parameters and delegate to the POST call
    Json json = new Parameters.Json(builder.build());
    Fhir fhir = new Parameters.Fhir(json.parameters());
    return validateCode(codeSystemId, fhir);
}
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) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 13 with Fhir

use of com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir in project snow-owl by b2ihealthcare.

the class FhirCodeSystemValidateCodeOperationController method validateCodeByUrl.

/**
 * HTTP Get request to validate that a coded value is in the code system specified by the URI parameter
 * The code system is identified by its Code System ID within the path
 * If the operation is not called at the instance level, one of the parameters "url" or "codeSystem" must be provided.
 * The operation returns a result (true / false), an error message, and the recommended display for the code.
 * When invoking this operation, a client SHALL provide one (and only one) of the parameters (code+system, coding, or codeableConcept).
 * Other parameters (including version and display) are optional.
 *
 * @param url the code system to validate against
 * @param code to code to validate
 * @param version the version of the code system to validate against
 * @param date the date for which the validation should be checked
 * @param isAbstract If this parameter has a value of true, the client is stating that the validation is being performed in a context
 * 			where a concept designated as 'abstract' is appropriate/allowed.
 *
 * @return validation results as {@link OperationOutcome}
 */
@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 = "400", description = "Bad request"), @ApiResponse(responseCode = "404", description = "Code system not found") })
@GetMapping("/$validate-code")
public Promise<Parameters.Fhir> validateCodeByUrl(@Parameter(description = "The uri of the code system to validate against") @RequestParam("url") String url, @Parameter(description = "The code to be validated") @RequestParam(value = "code") final String code, @Parameter(description = "The version of the code system") @RequestParam(value = "version") final Optional<String> version, @Parameter(description = "The display string of the code") @RequestParam(value = "display") final Optional<String> display, @Parameter(description = "The date stamp of the code system to validate against") @RequestParam(value = "date") final Optional<String> date, @Parameter(description = "The abstract status of the code") @RequestParam(value = "abstract") final Optional<Boolean> isAbstract) {
    ValidateCodeRequest.Builder builder = ValidateCodeRequest.builder().url(url).code(code).version(version.orElse(null)).display(display.orElse(null)).isAbstract(isAbstract.orElse(null));
    if (date.isPresent()) {
        builder.date(date.get());
    }
    // Convert to FHIR parameters and delegate to the POST call
    Json json = new Parameters.Json(builder.build());
    Fhir fhir = new Parameters.Fhir(json.parameters());
    return validateCode(fhir);
}
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) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 14 with Fhir

use of com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir in project snow-owl by b2ihealthcare.

the class PropertySerializationTest method basicPropertyTest.

@Test
public void basicPropertyTest() throws Exception {
    Property property = Property.builder().code("123").valueInteger(2).description("propertyDescription").build();
    Fhir fhirParameters = new Parameters.Fhir(property);
    JsonPath jsonPath = JsonPath.from(objectMapper.writeValueAsString(fhirParameters));
    assertThat(jsonPath.getString("resourceType"), equalTo("Parameters"));
    assertThat(jsonPath.getList("parameter").size(), is(3));
    assertThat(jsonPath, FhirParameterMatcher.hasParameter("code", FhirDataType.CODE, "123"));
    assertThat(jsonPath, FhirParameterMatcher.hasParameter("value", FhirDataType.INTEGER, 2));
    assertThat(jsonPath, FhirParameterMatcher.hasParameter("description", FhirDataType.STRING, "propertyDescription"));
}
Also used : Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) JsonPath(io.restassured.path.json.JsonPath) Property(com.b2international.snowowl.fhir.core.model.codesystem.Property) SubProperty(com.b2international.snowowl.fhir.core.model.dt.SubProperty) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 15 with Fhir

use of com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir in project snow-owl by b2ihealthcare.

the class PropertySerializationTest method minimalPropertyTest.

@Test
public void minimalPropertyTest() throws Exception {
    Property property = Property.builder().code("123").build();
    Fhir fhirParameters = new Parameters.Fhir(property);
    JsonPath jsonPath = JsonPath.from(objectMapper.writeValueAsString(fhirParameters));
    assertThat(jsonPath.getString("resourceType"), equalTo("Parameters"));
    assertThat(jsonPath.getList("parameter").size(), is(1));
    assertThat(jsonPath, FhirParameterMatcher.hasParameter("code", FhirDataType.CODE, "123"));
}
Also used : Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) JsonPath(io.restassured.path.json.JsonPath) Property(com.b2international.snowowl.fhir.core.model.codesystem.Property) SubProperty(com.b2international.snowowl.fhir.core.model.dt.SubProperty) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Aggregations

Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)52 Test (org.junit.Test)44 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)35 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)23 Parameters (com.b2international.snowowl.fhir.core.model.dt.Parameters)19 LookupRequest (com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest)11 Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)10 FhirRestTest (com.b2international.snowowl.fhir.tests.FhirRestTest)9 ValidateCodeRequest (com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest)8 JsonPath (io.restassured.path.json.JsonPath)8 TranslateResult (com.b2international.snowowl.fhir.core.model.conceptmap.TranslateResult)7 Optional (java.util.Optional)6 Assert.assertTrue (org.junit.Assert.assertTrue)6 Bundle (com.b2international.snowowl.fhir.core.model.Bundle)5 Entry (com.b2international.snowowl.fhir.core.model.Entry)5 Issue (com.b2international.snowowl.fhir.core.model.Issue)5 OperationOutcomeEntry (com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry)5 ParametersRequestEntry (com.b2international.snowowl.fhir.core.model.ParametersRequestEntry)5 ParametersResponseEntry (com.b2international.snowowl.fhir.core.model.ParametersResponseEntry)5 ResourceRequestEntry (com.b2international.snowowl.fhir.core.model.ResourceRequestEntry)5