Search in sources :

Example 11 with Json

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

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

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

the class LookupRequestDeserializationTest method fullCircleTest.

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

Example 14 with Json

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

the class BundleTest method deserializeResponseBundle.

@Test
public void deserializeResponseBundle() throws Exception {
    String jsonResponse = "{\"resourceType\":\"Bundle\"," + "\"id\":\"ID\"," + "\"type\":\"batch-response\"," + "\"link\":[" + "{" + "\"relation\":\"self\"," + "\"url\":\"http://b2i.sg\"" + "}" + "]," + "\"entry\":[" + "{" + "\"resource\":{" + "\"resourceType\":\"Parameters\"," + "\"parameter\":[" + "{" + "\"name\":\"name\"," + "\"valueString\":\"LOINC\"" + "}," + "{" + "\"name\":\"version\"," + "\"valueString\":\"2.61\"" + "}," + "{" + "\"name\":\"display\"," + "\"valueString\":\"LOINC code label\"" + "}," + "{" + "\"name\":\"property\"," + "\"part\":[" + "{" + "\"name\":\"code\"," + "\"valueCode\":\"parent\"" + "}," + "{" + "\"name\":\"value\"," + "\"valueCode\":\"Parent code\"" + "}" + "]" + "}," + "{" + "\"name\":\"designation\"," + "\"part\":[" + "{" + "\"name\":\"language\"," + "\"valueCode\":\"en\"" + "}," + "{" + "\"name\":\"use\"," + "\"valueCoding\":{" + "\"system\":\"http://snomed.info/sct\"," + "\"code\":\"900000000000013009\"," + "\"display\":\"Synonym\"" + "}" + "}," + "{" + "\"name\":\"value\"," + "\"valueString\":\"SNOMED CT synonym\"" + "}" + "]" + "}" + "]" + "}," + "\"response\":{" + "\"status\":\"200\"" + "}" + "}" + "]" + "}";
    Bundle bundle = objectMapper.readValue(jsonResponse, Bundle.class);
    assertEquals(BundleType.BATCH_RESPONSE.getCode(), bundle.getType());
    Iterator<Entry> iterator = bundle.getItems().iterator();
    Entry bundleEntry = iterator.next();
    assertTrue(bundleEntry instanceof ParametersResponseEntry);
    ParametersResponseEntry responseEntry = (ParametersResponseEntry) bundleEntry;
    Fhir responseResource = responseEntry.getResponseResource();
    // Back to Domain JSON...
    Json json = new Parameters.Json(responseResource);
    LookupResult lookupResult = objectMapper.convertValue(json, LookupResult.class);
    assertEquals("LOINC", lookupResult.getName());
}
Also used : ParametersRequestEntry(com.b2international.snowowl.fhir.core.model.ParametersRequestEntry) ParametersResponseEntry(com.b2international.snowowl.fhir.core.model.ParametersResponseEntry) ResourceRequestEntry(com.b2international.snowowl.fhir.core.model.ResourceRequestEntry) Entry(com.b2international.snowowl.fhir.core.model.Entry) ResourceResponseEntry(com.b2international.snowowl.fhir.core.model.ResourceResponseEntry) OperationOutcomeEntry(com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry) Bundle(com.b2international.snowowl.fhir.core.model.Bundle) ParametersResponseEntry(com.b2international.snowowl.fhir.core.model.ParametersResponseEntry) LookupResult(com.b2international.snowowl.fhir.core.model.codesystem.LookupResult) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) Json(com.b2international.snowowl.fhir.core.model.dt.Parameters.Json) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 15 with Json

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

the class BundleTest method buildRequestBundle.

@Test
public void buildRequestBundle() throws Exception {
    LookupRequest lookupRequest = LookupRequest.builder().code("23245-4").system("http://loinc.org").build();
    Json json1 = new Parameters.Json(lookupRequest);
    ParametersRequestEntry entry = ParametersRequestEntry.builder().request(BatchRequest.createPostRequest("CodeSystem/$lookup")).resource(new Parameters.Fhir(json1.parameters())).build();
    Bundle bundle = Bundle.builder().language("en").total(1).type(BundleType.BATCH).addLink("self", "http://localhost:8080/snowowl/CodeSystem").addEntry(entry).build();
    assertEquals("en", bundle.getLanguage().getCodeValue());
    assertEquals(1, bundle.getTotal());
    assertEquals(BundleType.BATCH.getCode(), bundle.getType());
    Link link = bundle.getLink().iterator().next();
    assertEquals("self", link.getRelation());
    assertEquals("http://localhost:8080/snowowl/CodeSystem", link.getUrl().getUriValue());
    Entry bundleEntry = bundle.getItems().iterator().next();
    assertTrue(bundleEntry instanceof ParametersRequestEntry);
    ParametersRequestEntry requestEntry = (ParametersRequestEntry) bundleEntry;
    BatchRequest batchRequest = requestEntry.getRequest();
    assertEquals(HttpVerb.POST.getCode(), batchRequest.getMethod());
    assertEquals("CodeSystem/$lookup", batchRequest.getUrl().getUriValue());
    Fhir requestResource = requestEntry.getRequestResource();
    // Back to Domain JSON...
    Json json = new Parameters.Json(requestResource);
    LookupRequest returnedLookupRequest = objectMapper.convertValue(json, LookupRequest.class);
    assertEquals("23245-4", returnedLookupRequest.getCode());
    assertEquals("http://loinc.org", returnedLookupRequest.getSystem());
}
Also used : BatchRequest(com.b2international.snowowl.fhir.core.model.BatchRequest) ParametersRequestEntry(com.b2international.snowowl.fhir.core.model.ParametersRequestEntry) ParametersResponseEntry(com.b2international.snowowl.fhir.core.model.ParametersResponseEntry) ResourceRequestEntry(com.b2international.snowowl.fhir.core.model.ResourceRequestEntry) Entry(com.b2international.snowowl.fhir.core.model.Entry) ResourceResponseEntry(com.b2international.snowowl.fhir.core.model.ResourceResponseEntry) OperationOutcomeEntry(com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry) Bundle(com.b2international.snowowl.fhir.core.model.Bundle) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) Json(com.b2international.snowowl.fhir.core.model.dt.Parameters.Json) ParametersRequestEntry(com.b2international.snowowl.fhir.core.model.ParametersRequestEntry) Link(com.b2international.snowowl.fhir.core.model.Link) LookupRequest(com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Aggregations

Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)27 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)21 Test (org.junit.Test)19 Parameters (com.b2international.snowowl.fhir.core.model.dt.Parameters)15 LookupRequest (com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest)12 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)12 FhirRestTest (com.b2international.snowowl.fhir.tests.FhirRestTest)7 Bundle (com.b2international.snowowl.fhir.core.model.Bundle)6 ParametersRequestEntry (com.b2international.snowowl.fhir.core.model.ParametersRequestEntry)6 Entry (com.b2international.snowowl.fhir.core.model.Entry)5 OperationOutcomeEntry (com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry)5 ParametersResponseEntry (com.b2international.snowowl.fhir.core.model.ParametersResponseEntry)5 ResourceRequestEntry (com.b2international.snowowl.fhir.core.model.ResourceRequestEntry)5 ResourceResponseEntry (com.b2international.snowowl.fhir.core.model.ResourceResponseEntry)5 LookupResult (com.b2international.snowowl.fhir.core.model.codesystem.LookupResult)4 Match (com.b2international.snowowl.fhir.core.model.conceptmap.Match)4 TranslateResult (com.b2international.snowowl.fhir.core.model.conceptmap.TranslateResult)4 Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)4 Link (com.b2international.snowowl.fhir.core.model.Link)3 ValidateCodeRequest (com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest)3