Search in sources :

Example 6 with LookupRequest

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

the class FhirBatchApiRestTest method singleLookupPost.

@Test
public void singleLookupPost() {
    LookupRequest request = LookupRequest.builder().coding(Coding.builder().system("http://snomed.info/sct").code(Concepts.IS_A).build()).build();
    Json json = new Parameters.Json(request);
    ParametersRequestEntry entry = ParametersRequestEntry.builder().request(BatchRequest.createPostRequest("CodeSystem/$lookup")).resource(new Parameters.Fhir(json.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")).root("entry[0]").body("response.status", equalTo("200")).root("entry[0].resource").body("resourceType", equalTo("Parameters"));
}
Also used : Json(com.b2international.snowowl.fhir.core.model.dt.Parameters.Json) LookupRequest(com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest) Test(org.junit.Test) FhirRestTest(com.b2international.snowowl.fhir.tests.FhirRestTest)

Example 7 with LookupRequest

use of com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest 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 8 with LookupRequest

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

the class ParameterDeserializationTest method lookupRequestParametersTest.

@Test
public void lookupRequestParametersTest() throws Exception {
    String jsonParam = "{\"resourceType\":\"Parameters\"," + "\"parameter\":[" + "{\"name\":\"system\",\"valueUri\":\"LOINC\"}," + "{\"name\":\"version\",\"valueString\":\"20180131\"}," + "{\"name\":\"code\",\"valueCode\":\"1234\"}" + "]}";
    // Magic to turn the FHIR params -> Parameters -> LookupRequest
    Parameters.Fhir fhirParameters = objectMapper.readValue(jsonParam, Parameters.Fhir.class);
    LookupRequest lookupRequest = objectMapper.convertValue(fhirParameters.toJson(), LookupRequest.class);
    assertEquals("LOINC", lookupRequest.getSystem());
    assertEquals("20180131", lookupRequest.getVersion());
    assertEquals("1234", lookupRequest.getCode());
    assertNull(lookupRequest.getProperties());
}
Also used : Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) LookupRequest(com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 9 with LookupRequest

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

the class ParameterDeserializationTest method lookupRequestCodingTest.

@Test
public void lookupRequestCodingTest() throws Exception {
    String jsonParam = "{\"resourceType\":\"Parameters\"," + "\"parameter\":[" + "{\"name\":\"code\",\"valueCode\":\"1234\"}," + "{\"name\":\"system\",\"valueUri\":\"http://snomed.info/sct/version/20180131\"}," + "{\"name\":\"date\",\"valueDateTime\":\"2018-03-09T20:50:21.000+0100\"}," + "{\"name\":\"displayLanguage\",\"valueCode\":\"us-en\"}," + "{\"name\":\"property\",\"valueCode\":\"prop1\"}," + "{\"name\":\"property\",\"valueCode\":\"prop2\"}," + "{\"name\":\"coding\", \"valueCoding\":" + "{\"code\":\"1234\"," + "\"system\":\"http://snomed.info/sct/version/20180131\"," + "\"userSelected\":false}}" + "]}";
    // Magic to turn the FHIR params -> Parameters -> LookupRequest
    Parameters.Fhir fhirParameters = objectMapper.readValue(jsonParam, Parameters.Fhir.class);
    LookupRequest lookupRequest = objectMapper.convertValue(fhirParameters.toJson(), LookupRequest.class);
    assertEquals("1234", lookupRequest.getCode());
    assertEquals("http://snomed.info/sct/version/20180131", lookupRequest.getSystem());
    assertEquals(Dates.parse("2018-03-09T20:50:21.000+0100", FhirDates.DATE_TIME_FORMAT), lookupRequest.getDate());
    assertEquals("us-en", lookupRequest.getDisplayLanguage().getCodeValue());
    Coding coding = lookupRequest.getCoding();
    assertEquals("1234", coding.getCodeValue());
    assertEquals("http://snomed.info/sct/version/20180131", coding.getSystemValue());
    assertEquals(false, coding.isUserSelected());
    assertFalse(lookupRequest.getProperties().isEmpty());
    Collection<String> properties = lookupRequest.getPropertyCodes();
    assertThat(properties.toArray(), arrayContainingInAnyOrder("prop1", "prop2"));
}
Also used : Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) LookupRequest(com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 10 with LookupRequest

use of com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest 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

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