Search in sources :

Example 1 with ValidateCodeResult

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

the class ValidateFhirCodeRestTest method validCodeGetTest.

@Test
public void validCodeGetTest() throws Exception {
    String responseString = givenAuthenticatedRequest(FHIR_ROOT_CONTEXT).pathParam("id", FHIR_ISSUE_TYPE_CODESYSTEM_ID).param("code", "login").param("_format", "json").when().get("/CodeSystem/{id}/$validate-code").then().assertThat().statusCode(200).extract().body().asString();
    ValidateCodeResult result = convertToValidateCodeResult(responseString);
    assertEquals(true, result.getResult());
}
Also used : ValidateCodeResult(com.b2international.snowowl.fhir.core.model.ValidateCodeResult) Test(org.junit.Test) FhirRestTest(com.b2international.snowowl.fhir.tests.FhirRestTest)

Example 2 with ValidateCodeResult

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

the class ValidateFhirCodeRestTest method invalidCodeGetTest.

// instance tests (with ID in the path)
@Test
public void invalidCodeGetTest() throws Exception {
    String responseString = givenAuthenticatedRequest(FHIR_ROOT_CONTEXT).pathParam("id", FHIR_ISSUE_TYPE_CODESYSTEM_ID).param("code", "unknownCode").param("_format", "json").when().get("/CodeSystem/{id}/$validate-code").then().assertThat().statusCode(200).extract().body().asString();
    ValidateCodeResult result = convertToValidateCodeResult(responseString);
    assertEquals(false, result.getResult());
    assertEquals("Could not find code(s) '[unknownCode]'", result.getMessage());
    assertNull(result.getDisplay());
}
Also used : ValidateCodeResult(com.b2international.snowowl.fhir.core.model.ValidateCodeResult) Test(org.junit.Test) FhirRestTest(com.b2international.snowowl.fhir.tests.FhirRestTest)

Example 3 with ValidateCodeResult

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

the class ValidateCodeResultTest method okResultTest.

@Test
public void okResultTest() {
    ValidateCodeResult result = ValidateCodeResult.builder().okResult("Test").build();
    assertTrue(result.getResult());
    result = ValidateCodeResult.builder().okMessage().build();
    assertFalse(result.getResult());
}
Also used : ValidateCodeResult(com.b2international.snowowl.fhir.core.model.ValidateCodeResult) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 4 with ValidateCodeResult

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

the class ValidateCodeResultTest method fullCircleTest.

@Test
public void fullCircleTest() throws Exception {
    ValidateCodeResult request = ValidateCodeResult.builder().artefactNotFoundResult("http://hl7.org/fhir/issue-severity").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);
    ValidateCodeResult validateRequest = objectMapper.convertValue(json, ValidateCodeResult.class);
    System.out.println("... and back to the object representation we started from:" + validateRequest);
}
Also used : Parameters(com.b2international.snowowl.fhir.core.model.dt.Parameters) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) ValidateCodeResult(com.b2international.snowowl.fhir.core.model.ValidateCodeResult) Json(com.b2international.snowowl.fhir.core.model.dt.Parameters.Json) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 5 with ValidateCodeResult

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

the class FhirValidateCodeRequest method doExecute.

@Override
public ValidateCodeResult doExecute(ServiceProvider context, CodeSystem codeSystem) {
    Set<Coding> codings = collectCodingsToValidate(request);
    Map<String, Coding> codingsById = codings.stream().collect(Collectors.toMap(Coding::getCodeValue, c -> c));
    // extract locales from the request
    Map<String, Concept> conceptsById = CodeSystemRequests.prepareSearchConcepts().setLimit(codingsById.keySet().size()).filterByCodeSystemUri(codeSystem.getResourceURI()).filterByIds(codingsById.keySet()).setLocales(extractLocales(request.getDisplayLanguage())).buildAsync().execute(context).stream().collect(Collectors.toMap(Concept::getId, c -> c));
    // check if both Maps have the same keys and report if not
    Set<String> missingConceptIds = Sets.difference(codingsById.keySet(), conceptsById.keySet());
    if (!missingConceptIds.isEmpty()) {
        return ValidateCodeResult.builder().result(false).message(String.format("Could not find code%s '%s'.", missingConceptIds.size() == 1 ? "" : "s", ImmutableSortedSet.copyOf(missingConceptIds))).build();
    }
    // XXX it would be great to have support for multiple messages/validation results in a single request
    for (String id : codingsById.keySet()) {
        // check display if provided
        Coding providedCoding = codingsById.get(id);
        if (providedCoding.getDisplay() != null) {
            Concept concept = conceptsById.get(id);
            if (!providedCoding.getDisplay().equals(concept.getTerm())) {
                return ValidateCodeResult.builder().result(false).display(concept.getTerm()).message(String.format("Incorrect display '%s' for code '%s'.", providedCoding.getDisplay(), providedCoding.getCodeValue())).build();
            }
        }
    }
    return ValidateCodeResult.builder().result(true).build();
}
Also used : ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) HashSet(java.util.HashSet) Valid(javax.validation.Valid) CodeSystem(com.b2international.snowowl.fhir.core.model.codesystem.CodeSystem) Concept(com.b2international.snowowl.core.domain.Concept) Map(java.util.Map) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) JsonUnwrapped(com.fasterxml.jackson.annotation.JsonUnwrapped) ValidateCodeResult(com.b2international.snowowl.fhir.core.model.ValidateCodeResult) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) CodeableConcept(com.b2international.snowowl.fhir.core.model.dt.CodeableConcept) Concept(com.b2international.snowowl.core.domain.Concept) CodeableConcept(com.b2international.snowowl.fhir.core.model.dt.CodeableConcept) Coding(com.b2international.snowowl.fhir.core.model.dt.Coding)

Aggregations

ValidateCodeResult (com.b2international.snowowl.fhir.core.model.ValidateCodeResult)7 Test (org.junit.Test)6 FhirRestTest (com.b2international.snowowl.fhir.tests.FhirRestTest)4 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)2 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)1 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)1 Concept (com.b2international.snowowl.core.domain.Concept)1 CodeSystem (com.b2international.snowowl.fhir.core.model.codesystem.CodeSystem)1 ValidateCodeRequest (com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest)1 CodeableConcept (com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)1 Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)1 Parameters (com.b2international.snowowl.fhir.core.model.dt.Parameters)1 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)1 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 JsonUnwrapped (com.fasterxml.jackson.annotation.JsonUnwrapped)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 Sets (com.google.common.collect.Sets)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1