public void ScanThroughSingle() { var xmlPatient = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\fp-test-patient.xml"); using (var stream = XmlNavigatorStream.FromPath(xmlPatient)) { Assert.IsFalse(stream.IsBundle); Assert.AreEqual("Patient", stream.ResourceType); Assert.IsNull(stream.Current); Assert.IsTrue(stream.MoveNext()); Assert.AreEqual("http://example.org/Patient/pat1", stream.Position); var current = stream.Position; var nav = stream.Current; Assert.IsTrue(nav.MoveToFirstChild("gender")); Assert.AreEqual("male", nav.Value); stream.Reset(); stream.Seek(current); Assert.AreEqual("http://example.org/Patient/pat1", stream.Position); Assert.IsFalse(stream.MoveNext()); Assert.AreEqual("http://example.org/Patient/pat1", stream.Position); } }
public void NavigateZipStream() { // Use XmlNavigatorStream to navigate resources stored inside a zip file // ZipDeflateStream does not support seeking (forward-only stream) // Therefore this only works for the XmlNavigatorStream, as the ctor does NOT (need to) call Reset() // JsonNavigatorStream cannot support zip streams; ctor needs to call Reset after scanning resourceType using (var archive = ZipFile.Open(ZipSource.SpecificationZipFileName, ZipArchiveMode.Read)) { var entry = archive.Entries.FirstOrDefault(e => e.Name == "profiles-resources.xml"); Assert.IsNotNull(entry); using (var entryStream = entry.Open()) { using (var navStream = new XmlNavigatorStream(entryStream, false)) { while (navStream.MoveNext()) { //Debug.WriteLine($"{navStream.Position} : {navStream.ResourceType} {(navStream.IsBundle ? "(Bundle)" : "")}"); Assert.IsTrue(navStream.IsBundle); Assert.AreEqual(ResourceType.Bundle.GetLiteral(), navStream.ResourceType); Assert.IsInstanceOfType(navStream.Current, typeof(XmlDomFhirNavigator)); } ; } } } }
public void ScanThroughSingle() { var xmlPatient = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine("TestData", "fp-test-patient.xml")); using (var stream = XmlNavigatorStream.FromPath(xmlPatient)) { Assert.IsFalse(stream.IsBundle); Assert.AreEqual("Patient", stream.ResourceType); Assert.IsNull(stream.Current); Assert.IsTrue(stream.MoveNext()); Assert.AreEqual("http://example.org/Patient/pat1", stream.Position); var current = stream.Position; var child = stream.Current.Children("gender").FirstOrDefault(); Assert.IsNotNull(child); Assert.AreEqual("male", child.Text); stream.Reset(); stream.Seek(current); Assert.AreEqual("http://example.org/Patient/pat1", stream.Position); Assert.IsFalse(stream.MoveNext()); Assert.AreEqual("http://example.org/Patient/pat1", stream.Position); } }
public void ReadCrap() { // Try a random other xml file var xmlfile = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\source-test\books.xml"); using (var stream = XmlNavigatorStream.FromPath(xmlfile)) { Assert.IsNull(stream.ResourceType); Assert.IsFalse(stream.MoveNext()); } }
public void TestLoadResourceFromZipStream() { // Harvest summaries and load artifact straight from core ZIP archive // Use XmlNavigatorStream to navigate resources stored inside a zip file // ZipDeflateStream does not support seeking (forward-only stream) // Therefore this only works for the XmlNavigatorStream, as the ctor does NOT (need to) call Reset() // JsonNavigatorStream cannot support zip streams; ctor needs to call Reset after scanning resourceType ArtifactSummary corePatientSummary; var corePatientUrl = ModelInfo.CanonicalUriForFhirCoreType(FHIRDefinedType.Patient); string zipEntryName = "profiles-resources.xml"; // Generate summaries from core ZIP resource definitions (extract in memory) using (var archive = ZipFile.Open(ZipSource.SpecificationZipFileName, ZipArchiveMode.Read)) { var entry = archive.Entries.FirstOrDefault(e => e.Name == zipEntryName); Assert.IsNotNull(entry); using (var entryStream = entry.Open()) using (var navStream = new XmlNavigatorStream(entryStream)) { var summaries = ArtifactSummaryGenerator.Default.Generate(navStream); Assert.IsNotNull(summaries); corePatientSummary = summaries.FindConformanceResources(corePatientUrl).FirstOrDefault(); } } Assert.IsNotNull(corePatientSummary); Assert.AreEqual(ResourceType.StructureDefinition, corePatientSummary.ResourceType); Assert.AreEqual(corePatientUrl, corePatientSummary.GetConformanceCanonicalUrl()); // Load core Patient resource from ZIP (extract in memory) using (var archive = ZipFile.Open(ZipSource.SpecificationZipFileName, ZipArchiveMode.Read)) { var entry = archive.Entries.FirstOrDefault(e => e.Name == zipEntryName); using (var entryStream = entry.Open()) using (var navStream = new XmlNavigatorStream(entryStream)) { var nav = navStream.Current; if (nav != null) { // Parse target resource from navigator var parser = new BaseFhirParser(); var corePatient = parser.Parse <StructureDefinition>(nav); Assert.IsNotNull(corePatient); Assert.AreEqual(corePatientUrl, corePatient.Url); } } } }
public void ScanPerformance() { var xmlBundle = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\profiles-types.xml"); var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 250; i++) { using (var stream = XmlNavigatorStream.FromPath(xmlBundle)) { Assert.IsTrue(stream.MoveNext("http://hl7.org/fhir/StructureDefinition/Age")); } } sw.Stop(); Debug.WriteLine($"Scanning took {sw.ElapsedMilliseconds / 250} ms"); }
public void ScanThroughBundle() { var xmlBundle = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\profiles-types.xml"); using (var stream = XmlNavigatorStream.FromPath(xmlBundle)) { Assert.IsTrue(stream.IsBundle); Assert.IsNull(stream.Current); Assert.IsTrue(stream.MoveNext()); Assert.IsTrue(stream.MoveNext()); Assert.AreEqual("http://hl7.org/fhir/StructureDefinition/dateTime", stream.Position); var nav = stream.Current; Assert.IsTrue(nav.MoveToFirstChild("name")); Assert.AreEqual("dateTime", nav.Value); var current = stream.Position; Assert.IsTrue(stream.MoveNext()); Assert.IsTrue(stream.MoveNext()); Assert.AreEqual("http://hl7.org/fhir/StructureDefinition/string", stream.Position); stream.Seek(current); Assert.AreEqual("http://hl7.org/fhir/StructureDefinition/dateTime", stream.Position); stream.Reset(); Assert.IsTrue(stream.MoveNext()); Assert.AreEqual("http://hl7.org/fhir/StructureDefinition/date", stream.Position); while (stream.MoveNext()) { ; // read to end } Assert.AreEqual("http://hl7.org/fhir/StructureDefinition/Age", stream.Position); // Reading past end does not change position Assert.IsFalse(stream.MoveNext()); Assert.AreEqual("http://hl7.org/fhir/StructureDefinition/Age", stream.Position); } }