.forResource(Patient.class) .where(Patient.BIRTHDATE.beforeOrEquals().day("2011-01-01")) .and(Patient.CAREPROVIDER.hasChainedProperty(Organization.NAME.matches().value("Health"))) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .execute(); .forResource(Patient.class) .where(Patient.ADDRESS.matches().values("Toronto")) .and(Patient.ADDRESS.matches().values("Ontario")) .and(Patient.ADDRESS.matches().values("Canada")) .returnBundle(Bundle.class) .execute(); .encodedJson() .where(Patient.BIRTHDATE.beforeOrEquals().day("2012-01-22")) .and(Patient.BIRTHDATE.after().day("2011-01-01")) .withTag("http://acme.org/codes", "needs-review") .include(Patient.INCLUDE_ORGANIZATION.asRecursive())
public static void main(String[] theArgs) { FhirContext ctx = FhirContext.forDstu3(); IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3"); // Build a search and execute it Bundle response = client.search() .forResource(Patient.class) .where(Patient.NAME.matches().value("Test")) .and(Patient.BIRTHDATE.before().day("2014-01-01")) .count(100) .returnBundle(Bundle.class) .execute(); // How many resources did we find? System.out.println("Responses: " + response.getTotal()); // Print the ID of the first one System.out.println("First response ID: " + response.getEntry().get(0).getResource().getId()); } }
/** * General purpose fluent find * * @param clazz Resource class to find * @param criterion Criterion to be applied to the query. Must include a patient matching criterion * @param <T> Resource * @return A list of resource matching the criterion */ public <T extends IBaseResource> Collection<T> find(Class<T> clazz, ICriterion<?>... criterion) { String patientId = session.getContext().getPatientResource().getId().getIdPart(); IQuery<Bundle> queryBuilder = session.search().forResource(clazz); // use reflection to match the getPatientContext criterion queryBuilder.where(findPatientReferenceOnResource(clazz).hasId(patientId)); for (ICriterion<?> theCriterion : criterion) { queryBuilder = queryBuilder.and(theCriterion); } Bundle results = queryBuilder.execute(); return asCollection(results); }
/** * General purpose find * * @param clazz Resource class to find * @param criterion Criterion to be applied to the query. Must include a patient matching criterion * @param <T> Resource * @return A list of resource matching the criterion */ public <T extends IResource> Collection<T> find(Class<T> clazz, ICriterion<?>... criterion) { String patientId = session.getContextDSTU2().getPatientResource().getIdElement().getIdPart(); IQuery<ca.uhn.fhir.model.api.Bundle> queryBuilder = session.search().forResource(clazz); // use reflection to match the getPatientContext criterion queryBuilder.where(findPatientReferenceOnResource(clazz).hasId(patientId)); for (ICriterion<?> theCriterion : criterion) { queryBuilder = queryBuilder.and(theCriterion); } IClientExecutable<IQuery<Bundle>, Bundle> results = queryBuilder.returnBundle(Bundle.class); return asCollection(results.execute()); }
/** * General purpose find * * @param clazz Resource class to find * @param criterion Criterion to be applied to the query. Must include a patient matching criterion * @param <T> Resource * @return A list of resource matching the criterion */ public <T extends IBaseResource> Collection<T> find(Class<T> clazz, ICriterion<?>... criterion) { String patientId = session.getContextSTU3().getPatientResource().getIdElement().getIdPart(); IQuery<ca.uhn.fhir.model.api.Bundle> queryBuilder = session.search().forResource(clazz); // use reflection to match the getPatientContext criterion queryBuilder.where(findPatientReferenceOnResource(clazz).hasId(patientId)); for (ICriterion<?> theCriterion : criterion) { queryBuilder = queryBuilder.and(theCriterion); } IClientExecutable<IQuery<Bundle>, Bundle> results = queryBuilder.returnBundle(Bundle.class); return asCollection(results.execute()); }
@Test public void testSendManualPdqmWithBirthdayRange() { Bundle result = client.search() .forResource(PdqPatient.class) .where(PdqPatient.BIRTHDATE.exactly().day("2011-12-31")) .and(PdqPatient.FAMILY.matches().value("Miller")) .returnBundle(Bundle.class) .execute(); assertEquals(Bundle.BundleType.SEARCHSET, result.getType()); assertEquals(ResourceType.Bundle, result.getResourceType()); assertTrue(result.hasEntry()); }