/// <summary>Writes an element.</summary> /// <param name="complex">The complex.</param> /// <param name="element">The element.</param> private void WriteElement( FhirComplex complex, FhirElement element) { string optionalFlagString = element.IsOptional ? "?" : string.Empty; string arrayFlagString = element.IsArray ? "[]" : string.Empty; Dictionary <string, string> values = element.NamesAndTypesForExport( FhirTypeBase.NamingConvention.CamelCase, FhirTypeBase.NamingConvention.PascalCase, false, string.Empty, complex.Components.ContainsKey(element.Path)); foreach (KeyValuePair <string, string> kvp in values) { if (!string.IsNullOrEmpty(element.Comment)) { WriteIndentedComment(element.Comment); } _writer.WriteLineIndented($"{kvp.Key}{optionalFlagString}: {kvp.Value}{arrayFlagString};"); if (RequiresExtension(kvp.Value)) { _writer.WriteLineIndented($"_{kvp.Key}?: Element;"); } } }
/// <summary>Writes an element.</summary> /// <param name="complex">The complex.</param> /// <param name="element">The element.</param> private void WriteElement( FhirComplex complex, FhirElement element) { Dictionary <string, string> values = element.NamesAndTypesForExport( FhirTypeBase.NamingConvention.PascalCase, FhirTypeBase.NamingConvention.PascalCase, false, string.Empty, complex.Components.ContainsKey(element.Path)); foreach (KeyValuePair <string, string> kvp in values) { string elementName; if (kvp.Key == complex.Name) { elementName = $"{kvp.Key}Field"; } else { elementName = kvp.Key; } string optionalFlagString = (element.IsOptional && IsNullable(kvp.Value)) ? "?" : string.Empty; if (!string.IsNullOrEmpty(element.Comment)) { WriteIndentedComment(element.Comment); } string elementType = element.IsArray ? $"List<{kvp.Value}{optionalFlagString}>" : $"{kvp.Value}{optionalFlagString}"; string camel = FhirUtils.ToConvention(kvp.Key, string.Empty, FhirTypeBase.NamingConvention.CamelCase); _writer.WriteLineIndented($"[JsonProperty(\"{camel}\")]"); _writer.WriteLineIndented($"public {elementType} {elementName} {{ get; set; }}"); if (RequiresExtension(kvp.Value)) { _writer.WriteLineIndented($"[JsonProperty(\"_{camel}\")]"); if (element.IsArray) { _writer.WriteLineIndented($"public List<Element> _{elementName} {{ get; set; }}"); } else { _writer.WriteLineIndented($"public Element _{elementName} {{ get; set; }}"); } } } }
/// <summary>Writes a code.</summary> /// <param name="element">The element.</param> private void WriteCode( FhirElement element) { string codeName = FhirUtils.ToConvention( $"{element.Path}.Codes", string.Empty, FhirTypeBase.NamingConvention.PascalCase); if (codeName.Contains("[x]")) { codeName = codeName.Replace("[x]", string.Empty); } if (codeName.Contains("[X]")) { codeName = codeName.Replace("[X]", string.Empty); } if (_exportedCodes.Contains(codeName)) { return; } _exportedCodes.Add(codeName); _writer.WriteLineIndented($"/// <summary>"); _writer.WriteLineIndented($"/// Code Values for the {element.Path} field"); _writer.WriteLineIndented($"/// </summary>"); if (codeName.EndsWith("Codes", StringComparison.Ordinal)) { _writer.WriteLineIndented($"public static class {codeName} {{"); } else { _writer.WriteLineIndented($"public static class {codeName}Codes {{"); } _writer.IncreaseIndent(); foreach (string code in element.Codes) { FhirUtils.SanitizeForCode(code, _reservedWords, out string name, out string value); _writer.WriteLineIndented($"public const string {name.ToUpperInvariant()} = \"{value}\";"); } _writer.DecreaseIndent(); _writer.WriteLineIndented("}"); }
/// <summary>Writes a code.</summary> /// <param name="element">The element.</param> private void WriteCode( FhirElement element) { string codeName = FhirUtils.ToConvention( $"{element.Path}.Codes", string.Empty, FhirTypeBase.NamingConvention.PascalCase); if (codeName.Contains("[x]")) { codeName = codeName.Replace("[x]", string.Empty); } if (_exportedCodes.Contains(codeName)) { return; } _exportedCodes.Add(codeName); _writer.WriteLineIndented($"/**"); _writer.WriteLineIndented($" * Code Values for the {element.Path} field"); _writer.WriteLineIndented($" */"); _writer.WriteLineIndented($"export enum {codeName} {{"); _writer.IncreaseIndent(); foreach (string code in element.Codes) { FhirUtils.SanitizeForCode(code, _reservedWords, out string name, out string value); _writer.WriteLineIndented($"{name.ToUpperInvariant()} = \"{value}\","); } _writer.DecreaseIndent(); _writer.WriteLineIndented("}"); }
/// <summary>Writes an element.</summary> /// <param name="complex">The complex.</param> /// <param name="element">The element.</param> private void WriteElement( FhirComplex complex, FhirElement element) { string propertyType = string.Empty; if (element.ElementTypes != null) { foreach (FhirElementType elementType in element.ElementTypes.Values.OrderBy(e => e.Name)) { string joiner = string.IsNullOrEmpty(propertyType) ? string.Empty : "|"; string profiles = string.Empty; if ((elementType.Profiles != null) && (elementType.Profiles.Count > 0)) { profiles = "(" + string.Join("|", elementType.Profiles.Values) + ")"; } propertyType = $"{propertyType}{joiner}{elementType.Name}{profiles}"; } } if (string.IsNullOrEmpty(propertyType)) { propertyType = element.BaseTypeName; } _writer.WriteLineIndented( $"-" + $" {element.NameForExport(FhirTypeBase.NamingConvention.CamelCase)}[{element.FhirCardinality}]:" + $" {propertyType}"); _writer.IncreaseIndent(); // check for regex if (!string.IsNullOrEmpty(element.ValidationRegEx)) { _writer.WriteLineIndented($"[{element.ValidationRegEx}]"); } // check for default value if (!string.IsNullOrEmpty(element.DefaultFieldName)) { _writer.WriteLineIndented($".{element.DefaultFieldName} = {element.DefaultFieldValue}"); } // check for fixed value if (!string.IsNullOrEmpty(element.FixedFieldName)) { _writer.WriteLineIndented($".{element.FixedFieldName} = {element.FixedFieldValue}"); } if ((element.Codes != null) && (element.Codes.Count > 0)) { string codes = string.Join("|", element.Codes); _writer.WriteLineIndented($"{{{codes}}}"); } // either step into backbone definition OR extensions, don't write both if (complex.Components.ContainsKey(element.Path)) { WriteComplex(complex.Components[element.Path]); } else if (_info.ExtensionsByPath.ContainsKey(element.Path)) { WriteExtensions(_info.ExtensionsByPath[element.Path].Values); } // check for slicing information if (element.Slicing != null) { WriteSlicings(element.Slicing.Values); } _writer.DecreaseIndent(); }
/// <summary>Gets an order.</summary> /// <param name="element">The element.</param> /// <returns>The order.</returns> public static int GetOrder(FhirElement element) { return((element.FieldOrder * 10) + 10); }