Package ca.uhn.fhir.model.api

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


    }
    return bundle;
  }

  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);
      do {
        List<IResource> addedResourcesThisPass = new ArrayList<IResource>();

        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);
                addedResourcesThisPass.add(nextRes);
              }

              nextRef.setResource(null);
              nextRef.setReference(id);
            }
          }
        }

        // Linked resources may themselves have linked resources
        references = new ArrayList<ResourceReferenceDt>();
        for (IResource iResource : addedResourcesThisPass) {
          List<ResourceReferenceDt> newReferences = theContext.newTerser().getAllPopulatedChildElementsOfType(iResource, ResourceReferenceDt.class);
          references.addAll(newReferences);
        }

        addedResources.addAll(addedResourcesThisPass);

      } while (references.isEmpty() == false);

      bundle.addResource(next, theContext, theServerBase);

    }

    /*
     * Actually add the resources to the bundle
     */
    for (IResource next : addedResources) {
      bundle.addResource(next, theContext, theServerBase);
    }

    bundle.getTotalResults().setValue(theTotalResults);
    return bundle;
  }
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

  @Override
  public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
    FhirContext context = getContext();
    if (theArgs[myTransactionParamIndex] instanceof Bundle) {
      Bundle bundle = (Bundle) theArgs[myTransactionParamIndex];
      return createTransactionInvocation(bundle, context);
    } else {
      @SuppressWarnings("unchecked")
      List<IResource> resources = (List<IResource>) theArgs[myTransactionParamIndex];
      return createTransactionInvocation(resources, context);
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

        contentType = encoding.getResourceContentType();
      } else if (myBundle != null) {
        contents = parser.encodeBundleToString(myBundle);
        contentType = encoding.getBundleContentType();
      } else if (myResources != null) {
        Bundle bundle = RestfulServer.createBundleFromResourceList(myContext, "", myResources, "", "", myResources.size());
        contents = parser.encodeBundleToString(bundle);
        contentType = encoding.getBundleContentType();
      } else if (myContents != null) {
        contents = myContents;
        if (myContentsIsBundle) {
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(binding, invocation);
    return resp;

  }
View Full Code Here

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

    BundleResponseHandler binding = new BundleResponseHandler(theType);
    Bundle resp = invokeClient(binding, invocation);
    return resp;
  }
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.