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); } }
org.hl7.fhir.dstu3.model.Bundle response = client .search() .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) Bundle response = client .search() .forResource(ConceptMap.class) .where(ConceptMap.URL.matches().value(conceptMapUrl)) .returnBundle(Bundle.class)
@Override public IBaseResource getResource(IIdType payloadId) throws ResourceGoneException { RuntimeResourceDefinition resourceDef = myFhirContext.getResourceDefinition(payloadId.getResourceType()); return myClient.search().forResource(resourceDef.getName()).withIdAndCompartment(payloadId.getIdPart(), payloadId.getResourceType()).execute(); } }
@Override public IBundleProvider search(SearchParameterMap theParams) { FhirContext fhirContext = myClient.getFhirContext(); IBaseBundle bundle = myClient .search() .forResource(ResourceTypeEnum.SEARCHPARAMETER.getCode()) .cacheControl(new CacheControlDirective().setNoCache(true)) .execute(); return new SimpleBundleProvider(BundleUtil.toListOfResources(fhirContext, bundle)); }
@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 } }
.forResource(MyPatient.class) .returnBundle(Bundle.class) .execute();
.forResource(Patient.class) .where(Patient.BIRTHDATE.beforeOrEquals().day("2011-01-01")) .and(Patient.CAREPROVIDER.hasChainedProperty(Organization.NAME.matches().value("Health"))) .forResource(Patient.class) .where(Patient.FAMILY.matches().values("Smith", "Smyth")) .returnBundle(Bundle.class) .forResource(Patient.class) .where(Patient.ADDRESS.matches().values("Toronto")) .and(Patient.ADDRESS.matches().values("Ontario")) .forResource(Patient.class) .withIdAndCompartment("123", "condition") .where(Patient.ADDRESS.matches().values("Toronto")) .forResource(Patient.class) .where(Patient.ADDRESS.matches().values("Toronto")) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .forResource(Patient.class) .where(Patient.ADDRESS.matches().values("Toronto")) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .forResource(Patient.class) .encodedJson() .where(Patient.BIRTHDATE.beforeOrEquals().day("2012-01-22")) .forResource("Patient")
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; }
/** * Fetch multiple instances of the domain class from the data store. */ @Override public <T extends BaseResource> List<T> fetchObjects(Class<T> clazz, String[] ids) { if (ids == null || ids.length == 0) { return Collections.emptyList(); } StringClientParam param = new StringClientParam(BaseResource.SP_RES_ID); Bundle results = fhirClient.search().forResource(clazz).where(param.matches().values(ids)).returnBundle(Bundle.class) .execute(); return FhirUtil.getEntries(results, clazz); }
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 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()); }