Search in sources :

Example 61 with Server

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

the class DiagnosticReportResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentPatientAsJson.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentPatientAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).accept(FhirMediaTypes.JSON).go();
    DiagnosticReport diagnosticReport = readResponse(response);
    // update the existing record
    diagnosticReport.setId(WRONG_DIAGNOSTIC_REPORT_UUID);
    // send the update to the server
    response = put("/DiagnosticReport/" + WRONG_DIAGNOSTIC_REPORT_UUID).jsonContent(toJson(diagnosticReport)).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) DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 62 with Server

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

the class GroupFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentGroupAsJSON.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentGroupAsJSON() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go();
    Group group = readResponse(response);
    // update the existing record
    group.setId(BAD_COHORT_UUID);
    // send the update to the server
    response = put("/Group/" + BAD_COHORT_UUID).jsonContent(toJson(group)).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 : Group(org.hl7.fhir.r4.model.Group) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 63 with Server

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

the class ImmunizationFhirResourceProviderIntegrationTest method shouldUpdateExistingImmunizationAsXML.

@Test
public void shouldUpdateExistingImmunizationAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.XML).go();
    Immunization immunization = readResponse(response);
    // update the existing record
    Date expirationDate = DateUtils.truncate(new Date(), Calendar.DATE);
    immunization.setExpirationDate(expirationDate);
    // send the update to the server
    response = put("/Immunization/" + IMMUNIZATION_UUID).xmlContent(toXML(immunization)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read the updated record
    Immunization updatedImmunization = readResponse(response);
    assertThat(updatedImmunization, notNullValue());
    assertThat(updatedImmunization.getIdElement().getIdPart(), equalTo(IMMUNIZATION_UUID));
    assertThat(updatedImmunization.getExpirationDate(), equalTo(expirationDate));
    assertThat(immunization, validResource());
    // double-check the record returned via get
    response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.XML).go();
    Immunization reReadImmunization = readResponse(response);
    assertThat(reReadImmunization.getExpirationDate(), equalTo(expirationDate));
}
Also used : Immunization(org.hl7.fhir.r4.model.Immunization) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 64 with Server

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

the class ImmunizationFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchImmunizationIdAsXML.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchImmunizationIdAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.XML).go();
    Immunization immunization = readResponse(response);
    // update the existing record
    immunization.setId(UNKNOWN_IMMUNIZATION_UUID);
    // send the update to the server
    response = put("/Immunization/" + IMMUNIZATION_UUID).xmlContent(toXML(immunization)).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 : Immunization(org.hl7.fhir.r4.model.Immunization) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 65 with Server

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

the class ImmunizationFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentImmunizationAsXML.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentImmunizationAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Immunization/" + IMMUNIZATION_UUID).accept(FhirMediaTypes.XML).go();
    Immunization immunization = readResponse(response);
    // update the existing record
    immunization.setId(UNKNOWN_IMMUNIZATION_UUID);
    // send the update to the server
    response = put("/Immunization/" + UNKNOWN_IMMUNIZATION_UUID).xmlContent(toXML(immunization)).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 : Immunization(org.hl7.fhir.r4.model.Immunization) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

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