Exemple #1
0
        void LoadFhirElement(StructureDefinition sDef)
        {
            const String fcn = "LoadFhirElement";

            /*
             * Eliminate all but the top level resources to simplify things.
             * Add them in later????
             */
            if (sDef.Type != sDef.Name)
            {
                this.ConversionWarn(this.GetType().Name, fcn, $"Skipping resource {sDef.Name}");
                return;
            }

            SDefInfo sDefInfo = new SDefInfo
            {
                SDef = sDef
            };

            switch (sDef.Url)
            {
            case "http://hl7.org/fhir/StructureDefinition/Element":
                sDefInfo.TFlag = SDefInfo.TypeFlag.Element;
                break;

            case "http://hl7.org/fhir/StructureDefinition/Resource":
                sDefInfo.TFlag = SDefInfo.TypeFlag.Resource;
                break;

            default:
                sDefInfo.TFlag = SDefInfo.TypeFlag.Unknown;
                break;
            }
            this.items.Add(sDef.Url, sDefInfo);
        }
Exemple #2
0
        void ProcessFhirComplex(SDefInfo sDefInfo)
        {
            const String fcn = "ProcessFhirPrimitive";

            StructureDefinition sDef = sDefInfo.SDef;

            ClearSDef(sDef);

            this.ConversionInfo(this.GetType().Name, fcn, $"Processing Complex {sDef.Name} {sDefInfo.TFlag}");

            String          instanceName   = TypeName(sDef.Name);
            CodeEditor      instanceEditor = this.project.CreateEditor(Path.Combine(ComplexGenPath, $"{instanceName}.cs"));
            CodeBlockNested instanceBlock  = instanceEditor.Blocks.AppendBlock();

            instanceBlock
            .AppendCode("using System;")
            .AppendCode("using System.Diagnostics;")
            .AppendCode("using System.IO;")
            .AppendCode("using System.Linq;")
            .AppendCode("using Hl7.Fhir.Model;")
            .BlankLine()
            .AppendCode($"namespace {ComplexNameSpace}")
            .OpenBrace()
            .AppendCode("#region Json")
            .AppendLine("#if NEVER")
            .AppendLines("", sDef.ToFormatedJson().ToLines())
            .AppendLine("#endif")
            .AppendCode("#endregion")
            .SummaryOpen()
            .Summary($"Fhir complex '{sDef.Name}'")
            .SummaryClose()
            .DefineBlock(out CodeBlockNested classBlock)
            .CloseBrace()
            ;

            Int32 i = 0;

            DefineClass(classBlock,
                        sDef.Differential.Element.ToArray(),
                        ref i,
                        sDef.Differential.Element[0].Path,
                        instanceName,
                        ComplexBase,
                        out CodeBlockNested dummy);

            if (i != sDef.Differential.Element.Count)
            {
                throw new ConvertErrorException(this.GetType().Name, fcn, $"Internal error. Invalid element index");
            }
        }
Exemple #3
0
        void ProcessFhirElements()
        {
            const String fcn = "ProcessFhirElements";

            foreach (string path in this.items.Keys)
            {
                SDefInfo            sDefInfo = this.GetTypedSDef(path);
                StructureDefinition sDef     = sDefInfo.SDef;
                switch (sDefInfo.SDef.Kind)
                {
                case StructureDefinition.StructureDefinitionKind.PrimitiveType:
                    ProcessFhirPrimitive(sDefInfo);
                    break;

                case StructureDefinition.StructureDefinitionKind.Logical:
                    break;

                case StructureDefinition.StructureDefinitionKind.ComplexType:
                    switch (sDefInfo.TFlag)
                    {
                    case SDefInfo.TypeFlag.Element:
                        ProcessFhirComplex(sDefInfo);
                        break;

                    default:
                        throw new ConvertErrorException(this.GetType().Name, fcn, $"Invalid TKind {sDefInfo.TFlag}. Item {path}");
                    }
                    break;

                case StructureDefinition.StructureDefinitionKind.Resource:
                    ProcessFhirResource(sDefInfo);
                    break;

                default:
                    throw new ConvertErrorException(this.GetType().Name, fcn, $"Invalid kind {sDefInfo.SDef.Kind}. Item {path}");
                }
            }
        }
Exemple #4
0
        void ProcessFhirPrimitive(SDefInfo sDefInfo)
        {
            const String fcn = "ProcessFhirPrimitive";

            StructureDefinition sDef = sDefInfo.SDef;

            ClearSDef(sDef);

            this.ConversionInfo(this.GetType().Name, fcn, $"Processing Primitive {sDef.Name} {sDefInfo.TFlag}");
            String          instanceName   = PrimitiveName(sDef.Name);
            CodeEditor      instanceEditor = this.project.CreateEditor(Path.Combine(PrimitiveGenPath, $"{instanceName}.cs"));
            CodeBlockNested instanceBlock  = instanceEditor.Blocks.AppendBlock();

            instanceBlock
            .AppendCode("using System;")
            .AppendCode("using System.Diagnostics;")
            .AppendCode("using System.IO;")
            .AppendCode("using System.Linq;")
            .AppendCode("using Hl7.Fhir.Model;")
            .BlankLine()
            .AppendCode($"namespace {PrimitiveNameSpace}")
            .OpenBrace()
            .AppendCode("#region Json")
            .AppendLine("#if NEVER")
            .AppendLines("", sDef.ToFormatedJson().ToLines())
            .AppendLine("#endif")
            .AppendCode("#endregion")
            .SummaryOpen()
            .Summary($"Fhir primitive '{sDef.Name}'")
            .SummaryClose()
            .AppendCode($"public partial class {instanceName} : {PrimitiveBase}")
            .OpenBrace()
            .CloseBrace()
            .CloseBrace()
            ;
        }
Exemple #5
0
        void ProcessFhirResource(SDefInfo sDefInfo)
        {
            const String fcn = "ProcessFhirResource";

            StructureDefinition sDef = sDefInfo.SDef;

            ClearSDef(sDef);

            this.ConversionInfo(this.GetType().Name, fcn, $"Processing Resource {sDef.Name} {sDefInfo.TFlag}");

            String          instanceName   = ResourceName(sDef.Name);
            CodeEditor      instanceEditor = this.project.CreateEditor(Path.Combine(ResourceGenPath, $"{instanceName}.cs"));
            CodeBlockNested instanceBlock  = instanceEditor.Blocks.AppendBlock();

            instanceBlock
            .AppendCode("using System;")
            .AppendCode("using System.Diagnostics;")
            .AppendCode("using System.IO;")
            .AppendCode("using System.Linq;")
            .AppendCode("using Hl7.Fhir.Model;")
            .BlankLine()
            .AppendCode($"namespace {ResourceNameSpace}")
            .OpenBrace()
            .AppendCode("#region Json")
            .AppendCode("#if NEVER")
            .AppendLines("", sDef.ToFormatedJson().ToLines())
            .AppendLine("#endif")
            .AppendCode("#endregion")
            .SummaryOpen()
            .Summary($"Fhir resource '{sDef.Name}'")
            .SummaryClose()
            .DefineBlock(out CodeBlockNested classBlock)
            .CloseBrace()
            ;

            String baseClass = ResourceBase;

            if (String.IsNullOrEmpty(sDef.BaseDefinition) == false)
            {
                String name = this.ResourceName(sDef.BaseDefinition.LastUriPart());
                baseClass = $"{ResourceNameSpace}.{name}";
            }
            Int32 i = 0;

            DefineClass(classBlock,
                        sDef.Differential.Element.ToArray(),
                        ref i,
                        sDef.Differential.Element[0].Path,
                        instanceName,
                        baseClass,
                        out CodeBlockNested constructorBlock);

            constructorBlock
            .AppendCode($"this.Name = \"{sDef.Name}\";")
            .AppendCode($"this.Uri = \"{sDef.Url}\";")
            ;

            if (i != sDef.Differential.Element.Count)
            {
                throw new ConvertErrorException(this.GetType().Name, fcn, $"Internal error. Invalid element index");
            }
        }