Search in sources :

Example 61 with DIAGNOSTICREPORT

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.DIAGNOSTICREPORT in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportFhirResourceProviderWebTest method deleteDiagnosticReport_shouldDeleteDiagnosticReport.

@Test
public void deleteDiagnosticReport_shouldDeleteDiagnosticReport() throws Exception {
    org.hl7.fhir.r4.model.DiagnosticReport diagnosticReport = new org.hl7.fhir.r4.model.DiagnosticReport();
    diagnosticReport.setId(DIAGNOSTIC_REPORT_UUID);
    diagnosticReport.setStatus(org.hl7.fhir.r4.model.DiagnosticReport.DiagnosticReportStatus.CANCELLED);
    when(service.delete(any(String.class))).thenReturn(diagnosticReport);
    MockHttpServletResponse response = delete("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
}
Also used : DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 62 with DIAGNOSTICREPORT

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.DIAGNOSTICREPORT in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportFhirResourceProviderWebTest method updateDiagnosticReport_shouldErrorForNonexistentDiagnosticReport.

@Test
public void updateDiagnosticReport_shouldErrorForNonexistentDiagnosticReport() throws Exception {
    String jsonDiagnosticReport;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_DIAGNOSTIC_REPORT_WRONG_UUID_PATH)) {
        Objects.requireNonNull(is);
        jsonDiagnosticReport = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    when(service.update(eq(WRONG_UUID), any(DiagnosticReport.class))).thenThrow(new MethodNotAllowedException("DiagnosticReport " + WRONG_UUID + " does not exist"));
    MockHttpServletResponse response = put("/DiagnosticReport/" + WRONG_UUID).jsonContent(jsonDiagnosticReport).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isMethodNotAllowed());
}
Also used : MethodNotAllowedException(ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException) InputStream(java.io.InputStream) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 63 with DIAGNOSTICREPORT

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.DIAGNOSTICREPORT in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportFhirResourceProviderWebTest method updateDiagnosticReport_shouldUpdateExistingDiagnosticReport.

@Test
public void updateDiagnosticReport_shouldUpdateExistingDiagnosticReport() throws Exception {
    String jsonDiagnosticReport;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_DIAGNOSTIC_REPORT_PATH)) {
        Objects.requireNonNull(is);
        jsonDiagnosticReport = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setId(DIAGNOSTIC_REPORT_UUID);
    when(service.update(anyString(), any(DiagnosticReport.class))).thenReturn(diagnosticReport);
    MockHttpServletResponse response = put("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).jsonContent(jsonDiagnosticReport).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
}
Also used : InputStream(java.io.InputStream) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 64 with DIAGNOSTICREPORT

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.DIAGNOSTICREPORT in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportFhirResourceProviderWebTest method createDiagnosticReport_shouldCreateNewDiagnosticReport.

@Test
public void createDiagnosticReport_shouldCreateNewDiagnosticReport() throws Exception {
    String jsonDiagnosticReport;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_DIAGNOSTIC_REPORT_PATH)) {
        Objects.requireNonNull(is);
        jsonDiagnosticReport = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setId(DIAGNOSTIC_REPORT_UUID);
    when(service.create(any(DiagnosticReport.class))).thenReturn(diagnosticReport);
    MockHttpServletResponse response = post("/DiagnosticReport").jsonContent(jsonDiagnosticReport).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isCreated());
}
Also used : InputStream(java.io.InputStream) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 65 with DIAGNOSTICREPORT

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.DIAGNOSTICREPORT in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportResourceProviderIntegrationTest method shouldReturnCountForDiagonosticReportAsJson.

@Test
public void shouldReturnCountForDiagonosticReportAsJson() throws Exception {
    MockHttpServletResponse response = get("/DiagnosticReport?patient.given=Collet&_summary=count").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle result = readBundleResponse(response);
    assertThat(result, notNullValue());
    assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(result, hasProperty("total", equalTo(2)));
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)133 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)115 FhirDiagnosticReport (org.openmrs.module.fhir2.model.FhirDiagnosticReport)65 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)52 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)50 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)42 Test (org.junit.jupiter.api.Test)39 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)39 DiagnosticReport (org.hl7.fhir.dstu3.model.DiagnosticReport)32 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)29 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)28 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)28 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)28 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)19 Reference (org.hl7.fhir.r4.model.Reference)19 Bundle (org.hl7.fhir.r4.model.Bundle)18 Resource (org.hl7.fhir.r4.model.Resource)18 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)16 Include (ca.uhn.fhir.model.api.Include)12 HashSet (java.util.HashSet)12