Package ca.uhn.fhir.model.api

Examples of ca.uhn.fhir.model.api.Bundle


   
  }

  @Override
  public Object translateQueryParametersIntoServerArgument(Request theRequest, Object theRequestContents) throws InternalErrorException, InvalidRequestException {
    Bundle resource = (Bundle) theRequestContents;
   
    ArrayList<IResource> retVal = new ArrayList<IResource>();
    for (BundleEntry next : resource.getEntries()) {
      if (next.getResource() != null) {
        retVal.add(next.getResource());
      }
    }
   
View Full Code Here


  public void setUseBrowserFriendlyContentTypes(boolean theUseBrowserFriendlyContentTypes) {
    myUseBrowserFriendlyContentTypes = theUseBrowserFriendlyContentTypes;
  }

  public static Bundle createBundleFromResourceList(FhirContext theContext, String theAuthor, List<IResource> theResult, String theServerBase, String theCompleteUrl, int theTotalResults) {
    Bundle bundle = new Bundle();
    bundle.getAuthorName().setValue(theAuthor);
    bundle.getBundleId().setValue(UUID.randomUUID().toString());
    bundle.getPublished().setToCurrentTimeInLocalTimeZone();
    bundle.getLinkBase().setValue(theServerBase);
    bundle.getLinkSelf().setValue(theCompleteUrl);

    List<IResource> addedResources = new ArrayList<IResource>();
    Set<IdDt> addedResourceIds = new HashSet<IdDt>();
    for (IResource next : theResult) {

      if (theContext.getNarrativeGenerator() != null) {
        String title = theContext.getNarrativeGenerator().generateTitle(next);
        ourLog.trace("Narrative generator created title: {}", title);
        if (StringUtils.isNotBlank(title)) {
          ResourceMetadataKeyEnum.TITLE.put(next, title);
        }
      } else {
        ourLog.trace("No narrative generator specified");
      }

      List<ResourceReferenceDt> references = theContext.newTerser().getAllPopulatedChildElementsOfType(next, ResourceReferenceDt.class);
      for (ResourceReferenceDt nextRef : references) {
        IResource nextRes = nextRef.getResource();
        if (nextRes != null) {
          if (nextRes.getId().hasIdPart()) {
            IdDt id = nextRes.getId().toVersionless();
            if (id.hasResourceType()==false) {
              String resName = theContext.getResourceDefinition(nextRes).getName();
              id = id.withResourceType(resName);
            }
           
            if (!addedResourceIds.contains(id)) {
              addedResourceIds.add(id);
              addedResources.add(nextRes);
            }
           
            nextRef.setResource(null);
            nextRef.setReference(id);
          }
        }
      }
     
      bundle.addResource(next, theContext, theServerBase);
    }

    for (IResource next : addedResources) {
      bundle.addResource(next, theContext, theServerBase);
    }
   
    bundle.getTotalResults().setValue(theTotalResults);
    return bundle;
  }
View Full Code Here

      if (next.getId() == null || next.getId().isEmpty()) {
        throw new InternalErrorException("Server method returned resource of type[" + next.getClass().getSimpleName() + "] with no ID specified (IResource#setId(IdDt) must be called)");
      }
    }

    Bundle bundle = createBundleFromResourceList(theServer.getFhirContext(), theServer.getServerName(), resourceList, theServerBase, theCompleteUrl, theResult.size());

    bundle.setPublished(theResult.getPublished());

    if (theServer.getPagingProvider() != null) {
      int limit;
      limit = theLimit != null ? theLimit : theServer.getPagingProvider().getDefaultPageSize();
      limit = Math.min(limit, theServer.getPagingProvider().getMaximumPageSize());

      if (searchId != null) {
        if (theOffset + numToReturn < theResult.size()) {
          bundle.getLinkNext().setValue(createPagingLink(theServerBase, searchId, theOffset + numToReturn, numToReturn, theResponseEncoding, thePrettyPrint));
        }
        if (theOffset > 0) {
          int start = Math.max(0, theOffset - limit);
          bundle.getLinkPrevious().setValue(createPagingLink(theServerBase, searchId, start, limit, theResponseEncoding, thePrettyPrint));
        }
      }
    }

    Writer writer = getWriter(theHttpResponse, theRespondGzip);
View Full Code Here

  @Override
  protected Object parseRequestObject(Request theRequest) throws IOException {
    EncodingEnum encoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest());
    IParser parser = encoding.newParser(getContext());
    Bundle bundle = parser.parseBundle(theRequest.getServletRequest().getReader());
    return bundle;
  }
View Full Code Here

    public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
      if (!"feed".equals(theLocalPart)) {
        throw new DataFormatException("Expecting outer element called 'feed', found: " + theLocalPart);
      }

      myInstance = new Bundle();
      push(new AtomState(myInstance, myResourceType));

    }
View Full Code Here

    if (isKeepResponses()) {
      myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
    }

    BundleResponseHandler binding = new BundleResponseHandler(theType);
    Bundle resp = invokeClient(myContext, binding, invocation, myLogRequestAndResponse);
    return resp;

  }
View Full Code Here

    if (isKeepResponses()) {
      myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
    }

    BundleResponseHandler binding = new BundleResponseHandler(theType);
    Bundle resp = invokeClient(myContext, binding, invocation, myLogRequestAndResponse);
    return resp;
  }
View Full Code Here

    BaseHttpClientInvocation invocation = TransactionMethodBinding.createTransactionInvocation(theResources, myContext);
    if (isKeepResponses()) {
      myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
    }

    Bundle resp = invokeClient(myContext, new BundleResponseHandler(null), invocation, myLogRequestAndResponse);

    return resp.toListOfResources();
  }
View Full Code Here

    parseBundleChildren(object, state);

    state.endingElement();

    Bundle retVal = state.getObject();

    return retVal;
  }
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.model.api.Bundle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.