Search in sources :

Example 11 with EncounterTranslator

use of org.openmrs.module.fhir2.api.translators.EncounterTranslator in project openmrs-module-fhir2 by openmrs.

the class FhirEncounterServiceImplTest method searchForEncounter_shouldReturnCollectionOfEncounterByParticipant.

@Test
public void searchForEncounter_shouldReturnCollectionOfEncounterByParticipant() {
    ReferenceAndListParam participant = new ReferenceAndListParam();
    participant.addValue(new ReferenceOrListParam().add(new ReferenceParam().setValue(PARTICIPANT_IDENTIFIER).setChain(Practitioner.SP_IDENTIFIER)));
    List<Encounter> encounters = new ArrayList<>();
    encounters.add(openMrsEncounter);
    fhirEncounter.setId(ENCOUNTER_UUID);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER, participant);
    when(dao.getSearchResults(any(), any())).thenReturn(encounters);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ENCOUNTER_UUID));
    when(encounterTranslator.toFhirResource(openMrsEncounter)).thenReturn(fhirEncounter);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, encounterTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(visitService.searchForVisits(any())).thenReturn(new SimpleBundleProvider());
    IBundleProvider results = encounterService.searchForEncounters(null, null, participant, null, null, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, Matchers.notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Also used : ArrayList(java.util.ArrayList) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Encounter(org.openmrs.Encounter) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 12 with EncounterTranslator

use of org.openmrs.module.fhir2.api.translators.EncounterTranslator in project openmrs-module-fhir2 by openmrs.

the class FhirEncounterServiceImplTest method searchForEncounter_shouldReturnCollectionOfEncounterByTypeUUID.

@Test
public void searchForEncounter_shouldReturnCollectionOfEncounterByTypeUUID() {
    TokenAndListParam typeUuid = new TokenAndListParam().addAnd(new TokenParam(ENCOUNTER_TYPE_UUID));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ENCOUNTER_TYPE_REFERENCE_SEARCH_HANDLER, typeUuid);
    List<Encounter> encounters = new ArrayList<>();
    encounters.add(openMrsEncounter);
    fhirEncounter.setId(ENCOUNTER_UUID);
    when(dao.getSearchResults(any(), any())).thenReturn(encounters);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(ENCOUNTER_UUID));
    when(encounterTranslator.toFhirResource(openMrsEncounter)).thenReturn(fhirEncounter);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, encounterTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(visitService.searchForVisits(any())).thenReturn(new SimpleBundleProvider());
    IBundleProvider results = encounterService.searchForEncounters(null, null, null, null, typeUuid, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Aggregations

IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)12 SimpleBundleProvider (ca.uhn.fhir.rest.server.SimpleBundleProvider)12 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)12 Test (org.junit.Test)12 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)12 ArrayList (java.util.ArrayList)5 Encounter (org.openmrs.Encounter)5 Include (ca.uhn.fhir.model.api.Include)4 HashSet (java.util.HashSet)4 SearchQueryInclude (org.openmrs.module.fhir2.api.search.SearchQueryInclude)4 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)3 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)3 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)3 TokenParam (ca.uhn.fhir.rest.param.TokenParam)3 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)2 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)2 DateParam (ca.uhn.fhir.rest.param.DateParam)1 Observation (org.hl7.fhir.r4.model.Observation)1 Patient (org.hl7.fhir.r4.model.Patient)1