AgainstSchema() public static method

public static AgainstSchema ( Hl7.Fhir.Model.Resource resource ) : Hl7.Fhir.Model.OperationOutcome
resource Hl7.Fhir.Model.Resource
return Hl7.Fhir.Model.OperationOutcome
Beispiel #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));
            }
        }