Search in sources :

Example 1 with IQuery

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");
}
Also used : IQuery(ca.uhn.fhir.rest.gclient.IQuery) List(java.util.List) ICriterion(ca.uhn.fhir.rest.gclient.ICriterion) Test(org.junit.jupiter.api.Test)

Example 2 with IQuery

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");
}
Also used : IQuery(ca.uhn.fhir.rest.gclient.IQuery) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) AbstractConsentTest(gov.cms.dpc.consent.AbstractConsentTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with IQuery

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));
}
Also used : HealthConcernQueryFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.query.HealthConcernQueryFactory) IQuery(ca.uhn.fhir.rest.gclient.IQuery) GoalQueryFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.query.GoalQueryFactory) TaskQueryFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.query.TaskQueryFactory) ActiveResourcesDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ActiveResourcesDto) SmartOnFhirContext(com.healthlx.smartonfhir.core.SmartOnFhirContext) ProblemQueryFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.query.ProblemQueryFactory)

Aggregations

IQuery (ca.uhn.fhir.rest.gclient.IQuery)3 Test (org.junit.jupiter.api.Test)2 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)1 ICriterion (ca.uhn.fhir.rest.gclient.ICriterion)1 SmartOnFhirContext (com.healthlx.smartonfhir.core.SmartOnFhirContext)1 AbstractConsentTest (gov.cms.dpc.consent.AbstractConsentTest)1 List (java.util.List)1 ActiveResourcesDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.ActiveResourcesDto)1 GoalQueryFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.query.GoalQueryFactory)1 HealthConcernQueryFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.query.HealthConcernQueryFactory)1 ProblemQueryFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.query.ProblemQueryFactory)1 TaskQueryFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.query.TaskQueryFactory)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1