public static ElementNavigator JumpToNameReference(this Profile.ProfileStructureComponent structure, string nameReference)
        {
            var nav = new ElementNavigator(structure);

            //TODO: In the current DSTU1 base profiles, nameReference is actually a path, not a name (to Element.Name)
            //this is a problem, since when doing slicing, the path may no longer point to a single set of constraints
            //so, we need to (temporarily) watch out for this
            if (nameReference.Contains("."))
            {
                // An incorrectly used nameReference, containing a Path, not a name
                if (nav.JumpToFirst(nameReference))
                {
                    return(nav);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                if (nav.JumpToNameReference(nameReference))
                {
                    return(nav);
                }
                else
                {
                    return(null);
                }
            }
        }
 private void HarvestElements(Profile.ProfileStructureComponent source, Structure target)
 {
     foreach (var element in source.Element)
     {
         target.Elements.Add(HarvestElement(element));
     }
 }
Beispiel #3
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;
 }
Beispiel #4
0
        private Profile.ProfileStructureComponent expandStructure(Profile.ProfileStructureComponent structure)
        {
            var expander = new StructureExpander(structure, _loader);
            var snapshot = expander.Expand(structure);

            return(snapshot);
        }
Beispiel #5
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);
        }
        private void generateStructure(Profile profile, int i, Profile.ProfileStructureComponent s)
        {
            write("<p><a name=\"i" + i.ToString() + "\"><b>" + s.Name + "</b></a></p>\r\n");
            write("<table class=\"dict\">\r\n");

            foreach (var ec in s.Element)
            {
                if (isProfiledExtension(ec))
                {
                    String name  = _pkp.MakeElementDictAnchor(s, ec);
                    String title = ec.Path + " (" + ec.Definition.Type[0].Profile + ")";
                    write("  <tr><td colspan=\"2\" class=\"structure\"><a name=\"" + name + "\"> </a><b>" + title + "</b></td></tr>\r\n");

                    var profExtDefn = _pkp.getExtensionDefinition(profile, ec.Definition.Type[0].Profile);
                    var extDefn     = ec.Definition;
                    if (profExtDefn != null)
                    {
                        extDefn = profExtDefn.Definition;
                    }

                    generateElementInner(profile, extDefn);
                }
                else
                {
                    String name  = _pkp.MakeElementDictAnchor(s, ec);
                    String title = ec.Path + (ec.Name == null ? "" : "(" + ec.Name + ")");
                    write("  <tr><td colspan=\"2\" class=\"structure\"><a name=\"" + name + "\"> </a><b>" + title + "</b></td></tr>\r\n");
                    generateElementInner(profile, ec.Definition);
                }
            }

            write("</table>\r\n");
        }
Beispiel #7
0
        public void MakeDifferentialTree()
        {
            var struc = new Profile.ProfileStructureComponent();

            struc.Differential         = new Profile.ConstraintComponent();
            struc.Differential.Element = new List <Profile.ElementComponent>();
            var e = struc.Differential.Element;

            e.Add(new Profile.ElementComponent()
            {
                Path = "A.B.C1"
            });
            e.Add(new Profile.ElementComponent()
            {
                Path = "A.B.C1"
            });
            e.Add(new Profile.ElementComponent()
            {
                Path = "A.B.C2"
            });
            e.Add(new Profile.ElementComponent()
            {
                Path = "A.B"
            });
            e.Add(new Profile.ElementComponent()
            {
                Path = "A.B.C1.D"
            });
            e.Add(new Profile.ElementComponent()
            {
                Path = "A.D.F"
            });

            var tree = new DifferentialTreeConstructor(struc.Differential).MakeTree();

            Assert.IsNotNull(tree);

            var nav = new ElementNavigator(tree);

            Assert.AreEqual(10, nav.Count);

            Assert.IsTrue(nav.MoveToChild("A"));
            Assert.IsTrue(nav.MoveToChild("B"));
            Assert.IsTrue(nav.MoveToChild("C1"));
            Assert.IsTrue(nav.MoveToNext("C1"));
            Assert.IsTrue(nav.MoveToNext("C2"));

            Assert.IsTrue(nav.MoveToParent());                    // 1st A.B
            Assert.IsTrue(nav.MoveToNext() && nav.Path == "A.B"); // (now) 2nd A.B
            Assert.IsTrue(nav.MoveToChild("C1"));
            Assert.IsTrue(nav.MoveToChild("D"));

            Assert.IsTrue(nav.MoveToParent());  // A.B.C1
            Assert.IsTrue(nav.MoveToParent());  // A.B (2nd)
            Assert.IsTrue(nav.MoveToNext() && nav.Path == "A.D");
            Assert.IsTrue(nav.MoveToChild("F"));
        }
 public void PrepareSlices(Profile.ProfileStructureComponent source)
 {
     foreach (Profile.ElementComponent e in source.Element)
     {
         if (e.Slicing != null)
         {
             Slicing s = PrepareSlice(e);
             Slicings.Add(s);
         }
     }
 }
Beispiel #9
0
        //
        // STRUCTURE_FORM
        //
        public static StructureForm?GetStructureForm(this Profile.ProfileStructureComponent structure)
        {
            var           val  = structure.GetExtensionValue(STRUCTURE_FORM) as Code;
            StructureForm?form = null;

            if (val != null)
            {
                form = (StructureForm)Enum.Parse(typeof(StructureForm), val.Value);
            }

            return(form);
        }
        public Structure HarvestStructure(Profile.ProfileStructureComponent source, Uri uri)
        {
            Structure target = new Structure();

            target.Name            = source.Name;
            target.Type            = source.Type;
            target.NameSpacePrefix = FhirNamespaceManager.Fhir;
            PrepareSlices(source);
            HarvestElements(source, target);
            fixUris(target, uri);
            return(target);
        }
Beispiel #11
0
        public void CopyChildTree()
        {
            var dest = createTestNav();

            var struc = new Profile.ProfileStructureComponent();

            struc.Element = new List <Profile.ElementComponent>();
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "X"
            });
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "X.Y1"
            });
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "X.Y2"
            });
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "X.Y2.Z1"
            });
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "X.Y2.Z2"
            });
            var source = new ElementNavigator(struc);

            Assert.IsTrue(dest.JumpToFirst("A.D"));
            var dstPos = dest.OrdinalPosition;

            source.MoveToFirstChild();
            var srcPos = source.OrdinalPosition;

            Assert.IsTrue(dest.CopyChildren(source));
            Assert.AreEqual(srcPos, source.OrdinalPosition, "source did not remain on original position");
            Assert.AreEqual(dstPos, dest.OrdinalPosition, "dest did not remain on original position");

            Assert.IsTrue(dest.MoveToFirstChild());
            Assert.AreEqual("Y1", dest.PathName);
            Assert.IsTrue(dest.MoveToNext());
            Assert.AreEqual("Y2", dest.PathName);
            Assert.IsFalse(dest.MoveToNext());
            Assert.IsTrue(dest.MoveToFirstChild());
            Assert.AreEqual("Z1", dest.PathName);
            Assert.IsTrue(dest.MoveToNext());
            Assert.AreEqual("Z2", dest.PathName);
            Assert.IsFalse(dest.MoveToNext());
        }
        public XElement generateStructureTable(Profile.ProfileStructureComponent structure, bool diff, Profile profile)
        {
            HierarchicalTableGenerator gen = new HierarchicalTableGenerator(_pkp);
            var model = TableModel.CreateNormalTable();

            // List<Profile.ElementComponent> list = diff ? structure.getDifferential().getElement() : structure.getSnapshot().getElement();   DSTU2
            var list = structure.Element;
            var nav  = new ElementNavigator(structure);

            nav.MoveToFirstChild();

            genElement(gen, model.Rows, nav, profile, true);
            return(gen.generate(model));
        }
Beispiel #13
0
 private static void mergeStructure(Profile.ProfileStructureComponent snapshot, Profile.ProfileStructureComponent differential)
 {
     if (differential.Name != null)
     {
         snapshot.Name = differential.Name;
     }
     if (differential.Publish != null)
     {
         snapshot.Publish = differential.Publish;
     }
     if (differential.Purpose != null)
     {
         snapshot.Purpose = differential.Purpose;
     }
 }
Beispiel #14
0
        public XElement generateStructureTable(String defFile, Profile.ProfileStructureComponent structure, bool diff, String imageFolder,
                                               bool inlineGraphics, Profile profile, string profileUrl, String profileBaseFileName)
        {
            HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
            TableModel model = gen.initNormalTable();

            // List<Profile.ElementComponent> list = diff ? structure.getDifferential().getElement() : structure.getSnapshot().getElement();   DSTU2
            var list = structure.Element;
            var nav  = new ElementNavigator(structure);

            nav.MoveToFirstChild();

            genElement(defFile == null ? null : defFile + "#" + structure.Name + ".", gen, model.getRows(), nav, profile, diff, profileUrl, profileBaseFileName);
            return(gen.generate(model));
        }
        public string MakeElementDictAnchor(Profile.ProfileStructureComponent s, Profile.ElementComponent element)
        {
            if (element.Name == null)
            {
                return(s.Name + "." + element.Path);
            }

            if (!element.Path.Contains("."))
            {
                return(s.Name + "." + element.Name);
            }
            else
            {
                return(s.Name + "." + element.Path.Substring(0, element.Path.LastIndexOf(".")) + "." + element.Name);
            }
        }
        public void Expand(Profile.ProfileStructureComponent structure)
        {
            if (structure.Differential == null)
            {
                throw Error.Argument("structure", "structure does not contain a differential specification");
            }
            var differential = structure.Differential;

            var baseStructure = _loader.LocateBaseStructure(structure.TypeElement);

            if (baseStructure == null)
            {
                throw Error.InvalidOperation("Could not locate the base profile for type {0}", structure.TypeElement.ToString());
            }
            if (baseStructure.Snapshot == null)
            {
                throw Error.InvalidOperation("Base definition to use for expansion lacks a snapshot representation");
            }

            //   var baseUri = StructureLoader.BuildBaseStructureUri(structure.TypeElement).ToString();

            var snapshot = (Profile.ConstraintComponent)baseStructure.Snapshot.DeepCopy();

            //DSTU1
            //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();
            structure.Snapshot = snapNav.Elements;
        }
Beispiel #17
0
        private static Profile.ProfileStructureComponent createTestStructure()
        {
            var struc = new Profile.ProfileStructureComponent();

            struc.Element = new List <Profile.ElementComponent>();

            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "A"
            });
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "A.B"
            });
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "A.B.C1"
            });
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "A.B.C2"
            });
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "A.B"
            });
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "A.B"
            });
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "A.B.C1"
            });
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "A.B.C1.D"
            });
            struc.Element.Add(new Profile.ElementComponent()
            {
                Path = "A.D"
            });
            return(struc);
        }
        /// <summary>
        /// Rewrites the Path's of the elements in a structure so they are based on the given path: the root
        /// of the given structure will become the given path, it's children will be relocated below that path
        /// </summary>
        /// <param name="root">The structure that will be rebased on the path</param>
        /// <param name="path">The path to rebase the structure on</param>
        public static void Rebase(this Profile.ProfileStructureComponent root, string path)
        {
            var nav = new ElementNavigator(root);

            if (nav.MoveToFirstChild())
            {
                var newPaths = new List <string>();
                newPaths.Add(path);

                rebaseChildren(nav, path, newPaths);

                // Can only change the paths after navigating the tree, otherwise the
                // navigation functions (which are based on the paths) won't function correctly
                for (var i = 0; i < root.Element.Count; i++)
                {
                    root.Element[i].Path = newPaths[i];
                }
            }
        }
Beispiel #19
0
 public static void SetStructureBaseUri(this Profile.ProfileStructureComponent structure, string baseUri)
 {
     structure.SetExtension(STRUCTURE_BASE_URI, new FhirUri(baseUri));
 }
 internal string GetLinkForLocalStructure(Profile profile, Profile.ProfileStructureComponent structure)
 {
     return(GetLinkForLocalStructure(profile, structure.Name));
 }
 internal string GetLinkForElementDefinition(Profile.ProfileStructureComponent s, Profile profile, Profile.ElementComponent element)
 {
     return(GetLinkForProfileDict(profile) + "#" + MakeElementDictAnchor(s, element));
 }
 public ElementNavigator(Profile.ProfileStructureComponent structure)
 {
     setupElems(structure.Element);
     Structure = structure;
 }
Beispiel #23
0
        private void expandStructure(Profile.ProfileStructureComponent structure)
        {
            var expander = new StructureExpander(_loader);

            expander.Expand(structure);
        }
 public DifferentialTreeConstructor(Profile.ProfileStructureComponent source)
 {
     _source = source;
 }
 private static ElementNavigator resolveNameReference(Profile.ProfileStructureComponent structure, string nameReference)
 {
     return(structure.JumpToNameReference(nameReference));
 }
Beispiel #26
0
 public static void SetStructureForm(this Profile.ProfileStructureComponent structure, StructureForm form)
 {
     structure.SetExtension(STRUCTURE_FORM, new Code(form.ToString()));
 }
Beispiel #27
0
 public static void RemoveStructureForm(this Profile.ProfileStructureComponent structure)
 {
     structure.RemoveExtension(STRUCTURE_FORM);
 }
Beispiel #28
0
        //
        // STRUCTURE_BASE_URI
        //
        public static string GetStructureBaseUri(this Profile.ProfileStructureComponent structure)
        {
            var val = structure.GetExtensionValue(STRUCTURE_BASE_URI) as FhirUri;

            return(val != null ? val.Value : null);
        }
Beispiel #29
0
 public static void RemoveStructureBaseUri(this Profile.ProfileStructureComponent structure)
 {
     structure.RemoveExtension(STRUCTURE_BASE_URI);
 }
Beispiel #30
0
 public StructureExpander(Profile.ProfileStructureComponent structure, StructureLoader loader)
 {
     Structure = structure;
     _loader   = loader;
 }