diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/CodeSystemRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/CodeSystemRenderer.java index a0f681e3e..a146aba27 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/CodeSystemRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/CodeSystemRenderer.java @@ -139,13 +139,26 @@ public class CodeSystemRenderer extends TerminologyRenderer { } } - private String sentenceForContent(CodeSystemContentMode mode) { + private String sentenceForContent(CodeSystemContentMode mode, CodeSystem cs) { switch (mode) { case COMPLETE: return "This code system defines the following codes:"; case EXAMPLE: return "This code system provides some example codes:"; case FRAGMENT: return "This code system provides a fragment that includes following codes:"; case NOTPRESENT: return "This code system defines codes, but no codes are represented here"; - case SUPPLEMENT: return "This code system defines properties on the following codes:"; + case SUPPLEMENT: + boolean properties = CodeSystemUtilities.hasProperties(cs); + boolean designations = CodeSystemUtilities.hasDesignations(cs); + String features; + if (properties && designations) { + features = "displays and properties"; + } else if (properties) { + features = "properties"; + } else if (designations) { + features = "displays"; + } else { + features = "features"; // ? + } + return "This code system defines "+features+" on the following codes:"; } throw new FHIRException("Unknown CodeSystemContentMode mode"); } @@ -157,7 +170,7 @@ public class CodeSystemRenderer extends TerminologyRenderer { XhtmlNode p = x.para(); p.param("cs").code().tx(cs.getUrl()); p.paramValue("code-count", CodeSystemUtilities.countCodes(cs)); - p.sentenceForParams(sentenceForContent(cs.getContent())); + p.sentenceForParams(sentenceForContent(cs.getContent(), cs)); if (cs.getContent() == CodeSystemContentMode.NOTPRESENT) { return false; } @@ -186,6 +199,7 @@ public class CodeSystemRenderer extends TerminologyRenderer { } } } + List langs = new ArrayList<>(); for (ConceptDefinitionComponent c : cs.getConcept()) { commentS = commentS || conceptsHaveComments(c); deprecated = deprecated || conceptsHaveDeprecated(cs, c, ignoreStatus); @@ -193,16 +207,20 @@ public class CodeSystemRenderer extends TerminologyRenderer { version = version || conceptsHaveVersion(c); hierarchy = hierarchy || c.hasConcept(); definitions = definitions || conceptsHaveDefinition(c); + listConceptLanguages(cs, c, langs); } CodeSystemNavigator csNav = new CodeSystemNavigator(cs); hierarchy = hierarchy || csNav.isRestructure(); - List langs = new ArrayList<>(); - addCopyColumn(addMapHeaders(addTableHeaderRowStandard(t, hierarchy, display, definitions, commentS, version, deprecated, properties, null, null, false), maps)); - for (ConceptDefinitionComponent c : csNav.getConcepts(null)) { - hasExtensions = addDefineRowToTable(t, c, 0, hierarchy, display, definitions, commentS, version, deprecated, maps, cs.getUrl(), cs, properties, csNav, langs, isSupplement) || hasExtensions; + if (langs.size() < 2) { + addCopyColumn(addMapHeaders(addTableHeaderRowStandard(t, hierarchy, display, definitions, commentS, version, deprecated, properties, langs, null, true), maps)); + } else { + addCopyColumn(addMapHeaders(addTableHeaderRowStandard(t, hierarchy, display, definitions, commentS, version, deprecated, properties, null, null, false), maps)); } - if (langs.size() > 0) { + for (ConceptDefinitionComponent c : csNav.getConcepts(null)) { + hasExtensions = addDefineRowToTable(t, c, 0, hierarchy, display, definitions, commentS, version, deprecated, maps, cs.getUrl(), cs, properties, csNav, langs.size() < 2 ? langs : null, isSupplement) || hasExtensions; + } + if (langs.size() >= 2) { Collections.sort(langs); x.para().b().tx("Additional Language Displays"); t = x.table("codes"); @@ -217,6 +235,18 @@ public class CodeSystemRenderer extends TerminologyRenderer { return hasExtensions; } + private void listConceptLanguages(CodeSystem cs, ConceptDefinitionComponent c, List langs) { + for (ConceptDefinitionDesignationComponent cd : c.getDesignation()) { + if (cd.hasLanguage() && !langs.contains(cd.getLanguage()) && (!cs.hasLanguage() || !cs.getLanguage().equals(cd.getLanguage()))) { + langs.add(cd.getLanguage()); + } + } + + for (ConceptDefinitionComponent g : c.getConcept()) { + listConceptLanguages(cs, g, langs); + } + } + private void addCopyColumn(XhtmlNode tr) { if (context.isCopyButton()) { tr.td().b().tx("Copy"); @@ -353,13 +383,6 @@ public class CodeSystemRenderer extends TerminologyRenderer { td.an(cs.getId()+"-" + Utilities.nmtokenize(c.getCode())); } - for (ConceptDefinitionDesignationComponent cd : c.getDesignation()) { - if (cd.hasLanguage() && !langs.contains(cd.getLanguage()) && (!cs.hasLanguage() || !cs.getLanguage().equals(cd.getLanguage()))) { - langs.add(cd.getLanguage()); - } - - } - if (hasDisplay) { td = tr.td(); renderDisplayName(c, cs, td); @@ -491,6 +514,11 @@ public class CodeSystemRenderer extends TerminologyRenderer { } } + if (langs != null) { + for (String lang : langs) { + td = tr.td().tx(getDisplay(lang, c)); + } + } for (UsedConceptMap m : maps) { td = tr.td(); List mappings = findMappingsForCode(c.getCode(), m.getMap()); @@ -540,6 +568,20 @@ public class CodeSystemRenderer extends TerminologyRenderer { return hasExtensions; } + private String getDisplay(String lang, ConceptDefinitionComponent c) { + for (ConceptDefinitionDesignationComponent cd : c.getDesignation()) { + if (cd.getUse().is("http://terminology.hl7.org/CodeSystem/designation-usage", "display") && cd.hasLanguage() && cd.getLanguage().equals(lang)) { + return cd.getValue(); + } + } + for (ConceptDefinitionDesignationComponent cd : c.getDesignation()) { + if (cd.hasLanguage() && cd.getLanguage().equals(lang)) { + return cd.getValue(); + } + } + return null; + } + private boolean hasMarkdownInDefinitions(CodeSystem cs) { return ToolingExtensions.readBoolExtension(cs, "http://hl7.org/fhir/StructureDefinition/codesystem-use-markdown"); } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/TerminologyRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/TerminologyRenderer.java index af2d4e5df..fe37c8be3 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/TerminologyRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/TerminologyRenderer.java @@ -240,11 +240,15 @@ public abstract class TerminologyRenderer extends ResourceRenderer { } } if (doDesignations) { - for (String url : designations.keySet()) { - tr.td().b().addText(designations.get(url)); + if (designations != null) { + for (String url : designations.keySet()) { + tr.td().b().addText(designations.get(url)); + } } - for (String lang : langs) { - tr.td().b().addText(describeLang(lang)); + if (langs != null) { + for (String lang : langs) { + tr.td().b().addText(describeLang(lang)); + } } } return tr; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/CodeSystemUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/CodeSystemUtilities.java index 709a5b10c..9bde1540e 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/CodeSystemUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/CodeSystemUtilities.java @@ -818,5 +818,31 @@ public class CodeSystemUtilities { } return null; } + + public static boolean hasProperties(CodeSystem cs) { + return hasProperties(cs.getConcept()); + } + + private static boolean hasProperties(List list) { + for (ConceptDefinitionComponent c : list) { + if (c.hasProperty() || hasProperties(c.getConcept())) { + return true; + } + } + return false; + } + + public static boolean hasDesignations(CodeSystem cs) { + return hasDesignations(cs.getConcept()); + } + + private static boolean hasDesignations(List list) { + for (ConceptDefinitionComponent c : list) { + if (c.hasDesignation() || hasDesignations(c.getConcept())) { + return true; + } + } + return false; + } }