Search in sources :

Example 51 with ENCOUNTER

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project openmrs-module-fhir2 by openmrs.

the class EncounterSearchQueryTest 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 : Matchers.not(org.hamcrest.Matchers.not) Autowired(org.springframework.beans.factory.annotation.Autowired) Encounter(org.hl7.fhir.r4.model.Encounter) Matchers.everyItem(org.hamcrest.Matchers.everyItem) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) FhirConstants(org.openmrs.module.fhir2.FhirConstants) Patient(org.hl7.fhir.r4.model.Patient) Practitioner(org.hl7.fhir.r4.model.Practitioner) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Matchers.allOf(org.hamcrest.Matchers.allOf) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Set(java.util.Set) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Collectors(java.util.stream.Collectors) Include(ca.uhn.fhir.model.api.Include) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) SortSpec(ca.uhn.fhir.rest.api.SortSpec) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Matchers.anyOf(org.hamcrest.Matchers.anyOf) Matchers.endsWith(org.hamcrest.Matchers.endsWith) DateParam(ca.uhn.fhir.rest.param.DateParam) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) EncounterTranslator(org.openmrs.module.fhir2.api.translators.EncounterTranslator) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) HashSet(java.util.HashSet) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Observation(org.hl7.fhir.r4.model.Observation) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) SortOrderEnum(ca.uhn.fhir.rest.api.SortOrderEnum) Location(org.hl7.fhir.r4.model.Location) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) 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) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Matchers.hasItem(org.hamcrest.Matchers.hasItem) ContextConfiguration(org.springframework.test.context.ContextConfiguration) FhirEncounterDao(org.openmrs.module.fhir2.api.dao.FhirEncounterDao) 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 52 with ENCOUNTER

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project openmrs-module-fhir2 by openmrs.

the class EncounterSearchQueryTest method searchForEncounters_shouldSearchForEncountersBySubjectUuid.

@Test
public void searchForEncounters_shouldSearchForEncountersBySubjectUuid() {
    ReferenceAndListParam subjectReference = new ReferenceAndListParam();
    ReferenceParam subject = new ReferenceParam();
    subject.setValue(PATIENT_UUID);
    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().getReferenceElement().getIdPart(), equalTo(PATIENT_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) 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)

Example 53 with ENCOUNTER

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project openmrs-module-fhir2 by openmrs.

the class EncounterSearchQueryTest method searchForEncounters_shouldSearchForEncountersByParticipantIdentifier.

@Test
public void searchForEncounters_shouldSearchForEncountersByParticipantIdentifier() {
    ReferenceAndListParam participantReference = new ReferenceAndListParam();
    ReferenceParam participant = new ReferenceParam();
    participant.setValue(PARTICIPANT_IDENTIFIER);
    participant.setChain(Practitioner.SP_IDENTIFIER);
    participantReference.addValue(new ReferenceOrListParam().add(participant));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER, participantReference);
    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()).getParticipantFirstRep().getIndividual().getIdentifier().getValue(), equalTo(PARTICIPANT_IDENTIFIER));
}
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)

Example 54 with ENCOUNTER

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project openmrs-module-fhir2 by openmrs.

the class EncounterSearchQueryTest method searchForEncounters_shouldSearchForEncountersBySubjectFamilyName.

@Test
public void searchForEncounters_shouldSearchForEncountersBySubjectFamilyName() {
    ReferenceAndListParam subjectReference = new ReferenceAndListParam();
    ReferenceParam subject = new ReferenceParam();
    subject.setValue(PATIENT_FAMILY_NAME);
    subject.setChain(Patient.SP_FAMILY);
    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()).getId(), 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) 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)

Example 55 with ENCOUNTER

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project openmrs-module-fhir2 by openmrs.

the class EncounterSearchQueryTest method searchForEncounters_shouldIncludeLocationsWithReturnedResults.

@Test
public void searchForEncounters_shouldIncludeLocationsWithReturnedResults() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(ENCOUNTER_UUID));
    HashSet<Include> includes = new HashSet<>();
    includes.add(new Include("Encounter:location"));
    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, notNullValue());
    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));
    Encounter returnedEncounter = (Encounter) resultList.iterator().next();
    assertThat(resultList, hasItem(allOf(is(instanceOf(Location.class)), hasProperty("id", equalTo(returnedEncounter.getLocationFirstRep().getLocation().getReferenceElement().getIdPart())))));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) Include(ca.uhn.fhir.model.api.Include) Encounter(org.hl7.fhir.r4.model.Encounter) 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

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