Beispiel #1
0
        public void SimpleMod()
        {
            StructureDefinition original = this.CreateBaseObservation();
            StructureDefinition modified = this.CreateBaseObservation();

            SnapshotCreator.Create(original);
            SnapshotCreator.Create(modified);
            ElementTreeLoader loader = new ElementTreeLoader(info);

            ElementTreeNode originalNode = loader.Create(original.Snapshot.Element);
            ElementTreeNode modifiedNode = loader.Create(modified.Snapshot.Element);

            Assert.True(modifiedNode.TryGetElementNode("Observation.value[x]", out ElementTreeNode n));
            n.ElementDefinition.Max = "0";

            ElementTreeDiffer differ = new ElementTreeDiffer(info);

            differ.Process(originalNode, modifiedNode);

            List <ElementDefinition> elementDefinitions = new List <ElementDefinition>();

            modifiedNode.CopyTo(elementDefinitions);
            Assert.True(elementDefinitions.Count == 2);
            Assert.True(elementDefinitions[1].Path == "Observation.value[x]");
            Assert.True(elementDefinitions[1].Max == "0");
        }
Beispiel #2
0
        void FixDifferential(ProcessItem processedItem)
        {
            const String        fcn  = "FixDifferentials";
            StructureDefinition sDef = (StructureDefinition)processedItem.Resource;

            this.ConversionInfo(this.GetType().Name,
                                fcn,
                                $"Computing differential for {processedItem.Resource.GetName()}");

            ElementTreeNode differentialNode = processedItem.SnapNode.Clone();
            {
                ElementTreeDiffer differ = new ElementTreeDiffer(this);
                if (differ.Process(processedItem.SnapNodeOriginal, differentialNode) == false)
                {
                    return;
                }
            }
            {
                ElementTreeSetBase setBase = new ElementTreeSetBase(this);
                if (setBase.Process(processedItem.SnapNodeOriginal, differentialNode) == false)
                {
                    return;
                }
            }

            {
                processedItem.DiffNode = differentialNode;
                List <ElementDefinition> elementDefinitions = new List <ElementDefinition>();
                differentialNode.CopyTo(elementDefinitions);
                sDef.Differential.Element = elementDefinitions;
            }
        }
Beispiel #3
0
        public bool Write(out String fragmentName)
        {
            fragmentName = null;

            this.sDef.Snapshot = null;

            // Create differential by comparing current snapshot with original.
            ElementTreeNode differentialNode = this.snapNode.Clone();

            {
                ElementTreeDiffer differ = new ElementTreeDiffer(this.info);
                if (differ.Process(this.snapNodeOriginal, differentialNode) == false)
                {
                    return(false);
                }
            }
            {
                ElementTreeSetBase setBase = new ElementTreeSetBase(this.info);
                if (setBase.Process(this.snapNodeOriginal, differentialNode) == false)
                {
                    return(false);
                }
            }

            // Patch Path and Id's with correct basePath.
            differentialNode.ReplaceBasePath(this.basePath);

            {
                List <ElementDefinition> elementDefinitions = new List <ElementDefinition>();
                differentialNode.CopyTo(elementDefinitions);
                this.sDef.Differential.Element = elementDefinitions;
            }

            fragmentName = Path.Combine(this.fragmentDir, $"StructureDefinition-{this.sDef.Name}.json");

            // Make sure that all Observation resources that are not fragments, have Observation.code
            // fixed properly.
            if (
                (this.sDef.IsFragment() == false) &&
                (this.sDef.BaseDefinition == Global.ObservationUrl)
                )
            {
                if (this.snapNode.TryGetElementNode("Observation.code", out ElementTreeNode codeNode) == false)
                {
                    throw new Exception("Observation.code not found");
                }
                if (codeNode.ElementDefinition.Pattern == null)
                {
                    this.info.ConversionError(nameof(SDefEditor),
                                              "Write",
                                              $"Observation {this.SDef.Name} lacks fixed Observation.code.");
                }
            }

            SnapshotCreator.Create(this.sDef);

            this.sDef.SaveJson(fragmentName);
            return(true);
        }
Beispiel #4
0
        public void NoMod()
        {
            StructureDefinition original = this.CreateBaseObservation();
            StructureDefinition modified = this.CreateBaseObservation();

            SnapshotCreator.Create(original);
            SnapshotCreator.Create(modified);
            ElementTreeLoader loader       = new ElementTreeLoader(info);
            ElementTreeNode   originalNode = loader.Create(original.Snapshot.Element);
            ElementTreeNode   modifiedNode = loader.Create(modified.Snapshot.Element);

            ElementTreeDiffer differ = new ElementTreeDiffer(info);

            differ.Process(originalNode, modifiedNode);

            List <ElementDefinition> elementDefinitions = new List <ElementDefinition>();

            modifiedNode.CopyTo(elementDefinitions);
            Assert.True(elementDefinitions.Count == 0);
        }