private XElement GetDescriptionTableCell(SDTreeNode treeNode)
        {
            ElementDefinition definition = treeNode.Element;

            List <object> lines = new List <object>();

            if (!treeNode.IsRemoved())
            {
                String shortDefExtension = null;
                if (treeNode.ExtensionDefinition != null)
                {
                    if (treeNode.ExtensionDefinition.GetRootPathElement() != null)
                    {
                        if (treeNode.ExtensionDefinition.GetRootPathElement().@short != null)
                        {
                            shortDefExtension = treeNode.ExtensionDefinition.GetRootPathElement()[email protected];
                        }
                    }
                }

                // short definition
                string shortDefinition = treeNode.GetShortDescription();

                if (string.IsNullOrWhiteSpace(shortDefinition) || shortDefinition == "Additional Content defined by implementations")
                {
                    shortDefinition = shortDefExtension;
                }

                if (!string.IsNullOrWhiteSpace(shortDefinition))
                {
                    lines.Add(Html.P(shortDefinition));
                }

                // extension details
                string extensionCanonicalUrl = definition.GetExtensionCanonicalUrl();

                if (!string.IsNullOrEmpty(extensionCanonicalUrl))
                {
                    Link link = _resourceFileSet.GetStructureDefinitionLink(extensionCanonicalUrl);
                    lines.Add(Html.P(GetLabelAndValue("Extension", Html.A(link))));
                }

                // fixed value
                if (definition.HasFixedValue())
                {
                    lines.Add(Html.P(GetLabelAndValue("Fixed value", definition.GetFixedValue())));
                }

                // valueset/bindings
                string valueSetUri = treeNode.GetValueSetUri();

                if (!string.IsNullOrWhiteSpace(valueSetUri))
                {
                    Link valuesetLink = _resourceFileSet.GetValueSetLink(valueSetUri);

                    lines.Add(Html.P(GetLabelAndValue("Valueset", new object[]
                    {
                        Html.A(valuesetLink.Url, valuesetLink.Display),
                        " (",
                        Html.A((treeNode.GetValueSetBindingStrength().GetUrl()), treeNode.GetValueSetBindingStrength().GetDescription()),
                        ")"
                    })));
                }

                // invariants
                string[] invariants = definition.GetInvariantText();

                if (invariants.Length > 0)
                {
                    lines.Add(Html.P(invariants.Select(t => Html.I(t)).Intersperse(Html.Br()).ToArray()));
                }
            }

            return(Html.Td(lines.ToArray()));
        }
Exemplo n.º 2
0
        private object[] GenerateDefinition(ConceptMap conceptMap)
        {
            List <object> result = new List <object>();
            List <object> table  = new List <object>();


            table.Add(Html.Tr(new object[]
            {
                Html.Td(Html.B("Source")),
                Html.Td(""),
                Html.Td(Html.B("Target")),
                Html.Td("")
            }
                              ));
            ValueSet sourceValueSet = null;
            ValueSet targetValueSet = null;


            if (conceptMap.Item != null && conceptMap.Item.GetType() == typeof(Reference))
            {
                // Cheating a little here at the mo. Not safe
                Reference source = (Reference)conceptMap.Item;
                Reference target = (Reference)conceptMap.Item1;

                Link sourceValuesetLink = _profileSet.GetValueSetLink(source.reference.GetValueAsString());
                Link targetValuesetLink = _profileSet.GetValueSetLink(target.reference.GetValueAsString());
                sourceValueSet = _profileSet.GetValueSet(source.reference.GetValueAsString());
                targetValueSet = _profileSet.GetValueSet(target.reference.GetValueAsString());

                table.Add(Html.Tr(new object[]
                {
                    Html.Td(Html.P(GetLabelAndValue("Valueset", new object[]
                    {
                        Html.A(sourceValuesetLink.Url, sourceValuesetLink.Display)
                    }))),
                    Html.Td(""),
                    Html.Td(Html.P(GetLabelAndValue("Valueset", new object[]
                    {
                        Html.A(targetValuesetLink.Url, targetValuesetLink.Display)
                    }))),
                    Html.Td("")
                }
                                  ));
            }

            if (conceptMap.element != null && sourceValueSet != null && targetValueSet != null)
            {
                foreach (ConceptMapElement element in conceptMap.element)
                {
                    string sourceCode = element.code.GetValueAsString();     // GetExtensionValueAsString(FhirConstants.ValueSetSystemNameExtensionUrl);
                    string sourceName = "";
                    foreach (ValueSetInclude include in sourceValueSet.compose.include)
                    {
                        foreach (ValueSetConcept1 concept in include.concept)
                        {
                            if (concept.code.value.Equals(sourceCode))
                            {
                                sourceName = concept.display.GetValueAsString();
                            }
                        }
                    }
                    if (element.code.WhenNotNull(t => t.ToString().Length) > 0)
                    {
                        if (element.target != null)
                        {
                            bool isFirstTarget = true;

                            foreach (ConceptMapTarget target in element.target)
                            {
                                if (!isFirstTarget)
                                {
                                    sourceCode = "";
                                }
                                isFirstTarget = true;
                                string targetCode = target.code.GetValueAsString();
                                string targetName = "";
                                foreach (ValueSetInclude include in targetValueSet.compose.include)
                                {
                                    foreach (ValueSetConcept1 concept in include.concept)
                                    {
                                        if (concept.code.value.Equals(targetCode))
                                        {
                                            targetName = concept.display.GetValueAsString();
                                        }
                                    }
                                }
                                // Need to check codeSystem is SNOMED
                                if (float.Parse(targetCode) > 0 && targetCode.Length > 7)
                                {
                                    table.Add(Html.Tr(new object[]
                                    {
                                        Html.Td(sourceCode),
                                        Html.Td(sourceName),
                                        Html.Td(Html.A(SnomedHelper.GetBrowserUrl(targetCode), targetCode)),
                                        Html.Td(targetName)
                                    }
                                                      ));
                                }
                                else
                                {
                                    table.Add(Html.Tr(new object[]
                                    {
                                        Html.Td(sourceCode),
                                        Html.Td(sourceName),
                                        Html.Td(targetCode),
                                        Html.Td(targetName)
                                    }
                                                      ));
                                }
                            }
                        }
                        else
                        {
                            table.Add(Html.Tr(new object[]
                            {
                                Html.Td(sourceCode),
                                Html.Td(""),
                                Html.Td(""),
                                Html.Td("")
                            }
                                              )
                                      );
                        }
                    }
                }
            }
            result.Add(Html.Table(new object[] { table, Html.Class(Styles.ValueSetReferenceTableClassName) }));

            return(result.ToArray());
        }