fix code system rendering when only 1 or 2 translations

This commit is contained in:
Grahame Grieve 2023-04-25 21:51:59 +10:00
parent 3ed7813973
commit 7487c978f2
3 changed files with 91 additions and 19 deletions

View File

@ -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 <param name='cs'/> defines the following code<if test='code-count != 1'>s</if>:";
case EXAMPLE: return "This code system <param name='cs'/> provides some example code<if test='code-count != 1'>s</if>:";
case FRAGMENT: return "This code system <param name='cs'/> provides a fragment that includes following code<if test='code-count != 1'>s</if>:";
case NOTPRESENT: return "This code system <param name='cs'/> defines codes, but no codes are represented here";
case SUPPLEMENT: return "This code system <param name='cs'/> defines properties on the following code<if test='code-count != 1'>s</if>:";
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 <param name='cs'/> defines "+features+" on the following code<if test='code-count != 1'>s</if>:";
}
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<String> 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<String> 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<String> 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<TargetElementComponentWrapper> 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");
}

View File

@ -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;

View File

@ -818,5 +818,31 @@ public class CodeSystemUtilities {
}
return null;
}
public static boolean hasProperties(CodeSystem cs) {
return hasProperties(cs.getConcept());
}
private static boolean hasProperties(List<ConceptDefinitionComponent> 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<ConceptDefinitionComponent> list) {
for (ConceptDefinitionComponent c : list) {
if (c.hasDesignation() || hasDesignations(c.getConcept())) {
return true;
}
}
return false;
}
}