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());
}
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());
}
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());
}
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);
}
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();
}
Aggregations