Search in sources :

Example 96 with Location

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()));
}
Also used : LocationTag(org.openmrs.LocationTag) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.dstu3.model.Location) Test(org.junit.Test)

Example 97 with Location

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"));
}
Also used : MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.dstu3.model.Location) Test(org.junit.Test)

Example 98 with Location

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()));
}
Also used : InputStream(java.io.InputStream) Observation(org.hl7.fhir.dstu3.model.Observation) Matchers.containsString(org.hamcrest.Matchers.containsString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 99 with Location

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()));
}
Also used : Task(org.hl7.fhir.dstu3.model.Task) InputStream(java.io.InputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) Test(org.junit.Test)

Example 100 with Location

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()));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) InputStream(java.io.InputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)215 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)94 Location (org.hl7.fhir.r4.model.Location)93 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)71 Location (org.hl7.fhir.dstu3.model.Location)66 InputStream (java.io.InputStream)46 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)39 Matchers.containsString (org.hamcrest.Matchers.containsString)38 Test (org.junit.jupiter.api.Test)38 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)37 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)35 ArrayList (java.util.ArrayList)29 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)29 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)26 Reference (org.hl7.fhir.r4.model.Reference)25 Date (java.util.Date)24 Bundle (org.hl7.fhir.r4.model.Bundle)24 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)24 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)23 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)23