Search in sources :

Example 66 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderIntegrationTest method shouldUpdateExistingLocationAsJson.

@Test
public void shouldUpdateExistingLocationAsJson() 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.getAddress().setCountry("France");
    // send the update to the server
    response = put("/Location/" + LOCATION_UUID).jsonContent(toJson(location)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.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.JSON).go();
    Location reReadLocation = readResponse(response);
    assertThat(reReadLocation.getAddress().getCountry(), equalTo("France"));
}
Also used : MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.r4.model.Location) Test(org.junit.Test)

Example 67 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchLocationIdAsJson.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchLocationIdAsJson() 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/" + LOCATION_UUID).jsonContent(toJson(location)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isBadRequest());
    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.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.r4.model.Location) Test(org.junit.Test)

Example 68 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchMedicationIdAsXML.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchMedicationIdAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(FhirMediaTypes.XML).go();
    Medication medication = readResponse(response);
    // update the existing record
    medication.setId(WRONG_MEDICATION_UUID);
    // send the update to the server
    response = put("/Medication/" + MEDICATION_UUID).xmlContent(toXML(medication)).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.r4.model.OperationOutcome) Medication(org.hl7.fhir.r4.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 69 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentMedicationAsXML.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentMedicationAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(FhirMediaTypes.XML).go();
    Medication medication = readResponse(response);
    // update the existing record
    medication.setId(WRONG_MEDICATION_UUID);
    // send the update to the server
    response = put("/Medication/" + WRONG_MEDICATION_UUID).xmlContent(toXML(medication)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isNotFound());
    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.r4.model.OperationOutcome) Medication(org.hl7.fhir.r4.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 70 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project Gravity-SDOH-Exchange-RI by FHIR.

the class TaskService method readAll.

public List<TaskDto> readAll() throws AuthClientException {
    List<Server> serverList = serverRepository.findAll();
    List<TaskDto> taskDtoList = new ArrayList<>();
    for (Server server : serverList) {
        IGenericClient fhirClient = fhirContext.newRestfulGenericClient(server.getFhirServerUrl());
        // Doesn't support now
        // fhirClient.registerInterceptor(new BearerTokenAuthInterceptor(
        // authorizationClient.getTokenResponse(URI.create(server.getAuthServerUrl()), server.getClientId(),
        // server.getClientSecret(), SCOPE)
        // .getAccessToken()));
        TaskRepository taskRepository = new TaskRepository(fhirClient, applicationUrl);
        taskDtoList.addAll(new TaskBundleToDtoConverter(server.getId()).convert(taskRepository.findAllTasks()));
    }
    return taskDtoList;
}
Also used : Server(org.hl7.gravity.refimpl.sdohexchange.model.Server) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) TaskRepository(org.hl7.gravity.refimpl.sdohexchange.dao.TaskRepository) TaskBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.TaskBundleToDtoConverter) ArrayList(java.util.ArrayList) TaskDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskDto)

Aggregations

Test (org.junit.Test)107 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)100 IOException (java.io.IOException)47 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)42 FHIRException (org.hl7.fhir.exceptions.FHIRException)39 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)38 ArrayList (java.util.ArrayList)25 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)24 FileNotFoundException (java.io.FileNotFoundException)21 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)19 Date (java.util.Date)18 Bundle (org.hl7.fhir.r4.model.Bundle)17 URISyntaxException (java.net.URISyntaxException)16 HashMap (java.util.HashMap)16 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 FhirContext (ca.uhn.fhir.context.FhirContext)14 LocalDate (java.time.LocalDate)14 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)13 File (java.io.File)12 Header (org.apache.http.Header)11