本文整理汇总了C#中Hl7.Fhir.Model.Bundle类的典型用法代码示例。如果您正苦于以下问题:C# Bundle类的具体用法?C# Bundle怎么用?C# Bundle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Bundle类属于Hl7.Fhir.Model命名空间,在下文中一共展示了Bundle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessEncounters
private static void ProcessEncounters(List<TimelineEntry> timeline, Bundle matchingEncounters)
{
foreach (var encounter in matchingEncounters.Entries.Select(x => (ResourceEntry<Encounter>)x))
{
DateTimeOffset? startTime;
DateTimeOffset? endTime;
if (encounter.Resource.Hospitalization != null)
{
startTime = DateTimeOffset.Parse(encounter.Resource.Hospitalization.Period.Start);
endTime = DateTimeOffset.Parse(encounter.Resource.Hospitalization.Period.End);
}
else
{
startTime = encounter.Published;
endTime = encounter.Published;
}
timeline.Add(new TimelineEntry
{
StartTime = startTime,
EndTime = endTime,
TypeOfEntry = TimelineEntryType.Encounter,
Summary = encounter.Resource.Reason.ToString()
});
}
}
示例2: TestSigning
public void TestSigning()
{
Bundle b = new Bundle();
b.Title = "Updates to resource 233";
b.Id = new Uri("urn:uuid:0d0dcca9-23b9-4149-8619-65002224c3");
b.LastUpdated = new DateTimeOffset(2012, 11, 2, 14, 17, 21, TimeSpan.Zero);
b.AuthorName = "Ewout Kramer";
ResourceEntry<Patient> p = new ResourceEntry<Patient>();
p.Id = new ResourceIdentity("http://test.com/fhir/Patient/233");
p.Resource = new Patient();
p.Resource.Name = new List<HumanName> { HumanName.ForFamily("Kramer").WithGiven("Ewout") };
b.Entries.Add(p);
var myAssembly = typeof(TestXmlSignature).Assembly;
var stream = myAssembly.GetManifestResourceStream("Spark.Tests.spark.pfx");
var data = new byte[stream.Length];
stream.Read(data,0,(int)stream.Length);
var certificate = new X509Certificate2(data);
var bundleData = FhirSerializer.SerializeBundleToXmlBytes(b);
var bundleXml = Encoding.UTF8.GetString(bundleData);
var bundleSigned = XmlSignatureHelper.Sign(bundleXml, certificate);
Assert.IsTrue(XmlSignatureHelper.IsSigned(bundleSigned));
Assert.IsTrue(XmlSignatureHelper.VerifySignature(bundleSigned));
var changedBundle = bundleSigned.Replace("<name>Ewout", "<name>Ewald");
Assert.AreEqual(bundleSigned.Length, changedBundle.Length);
Assert.IsFalse(XmlSignatureHelper.VerifySignature(changedBundle));
}
示例3: Load
internal static Bundle Load(JsonReader reader)
{
JObject feed;
try
{
reader.DateParseHandling = DateParseHandling.None;
reader.FloatParseHandling = FloatParseHandling.Decimal;
feed = JObject.Load(reader);
if( feed.Value<string>(JsonDomFhirReader.RESOURCETYPE_MEMBER_NAME) != "Bundle")
throw Error.Format("Input data is not an json FHIR bundle", null);
}
catch (Exception exc)
{
throw Error.Format("Exception while parsing feed: " + exc.Message, null);
}
Bundle result;
try
{
result = new Bundle()
{
Title = feed.Value<string>(BundleXmlParser.XATOM_TITLE),
LastUpdated = instantOrNull(feed[BundleXmlParser.XATOM_UPDATED]),
Id = SerializationUtil.UriValueOrNull(feed[BundleXmlParser.XATOM_ID]),
Links = getLinks(feed[BundleXmlParser.XATOM_LINK]),
Tags = TagListParser.ParseTags(feed[BundleXmlParser.XATOM_CATEGORY]),
AuthorName = feed[BundleXmlParser.XATOM_AUTHOR] as JArray != null ?
feed[BundleXmlParser.XATOM_AUTHOR]
.Select(auth => auth.Value<string>(BundleXmlParser.XATOM_AUTH_NAME))
.FirstOrDefault()
: null,
AuthorUri = feed[BundleXmlParser.XATOM_AUTHOR] as JArray != null ?
feed[BundleXmlParser.XATOM_AUTHOR]
.Select(auth => auth.Value<string>(BundleXmlParser.XATOM_AUTH_URI))
.FirstOrDefault() : null,
TotalResults = intValueOrNull(feed[BundleXmlParser.XATOM_TOTALRESULTS])
};
}
catch (Exception exc)
{
throw Error.Format("Exception while parsing json feed attributes: " + exc.Message, null);
}
var entries = feed[BundleXmlParser.XATOM_ENTRY];
if (entries != null)
{
if (!(entries is JArray))
{
throw Error.Format("The json feed contains a single entry, instead of an array", null);
}
result.Entries = loadEntries((JArray)entries, result);
}
return result;
}
示例4: CreateBundle
public static Bundle CreateBundle(this ILocalhost localhost, Bundle.BundleType type)
{
Bundle bundle = new Bundle();
bundle.Base = localhost.Base.ToString();
bundle.Type = type;
return bundle;
}
示例5: WriteTo
public static void WriteTo(Bundle bundle, XmlWriter writer, bool summary = false)
{
if (bundle == null) throw new ArgumentException("Bundle cannot be null");
var root = new XElement(BundleXmlParser.XATOMNS + BundleXmlParser.XATOM_FEED);
if (!String.IsNullOrWhiteSpace(bundle.Title)) root.Add(xmlCreateTitle(bundle.Title));
if (SerializationUtil.UriHasValue(bundle.Id)) root.Add(xmlCreateId(bundle.Id));
if (bundle.LastUpdated != null) root.Add(new XElement(BundleXmlParser.XATOMNS + BundleXmlParser.XATOM_UPDATED, bundle.LastUpdated));
if (!String.IsNullOrWhiteSpace(bundle.AuthorName))
root.Add(xmlCreateAuthor(bundle.AuthorName, bundle.AuthorUri));
if (bundle.TotalResults != null) root.Add(new XElement(BundleXmlParser.XOPENSEARCHNS + BundleXmlParser.XATOM_TOTALRESULTS, bundle.TotalResults));
if (bundle.Links != null)
{
foreach (var l in bundle.Links)
root.Add(xmlCreateLink(l.Rel, l.Uri));
}
if (bundle.Tags != null)
{
foreach (var tag in bundle.Tags)
root.Add(TagListSerializer.CreateTagCategoryPropertyXml(tag));
}
foreach (var entry in bundle.Entries)
root.Add(createEntry(entry, summary));
root.WriteTo(writer);
//var result = new XDocument(root);
//result.WriteTo(writer);
}
示例6: ResourceListFiltering
public void ResourceListFiltering()
{
var testBundle = new Bundle();
testBundle.Entry.Add(new Bundle.BundleEntryComponent { Resource = new Patient { Id = "1234", Meta = new Meta { VersionId = "v2" } } });
testBundle.Entry.Add(new Bundle.BundleEntryComponent { Resource = new Patient { Id = "1234", Meta = new Meta { VersionId = "v3" } } });
testBundle.Entry.Add(new Bundle.BundleEntryComponent { Resource = new Patient { Id = "1234", Meta = new Meta { VersionId = "v4"} },
Transaction = new Bundle.BundleEntryTransactionComponent {Method = Bundle.HTTPVerb.DELETE} });
testBundle.Entry.Add(new Bundle.BundleEntryComponent { Resource = new Patient { Id = "5678" }, Base = "http://server1.com/fhir" });
testBundle.Entry.Add(new Bundle.BundleEntryComponent { Resource = new Patient { Id = "1.2.3.4.5" }, Base = "urn:oid:" });
var result = testBundle.FindEntry("Patient", "1234");
Assert.AreEqual(2, result.Count());
result = testBundle.FindEntry("Patient", "1234", includeDeleted: true);
Assert.AreEqual(3, result.Count());
result = testBundle.FindEntry("Patient", "1234", "v3", includeDeleted: true);
Assert.AreEqual(1, result.Count());
result = testBundle.FindEntry(new Uri("http://server3.org/fhir/Patient/1234"));
Assert.AreEqual(0, result.Count());
result = testBundle.FindEntry("Patient", "5678");
Assert.AreEqual(1, result.Count());
result = testBundle.FindEntry(new Uri("http://server1.com/fhir/Patient/5678"));
Assert.AreEqual(1, result.Count());
result = testBundle.FindEntry(new Uri("http://server2.com/fhir/Patient/5678"));
Assert.AreEqual(0, result.Count());
result = testBundle.FindEntry(new Uri("urn:oid:1.2.3.4.5"));
Assert.AreEqual(1, result.Count());
}
示例7: ExtractKey
public static Key ExtractKey(this Localhost localhost, Bundle.BundleEntryComponent entry)
{
Uri uri = new Uri(entry.Request.Url, UriKind.RelativeOrAbsolute);
Key compare = ExtractKey(uri); // This fails!! ResourceIdentity does not work in this case.
return localhost.LocalUriToKey(uri);
}
示例8: Append
public static void Append(this Bundle bundle, Bundle.HTTPVerb method, IEnumerable<Resource> resources)
{
foreach (Resource resource in resources)
{
bundle.Append(method, resource);
}
}
示例9: CreateSnapshot
/// <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;
}
示例10: TryValidate
public static bool TryValidate(Bundle bundle, ICollection<ValidationResult> validationResults = null)
{
if (bundle == null) throw new ArgumentNullException("bundle");
var results = validationResults ?? new List<ValidationResult>();
return Validator.TryValidateObject(bundle, ValidationContextFactory.Create(bundle, null), results, true);
}
示例11: ResourceListFiltering
public void ResourceListFiltering()
{
var testBundle = new Bundle();
testBundle.AddResourceEntry(new Patient { Id = "1234", Meta = new Meta { VersionId = "v2" } }, "http://nu.nl/fhir/Patient/1234");
testBundle.AddResourceEntry(new Patient { Id = "1234", Meta = new Meta { VersionId = "v3" } }, "http://nu.nl/fhir/Patient/1234");
testBundle.AddResourceEntry(new Patient { Id = "1234", Meta = new Meta { VersionId = "v4" } }, "http://nu.nl/fhir/Patient/1234")
.Request = new Bundle.BundleEntryRequestComponent { Method = Bundle.HTTPVerb.DELETE } ;
testBundle.AddResourceEntry(new Patient { Id = "5678" }, "http://server1.com/fhir/Patient/5678");
testBundle.AddResourceEntry(new Patient { Id = "1.2.3.4.5" }, "urn:oid:1.2.3.4.5");
var result = testBundle.FindEntry("http://nu.nl/fhir/Patient/1234");
Assert.AreEqual(2, result.Count());
result = testBundle.FindEntry("http://nu.nl/fhir/Patient/1234", includeDeleted: true);
Assert.AreEqual(3, result.Count());
result = testBundle.FindEntry("http://nu.nl/fhir/Patient/1234/_history/v3", includeDeleted: true);
Assert.AreEqual(1, result.Count());
result = testBundle.FindEntry(new Uri("http://server3.org/fhir/Patient/1234"));
Assert.AreEqual(0, result.Count());
result = testBundle.FindEntry(new Uri("http://server1.com/fhir/Patient/5678"));
Assert.AreEqual(1, result.Count());
result = testBundle.FindEntry(new Uri("http://server2.com/fhir/Patient/5678"));
Assert.AreEqual(0, result.Count());
result = testBundle.FindEntry(new Uri("urn:oid:1.2.3.4.5"));
Assert.AreEqual(1, result.Count());
}
示例12: WriteTo
public static void WriteTo(Bundle bundle, JsonWriter writer, bool summary = false)
{
if (bundle == null) throw new ArgumentException("Bundle cannot be null");
JObject result = new JObject();
result.Add(new JProperty(JsonDomFhirReader.RESOURCETYPE_MEMBER_NAME, "Bundle"));
if (!String.IsNullOrWhiteSpace(bundle.Title))
result.Add(new JProperty(BundleXmlParser.XATOM_TITLE, bundle.Title));
if (SerializationUtil.UriHasValue(bundle.Id)) result.Add(new JProperty(BundleXmlParser.XATOM_ID, bundle.Id));
if (bundle.LastUpdated != null)
result.Add(new JProperty(BundleXmlParser.XATOM_UPDATED, bundle.LastUpdated));
if (!String.IsNullOrWhiteSpace(bundle.AuthorName))
result.Add(jsonCreateAuthor(bundle.AuthorName, bundle.AuthorUri));
if (bundle.TotalResults != null) result.Add(new JProperty(BundleXmlParser.XATOM_TOTALRESULTS, bundle.TotalResults.ToString()));
if (bundle.Links.Count > 0)
result.Add(new JProperty(BundleXmlParser.XATOM_LINK, jsonCreateLinkArray(bundle.Links)));
if (bundle.Tags != null && bundle.Tags.Count() > 0)
result.Add( TagListSerializer.CreateTagCategoryPropertyJson(bundle.Tags));
var entryArray = new JArray();
foreach (var entry in bundle.Entries)
entryArray.Add(createEntry(entry,summary));
result.Add(new JProperty(BundleXmlParser.XATOM_ENTRY, entryArray));
result.WriteTo(writer);
}
示例13: TestSigning
public void TestSigning()
{
Bundle b = new Bundle();
b.Title = "Updates to resource 233";
b.Id = new Uri("urn:uuid:0d0dcca9-23b9-4149-8619-65002224c3");
b.LastUpdated = new DateTimeOffset(2012, 11, 2, 14, 17, 21, TimeSpan.Zero);
b.AuthorName = "Ewout Kramer";
ResourceEntry<Patient> p = new ResourceEntry<Patient>();
p.Id = new ResourceIdentity("http://test.com/fhir/Patient/233");
p.Resource = new Patient();
p.Resource.Name = new List<HumanName> { HumanName.ForFamily("Kramer").WithGiven("Ewout") };
b.Entries.Add(p);
var certificate = getCertificate();
var bundleData = FhirSerializer.SerializeBundleToXmlBytes(b);
var bundleXml = Encoding.UTF8.GetString(bundleData);
var bundleSigned = XmlSignatureHelper.Sign(bundleXml, certificate);
_signedXml = bundleSigned;
using (var response = postBundle(bundleSigned))
{
if (response.StatusCode != HttpStatusCode.OK) TestResult.Fail("Server refused POSTing signed document at /");
}
}
示例14: newEntry
private Bundle.EntryComponent newEntry(Bundle.HTTPVerb method)
{
var newEntry = new Bundle.EntryComponent();
newEntry.Request = new Bundle.RequestComponent();
newEntry.Request.Method = method;
return newEntry;
}
示例15: newEntry
private Bundle.BundleEntryComponent newEntry(Bundle.HTTPVerb method)
{
var newEntry = new Bundle.BundleEntryComponent();
newEntry.Transaction = new Bundle.BundleEntryTransactionComponent();
newEntry.Transaction.Method = method;
return newEntry;
}