Пример #1
0
 private IMongoQuery ParametersToQuery(IEnumerable<IParameter> parameters)
 {
     List<IMongoQuery> queries = new List<IMongoQuery>();
     queries.Add(M.Query.EQ(InternalField.LEVEL, 0)); // geindexeerde contained documents overslaan
     IEnumerable<IMongoQuery> q = parameters.Select(p => ParameterToQuery(p));
     queries.AddRange(q);
     return M.Query.And(queries);
 }
Пример #2
0
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var result = new List<ValidationResult>();

            foreach (var tag in Category)
                result.AddRange(tag.Validate(validationContext));

            return result;
        }
Пример #3
0
        public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var result = new List<ValidationResult>();
            result.AddRange(base.Validate(validationContext));

            if (!result.Any()) result.Add(ValidationResult.Success);

            return result;
        }
Пример #4
0
        public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var result = new List<ValidationResult>();
            result.AddRange(base.Validate(validationContext));

            if (When == null)
                result.Add(new ValidationResult("A DeletedEntry must have a non-null deletion time (When)"));

            if (!result.Any()) result.Add(ValidationResult.Success);

            return result;
        }
Пример #5
0
        public static void SetTextTag(this BundleEntry entry, string text)
        {
            var result = new List<Tag>();

            if (entry.Tags != null) result.AddRange(entry.Tags);

            result.RemoveAll(t => Equals(t.Scheme,Tag.FHIRTAGSCHEME_GENERAL) &&
                    (t.Term != null && t.Term.StartsWith(TAG_TERM_TEXT)));

            result.Add(new Tag(TAG_TERM_TEXT + Uri.EscapeUriString(text), Tag.FHIRTAGSCHEME_GENERAL, text));

            entry.Tags = result;
        }
Пример #6
0
        public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var result = new List<ValidationResult>();
            result.AddRange(base.Validate(validationContext));

            if (Content == null)
                result.Add(new ValidationResult("Entry must contain (possibly 0-length) data in Content element"));

            if (ContentType == null)
                result.Add(new ValidationResult("Entry must contain a ContentType"));

            return result;
        }
Пример #7
0
 public static List<Tag> GetFhirTags(this HttpHeaders headers)
 {
     IEnumerable<string> tagstrings;
     List<Tag> tags = new List<Tag>();
     
     if (headers.TryGetValues(FhirHeader.CATEGORY, out tagstrings))
     {
         foreach (string tagstring in tagstrings)
         {
             tags.AddRange(HttpUtil.ParseCategoryHeader(tagstring));
         }
     }
     return tags;
 }
Пример #8
0
        public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var result = new List<ValidationResult>();

            if (!Bundle.UriHasValue(Id))
                result.Add(new ValidationResult("Entry must have an id"));
            else
                if (!Id.IsAbsoluteUri)
                    result.Add(new ValidationResult("Entry id must be an absolute URI"));

            if (Bundle.UriHasValue(SelfLink) && !SelfLink.IsAbsoluteUri)
                result.Add(new ValidationResult("Entry selflink must be an absolute URI"));

            if (Links.FirstLink != null || Links.LastLink != null || Links.PreviousLink != null || Links.NextLink != null)
                result.Add(new ValidationResult("Paging links can only be used on feeds, not entries"));

            if (Tags != null)
                result.AddRange(new TagList(Tags).Validate(validationContext));

            return result;
        }
        /// <summary>
        /// Unpacks zip-files containing the artifact files, and enumerates all (zipped/nonzipped) files.
        /// </summary>
        /// <remarks>This is an expensive operations and should be run once. As well, it unpacks files on the
        /// file system and is not thread-safe.</remarks>
        public void Prepare()
        {
#if !PORTABLE45
            _artifactFiles = new List<string>();

            var zips = Directory.GetFiles(_contentDirectory, "*.zip");

            // Get the files in each *.zip files present in the content directory
            // The ZipCacher will avoid re-extracting these files.
            foreach (string zipPath in zips)
            {
                ZipCacher zc = new ZipCacher(zipPath, CACHE_KEY);
                _artifactFiles.AddRange(zc.GetContents());
            }

            _isPrepared = true;
#else
            throw Error.NotImplemented("File based Core artifact source is not supported on the portable runtime");
#endif

        }
Пример #10
0
        public static IEnumerable<Tag> Merge(this IEnumerable<Tag> tags, IEnumerable<Tag> that)
        {
            var result = new List<Tag>(tags.Remove(that));

            result.AddRange(that);

            return result;
        }
Пример #11
0
        private static List<string> GetTargetedReferenceTypes(ModelInfo.SearchParamDefinition parameter, String modifier)
        {
            var allowedResourceTypes = ModelInfo.SupportedResources; //TODO: restrict to parameter.ReferencedResources. This means not making this static, because you want to use IFhirModel.
            List<string> searchResourceTypes = new List<string>();
            if (String.IsNullOrEmpty(modifier))
                searchResourceTypes.AddRange(allowedResourceTypes);
            else if (allowedResourceTypes.Contains(modifier))
            {
                searchResourceTypes.Add(modifier);
            }
            else
            {
                throw new NotSupportedException(String.Format("Referenced type cannot be of type %s.", modifier));
            }

            return searchResourceTypes;
        }
Пример #12
0
        public IEnumerable<string> ListArtifactNames()
        {
            var result = new List<string>();

            foreach (var source in Sources)
            {
                try
                {
                    result.AddRange(source.ListArtifactNames());
                }
                catch (NotImplementedException)
                {
                    // Don't do anything, just try the next IArtifactSource
                }
            }

            return result;
        }
Пример #13
0
 /// <summary>
 /// CloseCriterium("patient.name=\"Teun\"") -> "patient=id1,id2"
 /// </summary>
 /// <param name="resourceType"></param>
 /// <param name="crit"></param>
 /// <returns></returns>
 private Criterium CloseCriterium(Criterium crit, string resourceType)
 {
     List<string> targeted = crit.GetTargetedReferenceTypes(resourceType);
     List<string> allKeys = new List<string>();
     foreach (var target in targeted)
     {
         var keys = CollectKeys(target, new List<Criterium> { (Criterium)crit.Operand });               //Recursive call to CollectKeys!
         allKeys.AddRange(keys.Select(k => k.ToString()));
     }
     crit.Type = Operator.IN;
     crit.Operand = ChoiceValue.Parse(String.Join(",", allKeys));
     return crit;
 }
        private static IEnumerable<Bookmark> locateChildren(BaseElementNavigator nav, IEnumerable<string> path, bool partial)
        {
            var child = path.First();
            var rest = path.Skip(1);

            var bm = nav.Bookmark();

            if (nav.MoveToChild(child))
            {
                var result = new List<Bookmark>();

                do
                {
                    if (!rest.Any())
                    {
                        // Exact match!
                        result.Add(nav.Bookmark());
                    }
                    else if (!nav.HasChildren && partial)
                    {
                        // This is as far as we can get in this structure,
                        // so this is a hit too if partial hits are OK
                        result.Add(nav.Bookmark());
                    }
                    else
                    {
                        // So, no hit, but we have children that might fit the bill.
                        result.AddRange(locateChildren(nav, rest, partial));
                    }

                    // Try this for the other matching siblings too...
                }
                while (nav.MoveToNext(child));

                // We've scanned all my children and collected the results,
                // move the navigator back to where we were before
                nav.ReturnToBookmark(bm);
                return result;
            }
            else
                return Enumerable.Empty<Bookmark>();
        }
Пример #15
0
        /// <summary>
        /// CloseCriterium("patient.name=\"Teun\"") -> "patient IN (id1,id2)"
        /// </summary>
        /// <param name="resourceType"></param>
        /// <param name="crit"></param>
        /// <returns></returns>
        private Criterium CloseCriterium(Criterium crit, string resourceType, int level)
        {

            List<string> targeted = crit.GetTargetedReferenceTypes(resourceType);
            List<string> allKeys = new List<string>();
            var errors = new List<Exception>();
            foreach (var target in targeted)
            {
                try {
                    Criterium innerCriterium = (Criterium)crit.Operand;
                    var keys = CollectKeys(target, new List<Criterium> { innerCriterium }, ++level);               //Recursive call to CollectKeys!
                    allKeys.AddRange(keys.Select(k => k.ToString()));
                }
                catch (Exception ex)
                {
                    errors.Add(ex);
                }
                }
            if (errors.Count == targeted.Count())
            {
                //It is possible that some of the targets don't support the current parameter. But if none do, there is a serious problem.
                throw new ArgumentException(String.Format("None of the possible target resources support querying for parameter {0}", crit.ParamName));
            }
            crit.Operator = Operator.IN;
            crit.Operand = ChoiceValue.Parse(String.Join(",", allKeys));
            return crit;
        }
Пример #16
0
        /// <summary>
        /// Will match up the children of the current element in diffNav to the children of the element in snapNav.
        /// </summary>
        /// <param name="snapNav"></param>
        /// <param name="diffNav"></param>
        /// <returns>Returns a list of Bookmark combinations, the first bookmark pointing to an element in the base,
        /// the second a bookmark in the diff that matches the bookmark in the base.</returns>
        /// <remarks>Will match slices to base elements, re-sliced slices to slices and type-slice shorthands to choie elements.
        /// Note that this function may expand snapNav when it encounters paths in the differential that move into the complex types
        /// of one of snap's elements.  (NO NEED, it just has to match direct children, not deeper)
        /// This function assumes the differential is not sparse: it must have parent nodes for all child constraint paths.
        /// </remarks>
        public List<MatchInfo> Match(ElementNavigator snapNav, ElementNavigator diffNav)
        {
            if (!snapNav.HasChildren) throw Error.Argument("snapNav", "Cannot match base to diff: element '{0}' in snap has no children".FormatWith(snapNav.PathName));
            if (!diffNav.HasChildren) throw Error.Argument("diffNav", "Cannot match base to diff: element '{0}' in diff has no children".FormatWith(diffNav.PathName));

            // These bookmarks are used only in the finally {} to make sure we don't alter the position of the navs when leaving the merger
            var baseStartBM = snapNav.Bookmark();
            var diffStartBM = diffNav.Bookmark();

            snapNav.MoveToFirstChild();
            diffNav.MoveToFirstChild();

            var choiceNames = listChoiceElements(snapNav);

            var result = new List<MatchInfo>();

            try
            {
                do
                {
                    // First, match directly -> try to find the child in base with the same name as the path in the diff
                    if (snapNav.PathName != diffNav.PathName && !snapNav.MoveToNext(diffNav.PathName))
                    {
                        // Not found, maybe this is a type slice shorthand, look if we have a matching choice prefix in snap
                        var typeSliceShorthand = diffNav.PathName;

                        // Try to match nameXXXXX to name[x]
                        var matchingChoice = choiceNames.SingleOrDefault(prefix => isPossibleTypeSlice(prefix, typeSliceShorthand));

                        if (matchingChoice != null)
                            snapNav.MoveToNext(matchingChoice);
                        else
                            throw Error.InvalidOperation("Differential has a constraint for path '{0}', which does not exist in its base".FormatWith(diffNav.Path));
                    }

                    result.AddRange(constructMatch(snapNav, diffNav));
                }
                while (diffNav.MoveToNext());
            }
            finally
            {
                snapNav.ReturnToBookmark(baseStartBM);
                diffNav.ReturnToBookmark(diffStartBM);
            }

            return result;
        }
        /// <summary>
        /// Scan all xml files found by prepareFiles and find conformance resources + their id
        /// </summary>
        private void prepareResources()
        {
            if (_resourcesPrepared) return;

            prepareFiles();

            _resourceInformation = new List<ConformanceInformation>();

            foreach (var file in _artifactFilePaths.Where(af => Path.GetExtension(af) == ".xml"))
            {
                if (file.EndsWith("dataelements.xml")) continue;       // buggy file

                try
                {
                    var conformanceResources = readInformationFromFile(file).Where(ci =>
                           ResourceIdentity.IsRestResourceIdentity(ci.Url) &&
                           ModelInfo.IsConformanceResource((new ResourceIdentity(ci.Url)).ResourceType));
                    _resourceInformation.AddRange(conformanceResources);
                }
                catch(XmlException)
                {
                    throw;
                }
            }

            // Check for duplicate canonical urls, this is forbidden within a single source (and actually, universally,
            // but if another source has the same url, the order of polling in the MultiArtifactSource matters)
            var doubles = _resourceInformation.Where(ci=>ci.Url != null).GroupBy(ci => ci.Url).Where(group => group.Count() > 1);
            if (doubles.Any())
            {
                throw Error.InvalidOperation("The source has found multiple Conformance Resource artifacts with the same canonical url: {0} appears at {1}"
                        .FormatWith(doubles.First().Key, String.Join(", ", doubles.First().Select(hit => hit.Origin))));                        
            }

            _resourcesPrepared = true;
        }
Пример #18
0
        public static IEnumerable<Tag> Remove(this IEnumerable<Tag> tags, IEnumerable<Tag> that)
        {
            var result = new List<Tag>();

            result.AddRange(tags);

            if (that != null)
                result.RemoveAll(t => that.HasTag(t.Term, t.Scheme));

            return result;
        }
        /// <summary>
        /// Prepares the source by reading all files present in the directory (matching the mask, if given)
        /// </summary>
        private void prepareFiles()
        {
            if (_filesPrepared) return;

            IEnumerable<string> masks;
            if (Mask == null)
                masks = new string[] { "*.*" };
            else
                masks = Mask.Split('|').Select(s => s.Trim()).Where(s => !String.IsNullOrEmpty(s));

            // Add files present in the content directory
            var allFiles = new List<string>();

            foreach (var mask in masks)
            {
                allFiles.AddRange(Directory.GetFiles(_contentDirectory, mask, _includeSubs ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly));
            }

            allFiles.RemoveAll(name => Path.GetExtension(name) == ".exe" || Path.GetExtension(name) == ".dll");

            _artifactFilePaths = new List<string>(allFiles);
            _filesPrepared = true;
        }
Пример #20
0
        /// <summary>
        /// Prepares the source by reading all files present in the directory (matching the mask, if given)
        /// </summary>
        public void Prepare()
        {
#if !PORTABLE45
            _artifactFiles = new List<string>();

            IEnumerable<string> masks;
            if (Mask == null)
                masks = new string[] { "*.*" };
            else
                masks = Mask.Split('|').Select(s => s.Trim()).Where(s => !String.IsNullOrEmpty(s));

            // Add files present in the content directory
            var allFiles = new List<string>();

            foreach (var mask in masks)
            {
                allFiles.AddRange(Directory.GetFiles(_contentDirectory, mask, _includeSubs ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly));
            }

            var files = allFiles.Where(name => Path.GetExtension(name) != "exe" && Path.GetExtension(name) != "dll");
            
            _artifactFiles.AddRange(files);
            _isPrepared = true;
#else
            throw Error.NotImplemented("File based artifact source is not supported on the portable runtime");
#endif

        }
Пример #21
0
        public void SearchPatientByGenderMissing()
        {
            var patients = new List<ResourceEntry<Patient>>();
            var bundle = client.Search<Patient>();
            while (bundle != null && bundle.Entries.ByResourceType<Patient>().Count() > 0)
            {
                patients.AddRange(bundle.Entries.ByResourceType<Patient>());
                bundle = client.Continue(bundle);
            }
            var patientsNoGender = patients.Where(p => p.Resource.Gender == null);
            var nrOfPatientsWithMissingGender = patientsNoGender.Count();

            var actual = client.Search<Patient>(new string[] { "gender:missing=true" }, pageSize: 500).Entries.ByResourceType<Patient>();

            HttpTests.AssertCorrectNumberOfResults(nrOfPatientsWithMissingGender, actual.Count(), "Expected {0} patients without gender, but got {1}.");
        }