Example #1
0
        /// <summary>
        /// Create local code systems for those that are not defined in this project.
        /// Add all value set codes taht reference this code system into it.
        /// </summary>
        /// <param name="vi"></param>
        void BuildLocalCodeSystem(VSInfo vi)
        {
            foreach (ValueSet.ConceptSetComponent component in vi.ValueSet.Compose.Include)
            {
                foreach (ValueSet.ConceptReferenceComponent concept in component.Concept)
                {
                    // if code system not found
                    if (this.CodeSystems.TryGetValue(component.System, out CSInfo ci) == false)
                    {
                        if (this.LocalCodeSystems.TryGetValue(component.System, out ci) == false)
                        {
                            ci = new CSInfo(new CodeSystem
                            {
                                Name = component.System.LastUriPart(),
                                Url  = component.System
                            });
                            this.LocalCodeSystems.Add(component.System, ci);
                        }

                        CodeSystem.ConceptDefinitionComponent c = new CodeSystem.ConceptDefinitionComponent
                        {
                            Code    = concept.Code,
                            Display = concept.Display
                        };
                        ci.CodeSystem.Concept.Add(c);
                    }
                }
            }
        }
Example #2
0
        public void AddFragment(String filePath)
        {
            const String fcn = "AddFragment";

            DomainResource domainResource;

            switch (Path.GetExtension(filePath).ToUpper(CultureInfo.InvariantCulture))
            {
            case ".XML":
            {
                FhirXmlParser parser = new FhirXmlParser();
                domainResource = parser.Parse <DomainResource>(File.ReadAllText(filePath));
                break;
            }

            case ".JSON":
            {
                FhirJsonParser parser = new FhirJsonParser();
                domainResource = parser.Parse <DomainResource>(File.ReadAllText(filePath));
                break;
            }

            default:
                throw new Exception($"Unknown extension for serialized fhir resource '{filePath}'");
            }

            switch (domainResource)
            {
            case CodeSystem cs:
            {
                CSInfo ci = new CSInfo(cs);
                this.CodeSystems.Add(cs.Url, ci);
            }
            break;

            case ValueSet vs:
            {
                VSInfo vi = new VSInfo(vs);
                this.ValueSets.Add(vs.Url, vi);
            }
            break;

            case StructureDefinition sd:
            {
                SDInfo fi = new SDInfo(this, sd);
                this.SDFragments.Add(sd.Url.Trim(), fi);
            }
            break;

            default:
                this.ConversionError(this.GetType().Name,
                                     fcn,
                                     $"Unimplemented fragment resource type {domainResource.GetType().Name} file {filePath}");
                return;
            }
        }
Example #3
0
        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}\");")
                ;
            }
        }
Example #4
0
 public static String CodeSystemName(CSInfo ci) => $"{MachineName(ci.CodeSystem.Name)}";