Beispiel #1
0
        private Snapshot CreateSnapshot(Uri selflink, IEnumerable <string> keys, SearchParams searchCommand)
        {
            string sort = GetFirstSort(searchCommand);

            int?count = searchCommand.Count;

            if (count.HasValue)
            {
                //TODO: should we change count?
                //count = Math.Min(searchCommand.Count.Value, MAX_PAGE_SIZE);
                selflink = selflink.AddParam(SearchParams.SEARCH_PARAM_COUNT, new string[] { count.ToString() });
            }

            if (searchCommand.Sort.Any())
            {
                foreach (Tuple <string, SortOrder> tuple in searchCommand.Sort)
                {
                    selflink = selflink.AddParam(SearchParams.SEARCH_PARAM_SORT,
                                                 string.Format("{0}:{1}", tuple.Item1, tuple.Item2 == SortOrder.Ascending ? "asc" : "desc"));
                }
            }

            if (searchCommand.Include.Any())
            {
                selflink = selflink.AddParam(SearchParams.SEARCH_PARAM_INCLUDE, searchCommand.Include.ToArray());
            }

            if (searchCommand.RevInclude.Any())
            {
                selflink = selflink.AddParam(SearchParams.SEARCH_PARAM_REVINCLUDE, searchCommand.RevInclude.ToArray());
            }

            return(Snapshot.Create(Bundle.BundleType.Searchset, selflink, keys, sort, count, searchCommand.Include, searchCommand.RevInclude));
        }
Beispiel #2
0
        // Given a set of version id's, go fetch a subset of them from the store and build a Bundle

        /*private Bundle createBundle(Snapshot snapshot, int start, int count)
         * {
         *  var entryVersionIds = snapshot.Keys.Skip(start).Take(count).ToList();
         *  var pageContents = store.Get(entryVersionIds, snapshot.SortBy).ToList();
         *
         *  var bundle =
         *      BundleEntryFactory.CreateBundleWithEntries(snapshot.FeedTitle, new Uri(snapshot.FeedSelfLink),
         *            "Spark MatchBox Search Engine", null, pageContents);
         *
         *  if (snapshot.Count != Snapshot.NOCOUNT)
         *      bundle.TotalResults = snapshot.Count;
         *  else
         *      bundle.TotalResults = null;
         *
         *  var total = snapshot.Keys.Count();
         *
         *  // If we need paging, add the paging links
         *  if (total > count)
         *      buildLinks(bundle, snapshot, start, count);
         *
         *  return bundle;
         * }
         */

        private static void buildLinks(Bundle bundle, Snapshot snapshot, int start, int count)
        {
            var lastPage = snapshot.Count / count;

            // http://spark.furore.com/fhir/_snapshot/

            Uri baseurl = new Uri(Settings.Endpoint.ToString() + "/" + FhirRestOp.SNAPSHOT);

            bundle.Links.SelfLink =
                baseurl
                .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                .AddParam(FhirParameter.SNAPSHOT_INDEX, start.ToString())
                .AddParam(FhirParameter.COUNT, count.ToString());

            // First
            bundle.Links.FirstLink =
                baseurl
                .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                .AddParam(FhirParameter.SNAPSHOT_INDEX, "0");

            // Last
            bundle.Links.LastLink =
                baseurl
                .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                .AddParam(FhirParameter.SNAPSHOT_INDEX, (lastPage * count).ToString());

            // Only do a Previous if we can go back
            if (start > 0)
            {
                int prevIndex = start - count;
                if (prevIndex < 0)
                {
                    prevIndex = 0;
                }

                bundle.Links.PreviousLink =
                    baseurl
                    .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                    .AddParam(FhirParameter.SNAPSHOT_INDEX, prevIndex.ToString());
            }

            // Only do a Next if we can go forward
            if (start + count < snapshot.Count)
            {
                int nextIndex = start + count;

                bundle.Links.NextLink =
                    baseurl
                    .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                    .AddParam(FhirParameter.SNAPSHOT_INDEX, nextIndex.ToString());
            }
        }
Beispiel #3
0
        private static void buildLinks(Bundle bundle, string snapshotId, int index, int pageSize, int count)
        {
            var lastPage = count / pageSize;

            // http://spark.furore.com/fhir/_snapshot/

            Uri baseurl = new Uri(Settings.Endpoint.ToString() + "/" + FhirRestOp.SNAPSHOT);

            bundle.Links.SelfLink =
                baseurl
                .AddParam(FhirParameter.SNAPSHOT_ID, snapshotId)
                .AddParam(FhirParameter.SNAPSHOT_INDEX, index.ToString())
                .AddParam(FhirParameter.COUNT, pageSize.ToString());

            // First
            bundle.Links.FirstLink =
                baseurl
                .AddParam(FhirParameter.SNAPSHOT_ID, snapshotId)
                .AddParam(FhirParameter.SNAPSHOT_INDEX, "0");

            // Last
            bundle.Links.LastLink =
                baseurl
                .AddParam(FhirParameter.SNAPSHOT_ID, snapshotId)
                .AddParam(FhirParameter.SNAPSHOT_INDEX, (lastPage * pageSize).ToString());

            // Only do a Previous if we can go back
            if (index > 0)
            {
                int prevIndex = index - pageSize;
                if (prevIndex < 0)
                {
                    prevIndex = 0;
                }

                bundle.Links.PreviousLink =
                    baseurl
                    .AddParam(FhirParameter.SNAPSHOT_ID, snapshotId)
                    .AddParam(FhirParameter.SNAPSHOT_INDEX, prevIndex.ToString());
            }

            // Only do a Next if we can go forward
            if (index + pageSize < count)
            {
                int nextIndex = index + pageSize;

                bundle.Links.NextLink =
                    baseurl
                    .AddParam(FhirParameter.SNAPSHOT_ID, snapshotId)
                    .AddParam(FhirParameter.SNAPSHOT_INDEX, nextIndex.ToString());
            }
        }
Beispiel #4
0
        void BuildLinks(Bundle bundle, Snapshot snapshot, int start, int count)
        {
            var lastPage = snapshot.Count / count;
            Uri baseurl  = new Uri(localhost.Base.ToString() + "/" + FhirRestOp.SNAPSHOT);

            bundle.SelfLink =
                baseurl
                .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                .AddParam(FhirParameter.SNAPSHOT_INDEX, start.ToString())
                .AddParam(FhirParameter.COUNT, count.ToString());

            // First
            bundle.FirstLink =
                baseurl
                .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                .AddParam(FhirParameter.SNAPSHOT_INDEX, "0");

            // Last
            bundle.LastLink =
                baseurl
                .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                .AddParam(FhirParameter.SNAPSHOT_INDEX, (lastPage * count).ToString());

            // Only do a Previous if we can go back
            if (start > 0)
            {
                int prevIndex = start - count;
                if (prevIndex < 0)
                {
                    prevIndex = 0;
                }

                bundle.PreviousLink =
                    baseurl
                    .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                    .AddParam(FhirParameter.SNAPSHOT_INDEX, prevIndex.ToString());
            }

            // Only do a Next if we can go forward
            if (start + count < snapshot.Count)
            {
                int nextIndex = start + count;

                bundle.NextLink =
                    baseurl
                    .AddParam(FhirParameter.SNAPSHOT_ID, snapshot.Id)
                    .AddParam(FhirParameter.SNAPSHOT_INDEX, nextIndex.ToString());
            }
        }
Beispiel #5
0
        private HttpWebRequest prepareRequest(string method, Uri uri, object data, IEnumerable <Tag> tags, bool expectBundleResponse)
        {
            byte[] body = null;

            Uri api = uri;

            if (UseFormatParam)
            {
                api = api.AddParam(HttpUtil.RESTPARAM_FORMAT, ContentType.BuildFormatParam(PreferredFormat));
            }

            var req = initializeRequest(api, method);

            if (!UseFormatParam)
            {
                req.Accept = ContentType.BuildContentType(PreferredFormat, forBundle: expectBundleResponse);
            }

            if (data is Binary)
            {
                var bin = (Binary)data;
                body            = bin.Content;
                req.ContentType = bin.ContentType;
            }
            else if (data is Resource)
            {
                body = PreferredFormat == ResourceFormat.Xml ?
                       FhirSerializer.SerializeResourceToXmlBytes((Resource)data) :
                       FhirSerializer.SerializeResourceToJsonBytes((Resource)data);

                req.ContentType = ContentType.BuildContentType(PreferredFormat, false);
            }
            else if (data is Bundle)
            {
                body = PreferredFormat == ResourceFormat.Xml ?
                       FhirSerializer.SerializeBundleToXmlBytes((Bundle)data) :
                       FhirSerializer.SerializeBundleToJsonBytes((Bundle)data);

                req.ContentType = ContentType.BuildContentType(PreferredFormat, true);
            }
            else if (data is TagList)
            {
                body = PreferredFormat == ResourceFormat.Xml ?
                       FhirSerializer.SerializeTagListToXmlBytes((TagList)data) :
                       FhirSerializer.SerializeTagListToJsonBytes((TagList)data);

                req.ContentType = ContentType.BuildContentType(PreferredFormat, false);
            }

            if (tags != null)
            {
                req.Headers[HttpUtil.CATEGORY] = HttpUtil.BuildCategoryHeader(tags);
            }

            if (body != null)
            {
                writeBody(req, body);
            }
            return(req);
        }
Beispiel #6
0
        private static Snapshot CreateSnapshot(Uri selflink, IList <string> keys, SearchParams searchCommand)
        {
            var sort = GetFirstSort(searchCommand);

            var count = searchCommand.Count;

            if (count.HasValue)
            {
                //TODO: should we change count?
                //count = Math.Min(searchCommand.Count.Value, MAX_PAGE_SIZE);
                selflink = selflink.AddParam(SearchParams.SEARCH_PARAM_COUNT, count.ToString());
            }

            if (searchCommand.Sort.Any())
            {
                foreach (var(item1, sortOrder) in searchCommand.Sort)
                {
                    selflink = selflink.AddParam(
                        SearchParams.SEARCH_PARAM_SORT,
                        $"{item1}:{(sortOrder == SortOrder.Ascending ? "asc" : "desc")}");
                }
            }

            if (searchCommand.Include.Any())
            {
                selflink = selflink.AddParam(
                    SearchParams.SEARCH_PARAM_INCLUDE,
                    searchCommand.Include.Select(inc => inc.Item1).ToArray());
            }

            if (searchCommand.RevInclude.Any())
            {
                selflink = selflink.AddParam(
                    SearchParams.SEARCH_PARAM_REVINCLUDE,
                    searchCommand.RevInclude.Select(inc => inc.Item1).ToArray());
            }

            return(Snapshot.Create(
                       Bundle.BundleType.Searchset,
                       selflink,
                       keys,
                       sort,
                       count,
                       searchCommand.Include.Select(inc => inc.Item1).ToList(),
                       searchCommand.RevInclude.Select(inc => inc.Item1).ToList()));
        }
Beispiel #7
0
        public Snapshot CreateSnapshot(Uri selflink, IEnumerable <string> keys, SearchParams searchCommand)
        {
            string sort = GetFirstSort(searchCommand);

            int?count = null;

            if (searchCommand.Count.HasValue)
            {
                count    = Math.Min(searchCommand.Count.Value, MAX_PAGE_SIZE);
                selflink = selflink.AddParam(SearchParams.SEARCH_PARAM_COUNT, new string[] { count.ToString() });
            }

            if (string.IsNullOrEmpty(sort) == false)
            {
                selflink = selflink.AddParam(SearchParams.SEARCH_PARAM_SORT, new string[] { sort });
            }

            if (searchCommand.Include.Any())
            {
                selflink = selflink.AddParam(SearchParams.SEARCH_PARAM_INCLUDE, searchCommand.Include.ToArray());
            }

            return(CreateSnapshot(Bundle.BundleType.Searchset, selflink, keys, sort, count, searchCommand.Include));
        }
Beispiel #8
0
 private Uri BuildSnapshotPageLink(Uri baseurl, string snapshotId, int snapshotIndex)
 {
     return(baseurl
            .AddParam(FhirParameter.SNAPSHOT_ID, snapshotId)
            .AddParam(FhirParameter.SNAPSHOT_INDEX, snapshotIndex.ToString()));
 }