bool ILanguangeExporter.AppendValueSetCodeConcept( ref StringBuilder sb, string sanitizedValueSetName, string sanitizedCodeName, fhir.CodeSystemConcept concept, string systemUrl ) { string comment; // **** start with a comment **** if (!string.IsNullOrEmpty(concept.Definition)) { comment = FhirTypeManager.SanitizeComment(concept.Definition, _lineComment, _indentChar, 2); } else if (!string.IsNullOrEmpty(concept.Display)) { comment = FhirTypeManager.SanitizeComment(concept.Display, _lineComment, _indentChar, 2); } else { comment = $"Value for '{concept.Code}'</summary>\n"; } // **** coding is exported inline (before internal and external interfaces) **** sb.Append($"const {sanitizedValueSetName}_{sanitizedCodeName}: Coding = {{\n"); sb.Append($"\t\tcode: \"{concept.Code}\",\n"); if (!string.IsNullOrEmpty(concept.Display)) { sb.Append($"\t\tdisplay: \"{concept.Display.Replace("\"", "\\\"")}\",\n"); } sb.Append($"\t\tsystem: \"{systemUrl}\"\n"); sb.Append($"\t}};\n"); // **** add this code to our interface **** //_valueSetInterfaceSB.Append($"\t/**\n\t * {comment}\n\t */\n"); //_valueSetInterfaceSB.Append($"\t{sanitizedCodeName}: Coding,\n"); // **** add this code to our export **** _valueSetExportSB.Append($"\t/**\n\t * {comment}\n\t */\n"); _valueSetExportSB.Append($"\t{sanitizedCodeName}: {sanitizedValueSetName}_{sanitizedCodeName},\n"); return(true); }
bool ILanguangeExporter.AppendFhirProperty( ref StringBuilder sb, FhirProperty property, string typeName, bool useLowerCaseName ) { // **** always use lower-case start **** string name = FhirTypeManager.SanitizeForProperty(property.Name, _reservedWordsSet); string comment = FhirTypeManager.SanitizeComment(property.Comment, _lineComment, _indentChar, 2); string optionalFlagString = (_flagOptionals && property.IsOptional) ? "?" : ""; // **** **** if (property.IsArray) { sb.Append( $"\t/**\n" + $"\t * {comment}\n" + //$"\t * Cardinality: {property.Cardinality}\n" + $"\t */\n" + $"\t{name}{optionalFlagString}: {typeName}[];\n" + $"\t/**\n" + $"\t * May contain extended information for property: '{name}'\n" + $"\t */\n" + $"\t_{name}?: Element[];\n" ); return(true); } sb.Append( $"\t/**\n" + $"\t * {comment}\n" + //$"\t * Cardinality: {property.Cardinality}\n" + $"\t */\n" + $"\t{name}{optionalFlagString}: {typeName};\n" + $"\t/**\n" + $"\t * May contain extended information for property: '{name}'\n" + $"\t */\n" + $"\t_{name}?: Element;\n" ); return(true); }
bool ILanguangeExporter.AppendValueSetOpen(ref StringBuilder sb, string sanitizedAlias, string sanitizedName, fhir.ValueSet valueSet) { // **** start with a comment **** if (!string.IsNullOrEmpty(valueSet.Description)) { sb.Append($"\t///<summary>{FhirTypeManager.SanitizeComment(valueSet.Description, _lineComment, _indentChar, 1)}</summary>\n"); } else { sb.Append($"\t///<summary>Expanded ValueSet from {valueSet.Url}</summary>\n"); } // **** open our value set **** sb.Append($"\tpublic abstract class {sanitizedName}\n\t{{\n"); return(true); }
bool ILanguangeExporter.AppendValueSetOpen(ref StringBuilder sb, string sanitizedAlias, string sanitizedName, ValueSet valueSet) { // **** clear our related objects for the value set **** //_valueSetInterfaceSB.Clear(); _valueSetExportSB.Clear(); string comment; // **** start with a comment **** if (!string.IsNullOrEmpty(valueSet.Description)) { comment = $"/**\n" + $" * {FhirTypeManager.SanitizeComment(valueSet.Description, _lineComment, _indentChar, 1)}\n" + $" */\n"; } else { comment = $"/**\n" + $" * Expanded ValueSet from {valueSet.Url}\n" + $" */\n"; } // **** add our comment **** //_valueSetInterfaceSB.Append(comment); _valueSetExportSB.Append(comment); // **** open our value set (interface has to be before export) **** //_valueSetInterfaceSB.Append($"interface {sanitizedName}_Interface {{\n"); //_valueSetExportSB.Append($"export const {sanitizedName}: {sanitizedName}_Interface = {{\n"); _valueSetExportSB.Append($"export const {sanitizedName} = {{\n"); return(true); }
bool ILanguangeExporter.AppendValueSetCodeConcept( ref StringBuilder sb, string sanitizedValueSetName, string sanitizedCodeName, fhir.CodeSystemConcept concept, string systemUrl ) { // **** start with a comment **** if (!string.IsNullOrEmpty(concept.Definition)) { sb.Append($"\t\t///<summary>{FhirTypeManager.SanitizeComment(concept.Definition, _lineComment, _indentChar, 2)}</summary>\n"); } else if (!string.IsNullOrEmpty(concept.Display)) { sb.Append($"\t\t///<summary>{FhirTypeManager.SanitizeComment(concept.Display, _lineComment, _indentChar, 2)}</summary>\n"); } else { sb.Append($"\t\t///<summary>Value for '{concept.Code}'</summary>\n"); } // **** start our coding **** sb.Append($"\t\tpublic static readonly Coding {sanitizedCodeName} = new Coding\n\t\t{{\n"); sb.Append($"\t\t\tCode = \"{concept.Code}\",\n"); if (!string.IsNullOrEmpty(concept.Display)) { sb.Append($"\t\t\tDisplay = \"{concept.Display.Replace("\"", "\\\"")}\",\n"); } sb.Append($"\t\t\tSystem = \"{systemUrl}\"\n"); sb.Append($"\t\t}};\n"); return(true); }
bool ILanguangeExporter.AppendFhirTypeOpen(ref StringBuilder sb, FhirType fhirType) { string comment = FhirTypeManager.SanitizeComment(fhirType.Comment, _lineComment, _indentChar, 1); if ((fhirType.Properties == null) || (fhirType.Properties.Count == 0)) { //string typeName = string.IsNullOrEmpty(fhirType.TypeName) ? "object" : fhirType.TypeName; sb.Append( $"/**\n" + $" * {comment}\n" + $" * From: {fhirType.SourceFilename}\n" + $" */\n" + $"export type {fhirType.Name} = {fhirType.TypeName};\n" ); return(true); } // **** start with the interface open **** if (string.IsNullOrEmpty(fhirType.TypeName) || fhirType.Name.Equals("Element")) { sb.Append( $"/**\n" + $" * {comment}\n" + $" * From: {fhirType.SourceFilename}\n" + $" */\n" + $"export interface {fhirType.Name} {{\n" ); } else if (fhirType.Name.Equals(fhirType.TypeName, StringComparison.Ordinal)) { sb.Append( $"/**\n" + $" * {comment}\n" + $" * From: {fhirType.SourceFilename}\n" + $" */\n" + $"export interface {fhirType.Name} extends Element {{\n" ); } else { sb.Append( $"/**\n" + $" * {comment}\n" + $" * From: {fhirType.SourceFilename}\n" + $" */\n" + $"export interface {fhirType.Name} extends {fhirType.TypeName} {{\n" ); } // **** output resource type first (if necessary) **** if (FhirTypeManager.DoesTypeRequireResourceTag(fhirType.Name)) { sb.Append( $"\t/** Resource Type Name (for serialization) */\n" + $"\tresourceType: '{fhirType.Name}';\n" ); } return(true); }
bool ILanguangeExporter.AppendFhirTypeOpen(ref StringBuilder sb, FhirType fhirType) { string comment = FhirTypeManager.SanitizeComment(fhirType.Comment, _lineComment, _indentChar, 1); // **** start with the interface open **** if (string.IsNullOrEmpty(fhirType.TypeName) || fhirType.Name.Equals("Element")) { sb.Append( $"\t///<summary>\n" + $"\t///{comment}\n" + $"\t///</summary>\n" + $"\t///<source-file>{fhirType.SourceFilename}</source-file>\n" + $"\tpublic class {fhirType.NameCapitalized}\n" + $"\t{{\n" ); } else if (fhirType.Name.Equals(fhirType.TypeName, StringComparison.Ordinal)) { sb.Append( $"\t///<summary>\n" + $"\t///{comment}\n" + $"\t///</summary>\n" + $"\t///<source-file>{fhirType.SourceFilename}</source-file>\n" + $"\tpublic class {fhirType.NameCapitalized} : Element\n" + $"\t{{\n" ); } else { sb.Append( $"\t///<summary>\n" + $"\t///{comment}\n" + $"\t///</summary>\n" + $"\t///<source-file>{fhirType.SourceFilename}</source-file>\n" + $"\tpublic class {fhirType.NameCapitalized} : {fhirType.TypeName}\n" + $"\t{{\n"); } // **** output resource type first (if necessary) **** if (FhirTypeManager.DoesTypeRequireResourceTag(fhirType.Name)) { // **** add this resource to our list (for polymorphic deserialization) **** _exportedResourceNamesAndTypes.Add(fhirType.Name, fhirType.NameCapitalized); // **** output the correct ResourceType field based on style **** switch (LanguageStyle) { case (int)CSharpStyle.SystemTextJson: sb.Append( $"\t\t///<summary>Resource Type Name (for serialization)</summary>\n" + $"\t\t[JsonPropertyName(\"resourceType\")]\n" + $"\t\tpublic string ResourceType => \"{fhirType.Name}\";\n" ); break; case (int)CSharpStyle.Newtonsoft: sb.Append( $"\t\t///<summary>Resource Type Name (for serialization)</summary>\n" + $"\t\t[JsonProperty(PropertyName = \"resourceType\")]\n" + $"\t\tpublic string ResourceType => \"{fhirType.Name}\";\n" ); break; case (int)CSharpStyle.Plain: default: sb.Append( $"\t\t///<summary>Resource Type Name (for serialization)</summary>\n" + $"\t\tpublic string ResourceType => \"{fhirType.Name}\";\n" ); break; } } return(true); }
bool ILanguangeExporter.AppendFhirProperty( ref StringBuilder sb, FhirProperty property, string typeName, bool useLowerCaseName ) { string nameCamel = FhirTypeManager.SanitizeForProperty(property.Name, _reservedWordsSet); string namePascal = FhirTypeManager.SanitizeForProperty(property.NameCapitalized, _reservedWordsSet); string propertyName; string extendedName; if (useLowerCaseName) { propertyName = nameCamel; extendedName = nameCamel; } else { switch (LanguageStyle) { case (int)CSharpStyle.SystemTextJson: propertyName = namePascal; extendedName = namePascal; break; case (int)CSharpStyle.Newtonsoft: propertyName = namePascal; extendedName = namePascal; break; case (int)CSharpStyle.Plain: default: propertyName = namePascal; extendedName = nameCamel; break; } } string propertyAnnotation = ""; string extendedAnnotation = ""; switch (LanguageStyle) { case (int)CSharpStyle.SystemTextJson: propertyAnnotation = $"\t\t[JsonPropertyName(\"{property.Name}\")]\n"; extendedAnnotation = $"\t\t[JsonPropertyName(\"_{property.Name}\")]\n"; break; case (int)CSharpStyle.Newtonsoft: propertyAnnotation = $"\t\t[JsonProperty(PropertyName = \"{property.Name}\")]\n"; extendedAnnotation = $"\t\t[JsonProperty(PropertyName = \"_{property.Name}\")]\n"; break; case (int)CSharpStyle.Plain: default: break; } string comment = FhirTypeManager.SanitizeComment(property.Comment, _lineComment, _indentChar, 2); string optionalFlagString = (_flagOptionals && property.IsOptional) ? "?" : ""; // **** nullable reference types are not allowed in current C# **** switch (typeName) { case "bool": case "decimal": case "DateTime": case "int": case "uint": case "Guid": // **** ignore - types can be optional **** break; default: // **** do not allow reference types to be null (for now) **** optionalFlagString = ""; break; } // **** **** if (property.IsArray) { sb.Append( $"\t\t///<summary>{comment}</summary>\n" + propertyAnnotation + $"\t\tpublic {typeName}[] {propertyName} {{ get; set; }}\n" + $"\t\t///<summary>May contain extended information for property: '{propertyName}'</summary>\n" + extendedAnnotation + $"\t\tpublic Element[] _{extendedName} {{ get; set; }}\n"); return(true); } sb.Append( $"\t\t///<summary>{comment}</summary>\n" + propertyAnnotation + $"\t\tpublic {typeName}{optionalFlagString} {propertyName} {{ get; set; }}\n" + $"\t\t///<summary>May contain extended information for property: '{propertyName}'</summary>\n" + extendedAnnotation + $"\t\tpublic Element _{extendedName} {{ get; set; }}\n"); return(true); }