Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FM2-429: Support for instance-level $everything operation Encounters in R3 #368

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import java.util.List;

import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.Delete;
import ca.uhn.fhir.rest.annotation.History;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.IncludeParam;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OptionalParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.ResourceParam;
Expand All @@ -32,6 +34,7 @@
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
Expand Down Expand Up @@ -156,5 +159,22 @@ public IBundleProvider searchEncounter(@OptionalParam(name = Encounter.SP_DATE)
return new SearchQueryBundleProviderR3Wrapper(encounterService.searchForEncounters(date, location,
participantReference, subjectReference, id, lastUpdated, includes, revIncludes));
}


/**
* The $everything operation fetches all the information related the specified encounter
*
* @param encounterId The id of the encounter
* @return a bundle of resources which reference to or are referenced from the encounter
*/
@Operation(name = "everything", idempotent = true, type = Encounter.class, bundleType = BundleTypeEnum.SEARCHSET)
public IBundleProvider getEncounterEverything(@IdParam IdType encounterId) {

if (encounterId == null || encounterId.getIdPart() == null || encounterId.getIdPart().isEmpty()) {
return null;
}

TokenParam encounterReference = new TokenParam().setValue(encounterId.getIdPart());

return new SearchQueryBundleProviderR3Wrapper(encounterService.getEncounterEverything(encounterReference));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
Expand Down Expand Up @@ -331,4 +332,41 @@ public void deleteEncounter_shouldThrowResourceNotFoundExceptionWhenIdRefersToNo
when(encounterService.delete(WRONG_ENCOUNTER_UUID)).thenReturn(null);
resourceProvider.deleteEncounter(new IdType().setValue(WRONG_ENCOUNTER_UUID));
}

@Test
public void searchForEncounters_shouldReturnEncounterEverything() {
when(encounterService.getEncounterEverything(any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(encounter), 10, 1));

IBundleProvider results = resourceProvider.getEncounterEverything(new IdType(ENCOUNTER_UUID));

List<IBaseResource> resultList = getAllResources(results);

assertThat(resultList, notNullValue());
assertThat(resultList.size(), equalTo(1));
assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.ENCOUNTER));
assertThat(((Encounter) resultList.iterator().next()).getId(), equalTo(ENCOUNTER_UUID));
}

@Test
public void searchForEncounters_shouldReturnNullForEncounterEverythingWhenIdParamIsMissing() {
IBundleProvider results = resourceProvider.getEncounterEverything(null);
assertThat(results, nullValue());
}

@Test
public void searchForEncounters_shouldReturnNullForEncounterEverythingWhenIdPartIsMissingInIdParam() {
IBundleProvider results = resourceProvider.getEncounterEverything(new IdType());
assertThat(results, nullValue());
}

@Test
public void searchForEncounters_shouldReturnNullEncounterEverythingWhenIdPartIsEmptyInIdParam() {
IBundleProvider results = resourceProvider.getEncounterEverything(new IdType(""));
assertThat(results, nullValue());
}

private List<IBaseResource> getAllResources(IBundleProvider result) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @Medhavi-16 do you really need to add this method under the tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Medhavi-16 I'm also wondering this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HerbertYiga @ibacher I'm sorry, I've been M.I.A.. Yeah, we don't need this method. I'll remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibacher PTAL.

return result.getAllResources();
}
}