public void ScanThroughSingle()
        {
            var xmlPatient = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine("TestData", "fp-test-patient.json"));

            using (var stream = JsonNavigatorStream.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.Children("gender").FirstOrDefault();
                Assert.IsNotNull(nav);
                Assert.AreEqual("male", nav.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 jsonfile = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine("TestData", "source-test", "project.assets.json"));

            using (var stream = JsonNavigatorStream.FromPath(jsonfile))
            {
                Assert.IsNull(stream.ResourceType);
                Assert.IsFalse(stream.MoveNext());
            }
        }
Beispiel #3
0
        private async Task <List <ArtifactSummary> > GetSummaries()
        {
            var result = new Dictionary <string, ArtifactSummary>();

            using (IScoped <ISearchService> searchService = _searchServiceFactory())
            {
                foreach (var type in _supportedTypes)
                {
                    string ct = null;
                    {
                        do
                        {
                            var queryParameters = new List <Tuple <string, string> >();
                            if (ct != null)
                            {
                                ct = ContinuationTokenConverter.Encode(ct);
                                queryParameters.Add(new Tuple <string, string>(KnownQueryParameterNames.ContinuationToken, ct));
                            }

                            var searchResult = await searchService.Value.SearchAsync(type, queryParameters, CancellationToken.None);

                            foreach (var searchItem in searchResult.Results)
                            {
                                using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(searchItem.Resource.RawResource.Data)))
                                {
                                    using var navStream = new JsonNavigatorStream(memoryStream);
                                    Action <ArtifactSummaryPropertyBag> setOrigin =
                                        (properties) =>
                                    {
                                        properties[ArtifactSummaryProperties.OriginKey] = searchItem.Resource.RawResource.Data;
                                    };
                                    var artifacts = ArtifactSummaryGenerator.Default.Generate(navStream, setOrigin);

                                    foreach (var artifact in artifacts)
                                    {
                                        result[artifact.ResourceUri] = artifact;
                                    }
                                }
                            }

                            ct = searchResult.ContinuationToken;
                        }while (ct != null);
                    }
                }

                return(result.Values.ToList());
            }
        }
        public void ScanPerformance()
        {
            var xmlBundle = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine("TestData", "profiles-types.json"));

            var sw = new Stopwatch();

            sw.Start();

            for (int i = 0; i < 250; i++)
            {
                using (var stream = JsonNavigatorStream.FromPath(xmlBundle))
                {
                    Assert.IsTrue(stream.MoveNext("http://hl7.org/fhir/StructureDefinition/SimpleQuantity"));
                }
            }

            sw.Stop();
            Debug.WriteLine($"Scanning took {sw.ElapsedMilliseconds / 250} ms");
        }
        public void ScanThroughBundle()
        {
            var jsonBundle = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine("TestData", "profiles-types.json"));

            using (var stream = JsonNavigatorStream.FromPath(jsonBundle))
            {
                Assert.IsTrue(stream.IsBundle);
                Assert.IsNull(stream.Current);

                Assert.IsTrue(stream.MoveNext());
                Assert.IsTrue(stream.MoveNext());
                Assert.AreEqual("http://hl7.org/fhir/StructureDefinition/integer", stream.Position);

                var nav   = stream.Current;
                var child = nav.Children("name").FirstOrDefault();
                Assert.IsNotNull(child);
                Assert.AreEqual("integer", child.Text);

                var current = stream.Position;

                Assert.IsTrue(stream.MoveNext());
                Assert.IsTrue(stream.MoveNext());
                Assert.AreEqual("http://hl7.org/fhir/StructureDefinition/unsignedInt", stream.Position);

                stream.Seek(current);
                Assert.AreEqual("http://hl7.org/fhir/StructureDefinition/integer", stream.Position);

                stream.Reset();
                Assert.IsTrue(stream.MoveNext());
                Assert.AreEqual("http://hl7.org/fhir/StructureDefinition/markdown", stream.Position);

                while (stream.MoveNext())
                {
                    ;                           // read to end
                }
                Assert.AreEqual("http://hl7.org/fhir/StructureDefinition/SimpleQuantity", stream.Position);

                // Reading past end does not change position
                Assert.IsFalse(stream.MoveNext());
                Assert.AreEqual("http://hl7.org/fhir/StructureDefinition/SimpleQuantity", stream.Position);
            }
        }
Beispiel #6
0
        private static Resource LoadBySummary(ArtifactSummary summary)
        {
            if (summary == null)
            {
                return(null);
            }

            using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(summary.Origin)))
                using (var navStream = new JsonNavigatorStream(memoryStream))
                {
                    if (navStream.Seek(summary.Position))
                    {
                        if (navStream.Current != null)
                        {
                            // TODO: Cache this parsed resource, to prevent parsing again and again
                            var resource = navStream.Current.ToPoco <Resource>();
                            return(resource);
                        }
                    }
                }

            return(null);
        }