private ResourceElement CreateBundle(SearchResult result, Bundle.BundleType type, Func <ResourceWrapper, Bundle.EntryComponent> selectionFunction) { EnsureArg.IsNotNull(result, nameof(result)); // Create the bundle from the result. var bundle = new Bundle(); if (result != null) { IEnumerable <Bundle.EntryComponent> entries = result.Results.Select(selectionFunction); bundle.Entry.AddRange(entries); if (result.ContinuationToken != null) { bundle.NextLink = _urlResolver.ResolveRouteUrl( result.UnsupportedSearchParameters, Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(result.ContinuationToken))); } } // Add the self link to indicate which search parameters were used. bundle.SelfLink = _urlResolver.ResolveRouteUrl(result.UnsupportedSearchParameters); bundle.Id = _fhirRequestContextAccessor.FhirRequestContext.CorrelationId; bundle.Type = type; bundle.Total = result?.TotalCount; bundle.Meta = new Meta { LastUpdated = Clock.UtcNow, }; return(bundle.ToResourceElement()); }
public static Snapshot Create( Bundle.BundleType type, Uri selflink, IList <string> keys, string sortby, int?count, IList <string> includes, IList <string> reverseIncludes) { var snapshot = new Snapshot { Type = type, Id = CreateKey(), WhenCreated = DateTimeOffset.UtcNow, FeedSelfLink = selflink.ToString(), Includes = includes, ReverseIncludes = reverseIncludes, Keys = keys, Count = keys.Count, CountParam = NormalizeCount(count), SortBy = sortby }; return(snapshot); }
public Snapshot CreateSnapshot(Bundle.BundleType type, Uri link, IEnumerable <string> keys, string sortby, IEnumerable <string> includes = null) { Snapshot snapshot = Snapshot.Create(type, link, keys, sortby, includes); snapshotstore.AddSnapshot(snapshot); return(snapshot); }
/// <summary> /// Creates a snapshot for search commands /// </summary> public Snapshot CreateSnapshot(Bundle.BundleType type, Uri link, IEnumerable <string> keys, string sortby = null, int?count = null, IList <string> includes = null) { Snapshot snapshot = Snapshot.Create(type, link, keys, sortby, NormalizeCount(count), includes); snapshotstore.AddSnapshot(snapshot); return(snapshot); }
public static Bundle CreateBundle(this ILocalhost localhost, Bundle.BundleType type) { Bundle bundle = new Bundle(); bundle.Type = type; return(bundle); }
public ServerFhirResponse GetFhirResponse(IList <Entry> interactions, Bundle.BundleType bundleType) { //Bundle bundle = localhost.CreateBundle(bundleType).Append(interactions); Bundle bundle = new Bundle().Append(interactions); return(Respond.WithBundle(bundle)); }
public static Bundle ToBundle(this IEnumerable <Resource> resources, Bundle.BundleType type = Bundle.BundleType.Collection, Uri base_ = null) { Bundle bundle = new Bundle { Id = $"urn:uuid:{Guid.NewGuid().ToString("N")}", Type = type }; foreach (Resource resource in resources) { // TODO: Investigate further when it is appropriate to add request method entries. if (type == Bundle.BundleType.Transaction) { if (base_ != null) { resource.ResourceBase = base_; } // Make sure that resources without id's are posted. if (resource.Id != null) { bundle.Append(Bundle.HTTPVerb.PUT, resource); } else { bundle.Append(Bundle.HTTPVerb.POST, resource); } } else { bundle.Append(resource); } } return(bundle); }
public TransactionBuilder(string baseUrl, Bundle.BundleType type = Bundle.BundleType.Batch) { _result = new Bundle() { Type = type }; _baseUrl = new Uri(baseUrl); }
private ResourceElement CreateBundle(SearchResult result, Bundle.BundleType type, Func <SearchResultEntry, Bundle.EntryComponent> selectionFunction) { EnsureArg.IsNotNull(result, nameof(result)); // Create the bundle from the result. var bundle = new Bundle(); if (result != null) { IEnumerable <Bundle.EntryComponent> entries = result.Results.Select(selectionFunction); bundle.Entry.AddRange(entries); if (result.ContinuationToken != null) { bundle.NextLink = _urlResolver.ResolveRouteUrl( result.UnsupportedSearchParameters, result.UnsupportedSortingParameters, Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(result.ContinuationToken)), true); } if (result.Partial) { // if the query resulted in a partial indication, add appropriate outcome // as an entry var resource = new OperationOutcome(); resource.Issue = new List <OperationOutcome.IssueComponent>(); resource.Issue.Add(new OperationOutcome.IssueComponent { Severity = OperationOutcome.IssueSeverity.Warning, Code = OperationOutcome.IssueType.Incomplete, Diagnostics = Core.Resources.TruncatedIncludeMessage, }); bundle.Entry.Add(new Bundle.EntryComponent() { Resource = resource, }); } } // Add the self link to indicate which search parameters were used. bundle.SelfLink = _urlResolver.ResolveRouteUrl(result.UnsupportedSearchParameters, result.UnsupportedSortingParameters); bundle.Id = _fhirRequestContextAccessor.FhirRequestContext.CorrelationId; bundle.Type = type; bundle.Total = result?.TotalCount; bundle.Meta = new Meta { LastUpdated = Clock.UtcNow, }; return(bundle.ToResourceElement()); }
private ResourceElement CreateBundle(SearchResult result, Bundle.BundleType type, Func <SearchResultEntry, Bundle.EntryComponent> selectionFunction) { EnsureArg.IsNotNull(result, nameof(result)); // Create the bundle from the result. var bundle = new Bundle(); if (_fhirRequestContextAccessor.RequestContext.BundleIssues.Any()) { var operationOutcome = new OperationOutcome { Id = _fhirRequestContextAccessor.RequestContext.CorrelationId, Issue = new List <OperationOutcome.IssueComponent>(_fhirRequestContextAccessor.RequestContext.BundleIssues.Select(x => x.ToPoco())), }; bundle.Entry.Add(new Bundle.EntryComponent { Resource = operationOutcome, Search = new Bundle.SearchComponent { Mode = Bundle.SearchEntryMode.Outcome, }, }); } IEnumerable <Bundle.EntryComponent> entries = result.Results.Select(selectionFunction); bundle.Entry.AddRange(entries); if (result.ContinuationToken != null) { bundle.NextLink = _urlResolver.ResolveRouteUrl( result.UnsupportedSearchParameters, result.SortOrder, Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(result.ContinuationToken)), true); } // Add the self link to indicate which search parameters were used. bundle.SelfLink = _urlResolver.ResolveRouteUrl(result.UnsupportedSearchParameters, result.SortOrder); bundle.Id = _fhirRequestContextAccessor.RequestContext.CorrelationId; bundle.Type = type; bundle.Total = result?.TotalCount; bundle.Meta = new Meta { LastUpdated = Clock.UtcNow, }; return(bundle.ToResourceElement()); }
public FhirResponse GetFhirResponse( IEnumerable <Tuple <Entry, FhirResponse> > responses, Bundle.BundleType bundleType) { var bundle = new Bundle { Type = bundleType }; foreach (var response in responses) { bundle.Append(response.Item1, response.Item2); } return(Respond.WithBundle(bundle)); }
public static Snapshot Create(Bundle.BundleType type, Uri selflink, IEnumerable <string> keys, string sortby, IEnumerable <string> includes = null) { Snapshot snapshot = new Snapshot(); snapshot.Type = type; snapshot.Id = CreateKey(); snapshot.WhenCreated = DateTimeOffset.UtcNow; //snapshot.FeedTitle = title; snapshot.FeedSelfLink = selflink.ToString(); snapshot.Includes = (includes != null) ? includes.ToList() : null; snapshot.Keys = keys; snapshot.Count = keys.Count(); snapshot.SortBy = sortby; return(snapshot); }
public static Snapshot Create(Bundle.BundleType type, Uri selflink, IEnumerable <string> keys, string sortby, int?count, IList <string> includes) { Snapshot snapshot = new Snapshot(); snapshot.Type = type; snapshot.Id = Snapshot.CreateKey(); snapshot.WhenCreated = DateTimeOffset.UtcNow; snapshot.FeedSelfLink = selflink.ToString(); snapshot.Includes = includes; snapshot.Keys = keys; snapshot.Count = keys.Count(); snapshot.CountParam = count; snapshot.SortBy = sortby; return(snapshot); }
public void Test_Address_TokenIndexSetter_CodeT_IsNull() { //Arrange Bundle.BundleType TheCode = Bundle.BundleType.Document; string CodeString = TheCode.GetLiteral(); //string CodeString = Hl7.Fhir.Introspection.EnumMapping.Create(typeof(Hl7.Fhir.Model.Bundle.BundleType)).GetLiteral(TheCode); Code <Bundle.BundleType> Code = null; TokenIndex Index = new TokenIndex(); //Act ActualValueDelegate <TokenIndex> testDelegate = () => IndexSetterFactory.Create(typeof(TokenIndex)).Set(Code, Index) as TokenIndex; //Assert Assert.That(testDelegate, Throws.TypeOf <ArgumentNullException>()); }
public void Test_Address_TokenIndexSetter_GoodFormat() { //Arrange Bundle.BundleType TheCode = Bundle.BundleType.Document; string CodeString = TheCode.GetLiteral(); //string CodeString = Hl7.Fhir.Introspection.EnumMapping.Create(typeof(Hl7.Fhir.Model.Bundle.BundleType)).GetLiteral(TheCode); var Code = new Code <Bundle.BundleType>(); Code.Value = TheCode; TokenIndex Index = new TokenIndex(); //Act Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(Code, Index) as TokenIndex; //Assert Assert.AreEqual(Index.Code, CodeString); Assert.IsNull(Index.System); }
private ResourceElement CreateBundle(SearchResult result, Bundle.BundleType type, Func <SearchResultEntry, Bundle.EntryComponent> selectionFunction) { EnsureArg.IsNotNull(result, nameof(result)); // Create the bundle from the result. var bundle = new Bundle(); CreateLinks(result, bundle); if (_fhirRequestContextAccessor.RequestContext.BundleIssues.Any()) { var operationOutcome = new OperationOutcome { Id = _fhirRequestContextAccessor.RequestContext.CorrelationId, Issue = new List <OperationOutcome.IssueComponent>(_fhirRequestContextAccessor.RequestContext.BundleIssues.Select(x => x.ToPoco())), }; bundle.Entry.Add(new Bundle.EntryComponent { Resource = operationOutcome, Search = new Bundle.SearchComponent { Mode = Bundle.SearchEntryMode.Outcome, }, }); } IEnumerable <Bundle.EntryComponent> entries = result.Results.Select(selectionFunction); bundle.Entry.AddRange(entries); bundle.Id = _fhirRequestContextAccessor.RequestContext.CorrelationId; bundle.Type = type; bundle.Total = result?.TotalCount; bundle.Meta = new Meta { LastUpdated = Clock.UtcNow, }; return(bundle.ToResourceElement()); }
public FhirResponse GetFhirResponse(IEnumerable <Tuple <Entry, FhirResponse> > responses, Bundle.BundleType bundleType) { Bundle bundle = localhost.CreateBundle(bundleType); foreach (Tuple <Entry, FhirResponse> response in responses) { bundle.Append(response.Item1, response.Item2); } return(Respond.WithBundle(bundle)); }
public TransactionBuilder(Uri baseUri, Bundle.BundleType type = Bundle.BundleType.Batch) : this(baseUri.OriginalString, type) { }
public static Bundle CreateBundle(ICollection <DtoResource> ResourceList, Bundle.BundleType BundleType, IPyroRequestUri RequestUri, int SearchTotal, int PagesTotal, int PageRequested, Paging.IPagingSupport IPagingSupport, Uri SearchPerformedUri = null) { var FhirBundle = new Bundle() { Type = Bundle.BundleType.Searchset }; FhirBundle.Type = BundleType; FhirBundle.Total = SearchTotal; //Paging IPagingSupport.SetBundlePagnation(FhirBundle, RequestUri.FhirRequestUri.OriginalString, PagesTotal, PageRequested, SearchPerformedUri); foreach (DtoResource DtoResource in ResourceList) { Bundle.EntryComponent oResEntry = new Bundle.EntryComponent(); if (DtoResource.IsDeleted == false) { try { oResEntry.Resource = FhirResourceSerializationSupport.DeSerializeFromXml(DtoResource.Xml); } catch (Exception oExec) { string Message = string.Format("Internal Server Error: Serialization of a Resource retrieved from the servers database failed. The record details were: Key: {0}, ResourceVersion: {1}, Received: {2}. The parser exception error was '{3}", DtoResource.FhirId, DtoResource.Version, DtoResource.Received.ToString(), oExec.Message); OperationOutcome OpOutcome = FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.Exception, Message); throw new PyroException(System.Net.HttpStatusCode.InternalServerError, OpOutcome, Message); } } oResEntry.FullUrl = string.Join("/", RequestUri.FhirRequestUri.UriPrimaryServiceRoot.OriginalString, DtoResource.ResourceType.GetLiteral(), DtoResource.FhirId); if (BundleType == Bundle.BundleType.History) { oResEntry.FullUrl = string.Join("/", oResEntry.FullUrl); if (DtoResource.ResourceType.HasValue && DtoResource.ResourceType.HasValue) { oResEntry.Request = new Bundle.RequestComponent(); oResEntry.Request.Method = DtoResource.Method; switch (DtoResource.Method) { case Bundle.HTTPVerb.GET: oResEntry.Request.Url = string.Join("/", ModelInfo.FhirTypeToFhirTypeName(DtoResource.ResourceType.Value), DtoResource.FhirId, "_history", DtoResource.Version); break; case Bundle.HTTPVerb.POST: oResEntry.Request.Url = string.Join("/", ModelInfo.FhirTypeToFhirTypeName(DtoResource.ResourceType.Value), DtoResource.FhirId, "_history", DtoResource.Version); break; case Bundle.HTTPVerb.PUT: oResEntry.Request.Url = string.Join("/", ModelInfo.FhirTypeToFhirTypeName(DtoResource.ResourceType.Value), DtoResource.FhirId, "_history", DtoResource.Version); break; case Bundle.HTTPVerb.DELETE: oResEntry.Request.Url = string.Join("/", ModelInfo.FhirTypeToFhirTypeName(DtoResource.ResourceType.Value), DtoResource.FhirId, "_history", DtoResource.Version); break; default: throw new System.ComponentModel.InvalidEnumArgumentException(DtoResource.Method.ToString(), (int)DtoResource.Method, typeof(Bundle.HTTPVerb)); } } } if (BundleType == Bundle.BundleType.Searchset) { oResEntry.Search = new Bundle.SearchComponent(); oResEntry.Search.Mode = Bundle.SearchEntryMode.Match; if (DtoResource is DtoIncludeResource) { oResEntry.Search.Mode = Bundle.SearchEntryMode.Include; } oResEntry.Link = new List <Bundle.LinkComponent>(); } FhirBundle.Entry.Add(oResEntry); } return(FhirBundle); }
public ServerFhirResponse GetFhirResponse(IEnumerable <Tuple <Entry, ServerFhirResponse> > responses, Bundle.BundleType bundleType) { //Bundle bundle = localhost.CreateBundle(bundleType); Bundle bundle = new Bundle() { Type = bundleType }; foreach (Tuple <Entry, ServerFhirResponse> response in responses) { bundle.Append(response.Item1, response.Item2); } return(Respond.WithBundle(bundle)); }
/// <summary> /// Create a feed /// </summary> public static Bundle CreateBundle(FhirQueryResult result, Bundle.BundleType bundleType) { Bundle retVal = new Bundle(); FhirQueryResult queryResult = result as FhirQueryResult; retVal.Id = String.Format("urn:uuid:{0}", Guid.NewGuid()); retVal.Type = bundleType; // Make the Self uri String baseUri = $"{result.ResourceType}"; if (queryResult.Query != null) { int pageNo = queryResult == null || queryResult.Query.Quantity == 0 ? 0 : queryResult.Query.Start / queryResult.Query.Quantity, nPages = queryResult == null || queryResult.Query.Quantity == 0 ? 1 : (queryResult.TotalResults / queryResult.Query.Quantity); retVal.Type = Bundle.BundleType.Searchset; var queryUri = baseUri + "?"; // Self uri if (queryResult != null) { for (int i = 0; i < queryResult.Query.ActualParameters.Count; i++) { foreach (var itm in queryResult.Query.ActualParameters.GetValues(i)) { switch (queryResult.Query.ActualParameters.GetKey(i)) { case "_stateid": case "_page": case "_count": break; default: queryUri += string.Format("{0}={1}&", queryResult.Query.ActualParameters.GetKey(i), itm); break; } } } if (!baseUri.Contains("_stateid=") && queryResult.Query.QueryId != Guid.Empty) { queryUri += String.Format("_stateid={0}&", queryResult.Query.QueryId); } } // Self URI if (queryResult != null && queryResult.TotalResults > queryResult.Results.Count) { retVal.Link.Add(new Bundle.LinkComponent() { Url = $"{queryUri}_page={pageNo}&_count={queryResult?.Query.Quantity ?? 100}", Relation = "self" }); if (pageNo > 0) { retVal.Link.Add(new Bundle.LinkComponent() { Url = $"{queryUri}_page=0&_count={queryResult?.Query.Quantity ?? 100}", Relation = "first" }); retVal.Link.Add(new Bundle.LinkComponent() { Url = $"{queryUri}_page={pageNo - 1}&_count={queryResult?.Query.Quantity ?? 100}", Relation = "previous" }); } if (pageNo <= nPages) { retVal.Link.Add(new Bundle.LinkComponent() { Url = $"{queryUri}_page={pageNo + 1}&_count={queryResult?.Query.Quantity ?? 100}", Relation = "next" }); retVal.Link.Add(new Bundle.LinkComponent() { Url = $"{queryUri}_page={nPages}&_count={queryResult?.Query.Quantity ?? 100}", Relation = "last" }); } } else { retVal.Link.Add(new Bundle.LinkComponent() { Url = queryUri, Relation = "self" }); } } else //History { // History type retVal.Type = Bundle.BundleType.History; // Self URI retVal.Link.Add(new Bundle.LinkComponent() { Url = $"{baseUri}/_history", Relation = "self" }); } // Updated retVal.Timestamp = DateTime.Now; //retVal.Generator = "MARC-HI Service Core Framework"; // HACK: Remove me if (queryResult != null) { retVal.Total = queryResult.TotalResults; } // Results if (result.Results != null) { retVal.Entry = result.Results.Select(itm => { itm.Link = new List <Bundle.LinkComponent>() { new Bundle.LinkComponent() { Relation = "_self", Url = itm.Resource.HasVersionId ? $"{itm.Resource.TypeName}/{itm.Resource.Id}/_history/{itm.Resource.VersionId}" : $"{itm.Resource.TypeName}/{itm.Resource.Id}" } }; itm.FullUrl = itm.FullUrl ?? $"{GetBaseUri()}/{itm.Resource.TypeName}/{itm.Resource.Id}"; // Add confidence if the attribute permits if (itm.Search != null && itm.Search.Mode == Bundle.SearchEntryMode.Match) // Search data { var confidence = itm.Annotations(typeof(ITag)).OfType <ITag>().FirstOrDefault(t => t.TagKey == "$conf"); if (confidence != null) { itm.Search.Score = Decimal.Parse(confidence.Value); } } return(itm); }).ToList(); } // Outcome //if (result.Details.Count > 0 || result.Issues != null && result.Issues.Count > 0) //{ // var outcome = CreateOutcomeResource(result); // retVal.ElementExtensions.Add(outcome, XmlModelSerializerFactory.Current.CreateSerializer(typeof(OperationOutcome))); // retVal.Description = new TextSyndicationContent(outcome.Text.ToString(), TextSyndicationContentKind.Html); //} return(retVal); }