public static void main(String[] args) throws Exception { FhirContext ctx = FhirContext.forDstu2(); String serverBase = "http://fhirtest.uhn.ca/baseDstu2"; IGenericClient client = ctx.newRestfulGenericClient(serverBase); // use RelatedPerson because there aren't that many on the server Bundle bundle = client.search().forResource(RelatedPerson.class).returnBundle(Bundle.class).execute(); BundleFetcher.fetchRestOfBundle(client, bundle); if (bundle.getTotal() != bundle.getEntry().size()) { System.out.println("Counts didn't match! Expected " + bundle.getTotal() + " but bundle only had " + bundle.getEntry().size() + " entries!"); } // IParser parser = ctx.newXmlParser().setPrettyPrint(true); // System.out.println(parser.encodeResourceToString(bundle)); } }
public static void simpleExample() { // START SNIPPET: simple // We're connecting to a DSTU1 compliant server in this example FhirContext ctx = FhirContext.forDstu2(); String serverBase = "http://fhirtest.uhn.ca/baseDstu2"; IGenericClient client = ctx.newRestfulGenericClient(serverBase); // Perform a search Bundle results = client .search() .forResource(Patient.class) .where(Patient.FAMILY.matches().value("duck")) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .execute(); System.out.println("Found " + results.getEntry().size() + " patients named 'duck'"); // END SNIPPET: simple }
private static void copy(FhirContext theCtx, IGenericClient theSource, IGenericClient theTarget, String theResType, List<IBaseResource> theQueued, Set<String> theSent) { Bundle received = theSource .search() .forResource(theResType) .returnBundle(Bundle.class) .execute(); copy(theCtx, theTarget, theResType, theQueued, theSent, received); while (received.getLink("next") != null) { ourLog.info("Fetching next page..."); received = theSource.loadPage().next(received).execute(); copy(theCtx, theTarget, theResType, theQueued, theSent, received); } }
.forResource(org.hl7.fhir.dstu3.model.ConceptMap.class) .where(org.hl7.fhir.dstu3.model.ConceptMap.URL.matches().value(conceptMapUrl)) .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) .execute(); .forResource(ConceptMap.class) .where(ConceptMap.URL.matches().value(conceptMapUrl)) .returnBundle(Bundle.class) .execute();
@SuppressWarnings("unused") public void cacheControl() { FhirContext ctx = FhirContext.forDstu3(); // Create the client IGenericClient client = ctx.newRestfulGenericClient("http://localhost:9999/fhir"); Bundle bundle = new Bundle(); // ..populate the bundle.. // START SNIPPET: cacheControl Bundle response = client .search() .forResource(Patient.class) .returnBundle(Bundle.class) .cacheControl(new CacheControlDirective().setNoCache(true)) // <-- add a directive .execute(); // END SNIPPET: cacheControl }
private static void paging() { { // START SNIPPET: searchPaging FhirContext ctx = FhirContext.forDstu2(); IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2"); // Perform a search Bundle resultBundle = client.search() .forResource(Patient.class) .where(Patient.NAME.matches().value("Smith")) .returnBundle(Bundle.class) .execute(); if (resultBundle.getLink(Bundle.LINK_NEXT) != null) { // load next page Bundle nextPage = client.loadPage().next(resultBundle).execute(); } // END SNIPPET: searchPaging } }
.search() .forResource(MyPatient.class) .returnBundle(Bundle.class) .execute();
/** * Alternative method for performing a search that allows for external configuration of the * query object. * * @param query The query object. * @return List of matching resources. May return null to indicate no matches. */ @Override public List<R> search(IQuery<?> query) { return FhirUtil.getEntries(query.returnBundle(Bundle.class).execute(), resourceClass); } }
.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.FAMILY.matches().values("Smith", "Smyth")) .returnBundle(Bundle.class) .execute(); .and(Patient.ADDRESS.matches().values("Ontario")) .and(Patient.ADDRESS.matches().values("Canada")) .returnBundle(Bundle.class) .execute(); .withIdAndCompartment("123", "condition") .where(Patient.ADDRESS.matches().values("Toronto")) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .execute(); .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .execute(); .forResource(Patient.class) .where(Patient.ADDRESS.matches().values("Toronto")) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .summaryMode(SummaryEnum.TRUE) .execute();
public DefaultNamingSystemServiceImpl addNamingSystemsFromFhirServer(String url) { addNamingSystems(fhirContext.newRestfulGenericClient(url) .search() .forResource(NamingSystem.class) .returnBundle(Bundle.class) .execute()); return this; }
public DefaultNamingSystemServiceImpl addNamingSystemsFromFhirServer(String url) { addNamingSystems(fhirContext.newRestfulGenericClient(url) .search() .forResource(NamingSystem.class) .returnBundle(Bundle.class) .execute()); return this; }
@Override public void run(ThreadEx thread) throws Exception { Bundle bundle = fhirService.getClient().search().byUrl(url).returnBundle(Bundle.class).execute(); thread.setAttribute("bundle", bundle); }
protected Bundle sendManually(ICriterion<?> requestData) { return client.search() .forResource(DocumentReference.class) .where(requestData) .returnBundle(Bundle.class) .execute(); }
protected Bundle sendManually(ICriterion<?> requestData) { return client.search() .forResource(DocumentReference.class) .where(requestData) .returnBundle(Bundle.class) .execute(); }
protected Bundle sendManually(ICriterion<?> requestData) { return client.search() .forResource(PdqPatient.class) .where(requestData) .returnBundle(Bundle.class) .execute(); }
protected Bundle sendManually(ICriterion<?> requestData) { return client.search() .forResource(DocumentManifest.class) .where(requestData) .returnBundle(Bundle.class) .execute(); }
protected Bundle sendManually(ICriterion<?> requestData) { return client.search() .forResource(PdqPatient.class) .where(requestData) .returnBundle(Bundle.class) .execute(); }
protected Bundle sendManuallyWithCount(ICriterion<?> requestData, int count) { return client.search() .forResource(PdqPatient.class) .where(requestData) .count(count) .returnBundle(Bundle.class) .execute(); }
protected Bundle sendManuallyWithCount(ICriterion<?> requestData, int count) { return client.search() .forResource(PdqPatient.class) .where(requestData) .count(count) .returnBundle(Bundle.class) .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()); }