use of org.hl7.fhir.r4.model.Location in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderIntegrationTest method shouldCreateNewLocationWithExistingTagAsJson.
@Test
public void shouldCreateNewLocationWithExistingTagAsJson() throws Exception {
// Create Location Tag Before Posting LOcation
LocationTag tag = new LocationTag("mCSD_Location", "mCSD_Location");
locationService.saveLocationTag(tag);
// read JSON record
String jsonLocation;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_LOCATION_DOCUMENT)) {
Objects.requireNonNull(is);
jsonLocation = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create location
MockHttpServletResponse response = post("/Location").accept(FhirMediaTypes.JSON).jsonContent(jsonLocation).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Location location = readResponse(response);
assertThat(location, notNullValue());
assertThat(location.getName(), equalTo("Test location"));
assertThat(location.getAddress().getCity(), equalTo("kampala"));
assertThat(location.getAddress().getCountry(), equalTo("uganda"));
assertThat(location.getAddress().getState(), equalTo("MI"));
assertThat(location.getAddress().getPostalCode(), equalTo("9105 PZ"));
assertThat(location.getMeta().getTagFirstRep().getCode(), equalTo("mCSD_Location"));
assertThat(location.getMeta().getTagFirstRep().getDisplay(), equalTo("mCSD_Location"));
assertThat(location, validResource());
// try to get new location
response = get("/Location/" + location.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
Location newLocation = readResponse(response);
assertThat(newLocation.getId(), equalTo(location.getId()));
}
use of org.hl7.fhir.r4.model.Location in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderIntegrationTest method shouldUpdateExistingLocationAsXML.
@Test
public void shouldUpdateExistingLocationAsXML() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/Location/" + LOCATION_UUID).accept(FhirMediaTypes.XML).go();
Location location = readResponse(response);
// update the existing record
location.getAddress().setCountry("France");
// send the update to the server
response = put("/Location/" + LOCATION_UUID).xmlContent(toXML(location)).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
// read the updated record
Location updatedLocation = readResponse(response);
assertThat(updatedLocation, notNullValue());
assertThat(updatedLocation.getIdElement().getIdPart(), equalTo(LOCATION_UUID));
assertThat(updatedLocation.getAddress().getCountry(), equalTo("France"));
assertThat(updatedLocation, validResource());
// double-check the record returned via get
response = get("/Location/" + LOCATION_UUID).accept(FhirMediaTypes.XML).go();
Location reReadLocation = readResponse(response);
assertThat(reReadLocation.getAddress().getCountry(), equalTo("France"));
}
use of org.hl7.fhir.r4.model.Location in project openmrs-module-fhir2 by openmrs.
the class ObservationFhirResourceProviderIntegrationTest method shouldCreateNewObservationAsJson.
@Test
public void shouldCreateNewObservationAsJson() throws Exception {
// read JSON record
String jsonObs;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_OBS_DOCUMENT)) {
Objects.requireNonNull(is);
jsonObs = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create obs
MockHttpServletResponse response = post("/Observation").accept(FhirMediaTypes.JSON).jsonContent(jsonObs).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getHeader("Location"), notNullValue());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Observation observation = readResponse(response);
assertThat(observation.getIdElement().getIdPart(), notNullValue());
assertThat(observation.getCode(), notNullValue());
assertThat(observation.getCode().getCoding(), hasItem(hasProperty("code", equalTo("5090AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))));
assertThat(observation.getSubject(), notNullValue());
assertThat(observation.getSubject().getReference(), endsWith("5946f880-b197-400b-9caa-a3c661d23041"));
assertThat(observation.getContext(), notNullValue());
assertThat(observation.getContext().getReference(), endsWith("6519d653-393b-4118-9c83-a3715b82d4ac"));
assertThat(observation.getValue(), notNullValue());
assertThat(observation.getValueQuantity(), notNullValue());
assertThat(observation.getValueQuantity().getValue(), equalTo(BigDecimal.valueOf(156.0)));
assertThat(observation.getValueQuantity().getUnit(), equalTo("cm"));
assertThat(observation, validResource());
// try to fetch the new observation
response = get("/Observation/" + observation.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
Observation newObservation = readResponse(response);
assertThat(newObservation.getId(), equalTo(observation.getId()));
}
use of org.hl7.fhir.r4.model.Location in project openmrs-module-fhir2 by openmrs.
the class TaskFhirResourceIntegrationTest method shouldCreateNewTaskAsJson.
@Test
public void shouldCreateNewTaskAsJson() throws Exception {
String jsonTask;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_TASK_DOCUMENT)) {
assertThat(is, notNullValue());
jsonTask = IOUtils.toString(is, StandardCharsets.UTF_8);
}
MockHttpServletResponse response = post("/Task").accept(FhirMediaTypes.JSON).jsonContent(jsonTask).go();
assertThat(response, isCreated());
assertThat(response.getHeader("Location"), containsString("/Task/"));
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Task task = readResponse(response);
assertThat(task, notNullValue());
assertThat(task.getIdElement().getIdPart(), notNullValue());
assertThat(task.getStatus(), is(Task.TaskStatus.ACCEPTED));
assertThat(task.getIntent(), is(Task.TaskIntent.ORDER));
assertThat(task.getAuthoredOn(), within(1, ChronoUnit.MINUTES, new Date()));
assertThat(task.getLastModified(), within(1, ChronoUnit.MINUTES, new Date()));
assertThat(task, validResource());
response = get("/Task/" + task.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
Task newTask = readResponse(response);
assertThat(newTask, notNullValue());
assertThat(newTask.getIdElement().getIdPart(), equalTo(task.getIdElement().getIdPart()));
assertThat(newTask.getStatus(), equalTo(task.getStatus()));
assertThat(newTask.getIntent(), equalTo(task.getIntent()));
assertThat(task.getAuthoredOn(), equalTo(task.getAuthoredOn()));
assertThat(task.getLastModified(), equalTo(task.getLastModified()));
}
use of org.hl7.fhir.r4.model.Location in project openmrs-module-fhir2 by openmrs.
the class ConditionFhirResourceProviderIntegrationTest method shouldCreateNewConditionAsXML.
@Test
public void shouldCreateNewConditionAsXML() throws Exception {
String xmlCondition;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_CONDITION_DOCUMENT)) {
assertThat(is, notNullValue());
xmlCondition = IOUtils.toString(is, StandardCharsets.UTF_8);
assertThat(xmlCondition, notNullValue());
}
MockHttpServletResponse response = post("/Condition").accept(FhirMediaTypes.XML).xmlContent(xmlCondition).go();
assertThat(response, isCreated());
assertThat(response.getHeader("Location"), containsString("/Condition/"));
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentType(), notNullValue());
Condition condition = readResponse(response);
assertThat(condition, notNullValue());
assertThat(condition.getIdElement().getIdPart(), notNullValue());
assertThat(condition.getCode().getCoding(), hasItem(hasProperty("code", equalTo("116128AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))));
assertThat(condition.getSubject().getReference(), endsWith(CONDITION_SUBJECT_UUID));
assertThat(condition, validResource());
response = get("/Condition/" + condition.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
Condition newCondition = readResponse(response);
assertThat(newCondition.getId(), equalTo(condition.getId()));
}
Aggregations