Esempio n. 1
0
 public static SpecificationProvider GetProvider(bool online)
 {
     if (online)
     {
         return(SpecificationProvider.CreateDefault());
     }
     else
     {
         return(SpecificationProvider.CreateOffline());
     }
 }
Esempio n. 2
0
        public static void Init(TestContext context)
        {
            SpecificationProvider provider = SpecificationProvider.CreateOffline(new FileArtifactSource("TestData"));
            SpecificationBuilder  builder  = new SpecificationBuilder(provider);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.Add("http://disk/Profile/lipid.profile.xml#lipidPanel");
            builder.Expand();

            spec = builder.ToSpecification();
        }
Esempio n. 3
0
 private static SpecificationBuilder createSpecificationBuilder(SpecificationProvider provider, string[] uris)
 {
     var builder = new SpecificationBuilder(provider);
     builder.Add(StructureFactory.PrimitiveTypes());
     builder.Add(StructureFactory.MetaTypes());
     builder.Add(StructureFactory.NonFhirNamespaces());
     foreach(string uri in uris)
     {
         builder.Add(uri);
     }
     builder.Expand();
     return builder;
 }
Esempio n. 4
0
        public static Specification GetProfileSpec(bool expand, bool online)
        {
            SpecificationProvider resolver = GetProvider(online);
            SpecificationBuilder  builder  = new SpecificationBuilder(resolver);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            if (expand)
            {
                builder.Expand();
            }

            return(builder.ToSpecification());
        }
Esempio n. 5
0
        public static SpecificationWorkspace GetExtendedPatientSpec(bool expand, bool online)
        {
            SpecificationProvider resolver = GetProvider(online);
            SpecificationBuilder  builder  = new SpecificationBuilder(resolver);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.Add("http://here.there/patient.extended.profile.xml");
            builder.Add("http://here.there/type-Extension.profile.xml");
            if (expand)
            {
                builder.Expand();
            }
            return(builder.ToSpecification());
        }
Esempio n. 6
0
        public static Specification GetExtendedPatientSpec(bool expand, bool online)
        {
            SpecificationProvider resolver = GetProvider(online);
            SpecificationBuilder  builder  = new SpecificationBuilder(resolver);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.LoadXmlFile("TestData\\patient.extended.profile.xml");
            builder.LoadXmlFile("TestData\\type-Extension.profile.xml");
            if (expand)
            {
                builder.Expand();
            }
            return(builder.ToSpecification());
        }
Esempio n. 7
0
        public SpecificationWorkspace Spec(string fileuri, string structure)
        {
            FhirFile.ExpandProfileFile("TestData\\" + fileuri + ".xml", "TestData\\testprofile.xml");
            Uri uri = new Uri("http://disk/testdata/testprofile.xml#" + structure);

            SpecificationProvider provider = SpecificationProvider.CreateOffline(new FileArtifactSource("TestData"));
            SpecificationBuilder  builder  = new SpecificationBuilder(provider);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.Add(uri);
            builder.Expand();

            return(builder.ToSpecification());
        }
Esempio n. 8
0
        public static SpecificationWorkspace GetLipidSpec(bool expand, bool online)
        {
            SpecificationProvider resolver = GetProvider(online);
            SpecificationBuilder  builder  = new SpecificationBuilder(resolver);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.Add("http://here.there/TestData/valueset.profile.xml");
            builder.Add("http://here.there/TestData/lipid.profile.xml");
            if (expand)
            {
                builder.Expand();
            }

            return(builder.ToSpecification());
        }
Esempio n. 9
0
        public static SpecificationWorkspace GetPatientSpec(bool expand, bool online)
        {
            SpecificationProvider resolver = GetProvider(online);
            SpecificationBuilder  builder  = new SpecificationBuilder(resolver);

            builder.Add(StructureFactory.PrimitiveTypes());
            builder.Add(StructureFactory.MetaTypes());
            builder.Add(StructureFactory.NonFhirNamespaces());
            builder.Add("http://hl7.org/fhir/Profile/Patient");

            if (expand)
            {
                builder.Expand();
            }

            return(builder.ToSpecification());
        }
        /// <summary>
        /// Build a property string for the given column specification.
        /// </summary>
        /// <param name="columnSpecification">The column for which to build a property string.</param>
        /// <param name="provider">The column specification provider (e.g., SQL Server).</param>
        /// <returns>Property string.</returns>
        private string BuildPropertyString(ColumnSpecification columnSpecification, SpecificationProvider provider)
        {
            string prop     = null;
            Type   propType = null;

            switch (provider)
            {
            case SpecificationProvider.SqlServer:
                (prop, propType) = BuildSqlServerPropertyString(columnSpecification);
                break;

            default:
                break;
            }

            return(AddAnnotations ? BuildPropertyAnnotationString(columnSpecification, propType) + prop : prop);
        }
Esempio n. 11
0
        public static OperationOutcome ValidateEntry(ResourceEntry entry)
        {
            OperationOutcome result = new OperationOutcome();

            result.Issue = new List <OperationOutcome.OperationOutcomeIssueComponent>();

            ICollection <ValidationResult> vresults = new List <ValidationResult>();


            // Phase 1, validate against low-level rules built into the FHIR datatypes

            // todo: The API no longer seems to have the FhirValidator class.

            /*
             * (!FhirValidator.TryValidate(entry.Resource, vresults, recurse: true))
             * {
             *  foreach (var vresult in vresults)
             *      result.Issue.Add(createValidationResult("[.NET validation] " + vresult.ErrorMessage, vresult.MemberNames));
             * }
             */

            // Phase 2, validate against the XML schema
            var xml = FhirSerializer.SerializeResourceToXml(entry.Resource);
            var doc = XDocument.Parse(xml);

            doc.Validate(SchemaCollection.ValidationSchemaSet, (source, args) => result.Issue.Add(createValidationResult("[XSD validation] " + args.Message, null)));


            // Phase 3, validate against a profile, if present
            var profileTags = entry.GetAssertedProfiles();

            if (profileTags.Count() == 0)
            {
                // If there's no profile specified, at least compare it to the "base" profile
                string baseProfile = CoreZipArtifactSource.CORE_SPEC_PROFILE_URI_PREFIX + entry.Resource.GetCollectionName();
                profileTags = new Uri[] { new Uri(baseProfile, UriKind.Absolute) };
            }

            var artifactSource = ArtifactResolver.CreateOffline();
            var specProvider   = new SpecificationProvider(artifactSource);

            foreach (var profileTag in profileTags)
            {
                var specBuilder = new SpecificationBuilder(specProvider);
                specBuilder.Add(StructureFactory.PrimitiveTypes());
                specBuilder.Add(StructureFactory.MetaTypes());
                specBuilder.Add(StructureFactory.NonFhirNamespaces());
                specBuilder.Add(profileTag.ToString());
                specBuilder.Expand();

                string path = Directory.GetCurrentDirectory();

                var spec = specBuilder.ToSpecification();
                var nav  = doc.CreateNavigator();
                nav.MoveToFirstChild();

                Report report = spec.Validate(nav);
                var    errors = report.Errors;
                foreach (var error in errors)
                {
                    result.Issue.Add(createValidationResult("[Profile validator] " + error.Message, null));
                }
            }

            if (result.Issue.Count == 0)
            {
                return(null);
            }
            else
            {
                return(result);
            }
        }
 public SpecificationBuilder(SpecificationProvider provider)
 {
     this.provider = provider;
 }
Esempio n. 13
0
        public static OperationOutcome ValidateEntry(ResourceEntry entry)
        {
            OperationOutcome result = new OperationOutcome();
            result.Issue = new List<OperationOutcome.OperationOutcomeIssueComponent>();

            ICollection<ValidationResult> vresults = new List<ValidationResult>();

            // Phase 1, validate against low-level rules built into the FHIR datatypes

            // todo: The API no longer seems to have the FhirValidator class.
            /*
            (!FhirValidator.TryValidate(entry.Resource, vresults, recurse: true))
            {
                foreach (var vresult in vresults)
                    result.Issue.Add(createValidationResult("[.NET validation] " + vresult.ErrorMessage, vresult.MemberNames));
            }
            */

            // Phase 2, validate against the XML schema
            var xml = FhirSerializer.SerializeResourceToXml(entry.Resource);
            var doc = XDocument.Parse(xml);
            doc.Validate(SchemaCollection.ValidationSchemaSet, (source, args) => result.Issue.Add( createValidationResult("[XSD validation] " + args.Message,null) ));

            // Phase 3, validate against a profile, if present
            var profileTags = entry.GetAssertedProfiles();
            if (profileTags.Count() == 0)
            {
                // If there's no profile specified, at least compare it to the "base" profile
                string baseProfile = CoreZipArtifactSource.CORE_SPEC_PROFILE_URI_PREFIX + entry.Resource.GetCollectionName();
                profileTags = new Uri[] { new Uri(baseProfile, UriKind.Absolute) };
            }

            var artifactSource = ArtifactResolver.CreateOffline();
            var specProvider = new SpecificationProvider(artifactSource);

            foreach (var profileTag in profileTags)
            {
                var specBuilder = new SpecificationBuilder(specProvider);
                specBuilder.Add(StructureFactory.PrimitiveTypes());
                specBuilder.Add(StructureFactory.MetaTypes());
                specBuilder.Add(StructureFactory.NonFhirNamespaces());
                specBuilder.Add(profileTag.ToString());
                specBuilder.Expand();

                string path = Directory.GetCurrentDirectory();

                var spec = specBuilder.ToSpecification();
                var nav = doc.CreateNavigator();
                nav.MoveToFirstChild();

                Report report = spec.Validate(nav);
                var errors = report.Errors;
                foreach (var error in errors)
                {
                    result.Issue.Add(createValidationResult("[Profile validator] " + error.Message, null));
                }
            }

            if(result.Issue.Count == 0)
                return null;
            else
                return result;
        }