get mutli-languages displaying for code systems

This commit is contained in:
Grahame Grieve 2020-04-23 20:57:39 +10:00
parent 4316c81f7e
commit 01e0afd72a
3 changed files with 73 additions and 62 deletions

View File

@ -2,6 +2,7 @@ package org.hl7.fhir.r5.terminologies;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -161,23 +162,23 @@ public class CodeSystemRenderer extends TerminologyRenderer {
CodeSystemNavigator csNav = new CodeSystemNavigator(cs);
hierarchy = hierarchy || csNav.isRestructure();
Set<String> langs = new HashSet<>();
List<String> langs = new ArrayList<>();
addMapHeaders(addTableHeaderRowStandard(t, hierarchy, display, true, commentS, version, deprecated, properties), maps);
for (ConceptDefinitionComponent c : csNav.getConcepts(null)) {
hasExtensions = addDefineRowToTable(t, c, 0, hierarchy, display, commentS, version, deprecated, maps, cs.getUrl(), cs, properties, csNav, langs) || hasExtensions;
}
// if (langs.size() > 0) {
// Collections.sort(langs);
// x.para().b().tx("Additional Language Displays");
// t = x.table( "codes");
// XhtmlNode tr = t.tr();
// tr.td().b().tx("Code");
// for (String lang : langs)
// tr.td().b().addText(describeLang(lang));
// for (ConceptDefinitionComponent c : cs.getConcept()) {
// addLanguageRow(c, t, langs);
// }
// }
if (langs.size() > 0) {
Collections.sort(langs);
x.para().b().tx("Additional Language Displays");
t = x.table( "codes");
XhtmlNode tr = t.tr();
tr.td().b().tx("Code");
for (String lang : langs)
tr.td().b().addText(describeLang(lang));
for (ConceptDefinitionComponent c : cs.getConcept()) {
addLanguageRow(c, t, langs);
}
}
return hasExtensions;
}
@ -267,7 +268,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
private boolean addDefineRowToTable(XhtmlNode t, ConceptDefinitionComponent c, int level, boolean hasHierarchy, boolean hasDisplay, boolean comment, boolean version, boolean deprecated, List<UsedConceptMap> maps, String system, CodeSystem cs, List<PropertyComponent> properties, CodeSystemNavigator csNav, Set<String> langs) throws FHIRFormatError, DefinitionException, IOException {
private boolean addDefineRowToTable(XhtmlNode t, ConceptDefinitionComponent c, int level, boolean hasHierarchy, boolean hasDisplay, boolean comment, boolean version, boolean deprecated, List<UsedConceptMap> maps, String system, CodeSystem cs, List<PropertyComponent> properties, CodeSystemNavigator csNav, List<String> langs) throws FHIRFormatError, DefinitionException, IOException {
boolean hasExtensions = false;
XhtmlNode tr = t.tr();
XhtmlNode td = tr.td();
@ -283,6 +284,13 @@ 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())) {
langs.add(cd.getLanguage());
}
}
if (hasDisplay) {
td = tr.td();
renderDisplayName(c, cs, td);
@ -485,5 +493,19 @@ public class CodeSystemRenderer extends TerminologyRenderer {
}
private void addLanguageRow(ConceptDefinitionComponent c, XhtmlNode t, List<String> langs) {
XhtmlNode tr = t.tr();
tr.td().addText(c.getCode());
for (String lang : langs) {
ConceptDefinitionDesignationComponent d = null;
for (ConceptDefinitionDesignationComponent designation : c.getDesignation()) {
if (designation.hasLanguage()) {
if (lang.equals(designation.getLanguage()))
d = designation;
}
}
tr.td().addText(d == null ? "" : d.getValue());
}
}
}

View File

@ -24,6 +24,8 @@ import org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent;
import org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent;
import org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent;
import org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem;
import org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent;
import org.hl7.fhir.r5.model.ValueSet.ConceptReferenceDesignationComponent;
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent;
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent;
@ -457,4 +459,37 @@ public class TerminologyRenderer {
protected String describeLang(String lang) {
ValueSet v = context.fetchResource(ValueSet.class, "http://hl7.org/fhir/ValueSet/languages");
if (v != null) {
ConceptReferenceComponent l = null;
for (ConceptReferenceComponent cc : v.getCompose().getIncludeFirstRep().getConcept()) {
if (cc.getCode().equals(lang))
l = cc;
}
if (l == null) {
if (lang.contains("-"))
lang = lang.substring(0, lang.indexOf("-"));
for (ConceptReferenceComponent cc : v.getCompose().getIncludeFirstRep().getConcept()) {
if (cc.getCode().equals(lang) || cc.getCode().startsWith(lang+"-"))
l = cc;
}
}
if (l != null) {
if (lang.contains("-"))
lang = lang.substring(0, lang.indexOf("-"));
String en = l.getDisplay();
String nativelang = null;
for (ConceptReferenceDesignationComponent cd : l.getDesignation()) {
if (cd.getLanguage().equals(lang))
nativelang = cd.getValue();
}
if (nativelang == null)
return en+" ("+lang+")";
else
return nativelang+" ("+en+", "+lang+")";
}
}
return lang;
}
}

View File

@ -295,21 +295,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
}
private void addLanguageRow(ConceptDefinitionComponent c, XhtmlNode t, List<String> langs) {
XhtmlNode tr = t.tr();
tr.td().addText(c.getCode());
for (String lang : langs) {
ConceptDefinitionDesignationComponent d = null;
for (ConceptDefinitionDesignationComponent designation : c.getDesignation()) {
if (designation.hasLanguage()) {
if (lang.equals(designation.getLanguage()))
d = designation;
}
}
tr.td().addText(d == null ? "" : d.getValue());
}
}
private ConceptMapRenderInstructions findByTarget(DataType source) {
if (source == null) {
@ -656,39 +642,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
}
}
private String describeLang(String lang) {
ValueSet v = context.fetchResource(ValueSet.class, "http://hl7.org/fhir/ValueSet/languages");
if (v != null) {
ConceptReferenceComponent l = null;
for (ConceptReferenceComponent cc : v.getCompose().getIncludeFirstRep().getConcept()) {
if (cc.getCode().equals(lang))
l = cc;
}
if (l == null) {
if (lang.contains("-"))
lang = lang.substring(0, lang.indexOf("-"));
for (ConceptReferenceComponent cc : v.getCompose().getIncludeFirstRep().getConcept()) {
if (cc.getCode().equals(lang) || cc.getCode().startsWith(lang+"-"))
l = cc;
}
}
if (l != null) {
if (lang.contains("-"))
lang = lang.substring(0, lang.indexOf("-"));
String en = l.getDisplay();
String nativelang = null;
for (ConceptReferenceDesignationComponent cd : l.getDesignation()) {
if (cd.getLanguage().equals(lang))
nativelang = cd.getValue();
}
if (nativelang == null)
return en+" ("+lang+")";
else
return nativelang+" ("+en+", "+lang+")";
}
}
return lang;
}