use of ca.uhn.fhir.rest.gclient.IQuery in project dpc-app by CMSgov.
the class ConsentServiceImplUnitTest method getConsent.
@Test
public void getConsent() {
final String testMbi = "0OO0OO0OO00";
Bundle bundle = new Bundle();
IQuery queryExec = Mockito.mock(IQuery.class, Answers.RETURNS_DEEP_STUBS);
Mockito.when(mockConsentClient.search().forResource(Consent.class).encodedJson()).thenReturn(queryExec);
IQuery<Bundle> mockQuery = Mockito.mock(IQuery.class);
Mockito.when(queryExec.returnBundle(any(Class.class)).where(any(ICriterion.class))).thenReturn(mockQuery);
Mockito.when(mockQuery.execute()).thenReturn(bundle);
Optional<List<ConsentResult>> results = consentService.getConsent(testMbi);
assertTrue(results.isPresent(), "Expected optional to have a value.");
assertEquals(0, results.get().size(), "Expected consent results to be an empty list");
bundle.addEntry(new Bundle.BundleEntryComponent().setResource(createTestConsent(testMbi)));
bundle.addEntry(new Bundle.BundleEntryComponent().setResource(createTestConsent(testMbi)));
results = consentService.getConsent(testMbi);
assertTrue(results.isPresent(), "Expected optional to have a value");
assertEquals(2, results.get().size(), "Expected 2 consent results");
}
use of ca.uhn.fhir.rest.gclient.IQuery in project dpc-app by CMSgov.
the class ConsentResourceTest method searchConsentResource_fails_withNoParams.
@Test
final void searchConsentResource_fails_withNoParams() {
// an attempt to the resource with an empty value is routed to the search endpoint
final IGenericClient client = createFHIRClient(ctx, getServerURL());
@SuppressWarnings("rawtypes") final IQuery sut = client.search().forResource(Consent.class).encodedJson();
assertThrows(InvalidRequestException.class, sut::execute, "should fail with no search params");
}
use of ca.uhn.fhir.rest.gclient.IQuery in project Gravity-SDOH-Exchange-RI by FHIR.
the class SupportService method getActiveResources.
// TODO do this in parallel.
public ActiveResourcesDto getActiveResources() {
SmartOnFhirContext smartOnFhirContext = SmartOnFhirContext.get();
IQuery hcQuery = new HealthConcernQueryFactory().query(ehrClient, smartOnFhirContext.getPatient()).where(Condition.CLINICAL_STATUS.exactly().code(ConditionClinicalStatusCodes.ACTIVE.toCode()));
IQuery problemQuery = new ProblemQueryFactory().query(ehrClient, smartOnFhirContext.getPatient()).where(Condition.CLINICAL_STATUS.exactly().code(ConditionClinicalStatusCodes.ACTIVE.toCode()));
IQuery goalQuery = new GoalQueryFactory().query(ehrClient, smartOnFhirContext.getPatient()).where(Goal.LIFECYCLE_STATUS.exactly().code(Goal.GoalLifecycleStatus.ACTIVE.toCode()));
IQuery taskQuery = new TaskQueryFactory().query(ehrClient, smartOnFhirContext.getPatient()).where(Task.STATUS.exactly().codes(Task.TaskStatus.ACCEPTED.toCode(), Task.TaskStatus.DRAFT.toCode(), Task.TaskStatus.INPROGRESS.toCode(), Task.TaskStatus.ONHOLD.toCode(), Task.TaskStatus.READY.toCode(), Task.TaskStatus.RECEIVED.toCode(), Task.TaskStatus.REQUESTED.toCode()));
return new ActiveResourcesDto(getTotal(hcQuery), getTotal(problemQuery), getTotal(goalQuery), getTotal(taskQuery));
}
Aggregations