private boolean hasLink(String theLinkType, Bundle theBundle) { for (Link next : theBundle.getLink()) { if (theLinkType.equals(next.getRelation())) { return true; } } return false; }
public static void fetchRestOfBundle(IGenericClient theClient, Bundle theBundle) { // we need to keep track of which resources are already in the bundle so that if other resources (e.g. Practitioner) are _included, // we don't end up with multiple copies Set<String> resourcesAlreadyAdded = new HashSet<String>(); addInitialUrlsToSet(theBundle, resourcesAlreadyAdded); Bundle partialBundle = theBundle; for (;;) { if (partialBundle.getLink(IBaseBundle.LINK_NEXT) != null) { partialBundle = theClient.loadPage().next(partialBundle).execute(); addAnyResourcesNotAlreadyPresentToBundle(theBundle, partialBundle, resourcesAlreadyAdded); } else { break; } } // the self and next links for the aggregated bundle aren't really valid anymore, so remove them theBundle.getLink().clear(); }
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 } }
/** * Adds a given new value for <b>link</b> () * * <p> * <b>Definition:</b> * A series of links that provide context to this bundle * </p> * @param theValue The link to add (must not be <code>null</code>) */ public Bundle addLink(Link theValue) { if (theValue == null) { throw new NullPointerException("theValue must not be null"); } getLink().add(theValue); return this; }
private boolean hasLink(String theLinkType, Bundle theBundle) { for (Link next : theBundle.getLink()) { if (theLinkType.equals(next.getRelation())) { return true; } } return false; }
/** * Adds and returns a new value for <b>link</b> () * * <p> * <b>Definition:</b> * A series of links that provide context to this bundle * </p> */ public Link addLink() { Link newType = new Link(); getLink().add(newType); return newType; }
/** * Returns the {@link #getLink() link} which matches a given {@link Link#getRelation() relation}. * If no link is found which matches the given relation, returns <code>null</code>. If more than one * link is found which matches the given relation, returns the first matching Link. * * @param theRelation * The relation, such as "next", or "self. See the constants such as {@link IBaseBundle#LINK_SELF} and {@link IBaseBundle#LINK_NEXT}. * @return Returns a matching Link, or <code>null</code> * @see IBaseBundle#LINK_NEXT * @see IBaseBundle#LINK_PREV * @see IBaseBundle#LINK_SELF */ public Link getLink(String theRelation) { org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty"); for (Link next : getLink()) { if (theRelation.equals(next.getRelation())) { return next; } } return null; }
/** * Returns the {@link #getLink() link} which matches a given {@link Link#getRelation() relation}. * If no link is found which matches the given relation, creates a new Link with the * given relation and adds it to this Bundle. If more than one * link is found which matches the given relation, returns the first matching Link. * * @param theRelation * The relation, such as "next", or "self. See the constants such as {@link IBaseBundle#LINK_SELF} and {@link IBaseBundle#LINK_NEXT}. * @return Returns a matching Link, or <code>null</code> * @see IBaseBundle#LINK_NEXT * @see IBaseBundle#LINK_PREV * @see IBaseBundle#LINK_SELF */ public Link getLinkOrCreate(String theRelation) { org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty"); for (Link next : getLink()) { if (theRelation.equals(next.getRelation())) { return next; } } Link retVal = new Link(); retVal.setRelation(theRelation); getLink().add(retVal); return retVal; }