Example #1
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;
            }
        }
Example #2
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);
        }