Search in sources :

Example 66 with Encounter

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

the class FhirMedicationRequestServiceImplTest method searchForMedicationRequest_shouldReturnCollectionOfMedicationRequestByEncounter.

@Test
public void searchForMedicationRequest_shouldReturnCollectionOfMedicationRequestByEncounter() {
    ReferenceAndListParam encounter = new ReferenceAndListParam();
    encounter.addValue(new ReferenceOrListParam().add(new ReferenceParam().setValue("jdjdj-kdkdkkd-kddd").setChain(Encounter.SP_IDENTIFIER)));
    List<DrugOrder> drugOrders = new ArrayList<>();
    drugOrders.add(drugOrder);
    medicationRequest.setId(MEDICATION_REQUEST_UUID);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounter);
    when(dao.getSearchResults(any(), any())).thenReturn(drugOrders);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(MEDICATION_REQUEST_UUID));
    when(medicationRequestTranslator.toFhirResource(drugOrder)).thenReturn(medicationRequest);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, medicationRequestTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = medicationRequestService.searchForMedicationRequests(null, encounter, 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 : DrugOrder(org.openmrs.DrugOrder) ArrayList(java.util.ArrayList) 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 67 with Encounter

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

the class ServiceRequestSearchQueryTest method searchForServiceRequests_shouldReturnServiceRequestsByMultipleEncountersOr.

@Test
public void searchForServiceRequests_shouldReturnServiceRequestsByMultipleEncountersOr() {
    ReferenceAndListParam encounterReference = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(ENCOUNTER_UUID)).add(new ReferenceParam().setValue(ENCOUNTER_UUID_TWO)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounterReference);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(4));
    List<ServiceRequest> resources = get(results);
    assertThat(resources, not(empty()));
    assertThat(resources, hasSize(equalTo(4)));
    assertThat(resources, everyItem(anyOf(hasProperty("encounter", hasProperty("referenceElement", hasProperty("idPart", equalTo(ENCOUNTER_UUID)))), hasProperty("encounter", hasProperty("referenceElement", hasProperty("idPart", equalTo(ENCOUNTER_UUID_TWO)))))));
}
Also used : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 68 with Encounter

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

the class ServiceRequestSearchQueryTest method searchForServiceRequests_shouldReturnServiceRequestsByEncounter.

@Test
public void searchForServiceRequests_shouldReturnServiceRequestsByEncounter() {
    ReferenceAndListParam encounterReference = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(ENCOUNTER_UUID)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounterReference);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(4));
    List<ServiceRequest> resources = get(results);
    assertThat(resources, not(empty()));
    assertThat(resources, hasSize(equalTo(4)));
    assertThat(resources, everyItem(hasProperty("encounter", hasProperty("referenceElement", hasProperty("idPart", equalTo(ENCOUNTER_UUID))))));
}
Also used : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 69 with Encounter

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

the class VisitSearchQueryTest method shouldReturnCollectionOfEncountersSortedByEncounterDate.

@Test
public void shouldReturnCollectionOfEncountersSortedByEncounterDate() {
    SortSpec sort = new SortSpec();
    sort.setParamName("date");
    sort.setOrder(SortOrderEnum.ASC);
    SearchParameterMap theParams = new SearchParameterMap().setSortSpec(sort);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThan(1));
    List<Encounter> resultList = get(results).stream().filter(it -> it instanceof Encounter).map(it -> (Encounter) it).collect(Collectors.toList());
    assertThat(resultList, hasSize(greaterThan(1)));
    for (int i = 1; i < resultList.size(); i++) {
        assertNotNull(resultList.get(i - 1).getPeriod().getStart());
        assertNotNull(resultList.get(i).getPeriod().getStart());
        assertThat(resultList.get(i - 1).getPeriod().getStart(), lessThanOrEqualTo(resultList.get(i).getPeriod().getStart()));
    }
    sort.setOrder(SortOrderEnum.DESC);
    theParams.setSortSpec(sort);
    results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThan(1));
    resultList = get(results).stream().filter(it -> it instanceof Encounter).map(it -> (Encounter) it).collect(Collectors.toList());
    assertThat(resultList, hasSize(greaterThan(1)));
    for (int i = 1; i < resultList.size(); i++) {
        assertNotNull(resultList.get(i - 1).getPeriod().getStart());
        assertNotNull(resultList.get(i).getPeriod().getStart());
        assertThat(resultList.get(i - 1).getPeriod().getStart(), greaterThanOrEqualTo(resultList.get(i).getPeriod().getStart()));
    }
}
Also used : IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) Visit(org.openmrs.Visit) FhirVisitDao(org.openmrs.module.fhir2.api.dao.FhirVisitDao) Matchers.not(org.hamcrest.Matchers.not) Autowired(org.springframework.beans.factory.annotation.Autowired) EncounterTranslator(org.openmrs.module.fhir2.api.translators.EncounterTranslator) Encounter(org.hl7.fhir.r4.model.Encounter) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) FhirConstants(org.openmrs.module.fhir2.FhirConstants) Patient(org.hl7.fhir.r4.model.Patient) Practitioner(org.hl7.fhir.r4.model.Practitioner) Before(org.junit.Before) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) SortOrderEnum(ca.uhn.fhir.rest.api.SortOrderEnum) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Assert.assertNotNull(org.junit.Assert.assertNotNull) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) TestFhirSpringConfiguration(org.openmrs.module.fhir2.TestFhirSpringConfiguration) Test(org.junit.Test) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Collectors(java.util.stream.Collectors) TokenParam(ca.uhn.fhir.rest.param.TokenParam) List(java.util.List) SortSpec(ca.uhn.fhir.rest.api.SortSpec) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.endsWith(org.hamcrest.Matchers.endsWith) DateParam(ca.uhn.fhir.rest.param.DateParam) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) Encounter(org.hl7.fhir.r4.model.Encounter) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) SortSpec(ca.uhn.fhir.rest.api.SortSpec) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 70 with Encounter

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

the class VisitSearchQueryTest method searchForVisits_shouldSearchForVisitsBySubjectIdentifier.

@Test
public void searchForVisits_shouldSearchForVisitsBySubjectIdentifier() {
    ReferenceAndListParam subjectReference = new ReferenceAndListParam();
    ReferenceParam subject = new ReferenceParam();
    subject.setValue(PATIENT_IDENTIFIER);
    subject.setChain(Patient.SP_IDENTIFIER);
    subjectReference.addValue(new ReferenceOrListParam().add(subject));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, subjectReference);
    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()).getSubject().getReference(), endsWith(PATIENT_UUID));
}
Also used : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Encounter(org.hl7.fhir.r4.model.Encounter) 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) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)238 Encounter (org.hl7.fhir.r4.model.Encounter)166 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)100 Test (org.junit.jupiter.api.Test)93 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)87 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)79 Reference (org.hl7.fhir.r4.model.Reference)71 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)66 ArrayList (java.util.ArrayList)64 Resource (org.hl7.fhir.r4.model.Resource)61 Bundle (org.hl7.fhir.r4.model.Bundle)60 Date (java.util.Date)57 Encounter (org.hl7.fhir.dstu3.model.Encounter)55 Coding (org.hl7.fhir.r4.model.Coding)51 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)49 Reference (org.hl7.fhir.dstu3.model.Reference)48 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)43 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)41 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)38 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)37