Package ca.uhn.fhir.model.api

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


  public Object invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException {
    IParser parser = createAppropriateParser(theResponseMimeType, theResponseReader, theResponseStatusCode);

    switch (getReturnType()) {
    case BUNDLE: {
      Bundle bundle = parser.parseBundle(theResponseReader);
      switch (getMethodReturnType()) {
      case BUNDLE:
        return bundle;
      case LIST_OF_RESOURCES:
        return bundle.toListOfResources();
      case RESOURCE:
        List<IResource> list = bundle.toListOfResources();
        if (list.size() == 0) {
          return null;
        } else if (list.size() == 1) {
          return list.get(0);
        } else {
View Full Code Here


    theHttpResponse.setCharacterEncoding("UTF-8");

    theServer.addHapiHeader(theHttpResponse);

    Bundle bundle = new Bundle();
    bundle.getAuthorName().setValue(getClass().getCanonicalName());
    bundle.getBundleId().setValue(UUID.randomUUID().toString());
    bundle.getPublished().setToCurrentTimeInLocalTimeZone();
    bundle.getLinkBase().setValue(theServerBase);
    bundle.getLinkSelf().setValue(theCompleteUrl);

    for (IResource next : theResult) {
      BundleEntry entry = new BundleEntry();
      bundle.getEntries().add(entry);

      entry.setResource(next);

      RuntimeResourceDefinition def = getContext().getResourceDefinition(next);

      if (next.getId() != null && StringUtils.isNotBlank(next.getId().getValue())) {
        entry.getId().setValue(next.getId().getValue());
        entry.getTitle().setValue(def.getName() + " " + next.getId().getValue());

        StringBuilder b = new StringBuilder();
        b.append(theServerBase);
        b.append('/');
        b.append(def.getName());
        b.append('/');
        String resId = next.getId().getValue();
        b.append(resId);

        /*
         * If this is a history operation, we add the version of the
         * resource to the self link to indicate the version
         */
        if (getResourceOperationType() == RestfulOperationTypeEnum.HISTORY_INSTANCE || getResourceOperationType() == RestfulOperationTypeEnum.HISTORY_TYPE || getSystemOperationType() == RestfulOperationSystemEnum.HISTORY_SYSTEM) {
          IdDt versionId = getIdFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.VERSION_ID);
          if (versionId != null) {
            b.append('/');
            b.append(Constants.PARAM_HISTORY);
            b.append('/');
            b.append(versionId.getValue());
          } else {
            throw new InternalErrorException("Server did not provide a VERSION_ID in the resource metadata for resource with ID " + resId);
          }
        }

        InstantDt published = getInstantFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.PUBLISHED);
        if (published == null) {
          entry.getPublished().setToCurrentTimeInLocalTimeZone();
        } else {
          entry.setPublished(published);
        }

        InstantDt updated = getInstantFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.UPDATED);
        if (updated != null) {
          entry.setUpdated(updated);
        }

        boolean haveQ = false;
        if (thePrettyPrint) {
          b.append('?').append(Constants.PARAM_PRETTY).append("=true");
          haveQ = true;
        }
        if (theResponseEncoding == EncodingUtil.JSON) {
          if (!haveQ) {
            b.append('?');
            haveQ = true;
          } else {
            b.append('&');
          }
          b.append(Constants.PARAM_FORMAT).append("=json");
        }
        if (theNarrativeMode != NarrativeModeEnum.NORMAL) {
          b.append(Constants.PARAM_NARRATIVE).append("=").append(theNarrativeMode.name().toLowerCase());
        }
        entry.getLinkSelf().setValue(b.toString());
      }
    }

    bundle.getTotalResults().setValue(theResult.size());

    PrintWriter writer = theHttpResponse.getWriter();
    try {
      if (theNarrativeMode == NarrativeModeEnum.ONLY) {
        for (IResource next : theResult) {
View Full Code Here

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

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

  }
View Full Code Here

    parseBundleChildren(object, state);

    state.endingElement();

    Bundle retVal = state.getObject();

    return retVal;
  }
View Full Code Here

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

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

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

   
  }

  @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);

    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");
      }

      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

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.