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) { switch (mode) {
case COMPLETE: return "This code system <param name='cs'/> defines the following code<if test='code-count != 1'>s</if>:"; 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 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 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 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"); throw new FHIRException("Unknown CodeSystemContentMode mode");
} }
@ -157,7 +170,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
XhtmlNode p = x.para(); XhtmlNode p = x.para();
p.param("cs").code().tx(cs.getUrl()); p.param("cs").code().tx(cs.getUrl());
p.paramValue("code-count", CodeSystemUtilities.countCodes(cs)); p.paramValue("code-count", CodeSystemUtilities.countCodes(cs));
p.sentenceForParams(sentenceForContent(cs.getContent())); p.sentenceForParams(sentenceForContent(cs.getContent(), cs));
if (cs.getContent() == CodeSystemContentMode.NOTPRESENT) { if (cs.getContent() == CodeSystemContentMode.NOTPRESENT) {
return false; return false;
} }
@ -186,6 +199,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
} }
} }
} }
List<String> langs = new ArrayList<>();
for (ConceptDefinitionComponent c : cs.getConcept()) { for (ConceptDefinitionComponent c : cs.getConcept()) {
commentS = commentS || conceptsHaveComments(c); commentS = commentS || conceptsHaveComments(c);
deprecated = deprecated || conceptsHaveDeprecated(cs, c, ignoreStatus); deprecated = deprecated || conceptsHaveDeprecated(cs, c, ignoreStatus);
@ -193,16 +207,20 @@ public class CodeSystemRenderer extends TerminologyRenderer {
version = version || conceptsHaveVersion(c); version = version || conceptsHaveVersion(c);
hierarchy = hierarchy || c.hasConcept(); hierarchy = hierarchy || c.hasConcept();
definitions = definitions || conceptsHaveDefinition(c); definitions = definitions || conceptsHaveDefinition(c);
listConceptLanguages(cs, c, langs);
} }
CodeSystemNavigator csNav = new CodeSystemNavigator(cs); CodeSystemNavigator csNav = new CodeSystemNavigator(cs);
hierarchy = hierarchy || csNav.isRestructure(); hierarchy = hierarchy || csNav.isRestructure();
List<String> langs = new ArrayList<>(); 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)); 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() > 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); Collections.sort(langs);
x.para().b().tx("Additional Language Displays"); x.para().b().tx("Additional Language Displays");
t = x.table("codes"); t = x.table("codes");
@ -217,6 +235,18 @@ public class CodeSystemRenderer extends TerminologyRenderer {
return hasExtensions; 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) { private void addCopyColumn(XhtmlNode tr) {
if (context.isCopyButton()) { if (context.isCopyButton()) {
tr.td().b().tx("Copy"); tr.td().b().tx("Copy");
@ -353,13 +383,6 @@ public class CodeSystemRenderer extends TerminologyRenderer {
td.an(cs.getId()+"-" + Utilities.nmtokenize(c.getCode())); 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) { if (hasDisplay) {
td = tr.td(); td = tr.td();
renderDisplayName(c, cs, 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) { for (UsedConceptMap m : maps) {
td = tr.td(); td = tr.td();
List<TargetElementComponentWrapper> mappings = findMappingsForCode(c.getCode(), m.getMap()); List<TargetElementComponentWrapper> mappings = findMappingsForCode(c.getCode(), m.getMap());
@ -540,6 +568,20 @@ public class CodeSystemRenderer extends TerminologyRenderer {
return hasExtensions; 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) { private boolean hasMarkdownInDefinitions(CodeSystem cs) {
return ToolingExtensions.readBoolExtension(cs, "http://hl7.org/fhir/StructureDefinition/codesystem-use-markdown"); return ToolingExtensions.readBoolExtension(cs, "http://hl7.org/fhir/StructureDefinition/codesystem-use-markdown");
} }

View File

@ -240,13 +240,17 @@ public abstract class TerminologyRenderer extends ResourceRenderer {
} }
} }
if (doDesignations) { if (doDesignations) {
if (designations != null) {
for (String url : designations.keySet()) { for (String url : designations.keySet()) {
tr.td().b().addText(designations.get(url)); tr.td().b().addText(designations.get(url));
} }
}
if (langs != null) {
for (String lang : langs) { for (String lang : langs) {
tr.td().b().addText(describeLang(lang)); tr.td().b().addText(describeLang(lang));
} }
} }
}
return tr; return tr;
} }

View File

@ -818,5 +818,31 @@ public class CodeSystemUtilities {
} }
return null; 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;
}
} }