Esempio n. 1
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);
        }
Esempio n. 2
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();
        }
        public void PatchStructDef(StructureDefinition sd)
        {
            //const String fcn = "PatchStructDefObservation";

            CodeEditorXml c = new CodeEditorXml();

            c.IgnoreMacrosInQuotedStrings = false;

            ElementTreeLoader l        = new ElementTreeLoader(this);
            ElementTreeNode   diffNode = null;

            if (sd?.Differential?.Element != null)
            {
                diffNode = l.Create(sd.Differential.Element);
            }

            String[] CollateComponents()
            {
                SortedList <String, String> items = new SortedList <String, String>();

                if (diffNode == null)
                {
                    return(items.Values.ToArray());
                }

                if (diffNode.TryGetElementNode("Observation.component", out ElementTreeNode node) == false)
                {
                    return(items.Values.ToArray());
                }

                if (node.Slices.Count <= 1)
                {
                    return(items.Values.ToArray());
                }

                foreach (ElementTreeSlice slice in node.Slices.Skip(1))
                {
                    String shortDesc =
                        $"{slice.ElementDefinition.Short} [{slice.ElementDefinition.Min}..{slice.ElementDefinition.Max}]";
                    String anchor = Global.ElementAnchor(slice.ElementDefinition).Replace("{SDName}", sd.Name);
                    items.Add(shortDesc, $"<a href=\"{anchor}\">{shortDesc}</a>");
                }

                return(items.Values.ToArray());
            }

            String[] CollateFragments()
            {
                SortedList <String, String> items = new SortedList <String, String>();

                foreach (Extension frag in sd.GetExtensions(Global.FragmentUrl))
                {
                    FhirUrl fragmentUrl = (FhirUrl)frag.Value;
                    if (this.map.TryGetNode(fragmentUrl.Value, out ResourceMap.Node fragNode) == false)
                    {
                        throw new Exception($"Can not find fragment {frag.Url}");
                    }
                    String hRef = $"./{fragNode.StructureName}-{fragNode.Name}.html";
                    items.Add(fragNode.Title, $"<a href=\"{hRef}\">{fragNode.Title}</a>");
                }

                return(items.Values.ToArray());
            }

            String[] CollateHasMembers()
            {
                SortedList <String, String> items = new SortedList <String, String>();

                if (diffNode == null)
                {
                    return(items.Values.ToArray());
                }

                if (diffNode.TryGetElementNode("Observation.hasMember", out ElementTreeNode node) == false)
                {
                    return(items.Values.ToArray());
                }

                if (node.Slices.Count <= 1)
                {
                    return(items.Values.ToArray());
                }

                foreach (ElementTreeSlice slice in node.Slices.Skip(1))
                {
                    String shortDesc =
                        $"{slice.ElementDefinition.Short} [{slice.ElementDefinition.Min}..{slice.ElementDefinition.Max}]";
                    String anchor =
                        $"StructureDefinition-{sd.Name}-definitions.html#Observation.hasMember:{slice.ElementDefinition.SliceName}";
                    items.Add(shortDesc, $"<a href=\"{anchor}\">{shortDesc}</a>");
                }

                return(items.Values.ToArray());
            }

            String introName = sd.Url.LastUriPart();

            String introPath = Path.Combine(this.pageDir,
                                            $"StructureDefinition-{introName}-intro.xml");

            // Load and save will expand the macros.
            c.Load(introPath);
            {
                CodeBlockNested componentBlock = c.Blocks.Find("components");
                if (componentBlock != null)
                {
                    String[] componentItems = CollateComponents();
                    if (componentItems.Length > 0)
                    {
                        c.TryAddUserMacro("ComponentList", componentItems);
                        componentBlock.Reload();
                    }
                    else
                    {
                        componentBlock.Clear();
                    }
                }
            }
            {
                CodeBlockNested hasMemberBlock = c.Blocks.Find("hasMember");
                if (hasMemberBlock != null)
                {
                    String[] hasMembersItems = CollateHasMembers();
                    if (hasMembersItems.Length > 0)
                    {
                        c.TryAddUserMacro("HasMemberList", hasMembersItems);
                        hasMemberBlock.Reload();
                    }
                    else
                    {
                        hasMemberBlock.Clear();
                    }
                }
            }

            {
                CodeBlockNested fragBlock = c.Blocks.Find("profileFragments");
                if (fragBlock != null)
                {
                    String[] fragments = CollateFragments();
                    if (fragments.Length > 0)
                    {
                        c.TryAddUserMacro("FragmentList", fragments);
                        fragBlock.Reload();
                    }
                    else
                    {
                        fragBlock.Clear();
                    }
                }
            }

            c.Save();
        }
Esempio n. 4
0
        void WriteIds(String className,
                      String outputCodePath,
                      String csBlockName,
                      IEnumerable <String> penIdsEnum)
        {
            String[] penIds = penIdsEnum.ToArray();

            CodeEditor editor = new CodeEditor();

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

            CodeBlockNested concepts = editor.Blocks.Find(csBlockName);

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

            concepts.Clear();
            concepts.AppendLine($"#region Codes");
            for (Int32 i = 0; i < penIds.Length; i++)
            {
                String penId = penIds[i];
                UpdateClass(className, penId);

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

                String code             = FormatCode(row[this.spreadSheetData.itemNameCol].ToString());
                String conceptBlockName = CodeValue(code);

                String App(String s, Object t, String sb)
                {
                    switch (t)
                    {
                    case DBNull dbNullValue:
                        return(s);

                    case String stringValue:
                        // verify we have correct column.
                        if (stringValue != sb)
                        {
                            Trace.WriteLine($"Invalid Modality '{stringValue}'. Expected {sb}");
                        }
                        if (String.IsNullOrEmpty(s) == false)
                        {
                            s += " | ";
                        }
                        s += $"Modalities.{sb}";
                        return(s);

                    default:
                        throw new Exception("Invalid excel cell value");
                    }
                }

                String validWith = App("", row[this.spreadSheetData.mgCol], "MG");
                ;
                validWith = App(validWith, row[this.spreadSheetData.mriCol], "MRI");
                validWith = App(validWith, row[this.spreadSheetData.nmCol], "NM");
                validWith = App(validWith, row[this.spreadSheetData.usCol], "US");

                concepts
                .AppendLine($"new ConceptDef()")
                .AppendLine($"    .SetCode(\"{conceptBlockName}\")")
                .AppendLine($"    .SetDisplay(\"{code}\")")
                //.AppendLine($"    .SetDefinition(\"[PR] {code}\")")
                .AppendLine($"    .MammoId(\"{penId}\")")
                ;
                if (String.IsNullOrEmpty(validWith) == false)
                {
                    concepts.AppendLine($"    .ValidModalities({validWith})");
                }

                AppIfNotNull(concepts, penId, "SetDicom", row[DicomCol]);
                AppIfNotNull(concepts, penId, "SetSnomedCode", row[SnomedCol]);
                //AppIfNotNull(concepts, penId, "SetOneToMany", row[13]);
                AppIfNotNull(concepts, penId, "SetSnomedDescription", row[SnomedDescriptionCol]);
                //AppIfNotNull(concepts, "SetICD10", row[ICD10Col]);
                if (AppIfNotNull(concepts, penId, "SetUMLS", row[UMLSCol]) == false)
                {
                    AppIfNotNull(concepts, penId, "SetACR", row[ACRCol]);
                }
                if (i < penIds.Length - 1)
                {
                    concepts
                    .AppendLine($",");
                }
            }

            concepts.AppendLine($"#endregion // Codes");
            editor.Save();
        }