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());
}
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());
}
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());
}
Aggregations