Search in sources :

Example 56 with Server

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

the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentAllergyAsJson.

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

Example 57 with Server

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

the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldUpdateExistingAllergyAsXML.

@Test
public void shouldUpdateExistingAllergyAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.XML).go();
    AllergyIntolerance allergy = readResponse(response);
    // update the existing record
    Enumeration<AllergyIntolerance.AllergyIntoleranceCategory> category = new Enumeration<>(new AllergyIntolerance.AllergyIntoleranceCategoryEnumFactory());
    category.setValue(AllergyIntolerance.AllergyIntoleranceCategory.ENVIRONMENT);
    allergy.getCategory().set(0, category);
    // send the update to the server
    response = put("/AllergyIntolerance/" + ALLERGY_UUID).xmlContent(toXML(allergy)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read the updated record
    AllergyIntolerance updatedAllergy = readResponse(response);
    assertThat(updatedAllergy, notNullValue());
    assertThat(updatedAllergy.getIdElement().getIdPart(), equalTo(ALLERGY_UUID));
    assertThat(updatedAllergy.getCategory().get(0).getValue().toCode(), equalTo("environment"));
    assertThat(updatedAllergy, validResource());
    // double-check the record returned via get
    response = get("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.XML).go();
    AllergyIntolerance reReadAllergy = readResponse(response);
    assertThat(reReadAllergy.getCategory().get(0).getValue().toCode(), equalTo("environment"));
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) Enumeration(org.hl7.fhir.dstu3.model.Enumeration) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 58 with Server

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

the class DiagnosticReportResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchPatientIdAsXML.

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

Example 59 with Server

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

the class DiagnosticReportResourceProviderIntegrationTest method shouldUpdateExistingDiagnosticReportAsXML.

@Test
public void shouldUpdateExistingDiagnosticReportAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).accept(FhirMediaTypes.XML).go();
    DiagnosticReport diagnosticReport = readResponse(response);
    // verify condition we will change
    assertThat(diagnosticReport.getStatus(), not(is(DiagnosticReport.DiagnosticReportStatus.FINAL)));
    // update the existing record
    diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.FINAL);
    // send the update to the server
    response = put("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).xmlContent(toXML(diagnosticReport)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read the updated record
    DiagnosticReport updatedDiagnosticReport = readResponse(response);
    assertThat(updatedDiagnosticReport, notNullValue());
    assertThat(updatedDiagnosticReport.getIdElement().getIdPart(), equalTo(DIAGNOSTIC_REPORT_UUID));
    assertThat(updatedDiagnosticReport.getStatus(), is(DiagnosticReport.DiagnosticReportStatus.FINAL));
    assertThat(diagnosticReport, validResource());
    // double-check the record returned via get
    response = get("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).accept(FhirMediaTypes.JSON).go();
    DiagnosticReport reReadDiagnosticReport = readResponse(response);
    assertThat(reReadDiagnosticReport.getStatus(), is(DiagnosticReport.DiagnosticReportStatus.FINAL));
}
Also used : DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 60 with Server

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

the class DiagnosticReportResourceProviderIntegrationTest method shouldUpdateExistingDiagnosticReportAsJson.

@Test
public void shouldUpdateExistingDiagnosticReportAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).accept(FhirMediaTypes.JSON).go();
    DiagnosticReport diagnosticReport = readResponse(response);
    // verify condition we will change
    assertThat(diagnosticReport.getStatus(), not(is(DiagnosticReport.DiagnosticReportStatus.FINAL)));
    // update the existing record
    diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.FINAL);
    // send the update to the server
    response = put("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).jsonContent(toJson(diagnosticReport)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read the updated record
    DiagnosticReport updatedDiagnosticReport = readResponse(response);
    assertThat(updatedDiagnosticReport, notNullValue());
    assertThat(updatedDiagnosticReport.getIdElement().getIdPart(), equalTo(DIAGNOSTIC_REPORT_UUID));
    assertThat(updatedDiagnosticReport.getStatus(), is(DiagnosticReport.DiagnosticReportStatus.FINAL));
    assertThat(diagnosticReport, validResource());
    // double-check the record returned via get
    response = get("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).accept(FhirMediaTypes.JSON).go();
    DiagnosticReport reReadDiagnosticReport = readResponse(response);
    assertThat(reReadDiagnosticReport.getStatus(), is(DiagnosticReport.DiagnosticReportStatus.FINAL));
}
Also used : DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) 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