Search in sources :

Example 1 with BatchRequest

use of com.b2international.snowowl.fhir.core.model.BatchRequest 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 2 with BatchRequest

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

the class FhirRequestEntryProcessor method doProcess.

@Override
public void doProcess(ArrayNode arrayNode, HttpServletRequest request) throws Exception {
    BatchRequest batchRequest = requestEntry.getRequest();
    Code requestMethod = batchRequest.getMethod();
    if (!requestMethod.equals(HttpVerb.GET.getCode())) {
        createInvalidMethodResponse(arrayNode, requestMethod);
        return;
    }
    HttpHeaders headers = getHeaders(request);
    RestTemplate restTemplate = getRestTemplate();
    StringBuilder uriBuilder = new StringBuilder(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getLocalPort()).append(request.getRequestURI()).append(batchRequest.getUrl().getUriValue());
    HttpEntity<String> httpEntity = new HttpEntity<>(headers);
    ResponseEntity<String> response = restTemplate.exchange(uriBuilder.toString(), HttpMethod.GET, httpEntity, String.class);
    String json = response.getBody();
    ObjectNode resourceNode = (ObjectNode) objectMapper.readTree(json);
    addResponse(arrayNode, resourceNode, String.valueOf(response.getStatusCode().value()));
}
Also used : BatchRequest(com.b2international.snowowl.fhir.core.model.BatchRequest) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RestTemplate(org.springframework.web.client.RestTemplate) Code(com.b2international.snowowl.fhir.core.model.dt.Code)

Example 3 with BatchRequest

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

the class FhirResourceRequestEntryProcessor method doProcess.

@Override
public void doProcess(ArrayNode arrayNode, HttpServletRequest request) throws JsonMappingException, JsonProcessingException {
    BatchRequest batchRequest = requestEntry.getRequest();
    Code requestMethod = batchRequest.getMethod();
    if (!requestMethod.equals(HttpVerb.POST.getCode())) {
        createInvalidMethodResponse(arrayNode, requestMethod);
        return;
    }
    HttpHeaders headers = getHeaders(request);
    RestTemplate restTemplate = getRestTemplate();
    StringBuilder uriBuilder = new StringBuilder(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getLocalPort()).append(request.getRequestURI()).append(batchRequest.getUrl().getUriValue());
    HttpEntity<?> httpEntity = new HttpEntity<>(requestEntry.getRequestResource(), headers);
    ResponseEntity<String> response = restTemplate.exchange(uriBuilder.toString(), HttpMethod.POST, httpEntity, String.class);
    String json = response.getBody();
    ObjectNode resourceNode = (ObjectNode) objectMapper.readTree(json);
    addResponse(arrayNode, resourceNode, String.valueOf(response.getStatusCode().value()));
}
Also used : BatchRequest(com.b2international.snowowl.fhir.core.model.BatchRequest) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RestTemplate(org.springframework.web.client.RestTemplate) Code(com.b2international.snowowl.fhir.core.model.dt.Code)

Example 4 with BatchRequest

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

the class BundleTest method buildResourceRequestBundle.

@Test
public void buildResourceRequestBundle() throws Exception {
    CodeSystem codeSystem = CodeSystem.builder().status(PublicationStatus.ACTIVE).content(CodeSystemContentMode.COMPLETE).build();
    ResourceRequestEntry entry = ResourceRequestEntry.builder().request(BatchRequest.createPostRequest("/CodeSystem")).resource(codeSystem).build();
    Bundle bundle = Bundle.builder().language("en").total(1).type(BundleType.BATCH).addEntry(entry).addLink("self", "http://localhost:8080/snowowl/CodeSystem").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 ResourceRequestEntry);
    ResourceRequestEntry requestEntry = (ResourceRequestEntry) bundleEntry;
    BatchRequest batchRequest = requestEntry.getRequest();
    assertEquals(HttpVerb.POST.getCode(), batchRequest.getMethod());
    assertEquals("/CodeSystem", batchRequest.getUrl().getUriValue());
    FhirResource readCodeSystem = requestEntry.getRequestResource();
    assertTrue(readCodeSystem instanceof CodeSystem);
    String bundleString = objectMapper.writeValueAsString(bundle);
    Bundle readBundle = objectMapper.readValue(bundleString, Bundle.class);
    assertTrue(readBundle.getEntry().iterator().next() instanceof ResourceRequestEntry);
}
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) FhirResource(com.b2international.snowowl.fhir.core.model.FhirResource) Bundle(com.b2international.snowowl.fhir.core.model.Bundle) CodeSystem(com.b2international.snowowl.fhir.core.model.codesystem.CodeSystem) Link(com.b2international.snowowl.fhir.core.model.Link) ResourceRequestEntry(com.b2international.snowowl.fhir.core.model.ResourceRequestEntry) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 5 with BatchRequest

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

BatchRequest (com.b2international.snowowl.fhir.core.model.BatchRequest)6 Bundle (com.b2international.snowowl.fhir.core.model.Bundle)3 Entry (com.b2international.snowowl.fhir.core.model.Entry)3 OperationOutcomeEntry (com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry)3 ParametersRequestEntry (com.b2international.snowowl.fhir.core.model.ParametersRequestEntry)3 ParametersResponseEntry (com.b2international.snowowl.fhir.core.model.ParametersResponseEntry)3 ResourceRequestEntry (com.b2international.snowowl.fhir.core.model.ResourceRequestEntry)3 ResourceResponseEntry (com.b2international.snowowl.fhir.core.model.ResourceResponseEntry)3 Code (com.b2international.snowowl.fhir.core.model.dt.Code)3 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Test (org.junit.Test)3 HttpEntity (org.springframework.http.HttpEntity)3 HttpHeaders (org.springframework.http.HttpHeaders)3 RestTemplate (org.springframework.web.client.RestTemplate)3 Link (com.b2international.snowowl.fhir.core.model.Link)2 LookupRequest (com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest)2 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)2 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)2 FhirResource (com.b2international.snowowl.fhir.core.model.FhirResource)1