示例#1
0
        void WriteIntroDocDescription(String className,
                                      String blockName,
                                      String outputCodePath,
                                      String penId)
        {
            CodeEditor editor = new CodeEditor();

            editor.Load(Path.Combine(DirHelper.FindParentDir("BreastRadiology.XUnitTests"),
                                     "ResourcesMaker",
                                     outputCodePath));

            UpdateClass(className, penId);

            if (this.spreadSheetData.TryGetRow(penId, out DataRow row) == false)
            {
                throw new Exception($"Missing value for penid '{penId}'");
            }

            CodeBlockNested description = editor.Blocks.Find(blockName);

            if (description == null)
            {
                throw new Exception($"Can not find editor block {blockName}");
            }

            description.Clear();
            AppIfNotNull(description, penId, "Description", row[UMLSCol]);
            editor.Save();
        }
示例#2
0
        public static CodeBlockNested AppendStringArray(this CodeBlockNested block,
                                                        string fieldName,
                                                        IEnumerable <String> strings,
                                                        ref String sep,
                                                        [CallerFilePath] String filePath    = "",
                                                        [CallerLineNumber] Int32 lineNumber = 0)
        {
            if (strings.Any() == false)
            {
                return(block);
            }
            String[] profileArr = strings.ToArray();

            if (String.IsNullOrEmpty(sep) == false)
            {
                block.AppendCode($"{sep}", filePath, lineNumber);
            }
            sep = ",";
            block
            .AppendCode($"{fieldName} = new String[]", filePath, lineNumber)
            .OpenBrace()
            ;
            for (Int32 i = 0; i < profileArr.Length - 1; i++)
            {
                block.AppendCode($"\"{profileArr[i]}\",", filePath, lineNumber);
            }
            block
            .AppendCode($"\"{profileArr[profileArr.Length - 1]}\"", filePath, lineNumber)
            .CloseBrace()
            ;
            return(block);
        }
示例#3
0
        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);")
            ;
        }
示例#4
0
        bool AppIfNotNull(CodeBlockNested concept,
                          String penId,
                          String name,
                          Object value)
        {
            if (value is System.DBNull)
            {
                return(false);
            }

            String sValue = value.ToString();

            sValue = sValue.Trim()
                     .Replace("\r", "")
            ;
            if (String.IsNullOrEmpty(sValue) == false)
            {
                String[] lines = FormatMultiLineText(sValue).ToArray();
                concept.AppendLine($"    .{name}(\"{penId}\",");
                Int32 i = 0;
                while (i < lines.Length - 1)
                {
                    concept.AppendLine($"        {lines[i++]}");
                }
                concept.AppendLine($"        {lines[i]})");
            }

            return(true);
        }
        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);")
            //    ;
        }
示例#6
0
 /// <summary>
 /// End namespace.
 /// </summary>
 public void EndNameSpace()
 {
     this.nameSpaceBlock
     .CloseBrace()
     ;
     this.nameSpaceBlock = null;
 }
示例#7
0
        public void Build()
        {
            CodeEditor.DebugFlag       = true;
            this.resourceFactoryEditor = new CodeEditor();
            this.resourceFactoryEditor.Load(Path.Combine(this.OutputDir, "Generated", "ResourceFactory.cs"));
            this.resourceFactoryProfileBlock = this.resourceFactoryEditor.Blocks.Find("Profile");
            this.resourceFactoryProfileBlock.Clear();

            if (Directory.Exists(this.OutputDir) == false)
            {
                Directory.CreateDirectory(this.OutputDir);
            }

            if (this.CleanFlag)
            {
                this.fc = new FileCleaner();
                this.fc.Add(Path.Combine(this.OutputDir, "Generated"));
            }

            this.BuildReferences();
            this.BuildLocalCodeSystems();
            this.BuildCodeSystems();
            this.BuildValueSets();
            this.BuildFragments();
            this.SaveAll();

            this.fc?.Dispose();
        }
 protected override void BuildItemRead(CodeBlockNested b)
 {
     b
     .AppendCode("this.Value = new Members();")
     .AppendCode("this.Value.ReadMember(doc, item);")
     ;
 }
示例#9
0
        void ClearDuplicateLines(CodeBlockNested block)
        {
            List <String> lines = block.Lines().ToList();

            for (Int32 i = 0; i < lines.Count(); i++)
            {
                lines[i] = lines[i].Trim();
            }
            {
                Int32 i = 0;
                while (i < lines.Count())
                {
                    Int32 j = i + 1;
                    while (j < lines.Count())
                    {
                        if (String.Compare(lines[i], lines[j]) == 0)
                        {
                            lines.RemoveAt(j);
                        }
                        else
                        {
                            j += 1;
                        }
                    }
                    i += 1;
                }
            }
            block.Clear();
            block.AppendLines("", lines);
        }
示例#10
0
        public void AddItem(CodeBlockNested block,
                            IEnumerable <Tuple <String, String> > references,
                            Markdown text)
        {
            if ((text is null) && (references.Any() == false))
            {
                return;
            }

            if (text == null)
            {
                text = new Markdown("");
            }
            block.AppendRaw("<tr>");

            foreach (Tuple <String, String> reference in references)
            {
                String referenceName = reference.Item1;
                String referencePage = reference.Item2;
                block.AppendRaw($"<td><a href=\"{referencePage}\">{referenceName}</a></td>");
            }
            block
            .AppendRaw("<td>{% capture md_text %}")
            .AppendRaw(text.Value)
            .AppendRaw("{% endcapture %}{{ md_text | markdownify }}</td>")
            .AppendRaw("</tr>")
            ;
        }
示例#11
0
 public ImplementationGuideEditor(String templatePath)
 {
     this.implementationGuide = new CodeEditorXml();
     this.implementationGuide.Load(templatePath);
     this.groups    = this.implementationGuide.Blocks.Find("*Groups");
     this.resources = this.implementationGuide.Blocks.Find("*Resources");
 }
        protected override void BuildContainerWrite(CodeBlockNested b)
        {
            b
            .AppendCode("public IEnumerable<Composition.SectionComponent> Write(BreastRadiologyDocument doc)")
            .OpenBrace()
            .AppendCode($"if (this.Count == 0)")
            .AppendCode($"    return new Composition.SectionComponent[0];")
            .AppendCode($"Composition.SectionComponent section = new Composition.SectionComponent")
            .OpenBrace()
            .AppendCode($"Title = \"{this.title}\",")
            .AppendCode($"Code = {this.sectionCodeMethodName}()")
            .CloseBrace(";")
            .AppendCode($"section.Author.Add(doc.Author.ResourceReference());")
            .AppendCode($"foreach (Item item in this.GetAllItems())")
            .OpenBrace()
            .AppendCode($"section.Entry.Add(item.WriteItem(doc));")
            .CloseBrace()
            .AppendCode($"return new Composition.SectionComponent[] {{ section }};")
            .CloseBrace()
            ;

            this.writeBlock
            .AppendCode($"items.AddRange(this.{this.PropertyName}.Write(this.Doc));")
            ;
        }
        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);")
            ;
        }
示例#14
0
        public CodeEditor CreateMapEditor(String path)
        {
            const String fcn = "CreateMapEditor";

            String mapName = $"{path}_map_r4";

            if (this.editorDict.ContainsKey(mapName) == true)
            {
                throw new ConvertErrorException(this.GetType().Name, fcn, $"Path {path} has already been processed.");
            }

            CodeEditor mapEditor = new CodeEditor();

            mapEditor.SavePath = Path.Combine(this.GeneratedPath, $"{mapName}.txt");

            CodeBlockNested mapBlock = mapEditor.Blocks.AppendBlock();

            mapBlock
            .AppendLine($"Grammar: Map 5.1")
            .AppendLine($"Namespace: fhir")
            .AppendLine($"Target: FHIR_R4")
            .BlankLine()
            ;

            this.editorDict.Add(mapName, mapEditor);
            return(mapEditor);
        }
示例#15
0
 protected override void BuildItemWrite(CodeBlockNested b)
 {
     b
     .AppendCode($"{this.FhirClassName} retVal = this.Value;")
     .AppendCode($"List<Extension> extensionList = retVal.Extension;")
     ;
 }
示例#16
0
        public CSSliceCreator(String className,
                              CSCodeFormatter csCode,
                              CodeBlockNested subClassBlock,
                              CodeBlockNested methodsBlock,
                              ElementDefinitionNode elementNode,
                              Type fhirBaseClassType)
        {
            if (subClassBlock is null)
            {
                throw new ArgumentNullException(nameof(subClassBlock));
            }
            if (methodsBlock is null)
            {
                throw new ArgumentNullException(nameof(methodsBlock));
            }
            if (elementNode is null)
            {
                throw new ArgumentNullException(nameof(elementNode));
            }

            this.csCode = csCode;
            if (elementNode is null)
            {
                throw new ArgumentNullException(nameof(elementNode));
            }

            this.className         = className;
            this.subClassBlock     = subClassBlock.AppendBlock();
            this.methodsBlock      = methodsBlock.AppendBlock();
            this.elementNode       = elementNode;
            this.fhirBaseClassType = fhirBaseClassType;
        }
示例#17
0
        /// <summary>
        /// Start creating a class.
        /// </summary>
        public bool StartClass(String className, Type fhirBaseClassType)
        {
            this.fhirBaseClassType = fhirBaseClassType;
            this.className         = className;
            string fhirTypeName = fhirBaseClassType.FriendlyName();

            this.classBlock = this.nameSpaceBlock.AppendBlock();
            this.classBlock
            .BlankLine()
            .SummaryOpen()
            .Summary($"Extension class to add slicing helper methods to {fhirTypeName}")
            .SummaryClose()
            .AppendLine($"public static class {className}")
            .OpenBrace()
            ;

            this.subClassBlock = classBlock.AppendBlock();
            this.subClassBlock.AppendLine($"#region {className} sub classes");

            this.fieldsBlock = classBlock.AppendBlock();
            this.fieldsBlock.AppendLine($"#region fields {className} fields");

            this.methodsBlock = classBlock.AppendBlock();
            this.methodsBlock.AppendLine($"#region methods {className} methods");

            return(true);
        }
示例#18
0
        void Merge(CodeBlockNested codeBlock, CodeBlockNested mergeBlock)
        {
            foreach (CodeBlock mergeBlockChild in mergeBlock.Children)
            {
                switch (mergeBlockChild)
                {
                case CodeBlockText mergeBlockChildText:
                    // if the name starts with '!', then dont merge child
                    // text blocks. Throw away merge text.
                    if (mergeBlock.Name.StartsWith("!") == false)
                    {
                        foreach (String line in mergeBlockChild.AllLines())
                        {
                            codeBlock.AppendLine(line, "");
                        }
                    }
                    break;

                case CodeBlockNested mergeBlockChildNested:
                    CodeBlockNested codeBlockChildNested = codeBlock.Find(mergeBlockChildNested.Name);
                    if (codeBlockChildNested == null)
                    {
                        codeBlockChildNested = codeBlock.AppendBlock(mergeBlockChildNested.Name);
                        codeBlockChildNested.Load(mergeBlockChildNested.Lines(), false);
                    }
                    else
                    {
                        this.Merge(codeBlockChildNested, mergeBlockChildNested);
                    }
                    break;
                }
            }
        }
示例#19
0
        public void Merge(CodeBlock mergeBlock)
        {
            bool AllBlank(String[] lines)
            {
                foreach (String line in lines)
                {
                    if (line.Trim().Length > 0)
                    {
                        return(false);
                    }
                }
                return(true);
            }

            CodeBlockNested mergeBlockNested = mergeBlock as CodeBlockNested;

            if (mergeBlockNested == null)
            {
                if (AllBlank(mergeBlock.AllLines()) == false)
                {
                    throw new Exception($"Base merge block must be of type MergeBlockNested");
                }
                return;
            }

            CodeBlockNested codeBlockNested = this.code.Blocks.Find(mergeBlockNested.Name);

            if (codeBlockNested == null)
            {
                throw new Exception($"Base code editor does not contain a top level block named {mergeBlockNested.Name}");
            }
            this.Merge(codeBlockNested, mergeBlockNested);
        }
示例#20
0
 protected override void BuildItemRead(CodeBlockNested b)
 {
     b
     .AppendCode("this.Value = item;")
     .AppendCode("List<Extension> extensionList = item.Extension;")
     ;
 }
        void Dump(CodeBlockNested b)
        {
            String dir = Path.Combine(
                DirHelper.FindParentDir(BaseDirName),
                "IG",
                "Content",
                "Resources"
                );

            foreach (String file in Directory.GetFiles(dir, "*.json"))
            {
                String         fhirText = File.ReadAllText(file);
                FhirJsonParser parser   = new FhirJsonParser();
                var            resource = parser.Parse(fhirText, typeof(Resource));
                switch (resource)
                {
                case StructureDefinition structureDefinition:
                    this.Dump(b, structureDefinition);
                    break;

                case CodeSystem codeSystem:
                    this.Dump(b, codeSystem);
                    break;

                case ValueSet valueSet:
                    this.Dump(b, valueSet);
                    break;

                default:
                    throw new NotImplementedException($"Unknown resource type '{file}'");
                }
            }
        }
 void Dump(CodeBlockNested b, ValueSet vs)
 {
     b
     .AppendRaw($"<a name=\"{vs.Name}\">  </a>")
     .AppendRaw($"<h1>ValueSet: '{vs.Name}'</h1>")
     ;
     DumpLines(b, "h2", "Description", vs.Description.Value);
 }
示例#23
0
 public static CodeBlockNested AppendProfiles(this CodeBlockNested block,
                                              IEnumerable <String> profiles,
                                              ref String sep,
                                              [CallerFilePath] String filePath    = "",
                                              [CallerLineNumber] Int32 lineNumber = 0)
 {
     return(AppendStringArray(block, "Profile", profiles, ref sep, filePath, lineNumber));
 }
示例#24
0
 /// <summary>
 /// End namespace.
 /// </summary>
 public bool EndNameSpace()
 {
     this.nameSpaceBlock
     .CloseBrace()
     ;
     this.nameSpaceBlock = null;
     return(true);
 }
示例#25
0
 {                                                                                                                                       // CodeGeneration.cs:401
     /// <summary>
     /// Return c# text to create indicated element.
     /// </summary>
     static public bool Construct(CodeBlockNested block,
                                  Element fix,                                                                                           // CodeGeneration.cs:416
                                  String methodName,                                                                                     // CodeGeneration.cs:417
                                  out String propertyType)                                                                               // CodeGeneration.cs:418
     {                                                                                                                                   // CodeGeneration.cs:419
         propertyType = String.Empty;
         return(false);
     }
示例#26
0
        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()
            ;
        }
示例#27
0
        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()
            ;
        }
示例#28
0
 /// <summary>
 /// Create common static constructor method.
 /// </summary>
 public static CodeBlockNested WriteInit(this CodeBlockNested block,
                                         string className,
                                         [CallerFilePath] String filePath    = "",
                                         [CallerLineNumber] Int32 lineNumber = 0)
 {
     block.WriteInitStart(className, filePath, lineNumber);
     block.WriteInitEnd();
     return(block);
 }
 void DumpHeader(CodeBlockNested b,
                 String level,
                 String header)
 {
     b
     .AppendRaw($"<a name=\"{this.anchorNum++.ToString()}\">  </a>")
     .AppendRaw($"<{level}>{header}</{level}>")
     ;
 }
示例#30
0
 void FixElements(CodeBlockNested code,
                  Type csType,
                  String varName,
                  String retValName)
 {
     foreach (PropertyInfo pi in csType.GetProperties())
     {
         FixElement(code, pi, varName, retValName);
     }
 }