Esempio n. 1
0
        private IndexValue IndexResourceRecursively(Resource resource, IKey key, string rootPartName = "root")
        {
            var searchParametersForResource = _fhirModel.FindSearchParameters(resource.GetType());

            if (searchParametersForResource != null)
            {
                var result = new IndexValue(rootPartName);

                AddMetaParts(resource, key, result);

                foreach (var par in searchParametersForResource)
                {
                    var newIndexPart = new IndexValue(par.Code);
                    foreach (var path in par.GetPropertyPath())
                    {
                        _resourceVisitor.VisitByPath(resource,
                                                     obj =>
                        {
                            if (obj is Element)
                            {
                                newIndexPart.Values.AddRange(_elementIndexer.Map(obj as Element));
                            }
                        }
                                                     , path);
                    }
                    if (newIndexPart.Values.Any())
                    {
                        result.Values.Add(newIndexPart);
                    }
                }

                if (resource is DomainResource)
                {
                    AddContainedResources((DomainResource)resource, result);
                }

                return(result);
            }
            return(null);
        }
Esempio n. 2
0
        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);
        }