コード例 #1
0
 private void stashDifferentialStructure(Profile differential, Profile.ProfileStructureComponent structure)
 {
     structure.Name += "-differential";
     structure.SetStructureForm(StructureForm.Differential);
     structure.SetStructureBaseUri(StructureLoader.BuildBaseStructureUri(structure.TypeElement).ToString());
     structure.Publish = false;
 }
コード例 #2
0
        public Profile.ProfileStructureComponent Expand(Profile.ProfileStructureComponent differential)
        {
            var baseStructure = _loader.LocateBaseStructure(differential.TypeElement);

            if (baseStructure == null)
            {
                throw Error.InvalidOperation("Could not locate the base profile for type {0}", differential.TypeElement.ToString());
            }

            var baseUri = StructureLoader.BuildBaseStructureUri(differential.TypeElement).ToString();

            var snapshot = (Profile.ProfileStructureComponent)baseStructure.DeepCopy();

            snapshot.SetStructureForm(StructureForm.Snapshot);
            snapshot.SetStructureBaseUri(baseUri.ToString());

            mergeStructure(snapshot, differential);

            var fullDifferential = new DifferentialTreeConstructor(differential).MakeTree();

            var snapNav = new ElementNavigator(snapshot);

            snapNav.MoveToFirstChild();

            var diffNav = new ElementNavigator(fullDifferential);

            diffNav.MoveToFirstChild();

            merge(snapNav, diffNav);

            //TODO: Merge search params?

            snapNav.CommitChanges();
            return(snapshot);
        }
コード例 #3
0
        public static bool ExpandElement(this ElementNavigator nav, StructureLoader source)
        {
            if (source == null)
            {
                throw Error.ArgumentNull("source");
            }
            if (nav.Current == null)
            {
                throw Error.ArgumentNull("Navigator is not positioned on an element");
            }

            if (nav.Current.Definition == null)
            {
                throw Error.Argument("Cannot move down into element {0} since it has no element definition information", nav.Path);
            }

            if (nav.HasChildren)
            {
                return(true);                    // already has children, we're not doing anything extra
            }
            if (nav.Current.Definition != null)
            {
                var defn = nav.Current.Definition;
                if (!String.IsNullOrEmpty(defn.NameReference))
                {
                    var sourceNav = resolveNameReference(nav.Structure, defn.NameReference);
                    nav.CopyChildren(sourceNav);
                }
                else if (defn.Type != null && defn.Type.Count > 0)
                {
                    if (defn.Type.Count > 1)
                    {
                        throw new NotImplementedException("Don't know how to implement navigation into choice types yet at node " + nav.Path);
                    }
                    else
                    {
                        var sourceNav = resolveStructureReference(source, defn.Type[0].CodeElement);

                        if (sourceNav != null)
                        {
                            sourceNav.MoveToFirstChild();
                            nav.CopyChildren(sourceNav);
                        }
                        else
                        {
                            throw new FileNotFoundException("Cannot locate base-structure for datatype " + defn.Type[0].Code);
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
コード例 #4
0
        public void LocateStructure()
        {
            var locator = new StructureLoader(ArtifactResolver.CreateDefault());
            var profileUri = new Uri("http://hl7.org/fhir/Profile/Profile");

            var prof = locator.Locate(profileUri, new Code("Profile"));
            Assert.IsNotNull(prof);
            Assert.AreEqual("Profile", prof.Type);
            //Assert.AreEqual(profileUri.ToString(), prof.GetProfileLocation());

            // Try to locate a structure that cannot be found in the given profile
            prof = locator.Locate(profileUri, new Code("Patient"));
            Assert.IsNull(prof);

            profileUri = new Uri("http://take.from.disk/Profile/example-lipid-profile");
            var profileUriWithFrag = new Uri(profileUri.ToString() + "#lipidResultMessage");
            prof = locator.Locate(profileUriWithFrag, new Code("MessageHeader"));
            Assert.IsNotNull(prof);
            Assert.AreEqual("MessageHeader", prof.Type);
            Assert.AreEqual("lipidResultMessage", prof.Name);
            //Assert.AreEqual(profileUri.ToString(), prof.GetProfileLocation());

            // Try to locate a structure that cannot be found in the profile by name
            profileUriWithFrag = new Uri(profileUri.ToString() + "#XXX");
            prof = locator.Locate(profileUriWithFrag, new Code("Profile"));
            Assert.IsNull(prof);
        }
コード例 #5
0
        public void TestExpandChild()
        {
            var loader = new StructureLoader(ArtifactResolver.CreateDefault());
            var profStruct = loader.Locate(new Uri("http://hl7.org/fhir/Profile/Profile"), new Code("Profile"));

            var nav = new ElementNavigator(profStruct);
            
            nav.JumpToFirst("Profile.telecom");
            Assert.IsTrue(nav.ExpandElement(loader));
            Assert.IsTrue(nav.MoveToChild("period"));

            nav.JumpToFirst("Profile.extensionDefn.definition");
            Assert.IsTrue(nav.ExpandElement(loader));
            Assert.IsTrue(nav.MoveToChild("max"));
        }
コード例 #6
0
 private static ElementNavigator resolveStructureReference(StructureLoader loader, Code code)
 {
     var result = loader.LocateBaseStructure(code);
     return result != null ? new ElementNavigator(result) : null;
 }
コード例 #7
0
        public static bool ExpandElement(this ElementNavigator nav, StructureLoader source)
        {
            if(source == null) throw Error.ArgumentNull("source");
            if(nav.Current == null) throw Error.ArgumentNull("Navigator is not positioned on an element");

            if (nav.Current.Definition == null) throw Error.Argument("Cannot move down into element {0} since it has no element definition information", nav.Path);

            if(nav.HasChildren) return true;     // already has children, we're not doing anything extra

            if (nav.Current.Definition != null)
            {
                var defn = nav.Current.Definition;
                if (!String.IsNullOrEmpty(defn.NameReference))
                {
                    var sourceNav = resolveNameReference(nav.Structure, defn.NameReference);
                    nav.CopyChildren(sourceNav);
                }
                else if (defn.Type != null && defn.Type.Count > 0)
                {
                    if (defn.Type.Count > 1)
                        throw new NotImplementedException("Don't know how to implement navigation into choice types yet at node " + nav.Path);
                    else
                    {
                        var sourceNav = resolveStructureReference(source, defn.Type[0].CodeElement);

                        if (sourceNav != null)
                        {
                            sourceNav.MoveToFirstChild();
                            nav.CopyChildren(sourceNav);
                        }
                        else
                            throw new FileNotFoundException("Cannot locate base-structure for datatype " + defn.Type[0].Code);
                    }
                }

                return true;
            }

            return false;
        }
コード例 #8
0
        private static ElementNavigator resolveStructureReference(StructureLoader loader, Code code)
        {
            var result = loader.LocateBaseStructure(code);

            return(result != null ? new ElementNavigator(result) : null);
        }
コード例 #9
0
 public ProfileExpander(IArtifactSource source)
 {
     _loader = new StructureLoader(source);
 }
コード例 #10
0
 public ProfileExpander()
 {
     _loader = new StructureLoader(new CachedArtifactSource(ArtifactResolver.CreateDefault()));
 }
コード例 #11
0
 public StructureExpander(Profile.ProfileStructureComponent structure, StructureLoader loader)
 {
     Structure = structure;
     _loader = loader;
 }
コード例 #12
0
 public ProfileExpander(IArtifactSource source)
 {
     _loader = new StructureLoader(source);
 }
コード例 #13
0
 public ProfileExpander()
 {
     _loader = new StructureLoader(new CachedArtifactSource(ArtifactResolver.CreateDefault()));
 }
コード例 #14
0
 public StructureExpander(Profile.ProfileStructureComponent structure, StructureLoader loader)
 {
     Structure = structure;
     _loader   = loader;
 }