Search in sources :

Example 51 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class FhirObservationServiceImplTest method searchForObservations_shouldReturnObservationsByParameters.

@Test
public void searchForObservations_shouldReturnObservationsByParameters() {
    Obs obs = new Obs();
    obs.setUuid(OBS_UUID);
    Observation observation = new Observation();
    observation.setId(OBS_UUID);
    ReferenceAndListParam patientReference = new ReferenceAndListParam();
    ReferenceParam patient = new ReferenceParam();
    patient.setValue(PATIENT_GIVEN_NAME);
    patient.setChain(Patient.SP_GIVEN);
    patientReference.addValue(new ReferenceOrListParam().add(patient));
    SearchParameterMap theParams = new SearchParameterMap();
    theParams.addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference);
    when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(OBS_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(obs));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(translator.toFhirResource(obs)).thenReturn(observation);
    IBundleProvider results = fhirObservationService.searchForObservations(null, patientReference, null, null, null, null, null, null, null, null, null, null, null, null, null);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(1));
    assertThat(results.preferredPageSize(), equalTo(10));
    List<IBaseResource> resultList = results.getResources(1, 10);
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
}
Also used : Obs(org.openmrs.Obs) Observation(org.hl7.fhir.r4.model.Observation) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 52 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class FhirObservationServiceImplTest method getLastnObservations_shouldReturnRecentNObservations.

@Test
public void getLastnObservations_shouldReturnRecentNObservations() {
    Obs obs = new Obs();
    obs.setUuid(OBS_UUID);
    Observation observation = new Observation();
    observation.setId(OBS_UUID);
    NumberParam max = new NumberParam(2);
    ReferenceAndListParam referenceParam = new ReferenceAndListParam();
    ReferenceParam patient = new ReferenceParam();
    patient.setValue(PATIENT_UUID);
    referenceParam.addValue(new ReferenceOrListParam().add(patient));
    TokenAndListParam categories = new TokenAndListParam().addAnd(new TokenParam().setValue("laboratory"));
    TokenAndListParam code = new TokenAndListParam().addAnd(new TokenParam().setSystem(FhirTestConstants.LOINC_SYSTEM_URL).setValue(LOINC_SYSTOLIC_BP), new TokenParam().setSystem(FhirTestConstants.CIEL_SYSTEM_URN).setValue(CIEL_DIASTOLIC_BP));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, referenceParam).addParameter(FhirConstants.CODED_SEARCH_HANDLER, code).addParameter(FhirConstants.CATEGORY_SEARCH_HANDLER, categories).addParameter(FhirConstants.MAX_SEARCH_HANDLER, max).addParameter(FhirConstants.LASTN_OBSERVATION_SEARCH_HANDLER, new StringParam());
    when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(OBS_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(obs));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(translator.toFhirResource(obs)).thenReturn(observation);
    IBundleProvider results = fhirObservationService.getLastnObservations(max, referenceParam, categories, code);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(1));
    assertThat(results.preferredPageSize(), equalTo(10));
    List<IBaseResource> resultList = results.getResources(1, 10);
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
}
Also used : Obs(org.openmrs.Obs) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) NumberParam(ca.uhn.fhir.rest.param.NumberParam) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Observation(org.hl7.fhir.r4.model.Observation) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 53 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class FhirPatientServiceImplTest method searchForPatients_shouldAddReverseIncludedResourcesToResultList.

@Test
public void searchForPatients_shouldAddReverseIncludedResourcesToResultList() {
    HashSet<Include> revIncludes = new HashSet<>();
    revIncludes.add(new Include("Observation:patient"));
    SearchParameterMap theParams = new SearchParameterMap().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(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.singleton(new Observation()));
    when(patientTranslator.toFhirResource(patient)).thenReturn(fhirPatient);
    IBundleProvider results = patientService.searchForPatients(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, revIncludes);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList.size(), greaterThanOrEqualTo(2));
    assertThat(resultList, hasItem(is(instanceOf(Observation.class))));
}
Also used : Observation(org.hl7.fhir.r4.model.Observation) 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 54 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class FhirEncounterServiceImplTest method searchForEncounter_shouldAddReverseIncludedResourcesToResultList.

@Test
public void searchForEncounter_shouldAddReverseIncludedResourcesToResultList() {
    HashSet<Include> revIncludes = new HashSet<>();
    revIncludes.add(new Include("Observation:encounter"));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.REVERSE_INCLUDE_SEARCH_HANDLER, revIncludes);
    when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(openMrsEncounter));
    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.singleton(new Observation()));
    when(visitService.searchForVisits(any())).thenReturn(new SimpleBundleProvider());
    IBundleProvider results = encounterService.searchForEncounters(null, null, null, null, null, null, null, null, null, revIncludes);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList.size(), greaterThanOrEqualTo(2));
    assertThat(resultList, hasItem(is(instanceOf(Observation.class))));
}
Also used : Observation(org.hl7.fhir.r4.model.Observation) 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) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 55 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class ObservationSearchQueryTest method searchForObs_shouldAddNotNullEncounterToReturnedResults.

@Test
public void searchForObs_shouldAddNotNullEncounterToReturnedResults() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(OBS_UUID));
    HashSet<Include> includes = new HashSet<>();
    Include include = new Include("Observation:encounter");
    includes.add(include);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
    IBundleProvider results = search(theParams);
    assertThat(results.size(), equalTo(1));
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    // included resource added as part of the result list
    assertThat(resultList.size(), equalTo(2));
    Observation returnedObservation = (Observation) resultList.iterator().next();
    assertThat(resultList, hasItem(allOf(is(instanceOf(Encounter.class)), hasProperty("id", equalTo(returnedObservation.getEncounter().getReferenceElement().getIdPart())))));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) Observation(org.hl7.fhir.r4.model.Observation) Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

Observation (org.hl7.fhir.r4.model.Observation)237 Test (org.junit.Test)235 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)114 Test (org.junit.jupiter.api.Test)107 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)106 Observation (org.hl7.fhir.dstu3.model.Observation)94 Bundle (org.hl7.fhir.r4.model.Bundle)88 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)64 ArrayList (java.util.ArrayList)62 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)59 Resource (org.hl7.fhir.r4.model.Resource)55 Bundle (org.hl7.fhir.dstu3.model.Bundle)53 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)47 Coding (org.hl7.fhir.r4.model.Coding)46 Reference (org.hl7.fhir.r4.model.Reference)41 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)37 TokenParam (ca.uhn.fhir.rest.param.TokenParam)37 Date (java.util.Date)34 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)32 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)32