Search in sources :

Example 11 with Bundle

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

the class BundleTest method deserializeResourceBundle.

@Test
public void deserializeResourceBundle() throws JsonProcessingException {
    FhirResource resource = CodeSystem.builder().status(PublicationStatus.ACTIVE).content(CodeSystemContentMode.COMPLETE).build();
    String resourceString = objectMapper.writeValueAsString(resource);
    CodeSystem fhirResource = objectMapper.readValue(resourceString, CodeSystem.class);
    assertEquals(null, fhirResource.getId());
    ResourceRequestEntry entry = ResourceRequestEntry.builder().resource(resource).request(BatchRequest.createPostRequest("/url")).build();
    Bundle bundle = Bundle.builder().type(BundleType.BATCH).entry(ImmutableList.of(entry)).build();
    String bundleString = objectMapper.writeValueAsString(bundle);
    Bundle readBundle = objectMapper.readValue(bundleString, Bundle.class);
    assertEquals(null, readBundle.getId());
}
Also used : 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) ResourceRequestEntry(com.b2international.snowowl.fhir.core.model.ResourceRequestEntry) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 12 with Bundle

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

Example 13 with Bundle

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

the class SandBoxRestTest method restTemplateCallTest.

// @Test
public void restTemplateCallTest() {
    HttpHeaders headers = new HttpHeaders();
    headers.setBasicAuth(RestExtensions.USER, RestExtensions.PASS);
    MediaType mediaType = MediaType.parseMediaType("application/fhir+json;charset=utf-8");
    headers.setContentType(mediaType);
    HttpEntity<Bundle> request = new HttpEntity<>(headers);
    RestTemplate restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    MappingJackson2HttpMessageConverter jsonMessageConverter = new MappingJackson2HttpMessageConverter() {

        public boolean canRead(java.lang.Class<?> clazz, org.springframework.http.MediaType mediaType) {
            return true;
        }

        public boolean canRead(java.lang.reflect.Type type, java.lang.Class<?> contextClass, org.springframework.http.MediaType mediaType) {
            return true;
        }

        protected boolean canRead(org.springframework.http.MediaType mediaType) {
            return true;
        }
    };
    jsonMessageConverter.setObjectMapper(objectMapper);
    messageConverters.add(jsonMessageConverter);
    restTemplate.setMessageConverters(messageConverters);
    ResponseEntity<Bundle> response = restTemplate.exchange("http://localhost:8080/snowowl/fhir/CodeSystem", HttpMethod.GET, request, Bundle.class);
    // ResponseEntity<Bundle> bundle = restTemplate.getForEntity("http://localhost:8080/snowowl/fhir/CodeSystem", Bundle.class, request);
    System.out.println(response.getStatusCodeValue());
    System.out.println(response.getBody().getId());
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) Bundle(com.b2international.snowowl.fhir.core.model.Bundle) ArrayList(java.util.ArrayList) BundleType(com.b2international.snowowl.fhir.core.codesystems.BundleType) ContentType(io.restassured.http.ContentType) RestTemplate(org.springframework.web.client.RestTemplate) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter)

Aggregations

Bundle (com.b2international.snowowl.fhir.core.model.Bundle)13 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)10 Test (org.junit.Test)10 ResourceRequestEntry (com.b2international.snowowl.fhir.core.model.ResourceRequestEntry)8 Entry (com.b2international.snowowl.fhir.core.model.Entry)7 OperationOutcomeEntry (com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry)7 ParametersRequestEntry (com.b2international.snowowl.fhir.core.model.ParametersRequestEntry)7 ResourceResponseEntry (com.b2international.snowowl.fhir.core.model.ResourceResponseEntry)7 ParametersResponseEntry (com.b2international.snowowl.fhir.core.model.ParametersResponseEntry)6 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)6 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)6 Link (com.b2international.snowowl.fhir.core.model.Link)4 CodeSystem (com.b2international.snowowl.fhir.core.model.codesystem.CodeSystem)4 BatchRequest (com.b2international.snowowl.fhir.core.model.BatchRequest)3 FhirResource (com.b2international.snowowl.fhir.core.model.FhirResource)3 LookupRequest (com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest)3 LookupResult (com.b2international.snowowl.fhir.core.model.codesystem.LookupResult)3 Parameters (com.b2international.snowowl.fhir.core.model.dt.Parameters)3 OperationOutcome (com.b2international.snowowl.fhir.core.model.OperationOutcome)2 BundleType (com.b2international.snowowl.fhir.core.codesystems.BundleType)1