Search in sources :

Example 21 with DateParam

use of ca.uhn.fhir.rest.param.DateParam in project openmrs-module-fhir2 by openmrs.

the class EncounterSearchQueryTest method searchForEncounters_shouldSearchForEncountersByDate.

@Test
public void searchForEncounters_shouldSearchForEncountersByDate() {
    DateRangeParam date = new DateRangeParam(new DateParam(ENCOUNTER_DATETIME));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, date);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(((Encounter) resultList.iterator().next()).getId(), equalTo(ENC_UUID));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) DateParam(ca.uhn.fhir.rest.param.DateParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 22 with DateParam

use of ca.uhn.fhir.rest.param.DateParam in project openmrs-module-fhir2 by openmrs.

the class FhirEncounterServiceImplTest method searchForEncounter_shouldReturnCollectionOfEncounterByDate.

@Test
public void searchForEncounter_shouldReturnCollectionOfEncounterByDate() {
    List<Encounter> encounters = new ArrayList<>();
    DateRangeParam dateRangeParam = new DateRangeParam(new DateParam(ENCOUNTER_DATETIME));
    encounters.add(openMrsEncounter);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, dateRangeParam);
    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(dateRangeParam, null, null, null, null, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(((org.hl7.fhir.r4.model.Encounter) resultList.iterator().next()).getId(), equalTo(ENCOUNTER_UUID));
}
Also used : ArrayList(java.util.ArrayList) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) 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) DateParam(ca.uhn.fhir.rest.param.DateParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 23 with DateParam

use of ca.uhn.fhir.rest.param.DateParam in project openmrs-module-fhir2 by openmrs.

the class VisitSearchQueryTest method searchForVisits_shouldSearchForVisitsByDate.

@Test
public void searchForVisits_shouldSearchForVisitsByDate() {
    DateRangeParam date = new DateRangeParam(new DateParam(VISIT_STARTDATE));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, date);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(((Encounter) resultList.iterator().next()).getId(), equalTo(VISIT_UUID));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) DateParam(ca.uhn.fhir.rest.param.DateParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 24 with DateParam

use of ca.uhn.fhir.rest.param.DateParam in project openmrs-module-fhir2 by openmrs.

the class ConditionSearchQueryImpl_2_2Test method searchForConditions_shouldReturnConditionByOnsetDateRange.

@Test
public void searchForConditions_shouldReturnConditionByOnsetDateRange() {
    DateRangeParam onsetDate = new DateRangeParam(new DateParam(ONSET_START_DATE), new DateParam(ONSET_END_DATE));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "onsetDate", onsetDate);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getOnsetDateTimeType().getValue().toString(), containsString(ONSET_DATE));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) DateParam(ca.uhn.fhir.rest.param.DateParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 25 with DateParam

use of ca.uhn.fhir.rest.param.DateParam in project openmrs-module-fhir2 by openmrs.

the class ConditionSearchQueryImpl_2_2Test method searchForConditions_shouldReturnConditionByRecordedDate.

@Test
public void searchForConditions_shouldReturnConditionByRecordedDate() {
    DateRangeParam recordedDate = new DateRangeParam(new DateParam("eq" + RECORDED_DATE_TIME));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "dateCreated", recordedDate);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getRecordedDate().toString(), containsString(RECORDED_DATE));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Condition(org.openmrs.Condition) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) DateParam(ca.uhn.fhir.rest.param.DateParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

DateParam (ca.uhn.fhir.rest.param.DateParam)30 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)23 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)21 Test (org.junit.Test)21 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)21 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)20 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)19 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)3 StringParam (ca.uhn.fhir.rest.param.StringParam)3 TokenParam (ca.uhn.fhir.rest.param.TokenParam)3 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 FhirContext (ca.uhn.fhir.context.FhirContext)2 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)2 DateOrListParam (ca.uhn.fhir.rest.param.DateOrListParam)2 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)2 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)2 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)2 Date (java.util.Date)2 List (java.util.List)2