Esempio n. 1
0
        public void InitializationAndResolution()
        {
            var sd = _resolver.FindStructureDefinitionForCoreType(FHIRDefinedType.ValueSet);

            var assertion = new ProfileAssertion("Patient.name[0]", resolve);

            assertion.SetInstanceType(FHIRDefinedType.ValueSet);
            assertion.SetDeclaredType(FHIRDefinedType.ValueSet);
            assertion.AddStatedProfile("http://hl7.org/fhir/StructureDefinition/shareablevalueset");

            Assert.Equal(2, assertion.AllProfiles.Count());
            Assert.Equal(2, assertion.AllProfiles.Count(p => p.Status == null));    // status == null is only true for unresolved resources

            assertion.AddStatedProfile(sd);

            Assert.Equal(2, assertion.AllProfiles.Count());                      // Adding a ValueSet SD that was already there does not increase the profile count
            Assert.Equal(1, assertion.AllProfiles.Count(p => p.Status == null)); // but now there's 1 unresolved profile less
            Assert.True(assertion.AllProfiles.Contains(sd));                     // the other being the Sd we just added

            Assert.Equal(sd, assertion.InstanceType);
            Assert.Equal(sd, assertion.DeclaredType);

            var outcome = assertion.Resolve();

            Assert.True(outcome.Success);
            Assert.Equal(2, assertion.AllProfiles.Count());                      // We should still have 2 distinct SDs
            Assert.Equal(0, assertion.AllProfiles.Count(p => p.Status == null)); // none remain unresolved
            Assert.True(assertion.AllProfiles.Contains(sd));                     // one still being the Sd we manually added

            assertion.AddStatedProfile("http://hl7.org/fhir/StructureDefinition/unresolvable");

            outcome = assertion.Resolve();
            Assert.False(outcome.Success);
            Assert.Equal(3, assertion.AllProfiles.Count());                      // We should still have 3 distinct SDs
            Assert.Equal(1, assertion.AllProfiles.Count(p => p.Status == null)); // one remains unresolved
            Assert.True(assertion.AllProfiles.Contains(sd));                     // one still being the Sd we manually added
        }
Esempio n. 2
0
        public OperationOutcome Process()
        {
            var outcome = new OperationOutcome();

            // Start preprocessing by resolving the references to the profiles (if any)
            var resolveOutcome = _profiles.Resolve();

            outcome.Add(resolveOutcome);

            if (resolveOutcome.Success)
            {
                // Then, validate consistency of the profile assertions
                var validationOutcome = _profiles.Validate();
                outcome.Add(validationOutcome);

                if (validationOutcome.Success)
                {
                    if (_profiles.MinimalProfiles.Any())
                    {
                        // Then, generate snapshots for all sds that we have found
                        var genSnapshotOutcome = GenerateSnapshots(_profiles.MinimalProfiles, _snapshotGenerator, _path);
                        outcome.Add(genSnapshotOutcome);

                        if (genSnapshotOutcome.Success)
                        {
                            // Finally, return navigators to the definitions
                            Result = CreateNavigators(_profiles.MinimalProfiles);
                        }
                    }
                    else
                    {
                        outcome.AddIssue("There are no profile and type assertions at this point in the instance, so validation cannot succeed",
                                         Issue.PROFILE_NO_PROFILE_TO_VALIDATE_AGAINST, _path);
                    }
                }
            }

            return(outcome);
        }