Search in sources :

Example 31 with DiagnosticReport

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

the class FhirDiagnosticReportServiceImplTest method searchForDiagnosticReports_shouldNotAddRelatedResourcesForEmptyInclude.

@Test
public void searchForDiagnosticReports_shouldNotAddRelatedResourcesForEmptyInclude() {
    FhirDiagnosticReport fhirDiagnosticReport = new FhirDiagnosticReport();
    fhirDiagnosticReport.setUuid(UUID);
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setId(UUID);
    List<FhirDiagnosticReport> diagnosticReportList = new ArrayList<>();
    diagnosticReportList.add(fhirDiagnosticReport);
    HashSet<Include> includes = new HashSet<>();
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
    when(dao.getSearchResults(any(), any())).thenReturn(diagnosticReportList);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(UUID));
    when(translator.toFhirResource(fhirDiagnosticReport)).thenReturn(diagnosticReport);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = service.searchForDiagnosticReports(null, null, null, null, null, null, null, null, includes);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList.size(), equalTo(1));
    assertThat(resultList, hasItem(hasProperty("id", equalTo(UUID))));
}
Also used : FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) ArrayList(java.util.ArrayList) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) SearchQueryInclude(org.openmrs.module.fhir2.api.search.SearchQueryInclude) Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 32 with DiagnosticReport

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

the class FhirDiagnosticReportServiceImplTest method updateDiagnosticReport_shouldUpdateExistingDiagnosticReport.

@Test
public void updateDiagnosticReport_shouldUpdateExistingDiagnosticReport() {
    Date currentDate = new Date();
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setId(UUID);
    FhirDiagnosticReport fhirDiagnosticReport = new FhirDiagnosticReport();
    FhirDiagnosticReport updatedFhirDiagnosticReport = new FhirDiagnosticReport();
    Obs obsResult = new Obs();
    obsResult.setUuid(CHILD_UUID);
    fhirDiagnosticReport.setUuid(UUID);
    updatedFhirDiagnosticReport.setUuid(UUID);
    updatedFhirDiagnosticReport.setDateCreated(currentDate);
    fhirDiagnosticReport.getResults().add(obsResult);
    updatedFhirDiagnosticReport.getResults().add(obsResult);
    when(translator.toOpenmrsType(fhirDiagnosticReport, diagnosticReport)).thenReturn(updatedFhirDiagnosticReport);
    when(dao.createOrUpdate(updatedFhirDiagnosticReport)).thenReturn(updatedFhirDiagnosticReport);
    when(dao.get(UUID)).thenReturn(fhirDiagnosticReport);
    when(translator.toFhirResource(updatedFhirDiagnosticReport)).thenReturn(diagnosticReport);
    DiagnosticReport result = service.update(UUID, diagnosticReport);
    assertThat(result, notNullValue());
    assertThat(result, equalTo(diagnosticReport));
}
Also used : Obs(org.openmrs.Obs) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) Date(java.util.Date) Test(org.junit.Test)

Example 33 with DiagnosticReport

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

the class FhirDiagnosticReportServiceImplTest method searchForDiagnosticReports_shouldAddRelatedResourcesWhenIncluded.

@Test
public void searchForDiagnosticReports_shouldAddRelatedResourcesWhenIncluded() {
    FhirDiagnosticReport fhirDiagnosticReport = new FhirDiagnosticReport();
    fhirDiagnosticReport.setUuid(UUID);
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setId(UUID);
    List<FhirDiagnosticReport> diagnosticReportList = new ArrayList<>();
    diagnosticReportList.add(fhirDiagnosticReport);
    HashSet<Include> includes = new HashSet<>();
    includes.add(new Include("DiagnosticReport:patient"));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
    when(dao.getSearchResults(any(), any())).thenReturn(diagnosticReportList);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(UUID));
    when(translator.toFhirResource(fhirDiagnosticReport)).thenReturn(diagnosticReport);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.singleton(new Patient()));
    IBundleProvider results = service.searchForDiagnosticReports(null, null, null, null, null, null, null, null, includes);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList.size(), equalTo(2));
    assertThat(resultList, hasItem(is(instanceOf(Patient.class))));
    assertThat(resultList, hasItem(hasProperty("id", equalTo(UUID))));
}
Also used : FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) ArrayList(java.util.ArrayList) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) SearchQueryInclude(org.openmrs.module.fhir2.api.search.SearchQueryInclude) Include(ca.uhn.fhir.model.api.Include) Patient(org.hl7.fhir.r4.model.Patient) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 34 with DiagnosticReport

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

the class FhirDiagnosticReportServiceImplTest method updateTask_shouldThrowInvalidRequestForMissingUuid.

@Test(expected = InvalidRequestException.class)
public void updateTask_shouldThrowInvalidRequestForMissingUuid() {
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    service.update(UUID, diagnosticReport);
}
Also used : DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) Test(org.junit.Test)

Example 35 with DiagnosticReport

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

the class FhirDiagnosticReportServiceImplTest method createDiagnosticReport_shouldCreateNewDiagnosticReport.

@Test
public void createDiagnosticReport_shouldCreateNewDiagnosticReport() {
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setId(UUID);
    FhirDiagnosticReport fhirDiagnosticReport = new FhirDiagnosticReport();
    Obs obsResult = new Obs();
    obsResult.setUuid(CHILD_UUID);
    fhirDiagnosticReport.getResults().add(obsResult);
    fhirDiagnosticReport.setUuid(UUID);
    when(translator.toOpenmrsType(diagnosticReport)).thenReturn(fhirDiagnosticReport);
    when(dao.createOrUpdate(fhirDiagnosticReport)).thenReturn(fhirDiagnosticReport);
    when(translator.toFhirResource(fhirDiagnosticReport)).thenReturn(diagnosticReport);
    DiagnosticReport result = service.create(diagnosticReport);
    assertThat(result, notNullValue());
    assertThat(result, equalTo(diagnosticReport));
}
Also used : Obs(org.openmrs.Obs) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) 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