예제 #1
0
        public FhirPathEvaluatorTest(PatientFixture fixture, ITestOutputHelper output)
        {
            ElementNavFhirExtensions.PrepareFhirSymbolTableFunctions();

            this.fixture = fixture;
            this.output  = output;
        }
예제 #2
0
        public void SetupSource()
        {
            ElementNavFhirExtensions.PrepareFhirSymbolTableFunctions();
            var bundleXml = File.ReadAllText("TestData\\bundle-contained-references.xml");

            _parsed    = (new FhirXmlParser()).Parse <Bundle>(bundleXml);
            _bundleNav = new ScopedNavigator(new PocoNavigator(_parsed));
        }
        public void SetupSource()
        {
            ElementNavFhirExtensions.PrepareFhirSymbolTableFunctions();
            var bundleXml = File.ReadAllText(Path.Combine("TestData", "bundle-contained-references.xml"));

            _parsed        = (new FhirXmlParser()).Parse <Bundle>(bundleXml);
            _bundleElement = new ScopedNode(_parsed.ToTypedElement());
        }
예제 #4
0
        public void TestPocoPath()
        {
            // Ensure the FHIR extensions are registered
            ElementNavFhirExtensions.PrepareFhirSymbolTableFunctions();
            FhirPathCompiler.DefaultSymbolTable.Add("shortpathname",
                                                    (object f) =>
            {
                if (f is IEnumerable <IElementNavigator> )
                {
                    object[] bits = (f as IEnumerable <IElementNavigator>).Select(i =>
                    {
                        if (i is PocoNavigator)
                        {
                            return((i as PocoNavigator).ShortPath);
                        }
                        return("?");
                    }).ToArray();
                    return(FhirValueList.Create(bits));
                }
                return(FhirValueList.Create(new object[] { "?" }));
            });

            Patient p = new Patient();

            p.Active = true;
            p.ActiveElement.ElementId = "314";
            p.ActiveElement.AddExtension("http://something.org", new FhirBoolean(false));
            p.ActiveElement.AddExtension("http://something.org", new Integer(314));
            p.Telecom = new List <ContactPoint>();
            p.Telecom.Add(new ContactPoint(ContactPoint.ContactPointSystem.Phone, null, "555-phone"));
            p.Telecom[0].Rank = 1;

            foreach (var item in p.Select("descendants().shortpathname()"))
            {
                System.Diagnostics.Trace.WriteLine(item.ToString());
            }
            var patient = new PocoNavigator(p);

            Assert.AreEqual("Patient", patient.Location);

            patient.MoveToFirstChild();
            Assert.AreEqual("Patient.active[0]", patient.Location);
            Assert.AreEqual("Patient.active", patient.ShortPath);

            patient.MoveToFirstChild();
            Assert.AreEqual("Patient.active[0].id[0]", patient.Location);
            Assert.AreEqual("Patient.active.id", patient.ShortPath);

            Assert.IsTrue(patient.MoveToNext());
            Assert.AreEqual("Patient.active[0].extension[0]", patient.Location);
            Assert.AreEqual("Patient.active.extension[0]", patient.ShortPath);

            PocoNavigator v1 = patient.Clone() as PocoNavigator;

            v1.MoveToFirstChild();
            v1.MoveToNext();
            Assert.AreEqual("Patient.active[0].extension[0].value[0]", v1.Location);
            Assert.AreEqual("Patient.active.extension[0].value", v1.ShortPath);
            Assert.IsFalse(v1.MoveToNext());

            // Ensure that the original navigator hasn't changed
            Assert.AreEqual("Patient.active[0].extension[0]", patient.Location);
            Assert.AreEqual("Patient.active.extension[0]", patient.ShortPath);

            PocoNavigator v2 = patient.Clone() as PocoNavigator;

            v2.MoveToNext();
            v2.MoveToFirstChild();
            v2.MoveToNext();
            Assert.AreEqual("Patient.active[0].extension[1].value[0]", v2.Location);
            Assert.AreEqual("Patient.active.extension[1].value", v2.ShortPath);
            Assert.AreEqual("Patient.active.extension('http://something.org').value", v2.CommonPath);

            PocoNavigator v3 = new PocoNavigator(p);

            v3.MoveToFirstChild(); System.Diagnostics.Trace.WriteLine($"{v3.ShortPath} = {v3.FhirValue.ToString()}");
            v3.MoveToNext(); System.Diagnostics.Trace.WriteLine($"{v3.ShortPath} = {v3.FhirValue.ToString()}");
            // v3.MoveToNext(); System.Diagnostics.Trace.WriteLine($"{v3.ShortPath} = {v3.FhirValue.ToString()}");
            // v3.MoveToNext(); System.Diagnostics.Trace.WriteLine($"{v3.ShortPath} = {v3.FhirValue.ToString()}");
            v3.MoveToFirstChild("system"); System.Diagnostics.Trace.WriteLine($"{v3.ShortPath} = {v3.FhirValue.ToString()}");
            Assert.AreEqual("Patient.telecom[0].system[0]", v3.Location);
            Assert.AreEqual("Patient.telecom[0].system", v3.ShortPath);
            Assert.AreEqual("Patient.telecom.where(system='phone').system", v3.CommonPath);

            // Now check navigation bits
            var v4 = new PocoNavigator(p);

            Assert.AreEqual("Patient.telecom.where(system='phone').system",
                            (v4.Select("Patient.telecom.where(system='phone').system").First() as PocoNavigator).CommonPath);
            v4 = new PocoNavigator(p);
            Assert.AreEqual("Patient.telecom[0].system",
                            (v4.Select("Patient.telecom.where(system='phone').system").First() as PocoNavigator).ShortPath);
            v4 = new PocoNavigator(p);
            Assert.AreEqual("Patient.telecom[0].system[0]",
                            (v4.Select("Patient.telecom.where(system='phone').system").First() as PocoNavigator).Location);
            v4 = new PocoNavigator(p);
            Assert.AreEqual("Patient.telecom.where(system='phone').system",
                            (v4.Select("Patient.telecom[0].system").First() as PocoNavigator).CommonPath);
            v4 = new PocoNavigator(p);
            Assert.AreEqual("Patient.telecom[0].system",
                            (v4.Select("Patient.telecom[0].system").First() as PocoNavigator).ShortPath);
        }
예제 #5
0
파일: IndexService.cs 프로젝트: jjrdk/spark
        private IndexValue IndexResourceRecursively(Resource resource, IKey key, string rootPartName = "root")
        {
            var searchParameters = _fhirModel.FindSearchParameters(resource.GetType());

            if (searchParameters == null)
            {
                return(null);
            }

            var rootIndexValue = new IndexValue(rootPartName);

            AddMetaParts(resource, key, rootIndexValue);

            ElementNavFhirExtensions.PrepareFhirSymbolTableFunctions();

            foreach (var searchParameter in searchParameters)
            {
                if (string.IsNullOrWhiteSpace(searchParameter.Expression))
                {
                    continue;
                }

                // TODO: Do we need to index composite search parameters, some
                // of them are already indexed by ordinary search parameters so
                // need to make sure that we don't do overlapping indexing.
                if (searchParameter.Type == Hl7.Fhir.Model.SearchParamType.Composite)
                {
                    continue;
                }

                var indexValue = new IndexValue(searchParameter.Code);
                IEnumerable <Base> resolvedValues;
                // HACK: Ignoring search parameter expressions which the FhirPath engine does not yet have support for
                try
                {
                    resolvedValues = resource.SelectNew(searchParameter.Expression);
                }
                catch// (Exception e)
                {
                    // TODO: log error!
                    resolvedValues = new List <Base>();
                }

                foreach (var value in resolvedValues)
                {
                    if (value is not Element element)
                    {
                        continue;
                    }

                    indexValue.Values.AddRange(_elementIndexer.Map(element));
                }

                if (indexValue.Values.Any())
                {
                    rootIndexValue.Values.Add(indexValue);
                }
            }

            if (resource is DomainResource domainResource)
            {
                AddContainedResources(domainResource, rootIndexValue);
            }

            return(rootIndexValue);
        }