use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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))));
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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));
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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))));
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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);
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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));
}
Aggregations