Search in sources :

Example 41 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderWebTest method shouldGetLocationHistoryById.

@Test
public void shouldGetLocationHistoryById() throws IOException, ServletException {
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    provenance.setRecorded(new Date());
    provenance.setActivity(new CodeableConcept().addCoding(new Coding().setCode("CREATE").setSystem(FhirConstants.FHIR_TERMINOLOGY_DATA_OPERATION).setDisplay("create")));
    provenance.addAgent(new Provenance.ProvenanceAgentComponent().setType(new CodeableConcept().addCoding(new Coding().setCode(FhirConstants.AUT).setDisplay(FhirConstants.AUTHOR).setSystem(FhirConstants.FHIR_TERMINOLOGY_PROVENANCE_PARTICIPANT_TYPE))).addRole(new CodeableConcept().addCoding(new Coding().setCode("").setDisplay("").setSystem(FhirConstants.FHIR_TERMINOLOGY_PARTICIPATION_TYPE))));
    Location location = new Location();
    location.setId(LOCATION_UUID);
    location.addContained(provenance);
    when(locationService.get(LOCATION_UUID)).thenReturn(location);
    MockHttpServletResponse response = getLocationHistoryByIdRequest();
    Bundle results = readBundleResponse(response);
    assertThat(results, Matchers.notNullValue());
    assertThat(results.hasEntry(), is(true));
    assertThat(results.getEntry().get(0).getResource(), Matchers.notNullValue());
    assertThat(results.getEntry().get(0).getResource().getResourceType().name(), equalTo(Provenance.class.getSimpleName()));
}
Also used : Provenance(org.hl7.fhir.r4.model.Provenance) Coding(org.hl7.fhir.r4.model.Coding) Bundle(org.hl7.fhir.r4.model.Bundle) Date(java.util.Date) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) IdType(org.hl7.fhir.r4.model.IdType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Location(org.hl7.fhir.r4.model.Location) Test(org.junit.Test)

Example 42 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderIntegrationTest method shouldSearchForExistingLocationsAsJson.

@Test
public void shouldSearchForExistingLocationsAsJson() throws Exception {
    MockHttpServletResponse response = get("/Location").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle results = readBundleResponse(response);
    assertThat(results, notNullValue());
    assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(results.hasEntry(), is(true));
    List<Bundle.BundleEntryComponent> entries = results.getEntry();
    assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R3/Location/"))));
    assertThat(entries, everyItem(hasResource(instanceOf(Location.class))));
    assertThat(entries, everyItem(hasResource(validResource())));
    response = get("/Location?address-city=Kerio&partof=" + PARENT_LOCATION_UUID + "&_sort=name").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    results = readBundleResponse(response);
    assertThat(results, notNullValue());
    assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(results.hasEntry(), is(true));
    entries = results.getEntry();
    assertThat(entries, everyItem(hasResource(hasProperty("address", hasProperty("city", equalTo("Kerio"))))));
    assertThat(entries, everyItem(hasResource(hasProperty("partOf", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARENT_LOCATION_UUID)))))));
    assertThat(entries, containsInRelativeOrder(hasResource(hasProperty("name", equalTo("Test location 6"))), hasResource(hasProperty("name", equalTo("Test location 8")))));
    assertThat(entries, everyItem(hasResource(validResource())));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.dstu3.model.Location) Test(org.junit.Test)

Example 43 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentLocationAsJson.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentLocationAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Location/" + LOCATION_UUID).accept(FhirMediaTypes.JSON).go();
    Location location = readResponse(response);
    // update the existing record
    location.setId(UNKNOWN_LOCATION_UUID);
    // send the update to the server
    response = put("/Location/" + UNKNOWN_LOCATION_UUID).jsonContent(toJson(location)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isNotFound());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.dstu3.model.Location) Test(org.junit.Test)

Example 44 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderIntegrationTest method shouldCreateNewLocationAsXML.

@Test
public void shouldCreateNewLocationAsXML() throws Exception {
    // read XML record
    String xmlLocation;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_LOCATION_DOCUMENT)) {
        Objects.requireNonNull(is);
        xmlLocation = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // create location
    MockHttpServletResponse response = post("/Location").accept(FhirMediaTypes.XML).xmlContent(xmlLocation).go();
    // verify created correctly
    assertThat(response, isCreated());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.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, validResource());
    // try to get new location
    response = get("/Location/" + location.getIdElement().getIdPart()).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    Location newLocation = readResponse(response);
    assertThat(newLocation.getId(), equalTo(location.getId()));
}
Also used : InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.dstu3.model.Location) Test(org.junit.Test)

Example 45 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchLocationIdAsXML.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchLocationIdAsXML() 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.setId(UNKNOWN_LOCATION_UUID);
    // send the update to the server
    response = put("/Location/" + LOCATION_UUID).xmlContent(toXML(location)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isBadRequest());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.dstu3.model.Location) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)120 Location (org.hl7.fhir.r4.model.Location)93 Location (org.hl7.fhir.dstu3.model.Location)66 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)59 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)42 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)30 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)27 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)21 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)20 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)20 StringParam (ca.uhn.fhir.rest.param.StringParam)20 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)16 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)16 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)16 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)16 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)13 Test (org.junit.jupiter.api.Test)13 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)11 TokenParam (ca.uhn.fhir.rest.param.TokenParam)10