Search in sources :

Example 56 with DiagnosticReport

use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportFhirResourceProviderTest method updateDiagnosticReport_shouldThrowMethodNotAllowedIfDoesNotExist.

@Test(expected = MethodNotAllowedException.class)
public void updateDiagnosticReport_shouldThrowMethodNotAllowedIfDoesNotExist() {
    DiagnosticReport wrongDiagnosticReport = new DiagnosticReport();
    wrongDiagnosticReport.setId(WRONG_UUID);
    when(service.update(eq(WRONG_UUID), any(org.hl7.fhir.r4.model.DiagnosticReport.class))).thenThrow(MethodNotAllowedException.class);
    resourceProvider.updateDiagnosticReport(new IdType().setValue(WRONG_UUID), wrongDiagnosticReport);
}
Also used : DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.Test)

Example 57 with DiagnosticReport

use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportFhirResourceProviderTest method updateDiagnosticReport_shouldThrowInvalidRequestForMissingId.

@Test(expected = InvalidRequestException.class)
public void updateDiagnosticReport_shouldThrowInvalidRequestForMissingId() {
    DiagnosticReport noIdDiagnosticReport = new DiagnosticReport();
    when(service.update(eq(UUID), any(org.hl7.fhir.r4.model.DiagnosticReport.class))).thenThrow(InvalidRequestException.class);
    resourceProvider.updateDiagnosticReport(new IdType().setValue(UUID), noIdDiagnosticReport);
}
Also used : DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.Test)

Example 58 with DiagnosticReport

use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportFhirResourceProviderTest method findDiagnosticReports_shouldReturnRelatedResourcesIfIncludeIsSpecified.

@Test
public void findDiagnosticReports_shouldReturnRelatedResourcesIfIncludeIsSpecified() {
    HashSet<Include> includes = new HashSet<>();
    includes.add(new Include("DiagnosticReport:patient"));
    when(service.searchForDiagnosticReports(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(includes)))).thenReturn(new MockIBundleProvider<>(Arrays.asList(diagnosticReport, new Patient()), PREFERRED_PAGE_SIZE, COUNT));
    IBundleProvider results = resourceProvider.searchForDiagnosticReports(null, null, null, null, null, null, null, null, null, includes);
    List<IBaseResource> resultList = results.getResources(START_INDEX, END_INDEX);
    assertThat(results, notNullValue());
    assertThat(resultList.size(), greaterThanOrEqualTo(2));
    assertThat(resultList.get(1).fhirType(), is(FhirConstants.PATIENT));
    assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.DIAGNOSTIC_REPORT));
    assertThat(((DiagnosticReport) resultList.iterator().next()).getId(), equalTo(UUID));
}
Also used : Include(ca.uhn.fhir.model.api.Include) Patient(org.hl7.fhir.dstu3.model.Patient) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) MockIBundleProvider(org.openmrs.module.fhir2.providers.r4.MockIBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 59 with DiagnosticReport

use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportFhirResourceProviderWebTest method verifyUri.

private void verifyUri(String uri) throws Exception {
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setId(DIAGNOSTIC_REPORT_UUID);
    when(service.searchForDiagnosticReports(any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(diagnosticReport), 10, 1));
    MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
    Bundle results = readBundleResponse(response);
    assertThat(results.hasEntry(), is(true));
    assertThat(results.getEntry().get(0).getResource(), notNullValue());
    assertThat(results.getEntry().get(0).getResource().getIdElement().getIdPart(), equalTo(DIAGNOSTIC_REPORT_UUID));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 60 with DiagnosticReport

use of org.hl7.fhir.dstu3.model.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);
    }
    org.hl7.fhir.r4.model.DiagnosticReport diagnosticReport = new org.hl7.fhir.r4.model.DiagnosticReport();
    diagnosticReport.setId(DIAGNOSTIC_REPORT_UUID);
    when(service.update(anyString(), any(org.hl7.fhir.r4.model.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.dstu3.model.DiagnosticReport) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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