Beispiel #1
0
        public void SelectEnumerableValuesAsRelatedUsingRootPathFromEnumerableContainingOnlyPrimitives_Expected_ValuesForEachValueInEnumeration()
        {
            var testData = new List <int> {
                1, 2, 3
            };

            IPath path = new PocoPath("().", "().");

            var pocoNavigator = new PocoNavigator(testData);

            var data = pocoNavigator.SelectEnumerable(path);

            var expected = string.Join("|", testData.Select(e => e));
            var actual   = string.Join("|", data.Select(o => o.ToString()));

            Assert.AreEqual(expected, actual);
        }
        public static OperationOutcome ValidatePattern(this Validator v, ElementDefinition definition, IElementNavigator instance)
        {
            var outcome = new OperationOutcome();

            if (definition.Pattern != null)
            {
                IElementNavigator patternValueNav = new PocoNavigator(definition.Pattern);

                if (!instance.Matches(patternValueNav))
                {
                    v.Trace(outcome, $"Value does not match pattern '{toReadable(definition.Pattern)}'",
                            Issue.CONTENT_DOES_NOT_MATCH_PATTERN_VALUE, instance);
                }
            }

            return(outcome);
        }
        public static OperationOutcome ValidateFixed(this Validator v, ElementDefinition definition, IElementNavigator instance)
        {
            var outcome = new OperationOutcome();

            if (definition.Fixed != null)
            {
                IElementNavigator fixedValueNav = new PocoNavigator(definition.Fixed);

                if (!instance.IsExactlyEqualTo(fixedValueNav))
                {
                    v.Trace(outcome, $"Value is not exactly equal to fixed value '{toReadable(definition.Fixed)}'",
                            Issue.CONTENT_DOES_NOT_MATCH_FIXED_VALUE, instance);
                }
            }

            return(outcome);
        }
Beispiel #4
0
        public void SelectEnumerableValuesAsRelatedFromReferenceType_Where_PathsContainASinglePathWhichIsEnumerable_Expected_FlattenedDataWithValuesFromEnumerablePath()
        {
            PocoTestData testData = GivenWithParallelAndNestedEnumerables();

            PocoPath     enumerableNamePath = new PocoPath("EnumerableData().Name", "EnumerableData.Name");
            List <IPath> paths = new List <IPath> {
                enumerableNamePath
            };

            PocoNavigator pocoNavigator = new PocoNavigator(testData);
            Dictionary <IPath, IList <object> > data = pocoNavigator.SelectEnumerablesAsRelated(paths);

            string expected = string.Join("|", testData.EnumerableData.Select(e => e.Name));
            string actual   = string.Join("|", data[enumerableNamePath]);

            Assert.AreEqual(expected, actual);
        }
Beispiel #5
0
        public void SelectEnumerableValuesAsRelatedFromReferenceType_Where_PathsContainASinglePathWhichIsScalar_Expected_FlattenedDataWithValueFromScalarPath()
        {
            var testData = GivenWithParallelAndNestedEnumerables();

            var namePath = new PocoPath("Name", "Name");
            var paths    = new List <IPath> {
                namePath
            };

            var pocoNavigator = new PocoNavigator(testData);
            var data          = pocoNavigator.SelectEnumerablesAsRelated(paths);

            var expected = testData.Name;
            var actual   = string.Join("|", data[namePath]);

            Assert.AreEqual(expected, actual);
        }
Beispiel #6
0
        public void ProcessExpression()
        {
            //string Expression = $"(AuditEvent.entity.what.value as Reference).Url";
            string Expression = $"AuditEvent.agent.who.where(resolve() is Patient)";

            //string Expression = $"AuditEvent.entity.where(resolve() is Patient)";
            //string Expression = $"AuditEvent.entity.what.where(reference.startsWith('Patient/') or reference.contains('/Patient/')) | AuditEvent.agent.who.where(reference.startsWith('Patient/') or reference.contains('/Patient/'))";
            //string Expression = $"AuditEvent.agent.who(reference.startsWith('Patient'))";
            Console.Write($"FHIR Path Expression: {Expression}");
            FhirXmlParser FhirXmlParser = new FhirXmlParser();
            Resource      Resource      = FhirXmlParser.Parse <Resource>(ResourceStore.AuditEvent1);
            PocoNavigator Navigator     = new PocoNavigator(Resource);

            try
            {
                IEnumerable <IElementNavigator> ResultList = Navigator.Select(Expression, new EvaluationContext(Navigator));

                bool FoundValue = false;
                foreach (IElementNavigator oElement in ResultList)
                {
                    FoundValue = true;
                    if (oElement is Hl7.Fhir.ElementModel.PocoNavigator Poco && Poco.FhirValue != null)
                    {
                        Console.WriteLine();
                        if (Poco.FhirValue is ResourceReference Ref)
                        {
                            Console.Write($"Found: {Ref.Url.ToString()}");
                        }
                        else
                        {
                            Console.Write($"Found: {Poco.Value.ToString()}");
                        }
                    }
                }
                if (!FoundValue)
                {
                    Console.WriteLine();
                    Console.WriteLine("No Value Found!");
                }
            }
            catch (Exception Exec)
            {
                Console.WriteLine();
                Console.WriteLine($"Error Message: {Exec.Message}");
            }
        }
        public void TestResolution()
        {
            var bundleXml = File.ReadAllText("TestData\\validation\\bundle-contained-references.xml");

            var bundle = (new FhirXmlParser()).Parse <Bundle>(bundleXml);

            Assert.IsNotNull(bundle);
            IElementNavigator cpNav = new PocoNavigator(bundle);

            var tracker = new ScopeTracker();

            tracker.Enter(cpNav);

            var entries = cpNav.GetChildrenByName("entry");

            var index = 0;

            foreach (var entry in entries)
            {
                tracker.Enter(entry);

                var resource = entry.GetChildrenByName("resource").First();
                tracker.Enter(resource);

                if (index == 2 || index == 3 || index == 4 || index == 6)
                {
                    var refr = resource.GetChildrenByName("managingOrganization").GetChildrenByName("reference").First();
                    var res  = tracker.Resolve(refr, refr.Value as string);
                    Assert.IsNotNull(res);
                }
                else if (index == 5)
                {
                    var refr = resource.GetChildrenByName("managingOrganization").GetChildrenByName("reference").First();
                    var res  = tracker.Resolve(refr, refr.Value as string);
                    Assert.IsNull(res);
                }

                tracker.Leave(resource);


                tracker.Leave(entry);

                index += 1;
            }
        }
Beispiel #8
0
        public void TestFhirPathPolymporphism()
        {
            var patient = new Hl7.Fhir.Model.Patient()
            {
                Active = false
            };

            patient.Meta = new Meta()
            {
                LastUpdated = new DateTimeOffset(2018, 5, 24, 14, 48, 0, TimeSpan.Zero)
            };
            var nav = new PocoNavigator(patient);

            var result = nav.Select("Resource.meta.lastUpdated");

            Assert.IsNotNull(result.FirstOrDefault());
            Assert.AreEqual(PartialDateTime.Parse("2018-05-24T14:48:00+00:00"), result.First().Value);
        }
        public void SelectEnumerableValuesAsRelatedUsingRootPathFromPrimitive_Expected_SingleValueInEnumeration()
        {
            PocoTestData testData = Given();

            IPath        path  = new PocoPath(PocoPath.SeperatorSymbol, PocoPath.SeperatorSymbol);
            List <IPath> paths = new List <IPath> {
                path
            };

            PocoNavigator pocoNavigator = new PocoNavigator(1);

            Dictionary <IPath, IList <object> > data = pocoNavigator.SelectEnumerablesAsRelated(paths);

            string expected = "1";
            string actual   = string.Join("|", data[path]);

            Assert.AreEqual(expected, actual);
        }
Beispiel #10
0
        public void SelectEnumerableValuesAsRelatedUsingRootPathFromPrimitive_Expected_SingleValueInEnumeration()
        {
            Given();

            IPath path  = new PocoPath(PocoPath.SeperatorSymbol, PocoPath.SeperatorSymbol);
            var   paths = new List <IPath> {
                path
            };

            var pocoNavigator = new PocoNavigator(1);

            var data = pocoNavigator.SelectEnumerablesAsRelated(paths);

            const string expected = "1";
            var          actual   = string.Join("|", data[path]);

            Assert.AreEqual(expected, actual);
        }
Beispiel #11
0
        public void ValidateInvariants(ValidationContext context, OperationOutcome result)
        {
            if (InvariantConstraints != null && InvariantConstraints.Count > 0)
            {
                var sw = System.Diagnostics.Stopwatch.StartNew();
                // Need to serialize to XML until the object model processor exists
                // string tpXml = Fhir.Serialization.FhirSerializer.SerializeResourceToXml(this);
                // FhirPath.IFhirPathElement tree = FhirPath.InstanceTree.TreeConstructor.FromXml(tpXml);
                var tree = new PocoNavigator(this);
                foreach (var invariantRule in InvariantConstraints)
                {
                    ValidateInvariantRule(context, invariantRule, tree, result);
                }

                sw.Stop();
                // System.Diagnostics.Trace.WriteLine(String.Format("Validation of {0} execution took {1}", ResourceType.ToString(), sw.Elapsed.TotalSeconds));
            }
        }
Beispiel #12
0
        public void SelectEnumerableValuesAsRelatedFromReferenceType_Where_PathsContainAScalarPath_Expected_FlattenedDataWithValueFromScalarPathRepeatingForEachEnumeration()
        {
            var testData = GivenWithParallelAndNestedEnumerables();

            var namePath           = new PocoPath("Name", "Name");
            var enumerableNamePath = new PocoPath("EnumerableData().Name", "EnumerableData.Name");
            var paths = new List <IPath> {
                namePath, enumerableNamePath
            };

            var pocoNavigator = new PocoNavigator(testData);
            var data          = pocoNavigator.SelectEnumerablesAsRelated(paths);

            var expected = string.Join("|", testData.EnumerableData.Select(e => testData.Name));
            var actual   = string.Join("|", data[namePath]);

            Assert.AreEqual(expected, actual);
        }
        public void SelectEnumerableValuesUsingRootPathFromEnumerableContainingOnlyPrimitives_Expected_ValuesForEachValueInEnumeration()
        {
            List <int> testData = new List <int> {
                1, 2, 3
            };

            IPath        path  = new PocoPath("().", "().");
            List <IPath> paths = new List <IPath> {
                path
            };

            PocoNavigator pocoNavigator = new PocoNavigator(testData);

            Dictionary <IPath, IList <object> > data = pocoNavigator.SelectEnumerablesAsRelated(paths);

            string expected = string.Join("|", testData.Select(e => e));
            string actual   = string.Join("|", data[path]);

            Assert.AreEqual(expected, actual);
        }
        protected void ParseResponseBody()
        {
            var     tpXml   = this.Body;
            Patient Patient = null;

            if (this.Format == FhirApi.FhirFormat.Xml)
            {
                var parser = new Hl7.Fhir.Serialization.FhirXmlParser();
                Patient = parser.Parse <Patient>(tpXml);
            }
            else
            {
                var parser = new Hl7.Fhir.Serialization.FhirJsonParser();
                Patient = parser.Parse <Patient>(tpXml);
            }

            IElementNavigator PocoPatient = new PocoNavigator(Patient);

            this.ApiPatient = new ApiPatient(PocoPatient);
        }
Beispiel #15
0
        public void TestMinMaxValue()
        {
            var validator = new Validator();

            var ed = new ElementDefinition();

            ed.MinValue = new Model.Integer(4);
            ed.MaxValue = new Model.Integer(6);

            var nav     = new PocoNavigator(new Model.Integer(5));
            var outcome = validator.ValidateMinMaxValue(ed, nav);

            Assert.True(outcome.Success);
            Assert.Equal(0, outcome.Warnings);

            nav     = new PocoNavigator(new Model.Integer(4));
            outcome = validator.ValidateMinMaxValue(ed, nav);
            Assert.True(outcome.Success);
            Assert.Equal(0, outcome.Warnings);

            nav     = new PocoNavigator(new Model.Integer(6));
            outcome = validator.ValidateMinMaxValue(ed, nav);
            Assert.True(outcome.Success);
            Assert.Equal(0, outcome.Warnings);

            nav     = new PocoNavigator(new Model.Integer(1));
            outcome = validator.ValidateMinMaxValue(ed, nav);
            Assert.False(outcome.Success);
            Assert.Equal(0, outcome.Warnings);

            nav     = new PocoNavigator(new Model.FhirString("hi"));
            outcome = validator.ValidateMinMaxValue(ed, nav);
            Assert.True(outcome.Success);
            Assert.Equal(2, outcome.Warnings);

            ed.MinValue = new Model.HumanName();
            ed.MaxValue = new Model.FhirString("i comes after hi");
            outcome     = validator.ValidateMinMaxValue(ed, nav);
            Assert.True(outcome.Success);
            Assert.Equal(1, outcome.Warnings);
        }
        public void TestParseBindableExtension()
        {
            var ic  = new Coding("system", "code");
            var ext = new Extension {
                Value = ic
            };
            var nav = new PocoNavigator(ext);
            var c   = nav.ParseBindable() as Coding;

            Assert.NotNull(c);
            Assert.True(ic.IsExactly(c));

            ext.Value = new HumanName();
            nav       = new PocoNavigator(ext);
            c         = nav.ParseBindable() as Coding;
            Assert.Null(c);  // HumanName is not bindable

            ext.Value = null;
            nav       = new PocoNavigator(ext);
            c         = nav.ParseBindable() as Coding;
            Assert.Null(c);  // nothing to bind to
        }
        public async T.Task MassiveParallelSelectsShouldBeCorrect(string testDescriptor, Func <IElementNavigator, string, EvaluationContext, IEnumerable <IElementNavigator> > selector)
        {
            var actual    = new ConcurrentBag <(string canonical, DataElement resource)>();
            var buffer    = new BufferBlock <DataElement>();
            var processor = new ActionBlock <DataElement>(r =>
            {
                var pocoNav     = new PocoNavigator(r);
                var evalContext = new EvaluationContext(new PocoNavigator(r));
                var canonical   = selector(new PocoNavigator(r), "url", evalContext).Single().Value.ToString();
                actual.Add((canonical, r));
            }
                                                          ,
                                                          new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = 100
            });

            buffer.LinkTo(processor, new DataflowLinkOptions {
                PropagateCompletion = true
            });
            var resources = _fixture.Resources;

            var sw = new Stopwatch();

            sw.Restart();
            foreach (var resource in resources.Values)
            {
                buffer.Post(resource);
            }
            buffer.Complete();
            await processor.Completion;

            sw.Stop();
            _outputHelper.WriteLine($"{testDescriptor}: Extracting urls took {sw.Elapsed.ToString("c")} ms");

            actual.Count().Should().Be(resources.Count(), $"{testDescriptor}: All Resources should have a url.");
            actual.Select(sd => new { sd.canonical, sd.resource.Url, sd.resource.Id }).Where(check => check.canonical != check.Url).Should().BeEmpty($"{testDescriptor}: Extracted urls should be equal to url property values.");
        }
Beispiel #18
0
        public void TestGetComparable()
        {
            var navQ = new PocoNavigator(new Model.FhirDateTime(1972, 11, 30));

            Assert.Equal(0, navQ.GetComparableValue(typeof(Model.FhirDateTime)).CompareTo(Model.Primitives.PartialDateTime.Parse("1972-11-30")));

            navQ = new PocoNavigator(new Model.Quantity(3.14m, "kg"));
            Assert.Equal(-1, navQ.GetComparableValue(typeof(Model.Quantity)).CompareTo(new Model.Primitives.Quantity(5.0m, "kg")));

            navQ = new PocoNavigator(new Model.HumanName());
            Assert.Null(navQ.GetComparableValue(typeof(Model.HumanName)));

            var navQ2 = new PocoNavigator(new Model.Quantity(3.14m, "kg")
            {
                Comparator = Model.Quantity.QuantityComparator.GreaterOrEqual
            });

            Assert.Throws <NotSupportedException>(() => navQ2.GetComparableValue(typeof(Model.Quantity)));

            var navQ3 = new PocoNavigator(new Model.Quantity());

            Assert.Throws <NotSupportedException>(() => navQ3.GetComparableValue(typeof(Model.Quantity)));
        }
        private IValueProvider GetResourceNavigator()
        {
            DomainResource resource = null;

            try
            {
                if (textboxInputXML.Text.StartsWith("{"))
                {
                    resource = new dstu2.Hl7.Fhir.Serialization.FhirJsonParser().Parse <DomainResource>(textboxInputXML.Text);
                }
                else
                {
                    resource = new dstu2.Hl7.Fhir.Serialization.FhirXmlParser().Parse <DomainResource>(textboxInputXML.Text);
                }
            }
            catch (Exception ex)
            {
                textboxResult.Text = "Resource read error:\r\n" + ex.Message;
                return(null);
            }
            var inputNav = new PocoNavigator(resource);

            return(inputNav);
        }
Beispiel #20
0
        protected void ParseResponseBody()
        {
            var    tpXml  = this.Body;
            Bundle Bundle = null;

            if (this.Format == FhirApi.FhirFormat.Xml)
            {
                var parser = new Hl7.Fhir.Serialization.FhirXmlParser();
                Bundle = parser.Parse <Bundle>(tpXml);
            }
            else
            {
                var parser = new Hl7.Fhir.Serialization.FhirJsonParser();
                Bundle = parser.Parse <Bundle>(tpXml);
            }

            IElementNavigator PocoBundel = new PocoNavigator(Bundle);

            foreach (var RelatedPerson in PocoBundel.Select(@"Bundle.entry.select(resource as RelatedPerson)"))
            {
                ApiRelatedPerson ApiRelatedPerson = new ApiRelatedPerson(RelatedPerson);
                ApiRelatedPersonList.Add(ApiRelatedPerson);
            }
        }
Beispiel #21
0
        public void TestParseBindable()
        {
            var ic  = new Code("code");
            var nav = new PocoNavigator(ic);
            var c   = nav.ParseBindable(FHIRDefinedType.Code) as Coding;

            Assert.NotNull(c);
            Assert.Equal(ic.Value, c.Code);
            Assert.Null(c.System);

            var iq = new Model.Quantity(4.0m, "kg");

            nav = new PocoNavigator(iq);
            c   = nav.ParseBindable(FHIRDefinedType.Quantity) as Coding;
            Assert.NotNull(c);
            Assert.Equal(iq.Code, c.Code);
            Assert.Equal(iq.System, c.System);

            var ist = new Model.FhirString("Ewout");

            nav = new PocoNavigator(ist);
            c   = nav.ParseBindable(FHIRDefinedType.String) as Coding;
            Assert.NotNull(c);
            Assert.Equal(ist.Value, c.Code);
            Assert.Null(c.System);

            var iu = new Model.FhirUri("http://somewhere.org");

            nav = new PocoNavigator(iu);
            c   = nav.ParseBindable(FHIRDefinedType.Uri) as Coding;
            Assert.NotNull(c);
            Assert.Equal(iu.Value, c.Code);
            Assert.Null(c.System);

            // 'code','Coding','CodeableConcept','Quantity','Extension', 'string', 'uri'
        }
Beispiel #22
0
        public void SelectEnumerableValuesAsRelatedFromReferenceType_Where_PathsContainNestedEnumerablePaths_Expected_FlattenedDataWithValuesFromOuterEnumerablePathRepeatingForEveryValueFromNestedEnumerablePath()
        {
            var testData = GivenWithParallelAndNestedEnumerables();

            var enumerableNamePath       = new PocoPath("EnumerableData().Name", "EnumerableData.Name");
            var nestedEnumerableNamePath = new PocoPath("EnumerableData().EnumerableData().Name", "EnumerableData.EnumerableData.Name");
            var paths = new List <IPath> {
                enumerableNamePath, nestedEnumerableNamePath
            };

            var pocoNavigator = new PocoNavigator(testData);
            var data          = pocoNavigator.SelectEnumerablesAsRelated(paths);

            #region Complex Setup for Expected

            //
            // The code in this region is used to setup the exprected value.
            // It can't be reused for other tests and can't be made generic
            // without replicating the funcationality being tested.
            //
            var tmpExpected  = "";
            var tmpExpected1 = "";
            var separator    = "|";

            for (int outerCount = 0; outerCount < testData.EnumerableData.Count; outerCount++)
            {
                for (int innerCount = 0; innerCount < testData.EnumerableData[outerCount].EnumerableData.Count; innerCount++)
                {
                    if (outerCount == testData.EnumerableData.Count - 1 && innerCount == testData.EnumerableData[outerCount].EnumerableData.Count - 1)
                    {
                        separator = "";
                    }

                    if (outerCount < testData.EnumerableData.Count)
                    {
                        tmpExpected += testData.EnumerableData[outerCount].Name + separator;
                    }
                    else
                    {
                        tmpExpected += separator;
                    }

                    if (innerCount < testData.EnumerableData[outerCount].EnumerableData.Count)
                    {
                        tmpExpected1 += testData.EnumerableData[outerCount].EnumerableData[innerCount].Name + separator;
                    }
                    else
                    {
                        tmpExpected1 += separator;
                    }
                }
            }

            #endregion Complex Setup for Expected

            var expected = tmpExpected + "^" + tmpExpected1;
            var actual   = string.Join("|", data[enumerableNamePath]);
            actual += "^" + string.Join("|", data[nestedEnumerableNamePath]);

            Assert.AreEqual(expected, actual);
        }
        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);
        }
Beispiel #24
0
        public void Index(Resource Resource, PyroSearchParameters DtoSearchParameters = null)
        {
            this.ResourceType = Resource.ResourceType;
            this.FhirID       = Resource.Id;
            string ResourceName = Resource.ResourceType.GetLiteral();
            IList <DtoServiceSearchParameterLight> SearchParametersList = IServiceSearchParameterCache.GetSearchParameterForResource(ResourceName);

            //Filter the list by only the searech parameters provided, do not inex for all
            if (DtoSearchParameters != null)
            {
                SearchParametersList = SearchParametersList.Where(x => DtoSearchParameters.SearchParametersList.Any(d => d.Id == x.Id)).ToList();
            }

            PocoNavigator Navigator = new PocoNavigator(Resource);

            string Resource_ResourceName = FHIRAllTypes.Resource.GetLiteral();

            foreach (DtoServiceSearchParameterLight SearchParameter in SearchParametersList)
            {
                //Todo: Composite searchParameters are not supported as yet, need to do work to read
                // the sub search parameters of the composite directly fro the SearchParameter resources.
                if (SearchParameter.Type != SearchParamType.Composite)
                {
                    bool SetSearchParameterIndex = true;
                    //if ((SearchParameter.Resource == Resource_ResourceName && SearchParameter.Name == "_id") ||
                    //  (SearchParameter.Resource == Resource_ResourceName && SearchParameter.Name == "_lastUpdated"))
                    //{
                    //  SetSearchParameterIndex = false;
                    //}

                    if (SetSearchParameterIndex)
                    {
                        string Expression = SearchParameter.Expression;
                        if (SearchParameter.Resource == Resource_ResourceName)
                        {
                            //If the Expression is one with a parent resource of Resource then swap it for the actual current resource name
                            //For example make 'Resource._tag' be 'Observation._tag' for Observation resources.
                            Expression = Resource.TypeName + SearchParameter.Expression.TrimStart(Resource_ResourceName.ToCharArray());
                        }

                        IEnumerable <IElementNavigator> ResultList = Navigator.Select(Expression, new EvaluationContext(Navigator));
                        foreach (IElementNavigator oElement in ResultList)
                        {
                            if (oElement != null)
                            {
                                switch (SearchParameter.Type)
                                {
                                case SearchParamType.Number:
                                {
                                    this.IndexQuantityList.AddRange(IIndexSetterFactory.CreateNumberSetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                case SearchParamType.Date:
                                {
                                    this.IndexDateTimeList.AddRange(IIndexSetterFactory.CreateDateTimeSetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                case SearchParamType.String:
                                {
                                    this.IndexStringList.AddRange(IIndexSetterFactory.CreateStringSetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                case SearchParamType.Token:
                                {
                                    this.IndexTokenList.AddRange(IIndexSetterFactory.CreateTokenSetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                case SearchParamType.Reference:
                                {
                                    this.IndexReferenceList.AddRange(IIndexSetterFactory.CreateReferenceSetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                case SearchParamType.Composite:
                                {
                                    break;
                                }

                                case SearchParamType.Quantity:
                                {
                                    this.IndexQuantityList.AddRange(IIndexSetterFactory.CreateQuantitySetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                case SearchParamType.Uri:
                                {
                                    this.IndexUriList.AddRange(IIndexSetterFactory.CreateUriSetter().Set(oElement, SearchParameter));
                                    break;
                                }

                                default:
                                    throw new System.ComponentModel.InvalidEnumArgumentException(SearchParameter.Type.ToString(), (int)SearchParameter.Type, typeof(SearchParamType));
                                }
                            }
                        }
                    }
                }
            }
        }