Пример #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 Conformance()
        {
            var conformance = DependencyCoupler.Inject <Conformance>();

            return(Respond.WithResource(conformance));

            // DSTU2: conformance
            //var conformance = ConformanceBuilder.Build();

            //return Respond.WithResource(conformance);

            //var entry = new ResourceEntry<Conformance>(KeyHelper.NewCID(), DateTimeOffset.Now, conformance);
            //return entry;

            //Uri location =
            //     ResourceIdentity.Build(
            //        ConformanceBuilder.CONFORMANCE_COLLECTION_NAME,
            //        ConformanceBuilder.CONFORMANCE_ID
            //    ).OperationPath;

            //BundleEntry conformance = _store.FindEntryById(location);

            //if (conformance == null || !(conformance is ResourceEntry))
            //{
            //    throw new SparkException(
            //        HttpStatusCode.InternalServerError,
            //        "Cannot find an installed conformance statement for this server. Has it been initialized?");
            //}
            //else
            //    return (ResourceEntry)conformance;
        }
Пример #3
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));
        }
Пример #4
0
        public FhirResponse History(string type, DateTimeOffset?since, string sortby)
        {
            Validate.TypeName(type);
            Uri link = localhost.Uri(type, RestOperation.HISTORY);

            IEnumerable <string> keys = store.History(type, since);
            var    snapshot           = pager.CreateSnapshot(Bundle.BundleType.History, link, keys, sortby);
            Bundle bundle             = pager.GetFirstPage(snapshot);

            return(Respond.WithResource(bundle));
        }
Пример #5
0
        public FhirResponse ServerOperation(string operation, Parameters parameters)
        {
            switch (operation.ToLower())
            {
            case "guidance": return(Respond.WithResource(engine.Guidance(parameters)));

            case "error": throw new Exception("This error is for testing purposes");

            default: return(Respond.WithError(HttpStatusCode.NotFound, "Unknown operation"));
            }
        }
Пример #6
0
        public FhirResponse History(string type, HistoryParameters parameters)
        {
            Validate.TypeName(type);
            Uri link = localhost.Uri(type, RestOperation.HISTORY);

            IEnumerable <string> keys = fhirStore.History(type, parameters.Since);
            var    snapshot           = pager.CreateSnapshot(Bundle.BundleType.History, link, keys, parameters.SortBy, parameters.Count, null);
            Bundle bundle             = pager.GetFirstPage(snapshot);

            return(Respond.WithResource(bundle));
        }
Пример #7
0
        public async Task <FhirResponse> Create(IKey key, Resource resource)
        {
            Validate.Key(key);
            Validate.HasTypeName(key);
            Validate.ResourceType(key, resource);

            key = key.CleanupForCreate();
            var result = await Store(Entry.Post(key, resource)).ConfigureAwait(false);

            return(Respond.WithResource(HttpStatusCode.Created, result));
        }
Пример #8
0
        public FhirResponse Create(IKey key, Resource resource)
        {
            Validate.Key(key);
            Validate.HasTypeName(key);
            Validate.ResourceType(key, resource);

            Validate.HasNoResourceId(key);
            Validate.HasNoVersion(key);


            Entry result = Store(Entry.POST(key, resource));

            return(Respond.WithResource(HttpStatusCode.Created, result));
        }
Пример #9
0
        public FhirResponse History(Key key, HistoryParameters parameters)
        {
            if (!fhirStore.Exists(key))
            {
                return(Respond.NotFound(key));
            }

            Uri link = localhost.Uri(key);

            IEnumerable <string> keys = fhirStore.History(key, parameters.Since);
            var    snapshot           = pager.CreateSnapshot(Bundle.BundleType.History, link, keys, parameters.SortBy, parameters.Count);
            Bundle bundle             = pager.GetFirstPage(snapshot);

            return(Respond.WithResource(key, bundle));
        }
Пример #10
0
        public ServerFhirResponse GetFhirResponse(Entry entry, IKey key = null, IEnumerable <object> parameters = null)
        {
            if (entry == null)
            {
                return(Respond.NotFound(key));
            }
            if (entry.IsDeleted())
            {
                return(Respond.Gone(entry));
            }

            ServerFhirResponse response = null;

            return(response ?? Respond.WithResource(entry));
        }
Пример #11
0
        public FhirResponse Put(Entry entry)
        {
            Validate.Key(entry.Key);
            Validate.ResourceType(entry.Key, entry.Resource);
            Validate.HasTypeName(entry.Key);
            Validate.HasResourceId(entry.Key);


            var   storageService = GetFeature <IResourceStorageService>();
            Entry current        = storageService.Get(entry.Key.WithoutVersion());

            Entry result = Store(entry);

            return(Respond.WithResource(current != null ? HttpStatusCode.OK : HttpStatusCode.Created, result));
        }
        public FhirResponse GetFhirResponse(Interaction interaction, IEnumerable <object> parameters = null)
        {
            if (interaction.IsDeleted())
            {
                return(Respond.Gone(interaction));
            }

            FhirResponse response = null;

            if (parameters != null)
            {
                response = interceptorRunner.RunInterceptors(interaction, parameters);
            }

            return(response ?? Respond.WithResource(interaction));
        }
Пример #13
0
        public FhirResponse GetFhirResponse(Entry entry, IEnumerable <object> parameters = null)
        {
            if (entry.IsDeleted())
            {
                return(Respond.Gone(entry));
            }

            FhirResponse response = null;

            if (parameters != null)
            {
                response = interceptorRunner.RunInterceptors(entry, parameters);
            }

            return(response ?? Respond.WithResource(entry));
        }
Пример #14
0
        public FhirResponse Get([FromUri] string type, [FromUri] string id)
        {
            var searchParameters = new Dictionary <String, String>();

            searchParameters.Add("_id", id);
            var cursor = _cursorManager.AcquireCursor(type, searchParameters);

            try
            {
                return(Respond.WithResource(cursor.GetResource()));
            }
            finally
            {
                _cursorManager.ReleaseCursor(cursor);
            }
        }
Пример #15
0
        public FhirResponse Create(Entry entry)
        {
            Validate.Key(entry.Key);
            Validate.HasTypeName(entry.Key);
            Validate.ResourceType(entry.Key, entry.Resource);

            if (entry.State != EntryState.Internal)
            {
                Validate.HasNoResourceId(entry.Key);
                Validate.HasNoVersion(entry.Key);
            }


            Entry result = Store(entry);

            return(Respond.WithResource(HttpStatusCode.Created, result));
        }
Пример #16
0
        public FhirResponse History(Key key, DateTimeOffset?since, string sortby)
        {
            if (!store.Exists(key))
            {
                return(Respond.NotFound(key));
            }

            Uri link = localhost.Uri(key);

            IEnumerable <string> keys = store.History(key, since);
            var    snapshot           = pager.CreateSnapshot(Bundle.BundleType.History, link, keys, sortby);
            Bundle bundle             = pager.GetFirstPage(snapshot);

            bundle.Base = localhost.Base.AbsoluteUri;

            return(Respond.WithResource(key, bundle));
        }
Пример #17
0
        public FhirResponse ValidateOperation(IKey key, Resource resource)
        {
            if (resource == null)
            {
                throw Error.BadRequest("Validate needs a Resource in the body payload");
            }
            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));
            }
        }
Пример #18
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));
        }
Пример #19
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));
        }
Пример #20
0
        /// <summary>
        /// Read the state of a specific version of the resource.
        /// </summary>
        /// <param name="collectionName">The resource type, in lowercase</param>
        /// <param name="id">The id part of a version-specific reference</param>
        /// <param name="vid">The version part of a version-specific reference</param>
        /// <returns>A Result containing the resource, or an Issue</returns>
        /// <remarks>
        /// If the version referred to is actually one where the resource was deleted, the server should return a
        /// 410 status code.
        /// </remarks>
        public FhirResponse VersionRead(Key key)
        {
            Validate.HasTypeName(key);
            Validate.HasResourceId(key);
            Validate.HasVersion(key);
            Validate.Key(key);

            Interaction interaction = store.Get(key);

            if (interaction == null)
            {
                return(Respond.NotFound(key));
            }

            else if (interaction.IsDeleted())
            {
                return(Respond.Gone(interaction));
            }

            transfer.Externalize(interaction);
            return(Respond.WithResource(interaction));
        }
Пример #21
0
        public FhirResponse Conformance(string sparkVersion)
        {
            IConformanceService conformanceService = this.GetFeature <IConformanceService>();

            return(Respond.WithResource(conformanceService.GetSparkConformance(sparkVersion)));
        }
Пример #22
0
        public FhirResponse CapabilityStatement(string sparkVersion)
        {
            ICapabilityStatementService capabilityStatementService = this.GetFeature <ICapabilityStatementService>();

            return(Respond.WithResource(capabilityStatementService.GetSparkCapabilityStatement(sparkVersion)));
        }
Пример #23
0
 public FhirResponse Options()
 {
     return(Respond.WithResource(Factory.GetSparkConformance()));
 }
Пример #24
0
        public Task <FhirResponse> CapabilityStatement(string sparkVersion)
        {
            var response = Respond.WithResource(_capabilityStatementService.GetSparkCapabilityStatement(sparkVersion));

            return(Task.FromResult(response));
        }