void CreateConstructor(String className, String fieldName) { sliceClassMethods .BlankLine() .SummaryOpen() .Summary($"{className} constructor") .SummaryClose() .AppendCode($"public {className}({elementNode.FhirType.FriendlyName()} items)") .OpenBrace() .AppendCode($"this.Items = items;") .AppendCode($"this.Slicing = {fieldName};") .CloseBrace() ; }
protected override void BuildContainerRead(CodeBlockNested b) { b .BlankLine() .AppendCode($"public void Read(BreastRadiologyDocument doc, IEnumerable<{this.FhirClassName}> extensions)") .OpenBrace() .DefineBlock(out this.itemCodeBlocks.ClassReadCode) .AppendCode($"IEnumerable<Extension> memberExtensions = base.IsMember(doc,") .AppendCode($" extensions,") .AppendCode($" ExtensionUrl);") .AppendCode($"List<Item> items = new List<Item>();") .AppendCode($"foreach (Extension memberExtension in memberExtensions)") .OpenBrace() .AppendCode($" Item item = new Item();") .AppendCode($" item.ReadItem(doc, memberExtension);") .AppendCode($" items.Add(item);") .CloseBrace() .AppendCode($"this.SetAllItems(items);") .CloseBrace() ; //this.readBlock // .AppendCode($"this.{PropertyName}.Read(this.Doc, items);") // ; }
protected override void BuildContainerRead(CodeBlockNested b) { b .BlankLine() .AppendCode($"public void Read(BreastRadiologyDocument doc, IEnumerable<{this.FhirClassName}> extensions)") .OpenBrace() .AppendCode($"List<Extension> memberExtensions = extensions") .AppendCode($" .Where((a) => String.Compare(a.Url, ExtensionUrl, true) == 0)") .AppendCode($" .ToList()") .AppendCode($" ;") .AppendCode($"List<Item> items = new List<Item>();") .AppendCode($"foreach (Extension memberExtension in memberExtensions)") .OpenBrace() .AppendCode($" Item item = new Item();") .AppendCode($" item.ReadItem(doc, memberExtension);") .AppendCode($" items.Add(item);") .CloseBrace() .AppendCode($"this.SetAllItems(items);") .CloseBrace() ; this.codeBlocks.ClassReadCode .AppendCode($"this.{this.PropertyName}.Read(doc, extensionList);") ; }
protected override void BuildContainerRead(CodeBlockNested b) { b .BlankLine() .AppendCode($"public void Read(BreastRadiologyDocument doc, IEnumerable<Composition.SectionComponent> sections)") .OpenBrace() .AppendCode($"IEnumerable<Composition.SectionComponent> memberSections = base.IsMember(doc,") .AppendCode($" sections,") .AppendCode($" {this.sectionCodeMethodName}());") .AppendCode($"List<Item> items = new List<Item>();") .AppendCode($"// There really should only ever be one section...") .AppendCode($"foreach (Composition.SectionComponent memberSection in memberSections)") .OpenBrace() .AppendCode($"foreach (ResourceReference entryRef in memberSection.Entry)") .OpenBrace() .AppendCode($"Item item = new Item();") .AppendCode($"item.ReadItem(doc, entryRef);") .AppendCode($"items.Add(item);") .CloseBrace() .CloseBrace() .AppendCode($"this.SetAllItems(items);") .CloseBrace() ; this.readBlock .AppendCode($"this.{this.PropertyName}.Read(this.Doc, items);") ; }
void ConstructDataType(CodeBlockNested methods, CodeBlockNested construct, FHIRAllTypes fhirType) { if (GenerateCommon.Ignore(fhirType)) { return; } this.tempCounter = 0; String fhirTypeName = ModelInfo.FhirTypeToFhirTypeName(fhirType); Type csType = ModelInfo.GetTypeForFhirType(fhirTypeName); String csTypeName = csType.FriendlyName(); construct .AppendCode($"case \"{fhirTypeName}\": // {fhirType} - DataType") .OpenBrace() .AppendCode($"propertyType = \"{fhirTypeName}\";") .AppendCode($"return Construct(block, ({csTypeName})fix, varName);") .CloseBrace() .BlankLine() ; CodeBlockNested m = methods.AppendBlock(); m .BlankLine() .AppendLine($"/// <summary>") .AppendLine($"/// Return c# text to create indicated element.") .AppendLine($"/// </summary>") .AppendCode($"static public bool Construct(CodeBlockNested block,") .AppendCode($" {csTypeName} fix,") .AppendCode($" String varName)") .OpenBrace() //.AppendCode($"const String fcn = \"Construct({fhirTypeName})\";") .BlankLine() .AppendCode($"if (block is null)") .AppendCode($" throw new ArgumentNullException(nameof(block));") .AppendCode($"block") .AppendCode($" .OpenBrace()") .AppendCode($" .AppendCode(\"{csTypeName} temp = new {csTypeName}();\")") .AppendCode($" ;") .AppendCode($"if (fix != null)") .OpenBrace() ; FixElements(m, csType, "fix", "temp"); m .CloseBrace() .AppendCode($"block") .AppendCode($" .AppendCode($\"{{varName}} = temp;\")") .AppendCode($" .CloseBrace()") .AppendCode($" ;") .AppendCode($"return true;") .CloseBrace() ; }
void ConstructDataType(CodeBlockNested methods, CodeBlockNested construct, FHIRAllTypes fhirType) { if (Ignore(fhirType)) { return; } String fhirTypeName = ModelInfo.FhirTypeToFhirTypeName(fhirType); Type csType = ModelInfo.GetTypeForFhirType(fhirTypeName); String csTypeName = csType.FriendlyName(); construct .AppendCode($"case \"{fhirTypeName}\": // {fhirType} - DataType") .OpenBrace() .AppendCode($"propertyType = \"{fhirTypeName}\";") .AppendCode($"return Construct(block, ({csTypeName})fix, methodName, methodAccess);") .CloseBrace() .BlankLine() ; CodeBlockNested m = methods.AppendBlock(); m .BlankLine() .AppendLine($"/// <summary>") .AppendLine($"/// Return c# text to create indicated element.") .AppendLine($"/// </summary>") .AppendCode($"static public bool Construct(CodeBlockNested block,") .AppendCode($" {csTypeName} fix,") .AppendCode($" String methodName,") .AppendCode($" String methodAccess = \"public\")") .OpenBrace() //.AppendCode($"const String fcn = \"Construct({fhirTypeName})\";") .BlankLine() .AppendCode($"block") .AppendCode($" .AppendCode($\"{{methodAccess}} {csTypeName} {{methodName}}()\")") .AppendCode($" .OpenBrace()") .AppendCode($" .AppendCode(\"{csTypeName} retVal = new {csTypeName}();\")") .AppendCode($" ;") .AppendCode($"if (fix != null)") .OpenBrace() ; FixElements(m, csType, "fix", "retVal"); m .CloseBrace() .AppendCode($"block") .AppendCode($" .AppendCode(\"return retVal;\")") .AppendCode($" .CloseBrace()") .AppendCode($" ;") .AppendCode($"return true;") .CloseBrace() ; }
/// <summary> /// start Create common static constructor method. /// </summary> public static CodeBlockNested WriteInitStart(this CodeBlockNested block, string className, [CallerFilePath] String filePath = "", [CallerLineNumber] Int32 lineNumber = 0) { block .BlankLine() .AppendLine($"// called from {Path.GetFileName(filePath)} #{lineNumber}") .SummaryOpen() .Summary($"/// Init method") .SummaryClose() .AppendCode($"public override void Init({className} ptr)") .OpenBrace() .AppendCode($"base.Init(ptr);") ; return(block); }
/// <summary> /// Create common static constructor method. /// </summary> public static CodeBlockNested WriteConstructor(this CodeBlockNested block, string className, [CallerFilePath] String filePath = "", [CallerLineNumber] Int32 lineNumber = 0) { block .BlankLine() .OpenSummary() .AppendLine($"/// Constructor") .CloseSummary() .AppendLine($"// called from {Path.GetFileName(filePath)} #{lineNumber}") .AppendCode($"public {className}() : base()") .OpenBrace() .CloseBrace() ; return(block); }
void BuildCodeSystem(CSInfo ci) { CodeBlockNested csFields = ci.ClassCode.Blocks.Find("Fields"); csFields .AppendCode($"const string System = \"{ci.CodeSystem.Url}\";"); ; if (ci.CodeSystem.Filter.Count > 0) { throw new NotImplementedException("Have not implemented CodeSystem.Filter"); } foreach (CodeSystem.ConceptDefinitionComponent component in ci.CodeSystem.Concept) { String display = component.Display?.Replace("\"", "'"); String code = component.Code; csFields .BlankLine() .AppendLine("/// <summary>") ; if (component.Definition != null) { foreach (String line in component.Definition.Split('\n')) { String s = line .Trim() .Replace("\r", "") .Replace("%", "\\%") ; s = WebUtility.HtmlEncode(s); csFields.AppendLine($"/// {s}"); } } csFields .AppendLine("/// </summary>") .AppendCode($"public static Coding {CSMisc.CodeName(component.Code)} = new Coding(System, \"{code}\", \"{display}\");") ; } }
/// <summary> /// Create common static Create method. /// </summary> public static CodeBlockNested WriteStaticCreate(this CodeBlockNested block, string profileClassName, String fhirClassName, [CallerFilePath] String filePath = "", [CallerLineNumber] Int32 lineNumber = 0) { block .BlankLine() .OpenSummary() .AppendLine($"/// static creator") .CloseSummary() .AppendLine($"// called from {Path.GetFileName(filePath)} #{lineNumber}") .AppendCode($"public static {profileClassName} Create({fhirClassName} ptr)") .OpenBrace() .AppendLine($"{profileClassName} retVal = new {profileClassName}();") .AppendLine($"retVal.Init(ptr);") .AppendLine($"return retVal;") .CloseBrace() ; return(block); }
protected override void BuildContainerRead(CodeBlockNested b) { b .BlankLine() .AppendCode($"public void Read(BreastRadiologyDocument doc, IEnumerable<{this.FhirClassName}> elements)") .OpenBrace() .AppendCode($"List<Item> items = new List<Item>();") .AppendCode($"foreach (Element element in elements)") .OpenBrace() .AppendCode($"Item item = new Item();") .AppendCode($"item.ReadItem(doc, ({this.ElementGetName}) element);") .AppendCode($"items.Add(item);") .CloseBrace() .AppendCode($"this.SetAllItems(items);") .CloseBrace() ; this.codeBlocks.ClassReadCode .AppendCode($"this.BodySite.Read(this.Doc, this.Resource.GetValue<CodeableConcept>(\"bodySite\"));") ; }
/// <summary> /// Process one fhir element /// </summary> void ProcessFhirElementAbbreviated(SDefInfo sDefInfo) { const string fcn = "ProcessFhirElementAbbreviated"; StructureDefinition sDef = sDefInfo.SDef; { CodeEditor entryEditor = this.CreateEntryEditor(sDef.Id); CodeBlockNested entryBlock = entryEditor.Blocks.AppendBlock(); String typeName; switch (sDefInfo.TFlag) { case DirectFhirGenerator.SDefInfo.TypeFlag.Entry: typeName = "Entry"; break; case DirectFhirGenerator.SDefInfo.TypeFlag.Group: typeName = "Group"; break; default: throw new ConvertErrorException(this.GetType().Name, fcn, $"Invalid TFlag value"); } entryBlock .BlankLine() .AppendCode($"{typeName}: {sDef.Id}") ; } { CodeEditor mapEditor = this.CreateMapEditor(sDef.Id); CodeBlockNested mapBlock = mapEditor.Blocks.AppendBlock(); mapBlock .BlankLine() .AppendCode($"{sDef.Id} maps to {sDef.Id}:") ; } }
protected override void BuildContainerRead(CodeBlockNested b) { b .BlankLine() .AppendCode($"public void Read(BreastRadiologyDocument doc, IEnumerable<{this.FhirClassName}> references)") .OpenBrace() .AppendCode("IEnumerable<ResourceReference> resourceReferences = base.IsMember(doc,") .AppendCode(" references,") .AppendCode(" this.targetUrls);") .AppendCode($"List<Item> items = new List<Item>();") .AppendCode($"foreach (ResourceReference resourceReference in resourceReferences)") .OpenBrace() .AppendCode($"Item item = new Item();") .AppendCode($"item.ReadItem(doc, resourceReference);") .AppendCode($"items.Add(item);") .CloseBrace() .AppendCode($"this.SetAllItems(items);") .CloseBrace() ; this.readBlock .AppendCode($"this.{this.PropertyName}.Read(this.Doc, items);") ; }
protected override void BuildContainerRead(CodeBlockNested b) { b .BlankLine() .AppendCode($"public void Read(BreastRadiologyDocument doc, IEnumerable<{this.FhirClassName}> components)") .OpenBrace() .AppendCode($"IEnumerable<Observation.ComponentComponent> memberComponents = base.IsMember(doc,") .AppendCode($" components,") .AppendCode($" {this.componentCodeMethodName}());") .AppendCode($"List<Item> items = new List<Item>();") .AppendCode($"foreach (Observation.ComponentComponent memberComponent in memberComponents)") .OpenBrace() .AppendCode($"Item item = new Item();") .AppendCode($"item.ReadItem(doc, memberComponent);") .AppendCode($"items.Add(item);") .CloseBrace() .AppendCode($"this.SetAllItems(items);") .CloseBrace() ; this.readBlock .AppendCode($"this.{this.PropertyName}.Read(this.Doc, items);") ; }
/// <summary> /// Create new file containing the definition for the new item. /// The new entry is created in its own namespace. /// </summary> String ProcessSubEntry(Int32 indent, String elementPath, String entryPath, String suffix, String typeName, String parent, String description, String comment) { CodeBlockNested classBlock = entryEditor.Blocks.AppendBlock(); CodeBlockNested propertydefinitionsBlock = entryEditor.Blocks.AppendBlock(); CodeBlockNested mapBlock = mapEditor.Blocks.AppendBlock(); String entryName = this.gen.GetFieldMap(elementPath); if (String.IsNullOrEmpty(suffix) == false) { entryName += suffix; entryPath += suffix; } classBlock .BlankLine() .AppendComment(comment) .AppendCode($"{typeName}: {entryName}") ; if (indent == 0) { mapBlock .BlankLine() .AppendCode($"{entryPath} maps to {elementPath}:") ; } else { mapBlock .BlankLine() .AppendCode($" {entryPath.SkipFirstPathPart()} maps to {elementPath.SkipFirstPathPart()}") ; } switch (parent) { case null: case ResourceStr: case BackboneElementStr: case ElementStr: break; default: this.gen.AddResource(parent); classBlock.AppendCode($"Parent: {parent}"); break; } classBlock .AppendCode($"Description: \"{description}\"") ; while (this.elementIndex < this.elements.Length) { ElementDefinition subElement = this.elements[this.elementIndex]; if (subElement.Path.StartsWith($"{elementPath}.") == false) { break; } this.ProcessProperty(indent, classBlock, propertydefinitionsBlock, mapBlock, entryPath); } return(entryName); }
bool DefineSliceOnValueDiscriminator(Int32 index, CodeBlockNested sliceDiscriminators, ElementDefinitionNode sliceNode, String varName, ElementDefinition.DiscriminatorComponent discriminator, String valueFilterMethod, String leafType) { const String fcn = nameof(DefineSliceOnValueDiscriminator); var selectedNodes = sliceNode.Select(discriminator.Path).ToArray(); var fixedNodes = selectedNodes.FixedValues().ToArray(); Element fixedValue = fixedNodes.SingleOrDefault(); if (fixedValue == null) { this.gen.ConversionError(this.GetType().Name, fcn, $"Slice node lacks fixed element {discriminator.Path}"); return(false); } String sliceName = sliceNode.Element.SliceName; CodeBlockNested valueMethodBlock = sliceClassMethods.AppendBlock(); valueFilterMethod = CSMisc.ValueFilterName(CSMisc.MakePath(sliceNode.SlicePath(), discriminator.Path)); // Note: We are defining method here, after we know the return value type. valueMethodBlock .BlankLine() .SummaryOpen() .AppendCode($"/// Return all elements for discriminator # {index+1}'") .SummaryLines(discriminator.ToFormatedJson()) .SummaryClose() ; { GenerateFhirPathSearch g = new GenerateFhirPathSearch(this.gen); if (g.Generate(valueMethodBlock, "static", valueFilterMethod, elementNode, discriminator.Path, out Type leaf) == false) { return(false); } leafType = leaf.FriendlyName(); } String tempVarName = $"sliceOnValueDiscriminator"; sliceDiscriminators .OpenBrace() .AppendLine($"/// Define discriminator'") .AppendLines("/// ", discriminator.ToFormatedJson().ToLines()) .AppendCode($"var {tempVarName} = new SliceOnValueDiscriminator<{baseItemTypeName}, {leafType}>()") .OpenBrace() .AppendCode($"Path = \"{discriminator.Path}\",") .AppendCode($"ValueFilter = {valueFilterMethod}") .CloseBrace(";") ; ElementFixCode.Construct(sliceDiscriminators, fixedValue, $"{tempVarName}.Pattern", out String propertyType); sliceDiscriminators .AppendCode($"{varName} = {tempVarName};") .CloseBrace("") ; return(true); }
void ProcessProperty(Int32 indent, CodeBlockNested classBlock, CodeBlockNested propertiesBlock, CodeBlockNested mapBlock, String entryPath) { const string fcn = "ProcessProperty"; ElementDefinition ed = this.elements[this.elementIndex++]; // Note: Currently we do not handle extensions. if (ed.Path.LastPathPart() == "extension") { return; } if (ed.Path.LastPathPart() == "modifierExtension") { return; } if (String.IsNullOrEmpty(ed.SliceName) == false) { this.gen.ConversionWarn(this.GetType().Name, fcn, "Ignoring slice"); } if (ed.Slicing != null) { this.gen.ConversionWarn(this.GetType().Name, fcn, "Ignoring slicing"); } //if (ed.Fixed != null) // throw new ConvertErrorException(this.GetType().Name, fcn, $"Unexpected Fixed in element {ed.Path}."); //if (ed.Pattern != null) // throw new ConvertErrorException(this.GetType().Name, fcn, $"Unexpected Pattern in element {ed.Path}."); String propertyName = this.gen.UniquePropertyName(ed, out bool createFlag); String fullPropertyName; String propertyPath = $"{entryPath}.{propertyName}"; if (this.ContainsType(ed, BackboneElementStr)) { if (ed.Type.Count != 1) { throw new ConvertErrorException(this.GetType().Name, fcn, $"Backbone element {ed.Path} has multiple types."); } if (this.HasChildren(ed) == false) { throw new ConvertErrorException(this.GetType().Name, fcn, $"Backbone element {ed.Path} has no children."); } fullPropertyName = this.ProcessSubEntry(indent + 1, ed.Path, propertyPath, "Group", "Group", BackboneElementStr, $"Group definition of {ed.Path}", null); } else if (this.ContainsType(ed, ElementStr)) { if (ed.Type.Count != 1) { throw new ConvertErrorException(this.GetType().Name, fcn, $"Element {ed.Path} has multiple types."); } if (this.HasChildren(ed) == false) { throw new ConvertErrorException(this.GetType().Name, fcn, $"Element {ed.Path} has no children."); } fullPropertyName = this.ProcessSubEntry(indent + 1, ed.Path, propertyPath, "Group", "Group", ElementStr, $"Group definition of {ed.Path}", null); } else { fullPropertyName = propertyName; if (createFlag) { if (this.gen.IsSliceField(ed.Path)) { propertiesBlock .BlankLine() .AppendLine($"// Entry definition of {ed.Path}") .AppendCode($"Group: {propertyName}Slices") .AppendCode($"Property: {propertyName}Slice 0..*") .BlankLine() .AppendCode($"Group: {propertyName}Slice") .AppendCode($"Property: {propertyName} 1..1") .BlankLine() .AppendCode($"Element: {propertyName}") ; } else { propertiesBlock .BlankLine() .AppendLine($"// Entry definition of {ed.Path}") .AppendCode($"Element: {propertyName}") ; } HashSet <String> outputTypes = new HashSet <string>(); bool firstFlag = true; void OutputType(String pType) { if (outputTypes.Contains(pType)) { return; } outputTypes.Add(pType); if (firstFlag) { propertiesBlock.AppendCode($"Value: {pType}"); } else { propertiesBlock.AppendCode($" or {pType}"); } firstFlag = false; } { String basePropertyPath = propertyPath.SkipFirstPathPart(); String baseEdPath = ed.Path.SkipFirstPathPart(); if (this.gen.IsSliceField(ed.Path)) { mapBlock.AppendCode($" {basePropertyPath}Slices.{basePropertyPath}Slice.{basePropertyPath} maps to {baseEdPath}"); } else { mapBlock.AppendCode($" {basePropertyPath} maps to {baseEdPath}"); } } foreach (ElementDefinition.TypeRefComponent type in ed.Type) { switch (type.Code) { case null: break; case "boolean": case "integer": case "decimal": case "uri": case "string": case "base64Binary": case "instant": case "date": case "dateTime": case "time": case "oid": case "id": case "markdown": case "unsignedInt": case "positiveInt": case "xhtml": OutputType($"{type.Code}"); break; case "CodeableConcept": case "Coding": case "code": OutputType($"concept"); break; case "uuid": case "url": case "canonical": OutputType($"uri"); break; case "Reference": if (type.Profile.Any()) { throw new ConvertErrorException(this.GetType().Name, fcn, $"Unexpected profile in type {ed.Path}:{type.Code}."); } if (type.TargetProfile.Count() == 0) { this.gen.AddAbbreviatedResource(ResourceStr); OutputType($"Resource"); } else { foreach (string target in type.TargetProfile) { this.gen.AddAbbreviatedResource(target); String targetEntryName = target.LastUriPart().ToMachineName(); OutputType($"{targetEntryName}"); } } break; default: if (type.Profile.Count() == 0) { this.gen.AddAbbreviatedResource(type.Code); OutputType($"{type.Code.ToMachineName()}"); } else { foreach (string profile in type.Profile) { this.gen.AddAbbreviatedResource(profile); String profileName = profile.LastUriPart().ToMachineName(); OutputType($"{profileName}"); } } break; } } } } if (this.gen.IsSliceField(ed.Path)) { classBlock.AppendCode($"Property: {fullPropertyName}Slices 0..1"); } else { classBlock.AppendCode($"Property: {fullPropertyName} {ed.Min}..{ed.Max}"); } }
void GenerateCIMPLDataType(CodeBlockNested entryBlock, CodeBlockNested mapBlock, FHIRAllTypes fhirType) { String fhirTypeName = ModelInfo.FhirTypeToFhirTypeName(fhirType); Type fhirCSType = ModelInfo.GetTypeForFhirType(fhirTypeName); entryBlock .BlankLine() .AppendLine($"// Fhir data element {fhirTypeName} definition") .AppendCode($"Entry: {fhirTypeName}") ; CodeBlockNested item = entryBlock.AppendBlock(); CodeBlockNested vars = entryBlock.AppendBlock(); foreach (PropertyInfo pi in fhirCSType.GetProperties()) { FhirElementAttribute attribute = pi.GetCustomAttribute <FhirElementAttribute>(); if (attribute != null) { String min; String max; Type csType; if (pi.PropertyType.IsList()) { min = "0"; max = "*"; csType = pi.PropertyType.GenericTypeArguments[0]; } if (pi.PropertyType.IsNullable()) { min = "0"; max = "1"; csType = pi.PropertyType.GenericTypeArguments[0]; } else { csType = pi.PropertyType; min = "1"; max = "1"; } String name = attribute.Name.ToMachineName(); item .AppendCode($"Property: {name} {min}..{max}") ; String typeName = null; String csTypeName = csType.FriendlyName(); switch (csTypeName) { case "string": OutputProperty(attribute, item, min, max); break; default: typeName = ModelInfo.GetFhirTypeNameForType(pi.PropertyType); if (String.IsNullOrEmpty(typeName)) { throw new Exception($"Can not determine fhir type for c# type {csTypeName}"); } break; } vars .BlankLine() .AppendCode($"Element: {name}") .AppendCode($"Value: {typeName}") ; // methods // .AppendCode($"case \"{attribute.Name}\":") // .OpenBrace() // .AppendCode($"ElementDefinition e = new ElementDefinition") // .OpenBrace() // .AppendCode($"Path = $\"{{parentPath}}.{attribute.Name}\",") // .AppendCode($"Short = \"{fhirType}.{attribute.Name} common attribute\",") // .AppendCode($"Min = {min},") // .AppendCode($"Max = \"{max}\"") // .CloseBrace(";") // .AppendCode($"retVal = new ElementNode(this, e, typeof({pi.PropertyType.FriendlyName()}), nameof({fhirCSType.FriendlyName()}.{pi.Name}));") // .AppendCode($"retVal.AutoGeneratedFlag = true;") // .AppendCode($"break;") // .CloseBrace(";") // ; } } }
void GenerateFindCommonChild(CodeBlockNested construct, CodeBlockNested methods, FHIRAllTypes fhirType) { String fhirTypeName = ModelInfo.FhirTypeToFhirTypeName(fhirType); Type fhirCSType = ModelInfo.GetTypeForFhirType(fhirTypeName); String methodName = $"FindChild{fhirTypeName}"; construct .AppendCode($"case \"{fhirCSType.FriendlyName()}\": return {methodName}(parentPath, childName);") ; methods .BlankLine() .SummaryOpen() .Summary($"Manually add the children of a Coding element.") .SummaryClose() .AppendCode($"ElementDefinitionNode {methodName}(String parentPath, String childName)") .OpenBrace() .AppendCode($"ElementDefinitionNode retVal;") .AppendCode($"switch (childName)") .OpenBrace() ; foreach (PropertyInfo pi in fhirCSType.GetProperties()) { FhirElementAttribute attribute = pi.GetCustomAttribute <FhirElementAttribute>(); if (attribute != null) { String min; String max; if (pi.PropertyType.IsList()) { min = "0"; max = "*"; } if (pi.PropertyType.IsNullable()) { min = "0"; max = "1"; } else { min = "1"; max = "1"; } String varName = $"{attribute.Name}Var"; methods .AppendCode($"case \"{attribute.Name}\":") .OpenBrace() .AppendCode($"ElementDefinition e = new ElementDefinition") .OpenBrace() .AppendCode($"Path = $\"{{parentPath}}.{attribute.Name}\",") .AppendCode($"Short = \"{fhirType}.{attribute.Name} common attribute\",") .AppendCode($"Min = {min},") .AppendCode($"Max = \"{max}\"") .CloseBrace(";") .AppendCode($"retVal = new ElementDefinitionNode(this, e, typeof({pi.PropertyType.FriendlyName()}), nameof({fhirCSType.FriendlyName()}.{pi.Name}));") .AppendCode($"retVal.AutoGeneratedFlag = true;") .AppendCode($"break;") .CloseBrace(";") ; } } methods .AppendCode($"default: return null;") .CloseBrace() .AppendCode($"this.childNodeDictionary.Add(childName, retVal);") .AppendCode($"return retVal;") .CloseBrace() ; }