use of org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method addLangaugesToRow.
public void addLangaugesToRow(ConceptReferenceComponent c, List<String> langs, XhtmlNode tr) {
for (String lang : langs) {
String d = null;
for (Extension ext : c.getExtension()) {
if (ToolingExtensions.EXT_TRANSLATION.equals(ext.getUrl())) {
String l = ToolingExtensions.readStringExtension(ext, "lang");
if (lang.equals(l)) {
d = ToolingExtensions.readStringExtension(ext, "content");
}
}
}
if (d == null) {
for (ConceptReferenceDesignationComponent dd : c.getDesignation()) {
String l = dd.getLanguage();
if (lang.equals(l)) {
d = dd.getValue();
}
}
}
tr.td().addText(d == null ? "" : d);
}
}
use of org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method generateComposition.
private boolean generateComposition(XhtmlNode x, ValueSet vs, boolean header, List<UsedConceptMap> maps) throws FHIRException, IOException {
boolean hasExtensions = false;
List<String> langs = new ArrayList<String>();
// map of url = description, where url is the designation code. Designations that are for languages won't make it into this list
Map<String, String> designations = new HashMap<>();
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
scanDesignations(inc, langs, designations);
}
for (ConceptSetComponent inc : vs.getCompose().getExclude()) {
scanDesignations(inc, langs, designations);
}
boolean doDesignations = langs.size() + designations.size() < MAX_DESIGNATIONS_IN_LINE;
if (header) {
XhtmlNode h = x.h2();
h.addText(vs.present());
addMarkdown(x, vs.getDescription());
if (vs.hasCopyrightElement())
generateCopyright(x, vs);
}
int index = 0;
if (vs.getCompose().getInclude().size() == 1 && vs.getCompose().getExclude().size() == 0) {
hasExtensions = genInclude(x.ul(), vs.getCompose().getInclude().get(0), "Include", langs, doDesignations, maps, designations, index) || hasExtensions;
} else {
XhtmlNode p = x.para();
p.tx("This value set includes codes based on the following rules:");
XhtmlNode ul = x.ul();
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
hasExtensions = genInclude(ul, inc, "Include", langs, doDesignations, maps, designations, index) || hasExtensions;
index++;
}
if (vs.getCompose().hasExclude()) {
p = x.para();
p.tx("This value set excludes codes based on the following rules:");
ul = x.ul();
for (ConceptSetComponent exc : vs.getCompose().getExclude()) {
hasExtensions = genInclude(ul, exc, "Exclude", langs, doDesignations, maps, designations, index) || hasExtensions;
index++;
}
}
}
if (!doDesignations && langs.size() + designations.size() > 0) {
Collections.sort(langs);
if (designations.size() == 0) {
x.para().b().tx("Additional Language Displays");
} else if (langs.size() == 0) {
x.para().b().tx("Additional Designations");
} else {
x.para().b().tx("Additional Designations and Language Displays");
}
XhtmlNode t = x.table("codes");
XhtmlNode tr = t.tr();
tr.td().b().tx("Code");
for (String url : designations.keySet()) {
tr.td().b().addText(designations.get(url));
}
for (String lang : langs) {
tr.td().b().addText(describeLang(lang));
}
for (ConceptSetComponent c : vs.getCompose().getInclude()) {
for (ConceptReferenceComponent cc : c.getConcept()) {
addDesignationRow(cc, t, langs, designations);
}
}
}
return hasExtensions;
}
use of org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent in project org.hl7.fhir.core by hapifhir.
the class DataRenderer method describeLang.
protected String describeLang(String lang) {
// special cases:
if ("fr-CA".equals(lang)) {
// this one was omitted from the value set
return "French (Canadian)";
}
ValueSet v = getContext().getWorker().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)) {
l = cc;
break;
}
}
if (l == null) {
for (ConceptReferenceComponent cc : v.getCompose().getIncludeFirstRep().getConcept()) {
if (cc.getCode().startsWith(lang + "-")) {
l = cc;
break;
}
}
}
}
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;
}
use of org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method describeLang.
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;
}
use of org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceComponent in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method genInclude.
private boolean genInclude(ResourceContext rcontext, XhtmlNode ul, ConceptSetComponent inc, String type, List<String> langs, List<UsedConceptMap> maps) throws FHIRException, IOException {
boolean hasExtensions = false;
XhtmlNode li;
li = ul.li();
CodeSystem e = context.fetchCodeSystem(inc.getSystem());
if (inc.hasSystem()) {
if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
li.addText(type + " all codes defined in ");
addCsRef(inc, li, e);
} else {
if (inc.getConcept().size() > 0) {
li.addText(type + " these codes as defined in ");
addCsRef(inc, li, e);
XhtmlNode t = li.table("none");
boolean hasComments = false;
boolean hasDefinition = false;
for (ConceptReferenceComponent c : inc.getConcept()) {
hasComments = hasComments || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT);
hasDefinition = hasDefinition || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION);
}
if (hasComments || hasDefinition)
hasExtensions = true;
addMapHeaders(addTableHeaderRowStandard(t, false, true, hasDefinition, hasComments, false, false, null), maps);
for (ConceptReferenceComponent c : inc.getConcept()) {
XhtmlNode tr = t.tr();
XhtmlNode td = tr.td();
ConceptDefinitionComponent cc = getConceptForCode(e, c.getCode(), inc);
addCodeToTable(false, inc.getSystem(), c.getCode(), c.hasDisplay() ? c.getDisplay() : cc != null ? cc.getDisplay() : "", td);
td = tr.td();
if (!Utilities.noString(c.getDisplay()))
td.addText(c.getDisplay());
else if (cc != null && !Utilities.noString(cc.getDisplay()))
td.addText(cc.getDisplay());
td = tr.td();
if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION))
smartAddText(td, ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_DEFINITION));
else if (cc != null && !Utilities.noString(cc.getDefinition()))
smartAddText(td, cc.getDefinition());
if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT)) {
smartAddText(tr.td(), "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_VS_COMMENT));
}
for (ConceptReferenceDesignationComponent cd : c.getDesignation()) {
if (cd.hasLanguage() && !langs.contains(cd.getLanguage()))
langs.add(cd.getLanguage());
}
}
}
boolean first = true;
for (ConceptSetFilterComponent f : inc.getFilter()) {
if (first) {
li.addText(type + " codes from ");
first = false;
} else
li.tx(" and ");
addCsRef(inc, li, e);
li.tx(" where " + f.getProperty() + " " + describe(f.getOp()) + " ");
if (e != null && codeExistsInValueSet(e, f.getValue())) {
String href = prefix + getCsRef(e);
if (href.contains("#"))
href = href + "-" + Utilities.nmtokenize(f.getValue());
else
href = href + "#" + e.getId() + "-" + Utilities.nmtokenize(f.getValue());
li.ah(href).addText(f.getValue());
} else if ("concept".equals(f.getProperty()) && inc.hasSystem()) {
li.addText(f.getValue());
ValidationResult vr = context.validateCode(terminologyServiceOptions, inc.getSystem(), f.getValue(), null);
if (vr.isOk()) {
li.tx(" (" + vr.getDisplay() + ")");
}
} else
li.addText(f.getValue());
String disp = ToolingExtensions.getDisplayHint(f);
if (disp != null)
li.tx(" (" + disp + ")");
}
}
if (inc.hasValueSet()) {
li.tx(", where the codes are contained in ");
boolean first = true;
for (UriType vs : inc.getValueSet()) {
if (first)
first = false;
else
li.tx(", ");
AddVsRef(rcontext, vs.asStringValue(), li);
}
}
} else {
li.tx("Import all the codes that are contained in ");
boolean first = true;
for (UriType vs : inc.getValueSet()) {
if (first)
first = false;
else
li.tx(", ");
AddVsRef(rcontext, vs.asStringValue(), li);
}
}
return hasExtensions;
}
Aggregations