ResourceType() 공개 정적인 메소드

public static ResourceType ( IKey key, Hl7.Fhir.Model.Resource resource ) : void
key IKey
resource Hl7.Fhir.Model.Resource
리턴 void
예제 #1
0
        /*
         * public TagList TagsFromServer()
         * {
         *  IEnumerable<Tag> tags = tagstore.Tags();
         *  return new TagList(tags);
         * }
         *
         * public TagList TagsFromResource(string resourcetype)
         * {
         *  RequestValidator.ValidateCollectionName(resourcetype);
         *  IEnumerable<Tag> tags = tagstore.Tags(resourcetype);
         *  return new TagList(tags);
         * }
         *
         *
         * public TagList TagsFromInstance(string collection, string id)
         * {
         *  Uri key = BuildKey(collection, id);
         *  BundleEntry entry = store.Get(key);
         *
         *  if (entry == null)
         *      throwNotFound("Cannot retrieve tags because entry {0}/{1} does not exist", collection, id);
         *
         *  return new TagList(entry.Tags);
         * }
         *
         *
         * public TagList TagsFromHistory(string collection, string id, string vid)
         * {
         *  Uri key = BuildKey(collection, id, vid);
         *  BundleEntry entry = store.Get(key);
         *
         *  if (entry == null)
         *      throwNotFound("Cannot retrieve tags because entry {0}/{1} does not exist", collection, id, vid);
         *
         *  else if (entry is DeletedEntry)
         *  {
         *      throw new SparkException(HttpStatusCode.Gone,
         *          "A {0} resource with version {1} and id {2} exists, but it is a deletion (deleted on {3}).",
         *          collection, vid, id, (entry as DeletedEntry).When);
         *  }
         *
         *  return new TagList(entry.Tags);
         * }
         *
         * public void AffixTags(string collection, string id, IEnumerable<Tag> tags)
         * {
         *  if (tags == null) throw new SparkException("No tags specified on the request");
         *  Uri key = BuildKey(collection, id);
         *  BundleEntry entry = store.Get(key);
         *
         *  if (entry == null)
         *      throw new SparkException(HttpStatusCode.NotFound, "Could not set tags. The resource was not found.");
         *
         *  entry.AffixTags(tags);
         *  store.Add(entry);
         * }
         *
         * public void AffixTags(string collection, string id, string vid, IEnumerable<Tag> tags)
         * {
         *  Uri key = BuildKey(collection, id, vid);
         *  if (tags == null) throw new SparkException("No tags specified on the request");
         *
         *  BundleEntry entry = store.Get(key);
         *  if (entry == null)
         *      throw new SparkException(HttpStatusCode.NotFound, "Could not set tags. The resource was not found.");
         *
         *  entry.AffixTags(tags);
         *  store.Replace(entry);
         * }
         *
         * public void RemoveTags(string collection, string id, IEnumerable<Tag> tags)
         * {
         *  if (tags == null) throw new SparkException("No tags specified on the request");
         *
         *  Uri key = BuildKey(collection, id);
         *  BundleEntry entry = store.Get(key);
         *  if (entry == null)
         *      throw new SparkException(HttpStatusCode.NotFound, "Could not set tags. The resource was not found.");
         *
         *  if (entry.Tags != null)
         *  {
         *      entry.Tags = entry.Tags.Exclude(tags).ToList();
         *  }
         *
         *  store.Replace(entry);
         * }
         *
         * public void RemoveTags(string collection, string id, string vid, IEnumerable<Tag> tags)
         * {
         *  if (tags == null) throw new SparkException("Can not delete tags if no tags specified were specified");
         *
         *  Uri key = BuildKey(collection, id, vid);
         *
         *  ResourceEntry entry = (ResourceEntry)store.Get(key);
         *  if (entry == null)
         *      throw new SparkException(HttpStatusCode.NotFound, "Could not set tags. The resource was not found.");
         *
         *
         *  if (entry.Tags != null)
         *      entry.Tags = entry.Tags.Exclude(tags).ToList();
         *
         *  store.Replace(entry);
         * }
         */

        public FhirResponse ValidateOperation(Key key, Resource resource)
        {
            if (resource == null)
            {
                throw Error.BadRequest("Validate needs a Resource in the body payload");
            }
            //if (entry.Resource == null) throw new SparkException("Validate needs a Resource in the body payload");

            //  DSTU2: validation
            // entry.Resource.Title = "Validation test entity";
            // entry.LastUpdated = DateTime.Now;
            // entry.Id = id != null ? ResourceIdentity.Build(Endpoint, collection, id) : null;

            Validate.ResourceType(key, resource);

            // DSTU2: validation
            var outcome = Validate.AgainstSchema(resource);

            if (outcome == null)
            {
                return(Respond.WithCode(HttpStatusCode.OK));
            }
            else
            {
                return(Respond.WithResource(422, outcome));
            }
        }
예제 #2
0
        public FhirResponse Put(IKey key, Resource resource)
        {
            Validate.Key(key);
            Validate.ResourceType(key, resource);
            Validate.HasTypeName(key);
            Validate.HasResourceId(key);
            Validate.HasResourceId(resource);
            Validate.IsResourceIdEqual(key, resource);

            Entry current = fhirStore.Get(key);

            Entry entry = Entry.PUT(key, resource);

            transfer.Internalize(entry);


            Store(entry);

            // API: The api demands a body. This is wrong
            //CCR: The documentations specifies that servers should honor the Http return preference header
            Entry result = fhirStore.Get(entry.Key);

            transfer.Externalize(result);

            return(Respond.WithResource(current != null ? HttpStatusCode.OK : HttpStatusCode.Created, result));
        }
예제 #3
0
        /// <summary>
        /// Create a new resource with a server assigned id.
        /// </summary>
        /// <param name="collection">The resource type, in lowercase</param>
        /// <param name="resource">The data for the Resource to be created</param>
        /// <returns>
        /// Returns
        ///     201 Created - on successful creation
        /// </returns>
        public FhirResponse Create(IKey key, Resource resource)
        {
            Validate.Key(key);
            Validate.ResourceType(key, resource);
            Validate.HasTypeName(key);
            Validate.HasNoResourceId(key);
            Validate.HasNoVersion(key);

            Interaction interaction = Interaction.POST(key, resource);

            transfer.Internalize(interaction);

            Store(interaction);

            // API: The api demands a body. This is wrong
            Interaction result = store.Get(interaction.Key);

            transfer.Externalize(result);
            return(Respond.WithResource(HttpStatusCode.Created, interaction));
        }
예제 #4
0
        /// <summary>
        /// Create a new resource with a server assigned id.
        /// </summary>
        /// <param name="collection">The resource type, in lowercase</param>
        /// <param name="resource">The data for the Resource to be created</param>
        /// <returns>
        /// Returns
        ///     201 Created - on successful creation
        /// </returns>
        public FhirResponse Create(IKey key, Resource resource)
        {
            Validate.Key(key);
            Validate.ResourceType(key, resource);
            Validate.HasTypeName(key);
            Validate.HasNoResourceId(key);
            Validate.HasNoVersion(key);

            Interaction interaction = Interaction.POST(key, resource);

            transfer.Internalize(interaction);

            Store(interaction);

            // API: The api demands a body. This is wrong
            //CCR: The documentations specifies that servers should honor the Http return preference header
            Interaction result = fhirStore.Get(interaction.Key);

            transfer.Externalize(result);
            return(Respond.WithResource(HttpStatusCode.Created, result));
        }