Search in sources :

Example 1 with LookupRequest

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

the class SandBoxRestTest method bulkRequestTest.

// @Test
public void bulkRequestTest() {
    LookupRequest lookupRequest = LookupRequest.builder().code("23245-4").system("http://loinc.org").build();
    Json json1 = new Parameters.Json(lookupRequest);
    System.out.println("JSON params:" + json1);
    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).addEntry(entry).build();
    givenAuthenticatedRequest(FHIR_ROOT_CONTEXT).contentType(APPLICATION_FHIR_JSON).body(bundle).when().post("/").prettyPeek().then().statusCode(200).body("resourceType", equalTo("Bundle")).body("type", is("batch-response"));
}
Also used : 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) LookupRequest(com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest)

Example 2 with LookupRequest

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

the class BundleTest method deserializeRequestBundle.

@Test
public void deserializeRequestBundle() throws Exception {
    String jsonCoding = "{ \"type\" : \"batch\", " + "\"resourceType\" : \"Bundle\", " + "\"entry\" : " + "[{\"request\" : " + "{\"method\" : \"POST\"," + "\"url\" : \"CodeSystem/$lookup\"}," + "\"resource\" : " + "{\"resourceType\" : \"Parameters\"," + "\"parameter\" : [" + "{\"valueUri\" : \"http://loinc.org\"," + "\"name\" : \"system\"}," + "{\"valueCode\" : \"23245-4\"," + "\"name\" : \"code\"}" + "]" + "}" + "}," + "{\"request\" : " + "{\"method\" : \"POST\"," + "\"url\" : \"CodeSystem/$lookup\"}," + "\"resource\" : " + "{\"resourceType\" : \"Parameters\"," + "\"parameter\" : [" + "{\"name\" : \"system\"," + "\"valueUri\" : \"http://snomed.info/sct\"}" + ",{\"valueCode\" : \"263495000\"," + "\"name\" : \"code\"}" + "]" + "}}" + "]}";
    Bundle bundle = objectMapper.readValue(jsonCoding, Bundle.class);
    assertEquals(BundleType.BATCH.getCode(), bundle.getType());
    Iterator<Entry> iterator = bundle.getItems().iterator();
    Entry bundleEntry = 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());
    bundleEntry = iterator.next();
    assertTrue(bundleEntry instanceof ParametersRequestEntry);
    requestEntry = (ParametersRequestEntry) bundleEntry;
    batchRequest = requestEntry.getRequest();
    assertEquals(HttpVerb.POST.getCode(), batchRequest.getMethod());
    assertEquals("CodeSystem/$lookup", batchRequest.getUrl().getUriValue());
    requestResource = requestEntry.getRequestResource();
    // Back to Domain JSON...
    json = new Parameters.Json(requestResource);
    returnedLookupRequest = objectMapper.convertValue(json, LookupRequest.class);
    assertEquals("263495000", returnedLookupRequest.getCode());
    assertEquals("http://snomed.info/sct", 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) Parameters(com.b2international.snowowl.fhir.core.model.dt.Parameters) Bundle(com.b2international.snowowl.fhir.core.model.Bundle) Json(com.b2international.snowowl.fhir.core.model.dt.Parameters.Json) 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) LookupRequest(com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 3 with LookupRequest

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

the class SandBoxRestTest method buildCode.

// @Test
public void buildCode() throws IOException {
    Coding coding = Coding.builder().system("http://hl7.org/fhir/issue-severity").code("fatal").build();
    LookupRequest request = LookupRequest.builder().coding(coding).addProperty("name").build();
    Json json1 = new Parameters.Json(request);
    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);
    Parameters parameters2 = json.parameters();
    List<Parameter> parameters3 = parameters2.getParameters();
    for (Parameter parameter : parameters3) {
        System.out.println("P: " + parameter);
    }
    LookupRequest lookupRequest = objectMapper.convertValue(json, LookupRequest.class);
    System.out.println("... and back to the object representation we started from:" + lookupRequest);
    Json finalJson = new Parameters.Json(lookupRequest);
    Fhir finalFhir = new Parameters.Fhir(finalJson.parameters());
    String stringJson = objectMapper.writeValueAsString(finalFhir);
    System.out.println("Final final: " + stringJson);
/*
			*/
// String jsonBody = objectMapper.writeValueAsString(fhirParameters);
// System.out.println("Json: " + jsonBody);
}
Also used : Parameters(com.b2international.snowowl.fhir.core.model.dt.Parameters) Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) Parameter(com.b2international.snowowl.fhir.core.model.dt.Parameter) 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)

Example 4 with LookupRequest

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

the class FhirCodeSystemLookupOperationTest method POST_CodeSystem_$lookup_Existing.

@Test
public void POST_CodeSystem_$lookup_Existing() throws Exception {
    LookupRequest request = LookupRequest.builder().coding(Coding.of(SNOMEDCT_URL, Concepts.ROOT_CONCEPT)).build();
    givenAuthenticatedRequest(FHIR_ROOT_CONTEXT).contentType(APPLICATION_FHIR_JSON).body(toFhirParameters(request)).when().post(CODESYSTEM_LOOKUP).then().assertThat().statusCode(200).body("resourceType", equalTo("Parameters")).body("parameter[0].name", equalTo("name")).body("parameter[0].valueString", equalTo("SNOMEDCT")).body("parameter[1].name", equalTo("display")).body("parameter[1].valueString", equalTo("SNOMED CT Concept"));
}
Also used : LookupRequest(com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest) FhirRestTest(com.b2international.snowowl.fhir.tests.FhirRestTest) Test(org.junit.Test)

Example 5 with LookupRequest

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

the class FhirCodeSystemLookupOperationTest method POST_CodeSystem_$lookup_Existing_WithInvalidProperty.

@Test
public void POST_CodeSystem_$lookup_Existing_WithInvalidProperty() throws Exception {
    LookupRequest request = LookupRequest.builder().coding(Coding.of(SNOMEDCT_URL, Concepts.ROOT_CONCEPT)).addProperty("http://snomed.info/id/12345").build();
    givenAuthenticatedRequest(FHIR_ROOT_CONTEXT).contentType(APPLICATION_FHIR_JSON).body(toFhirParameters(request)).when().post(CODESYSTEM_LOOKUP).then().assertThat().statusCode(400).body("resourceType", equalTo("OperationOutcome")).body("issue.severity", hasItem("error")).body("issue.code", hasItem("invalid")).body("issue.diagnostics[0]", containsString("Unrecognized property [http://snomed.info/id/12345]."));
}
Also used : LookupRequest(com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest) FhirRestTest(com.b2international.snowowl.fhir.tests.FhirRestTest) Test(org.junit.Test)

Aggregations

LookupRequest (com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest)19 Test (org.junit.Test)16 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)13 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)11 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)9 FhirRestTest (com.b2international.snowowl.fhir.tests.FhirRestTest)7 Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)6 Parameters (com.b2international.snowowl.fhir.core.model.dt.Parameters)6 ValidationException (com.b2international.snowowl.fhir.core.exceptions.ValidationException)3 Bundle (com.b2international.snowowl.fhir.core.model.Bundle)3 ParametersRequestEntry (com.b2international.snowowl.fhir.core.model.ParametersRequestEntry)3 Parameter (com.b2international.snowowl.fhir.core.model.dt.Parameter)3 IssueSeverity (com.b2international.snowowl.fhir.core.codesystems.IssueSeverity)2 IssueType (com.b2international.snowowl.fhir.core.codesystems.IssueType)2 OperationOutcomeCode (com.b2international.snowowl.fhir.core.codesystems.OperationOutcomeCode)2 BatchRequest (com.b2international.snowowl.fhir.core.model.BatchRequest)2 Entry (com.b2international.snowowl.fhir.core.model.Entry)2 Issue (com.b2international.snowowl.fhir.core.model.Issue)2 Builder (com.b2international.snowowl.fhir.core.model.Issue.Builder)2 OperationOutcomeEntry (com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry)2