Package ca.uhn.fhir.context

Examples of ca.uhn.fhir.context.RuntimeResourceDefinition


      return this;
    }

    private void setType(Class<? extends IResource> theResourceType) {
      myResourceType = theResourceType;
      RuntimeResourceDefinition definition = myContext.getResourceDefinition(theResourceType);
      myResourceName = definition.getName();
    }
View Full Code Here


    BundleEntry entry = addEntry();
    entry.setResource(theResource);

    entry.setResource(theResource);

    RuntimeResourceDefinition def = theContext.getResourceDefinition(theResource);

    if (theResource.getId() != null && StringUtils.isNotBlank(theResource.getId().getValue())) {
      String title = ResourceMetadataKeyEnum.TITLE.get(theResource);
      if (title != null) {
        entry.getTitle().setValue(title);
      } else {
        entry.getTitle().setValue(def.getName() + " " + theResource.getId().getValue());
      }

      StringBuilder b = new StringBuilder();
      b.append(theServerBase);
      if (b.length() > 0 && b.charAt(b.length() - 1) != '/') {
        b.append('/');
      }
      b.append(def.getName());
      b.append('/');
      String resId = theResource.getId().getIdPart();
      b.append(resId);

      entry.getId().setValue(b.toString());

      if (isNotBlank(theResource.getId().getVersionIdPart())) {
        b.append('/');
        b.append(Constants.PARAM_HISTORY);
        b.append('/');
        b.append(theResource.getId().getVersionIdPart());
      } else {
        IdDt versionId = (IdDt) ResourceMetadataKeyEnum.VERSION_ID.get(theResource);
        if (versionId != null) {
          b.append('/');
          b.append(Constants.PARAM_HISTORY);
          b.append('/');
          b.append(versionId.getValue());
        }
      }

      String qualifiedId = b.toString();
      entry.getLinkSelf().setValue(qualifiedId);
     
    }

    InstantDt published = ResourceMetadataKeyEnum.PUBLISHED.get(theResource);
    if (published == null) {
      entry.getPublished().setToCurrentTimeInLocalTimeZone();
    } else {
      entry.setPublished(published);
    }

    InstantDt updated = ResourceMetadataKeyEnum.UPDATED.get(theResource);
    if (updated != null) {
      entry.setUpdated(updated);
    }

    InstantDt deleted = ResourceMetadataKeyEnum.DELETED_AT.get(theResource);
    if (deleted != null) {
      entry.setDeleted(deleted);
    }

    IdDt previous = ResourceMetadataKeyEnum.PREVIOUS_ID.get(theResource);
    if (previous != null) {
      entry.getLinkAlternate().setValue(previous.withServerBase(theServerBase, def.getName()));
    }

    TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(theResource);
    if (tagList != null) {
      for (Tag nextTag : tagList) {
View Full Code Here

  private void encodeResourceToXmlStreamWriter(IResource theResource, XMLStreamWriter theEventWriter, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
    if (!theIncludedResource) {
      super.containResourcesForEncoding(theResource);
    }

    RuntimeResourceDefinition resDef = myContext.getResourceDefinition(theResource);
    if (resDef == null) {
      throw new ConfigurationException("Unknown resource type: " + theResource.getClass());
    }

    theEventWriter.writeStartElement(resDef.getName());
    theEventWriter.writeDefaultNamespace(FHIR_NS);

    if (theIncludedResource && StringUtils.isNotBlank(theResource.getId().getValue())) {
      theEventWriter.writeAttribute("id", theResource.getId().getValue());
    }
View Full Code Here

      Set<RestfulOperationTypeEnum> resourceOps = new HashSet<RestfulOperationTypeEnum>();
      RestResource resource = rest.addResource();

      String resourceName = next.getResourceName();
      RuntimeResourceDefinition def = myRestfulServer.getFhirContext().getResourceDefinition(resourceName);
      resource.getType().setValue(def.getName());
      resource.getProfile().setReference(new IdDt(def.getResourceProfile()));

      TreeSet<String> includes = new TreeSet<String>();

      // Map<String, Conformance.RestResourceSearchParam> nameToSearchParam = new HashMap<String,
      // Conformance.RestResourceSearchParam>();
      for (BaseMethodBinding<?> nextMethodBinding : next.getMethodBindings()) {
        RestfulOperationTypeEnum resOp = nextMethodBinding.getResourceOperationType();
        if (resOp != null) {
          if (resourceOps.contains(resOp) == false) {
            resourceOps.add(resOp);
            resource.addOperation().setCode(resOp);
          }
        }

        RestfulOperationSystemEnum sysOp = nextMethodBinding.getSystemOperationType();
        if (sysOp != null) {
          if (systemOps.contains(sysOp) == false) {
            systemOps.add(sysOp);
            rest.addOperation().setCode(sysOp);
          }
        }

        if (nextMethodBinding instanceof SearchMethodBinding) {
          SearchMethodBinding searchMethodBinding = (SearchMethodBinding) nextMethodBinding;
          includes.addAll(searchMethodBinding.getIncludes());

          List<IParameter> params = searchMethodBinding.getParameters();
          List<SearchParameter> searchParameters = new ArrayList<SearchParameter>();
          for (IParameter nextParameter : params) {
            if ((nextParameter instanceof SearchParameter)) {
              searchParameters.add((SearchParameter) nextParameter);
            }
          }
          Collections.sort(searchParameters, new Comparator<SearchParameter>() {
            @Override
            public int compare(SearchParameter theO1, SearchParameter theO2) {
              if (theO1.isRequired() == theO2.isRequired()) {
                return theO1.getName().compareTo(theO2.getName());
              }
              if (theO1.isRequired()) {
                return -1;
              }
              return 1;
            }
          });
          if (searchParameters.isEmpty()) {
            continue;
          }
          boolean allOptional = searchParameters.get(0).isRequired() == false;

          RestQuery query = null;
          if (!allOptional) {
            query = rest.addQuery();
            query.getDocumentation().setValue(searchMethodBinding.getDescription());
            query.addUndeclaredExtension(false, ExtensionConstants.QUERY_RETURN_TYPE, new CodeDt(resourceName));
            for (String nextInclude : searchMethodBinding.getIncludes()) {
              query.addUndeclaredExtension(false, ExtensionConstants.QUERY_ALLOWED_INCLUDE, new StringDt(nextInclude));
            }
          }

          for (SearchParameter nextParameter : searchParameters) {

            String nextParamName = nextParameter.getName();

//            String chain = null;
            String nextParamUnchainedName = nextParamName;
            if (nextParamName.contains(".")) {
//              chain = nextParamName.substring(nextParamName.indexOf('.') + 1);
              nextParamUnchainedName = nextParamName.substring(0, nextParamName.indexOf('.'));
            }

            String nextParamDescription = nextParameter.getDescription();

            /*
             * If the parameter has no description, default to the one from the resource
             */
            if (StringUtils.isBlank(nextParamDescription)) {
              RuntimeSearchParam paramDef = def.getSearchParam(nextParamUnchainedName);
              if (paramDef != null) {
                nextParamDescription = paramDef.getDescription();
              }
            }

            RestResourceSearchParam param;
            if (query == null) {
              param = resource.addSearchParam();
            } else {
              param = query.addParameter();
              param.addUndeclaredExtension(false, ExtensionConstants.PARAM_IS_REQUIRED, new BooleanDt(nextParameter.isRequired()));
            }

            param.setName(nextParamName);
//            if (StringUtils.isNotBlank(chain)) {
//              param.addChain(chain);
//            }
            param.setDocumentation(nextParamDescription);
            param.setType(nextParameter.getParamType());
            for (Class<? extends IResource> nextTarget : nextParameter.getDeclaredTypes()) {
              RuntimeResourceDefinition targetDef = myRestfulServer.getFhirContext().getResourceDefinition(nextTarget);
              if (targetDef != null) {
                ResourceTypeEnum code = ResourceTypeEnum.VALUESET_BINDER.fromCodeString(targetDef.getName());
                if (code != null) {
                  param.addTarget(code);
                }
              }
            }
View Full Code Here

    return Profile.class;
  }
 
  @Read()
  public Profile getProfileById(@IdParam IdDt theId) {
    RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getValue());
    if (retVal==null) {
      return null;
    }
    return retVal.toProfile();
  }
View Full Code Here

  public static HttpPostClientInvocation createCreateInvocation(IResource theResource, FhirContext theContext) {
    return createCreateInvocation(theResource, null, null, theContext);
  }

  public static HttpPostClientInvocation createCreateInvocation(IResource theResource, String theResourceBody, String theId, FhirContext theContext) {
    RuntimeResourceDefinition def = theContext.getResourceDefinition(theResource);
    String resourceName = def.getName();

    StringBuilder urlExtension = new StringBuilder();
    urlExtension.append(resourceName);
    if (StringUtils.isNotBlank(theId)) {
      urlExtension.append('/');
View Full Code Here

    BaseHttpClientInvocation invocation = MethodUtil.createCreateInvocation(theResource, myContext);
    if (isKeepResponses()) {
      myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
    }

    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
    final String resourceName = def.getName();

    OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);

    MethodOutcome resp = invokeClient(myContext, binding, invocation, myLogRequestAndResponse);
    return resp;
View Full Code Here

    BaseHttpClientInvocation invocation = MethodUtil.createUpdateInvocation(theResource, null, theIdDt, myContext);
    if (isKeepResponses()) {
      myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
    }

    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
    final String resourceName = def.getName();

    OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);
    MethodOutcome resp = invokeClient(myContext, binding, invocation, myLogRequestAndResponse);
    return resp;
  }
View Full Code Here

    BaseHttpClientInvocation invocation = ValidateMethodBinding.createValidateInvocation(theResource, null, myContext);
    if (isKeepResponses()) {
      myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
    }

    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
    final String resourceName = def.getName();

    OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);
    MethodOutcome resp = invokeClient(myContext, binding, invocation, myLogRequestAndResponse);
    return resp;
  }
View Full Code Here

      writeAuthor(nextEntry, eventWriter);

      IResource resource = nextEntry.getResource();
      if (resource != null && !resource.isEmpty() && !deleted) {
        RuntimeResourceDefinition resDef = myContext.getResourceDefinition(resource);
        encodeResourceToJsonStreamWriter(resDef, resource, eventWriter, "content", false);
      }

      eventWriter.writeEnd(); // entry object
    }
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.context.RuntimeResourceDefinition

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.