public override void Build()
        {
            Int32 max = CSMisc.ToMax(this.extensionSlice.ElementDefinition.Max);
            Int32 min = this.extensionSlice.ElementDefinition.Min.Value;

            base.BuildOne(this.extensionName, min, max);
            this.BuildExtensionItemClass();
        }
        /// <summary>
        /// Build a class to implement an extension.
        /// This determines if a simple extension is to be defined,
        /// or a complex extension.
        /// </summary>
        public void Build()
        {
            //$ TODO: Implement validation

            const String      fcn          = "Build";
            ElementDefinition extensionDef = this.extensionSlice.ElementDefinition;

            if (
                (extensionDef.Type.Count == 1) &&
                (extensionDef.Type[0].Code == "Extension")
                )
            {
                if (extensionDef.Type[0].Profile.Count() > 0)
                {
                    if (extensionDef.Type[0].Profile.Count() != 1)
                    {
                        throw new Exception($"Invalid extension ProfileProfile definition {this.extensionName}");
                    }
                    if (this.extensionSlice.Nodes.Count > 0)
                    {
                        throw new Exception($"Invalid eternal extension {this.extensionName}. Nodes.Count ==  {this.extensionSlice.Nodes.Count}. Expected 0.");
                    }
                    BuildExtensionReference(extensionDef);
                    return;
                }
            }

            ElementTreeNode valueXNode       = this.extensionSlice.Nodes.GetItem("value[x]");
            ElementTreeNode subExtensionNode = this.extensionSlice.Nodes.GetItem("extension");
            Int32           valueXCardMax    = CSMisc.ToMax(valueXNode.ElementDefinition.Max);

            if ((valueXCardMax != 0) && (subExtensionNode.Slices.Count > 1))
            {
                // Cant build both simple and complex extension.
                throw new Exception($"Both Simple and Complex extension found. Not implemented");
            }
            else if ((valueXCardMax == 0) && (subExtensionNode.Slices.Count == 0))
            {
                // Neither simple and complex extension?
                throw new Exception($"Neither Simple and Complex extension found. Not implemented");
            }
            else if (valueXCardMax != 0)
            {
                // Build Simple Extension
                this.BuildOneSimpleExtension(this.extensionName);
            }
            else
            {
                // Build Complex Extension
                this.BuildOneComplexExtension(this.extensionName);
            }
        }
Beispiel #3
0
        public override void Build()
        {
            Int32 max = CSMisc.ToMax(this.extensionSlice.ElementDefinition.Max);
            Int32 min = this.extensionSlice.ElementDefinition.Min.Value;

            ElementTreeNode valueNode = this.extensionSlice.Nodes["value[x]"];

            this.itemElementSetName.Clear();
            foreach (var type in valueNode.ElementDefinition.Type)
            {
                this.itemElementSetName.Add(type.Code);
            }
            this.itemElementGetName = (this.itemElementSetName.Count == 1) ? valueNode.ElementDefinition.Type[0].Code : "Element";

            base.BuildOne(this.extensionSlice.ElementDefinition.ElementId, min, max);
        }
Beispiel #4
0
        public override void Build()
        {
            Int32 max = CSMisc.ToMax(this.valueNode.ElementDefinition.Max);
            Int32 min = this.valueNode.ElementDefinition.Min.Value;

            this.itemElementSetName.Clear();
            foreach (var type in this.valueNode.ElementDefinition.Type)
            {
                this.itemElementSetName.Add(type.Code);
            }

            this.containerClassName = $"M{this.ElementName.ToMachineName()}";
            this.itemElementGetName = (this.itemElementSetName.Count == 1) ?
                                      this.valueNode.ElementDefinition.Type[0].Code : "Element";
            base.BuildOne(this.valueNode.ElementDefinition.ElementId, min, max);
            this.BuildExtensions();
        }
        /// <summary>
        /// Extension is a reference to a predefined extension. Build a reference to the
        /// class that implements that extension.
        /// </summary>
        void BuildExtensionReference(ElementDefinition extensionDef)
        {
            const String fcn = "BuildExtensionReference";

            if (extensionDef.Type[0].Profile.Count() > 1)
            {
                this.defineBase.CSBuilder.ConversionError(this.GetType().Name,
                                                          fcn,
                                                          $"Don't know how to handle multiple extension type profiles.");
                return;
            }
            String extensionUrl = extensionDef.Type[0].Profile.First();

            if (extensionUrl.StartsWith(Global.BreastRadBaseUrl) == false)
            {
                this.defineBase.CSBuilder.ConversionError(this.GetType().Name,
                                                          fcn,
                                                          $"Don't know how to handle externally defined extension profiles.");
                return;
            }

            String extensionClass = CSMisc.ClassName(extensionUrl.LastUriPart());
            String propertyName   = this.extensionSlice.ElementDefinition.SliceName.ToMachineName();

            this.codeBlocks.LocalUsings
            .AppendUniqueLine($"using {CSMisc.LocalClassNameSpace(extensionClass)}")
            ;
            this.codeBlocks.ClassProperties
            .AppendCode($"M{extensionClass} {propertyName};")
            ;

            Int32 min = this.extensionSlice.ElementDefinition.Min.Value;
            Int32 max = CSMisc.ToMax(this.extensionSlice.ElementDefinition.Max);

            this.codeBlocks.ClassConstructor
            .AppendCode($"this.{propertyName} = new M{extensionClass}({min}, {max});")
            ;

            this.codeBlocks.ClassWriteCode
            .AppendCode($"extensionList.AddRange(this.{propertyName}.Write(doc));")
            ;

            this.codeBlocks.ClassReadCode
            .AppendCode($"this.{propertyName}.Read(doc, extensionList);")
            ;
        }
Beispiel #6
0
        public override void Build()
        {
            if (this.memberNode.Slices.Count <= 1)
            {
                return;
            }

            // Block is marked with !, so the top level lines are not merged, so we
            // dont have duplicate Read/Write methods.
            // block may have been defined in a class merged into this one,
            // so check to see if it exists.
            String          readBlockName      = $"ReadHasMembers";
            String          writeBlockName     = $"WriteHasMembers";
            String          referenceBlockName = $"!HasMembers";
            CodeBlockNested memberBlock        = this.codeBlocks.ClassMethods.Find(referenceBlockName, false);

            if (memberBlock == null)
            {
                this.codeBlocks.ClassMethods
                .BlankLine()
                .StartBlock(referenceBlockName)

                .BlankLine()
                .SummaryOpen()
                .Summary($"Read all values from resource into this instance")
                .SummaryClose()
                .AppendCode($"private void ReadHasMembers(BreastRadiologyDocument doc)")
                .OpenBrace()
                .AppendCode($"List<{this.FhirClassName}> items = this.Resource.GetValue<{this.FhirClassName}>(\"hasMember\").ToList();")
                .DefineBlock(out this.readBlock, readBlockName)
                .CloseBrace()

                .BlankLine()
                .SummaryOpen()
                .Summary($"Write all values from this instance into resource")
                .SummaryClose()
                .AppendCode($"private void WriteHasMembers(BreastRadiologyDocument doc)")
                .OpenBrace()
                .AppendCode($"List<{this.FhirClassName}> items = new List<{this.FhirClassName}>();")
                .DefineBlock(out this.writeBlock, writeBlockName)
                .AppendCode($"this.Resource.SetValue(\"hasMember\", items);")
                .CloseBrace()
                .EndBlock()
                ;
            }
            else
            {
                this.readBlock  = memberBlock.Find(readBlockName);
                this.writeBlock = memberBlock.Find(writeBlockName);
            }

            if (this.codeBlocks.ClassWriteCode.Find("!WriteHasMembers") == null)
            {
                this.codeBlocks.ClassWriteCode
                .StartBlock("!WriteHasMembers")
                .AppendCode($"this.WriteHasMembers(this.Doc);")
                .EndBlock()
                ;
            }

            if (this.codeBlocks.ClassReadCode.Find("!ReadHasMembers") == null)
            {
                this.codeBlocks.ClassReadCode
                .StartBlock("!ReadHasMembers")
                .AppendCode($"this.ReadHasMembers(this.Doc);")
                .EndBlock()
                ;
            }

            foreach (ElementTreeSlice memberSlice in this.memberNode.Slices.Skip(1))
            {
                ElementDefinition sliceDef = memberSlice.ElementDefinition;
                this.sliceName = sliceDef.SliceName;

                Int32 max = CSMisc.ToMax(sliceDef.Max);
                Int32 min = sliceDef.Min.Value;
                this.sliceName = this.sliceName.ToMachineName();

                if ((sliceDef.Type.Count != 1) || (sliceDef.Type[0].Code != "Reference"))
                {
                    throw new Exception($"Invalid reference types");
                }
                this.itemElementSetName.Clear();
                this.targetProfiles.Clear();
                foreach (String profile in sliceDef.Type[0].TargetProfile)
                {
                    this.targetProfiles.Add(profile);
                    String propertyClassName = CSMisc.ResourceClassName(profile);
                    this.itemElementSetName.Add(propertyClassName);
                }

                this.containerClassName = $"M{this.sliceName.ToMachineName()}";
                this.itemElementGetName = (this.itemElementSetName.Count == 1) ? this.itemElementSetName [0] : "ResourceBase";
                base.BuildOne(memberSlice.ElementDefinition.ElementId, min, max);
            }
        }
        public override void Build()
        {
            if (this.memberNode.Slices.Count <= 1)
            {
                return;
            }

            // Block is marked with !, so the top level lines are not merged, so we
            // dont have duplicate Read/Write Components methods.
            // component block may have been defined in a class merged into this one,
            // so check to see if it exists.
            String          readBlockName      = $"ReadComponents";
            String          writeBlockName     = $"WriteComponents";
            String          componentBlockName = $"!Components";
            CodeBlockNested componentBlock     = this.codeBlocks.ClassMethods?.Find(componentBlockName, false);

            if (componentBlock == null)
            {
                this.codeBlocks.ClassMethods
                .BlankLine()
                .StartBlock(componentBlockName)

                .BlankLine()
                .SummaryOpen()
                .Summary($"Read all component values from resource into this instance")
                .SummaryClose()
                .AppendCode($"private void ReadComponents(BreastRadiologyDocument doc)")
                .OpenBrace()
                .AppendCode($"List<{this.FhirClassName}> items = this.Resource.GetValue<{this.FhirClassName}>(\"{this.fhirName}\").ToList();")
                .DefineBlock(out this.readBlock, readBlockName)
                .CloseBrace()

                .BlankLine()
                .SummaryOpen()
                .Summary($"Write all values from this instance into resource")
                .SummaryClose()
                .AppendCode($"private void WriteComponents(BreastRadiologyDocument doc)")
                .OpenBrace()
                .AppendCode($"List<{this.FhirClassName}> items = new List<{this.FhirClassName}>();")
                .DefineBlock(out this.writeBlock, writeBlockName)
                .AppendCode($"this.Resource.SetValue(\"{this.fhirName}\", items);")
                .CloseBrace()
                .EndBlock()
                ;
            }
            else
            {
                this.readBlock  = componentBlock.Find(readBlockName);
                this.writeBlock = componentBlock.Find(writeBlockName);
            }

            if (this.codeBlocks.ClassWriteCode.Find("!WriteComponents") == null)
            {
                this.codeBlocks.ClassWriteCode
                .StartBlock("!WriteComponents")
                .AppendCode($"this.WriteComponents(this.Doc);")
                .EndBlock()
                ;
            }

            if (this.codeBlocks.ClassReadCode.Find("!ReadComponents") == null)
            {
                this.codeBlocks.ClassReadCode
                .StartBlock("!ReadComponents")
                .AppendCode($"this.ReadComponents(this.Doc);")
                .EndBlock()
                ;
            }

            foreach (ElementTreeSlice memberSlice in this.memberNode.Slices.Skip(1))
            {
                this.sliceName = memberSlice.ElementDefinition.SliceName;

                ElementTreeNode valueNode = memberSlice.Nodes.GetItem("value[x]");
                ElementTreeNode codeNode  = memberSlice.Nodes.GetItem("code");

                this.componentCode = (CodeableConcept)codeNode.ElementDefinition.Fixed;
                if (this.componentCode == null)
                {
                    this.componentCode = (CodeableConcept)codeNode.ElementDefinition.Pattern;
                }
                if (this.componentCode == null)
                {
                    throw new Exception("Missing {this.fhirName}.code fixed value");
                }

                ElementDefinition sliceDef = memberSlice.ElementDefinition;
                Int32             max      = CSMisc.ToMax(sliceDef.Max);
                Int32             min      = sliceDef.Min.Value;
                this.sliceName = this.sliceName.ToMachineName();

                this.itemElementSetName.Clear();
                foreach (var type in valueNode.ElementDefinition.Type)
                {
                    this.itemElementSetName.Add(type.Code);
                }

                this.containerClassName = $"M{this.sliceName.ToMachineName()}";
                this.itemElementGetName = (this.itemElementSetName.Count == 1) ? valueNode.ElementDefinition.Type[0].Code : "Element";
                base.BuildOne(memberSlice.ElementDefinition.ElementId, min, max);
            }
        }
        public override void Build()
        {
            if (this.memberNode.Slices.Count <= 1)
            {
                return;
            }

            // Block is marked with !, so the top level lines are not merged, so we
            // dont have duplicate Read/Write methods.
            // block may have been defined in a class merged into this one,
            // so check to see if it exists.
            String          readBlockName    = $"ReadSections";
            String          writeBlockName   = $"WriteSections";
            String          sectionBlockName = $"!Sections";
            CodeBlockNested sectionBlock     = this.codeBlocks.ClassMethods.Find(sectionBlockName, false);

            if (sectionBlock == null)
            {
                this.codeBlocks.ClassMethods
                .BlankLine()
                .StartBlock(sectionBlockName)

                .BlankLine()
                .SummaryOpen()
                .Summary($"Read all values from resource into this instance")
                .SummaryClose()
                .AppendCode($"private void ReadSections(BreastRadiologyDocument doc)")
                .OpenBrace()
                .AppendCode($"List<{this.FhirClassName}> items = this.Resource.GetValue<{this.FhirClassName}>(\"{this.fhirName}\").ToList();")
                .DefineBlock(out this.readBlock, readBlockName)
                .CloseBrace()

                .BlankLine()
                .SummaryOpen()
                .Summary($"Write all values from this instance into resource")
                .SummaryClose()
                .AppendCode($"private void WriteSections(BreastRadiologyDocument doc)")
                .OpenBrace()
                .AppendCode($"List<{this.FhirClassName}> items = new List<{this.FhirClassName}>();")
                .DefineBlock(out this.writeBlock, writeBlockName)
                .AppendCode($"this.Resource.SetValue(\"{this.fhirName}\", items);")
                .CloseBrace()
                .EndBlock()
                ;
            }
            else
            {
                this.readBlock  = sectionBlock.Find(readBlockName);
                this.writeBlock = sectionBlock.Find(writeBlockName);
            }

            if (this.codeBlocks.ClassWriteCode.Find("!WriteSections") == null)
            {
                this.codeBlocks.ClassWriteCode
                .StartBlock("!WriteSections")
                .AppendCode($"this.WriteSections(this.Doc);")
                .EndBlock()
                ;
            }

            if (this.codeBlocks.ClassReadCode.Find("!ReadSections") == null)
            {
                this.codeBlocks.ClassReadCode
                .StartBlock("!ReadSections")
                .AppendCode($"this.ReadSections(this.Doc);")
                .EndBlock()
                ;
            }

            foreach (ElementTreeSlice memberSlice in this.memberNode.Slices.Skip(1))
            {
                ElementDefinition memberDef = memberSlice.ElementDefinition;
                this.sliceName = memberDef.SliceName;

                ElementTreeNode entryNode = memberSlice.Nodes.GetItem("entry");
                ElementTreeNode titleNode = memberSlice.Nodes.GetItem("title");
                ElementTreeNode codeNode  = memberSlice.Nodes.GetItem("code");

                this.sectionCode = (CodeableConcept)codeNode.ElementDefinition.Fixed;
                if (this.sectionCode == null)
                {
                    this.sectionCode = (CodeableConcept)codeNode.ElementDefinition.Pattern;
                }
                if (this.sectionCode == null)
                {
                    throw new Exception("Missing section.code fixed value");
                }

                this.title = ((FhirString)titleNode.ElementDefinition?.Fixed)?.Value;
                if (String.IsNullOrEmpty(this.title) == true)
                {
                    throw new Exception("Section missing title value");
                }

                ElementDefinition entryDef     = entryNode.ElementDefinition;
                Int32             max          = CSMisc.ToMax(entryDef.Max);
                Int32             min          = entryDef.Min.Value;
                String            propertyName = this.sliceName.ToMachineName();

                if (entryDef.Type.Count != 1)
                {
                    throw new Exception($"Error processing slice {this.sliceName}. Expected single type. Got {entryDef.Type.Count}");
                }
                if (entryDef.Type[0].Code != "Reference")
                {
                    throw new Exception($"Error processing slice {this.sliceName}. Expected type Section. Got {entryDef.Type[0].Code}");
                }

                this.itemElementSetName.Clear();
                foreach (String profile in entryDef.Type[0].TargetProfile)
                {
                    String propertyClassName = CSMisc.ResourceClassName(profile);
                    this.itemElementSetName.Add(propertyClassName);
                }

                this.containerClassName = $"M{this.sliceName.ToMachineName()}";
                this.itemElementGetName = (this.itemElementSetName.Count == 1) ? this.itemElementSetName[0] : "ResourceBase";
                base.BuildOne(memberDef.ElementId, min, max);
            }
        }