Search in sources :

Example 16 with PatientTranslator

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

the class FhirPatientServiceImplTest method searchForPatients_shouldReturnCollectionOfPatientsForPartialMatchOnGivenName.

@Test
public void searchForPatients_shouldReturnCollectionOfPatientsForPartialMatchOnGivenName() {
    List<Patient> patients = new ArrayList<>();
    patients.add(patient);
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(PATIENT_PARTIAL_GIVEN_NAME));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, stringAndListParam);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(PATIENT_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(patients);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, patientTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(patientTranslator.toFhirResource(patient)).thenReturn(fhirPatient);
    IBundleProvider results = patientService.searchForPatients(null, stringAndListParam, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThanOrEqualTo(1));
    assertThat(get(results), not(empty()));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 17 with PatientTranslator

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

the class FhirPatientServiceImplTest method getPatientEverything_shouldReturnAllInformationAboutSpecifiedPatient.

@Test
public void getPatientEverything_shouldReturnAllInformationAboutSpecifiedPatient() {
    TokenParam patientId = new TokenParam().setValue(PATIENT_UUID);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.EVERYTHING_SEARCH_HANDLER, "").addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, patientId);
    HashSet<Include> revIncludes = new HashSet<>();
    revIncludes.add(new Include(FhirConstants.OBSERVATION + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
    revIncludes.add(new Include(FhirConstants.ALLERGY_INTOLERANCE + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
    revIncludes.add(new Include(FhirConstants.DIAGNOSTIC_REPORT + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
    revIncludes.add(new Include(FhirConstants.ENCOUNTER + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
    revIncludes.add(new Include(FhirConstants.MEDICATION_REQUEST + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
    revIncludes.add(new Include(FhirConstants.SERVICE_REQUEST + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
    revIncludes.add(new Include(FhirConstants.PROCEDURE_REQUEST + ":" + FhirConstants.INCLUDE_PATIENT_PARAM));
    theParams.addParameter(FhirConstants.REVERSE_INCLUDE_SEARCH_HANDLER, revIncludes);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(PATIENT_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(patient));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, patientTranslator, globalPropertyService, searchQueryInclude));
    when(patientTranslator.toFhirResource(patient)).thenReturn(fhirPatient);
    IBundleProvider results = patientService.getPatientEverything(patientId);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList.size(), greaterThanOrEqualTo(1));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) 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) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with PatientTranslator

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

the class FhirPatientServiceImplTest method searchForPatients_shouldReturnEmptyCollectionWhenPatientCountryNotMatched.

@Test
public void searchForPatients_shouldReturnEmptyCollectionWhenPatientCountryNotMatched() {
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(UNKNOWN_ADDRESS));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, stringAndListParam);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, patientTranslator, globalPropertyService, searchQueryInclude));
    IBundleProvider results = patientService.searchForPatients(null, null, null, null, null, null, null, null, null, null, null, stringAndListParam, null, null, null, null);
    assertThat(results, notNullValue());
    assertThat(get(results), empty());
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 19 with PatientTranslator

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

the class FhirPatientServiceImplTest method searchForPatients_shouldReturnCollectionOfPatientWhenPatientPostalCodeMatched.

@Test
public void searchForPatients_shouldReturnCollectionOfPatientWhenPatientPostalCodeMatched() {
    List<Patient> patients = new ArrayList<>();
    patients.add(patient);
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(POSTAL_CODE));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, "postalCode", stringAndListParam);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(PATIENT_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(patients);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, patientTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(patientTranslator.toFhirResource(patient)).thenReturn(fhirPatient);
    IBundleProvider results = patientService.searchForPatients(null, null, null, null, null, null, null, null, null, null, stringAndListParam, null, null, null, null, null);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThanOrEqualTo(1));
    assertThat(get(results), not(empty()));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 20 with PatientTranslator

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

the class FhirPatientServiceImplTest method searchForPatients_shouldSearchForPatientsByFamilyName.

@Test
public void searchForPatients_shouldSearchForPatientsByFamilyName() {
    List<Patient> patients = new ArrayList<>();
    patients.add(patient);
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringParam(PATIENT_FAMILY_NAME));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, stringAndListParam);
    when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(PATIENT_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(patients);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, patientTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(patientTranslator.toFhirResource(patient)).thenReturn(fhirPatient);
    IBundleProvider results = patientService.searchForPatients(null, null, stringAndListParam, null, null, null, null, null, null, null, null, null, null, null, null, null);
    assertThat(results.getUuid(), notNullValue());
    assertThat(results.size(), equalTo(1));
    assertThat(results.preferredPageSize(), equalTo(10));
    assertThat(get(results), not(empty()));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Aggregations

IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)30 Test (org.junit.Test)30 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)30 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)16 StringParam (ca.uhn.fhir.rest.param.StringParam)16 ArrayList (java.util.ArrayList)12 Patient (org.openmrs.Patient)12 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)6 TokenParam (ca.uhn.fhir.rest.param.TokenParam)5 Include (ca.uhn.fhir.model.api.Include)4 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)4 HashSet (java.util.HashSet)4 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)4 SearchQueryInclude (org.openmrs.module.fhir2.api.search.SearchQueryInclude)4 Date (java.util.Date)2 Observation (org.hl7.fhir.r4.model.Observation)1