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