use of org.hl7.fhir.r4.model.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()));
}
}
use of org.hl7.fhir.r4.model.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));
}
use of org.hl7.fhir.r4.model.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));
}
use of org.hl7.fhir.r4.model.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));
}
use of org.hl7.fhir.r4.model.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())))));
}
Aggregations