use of com.nedap.archie.aom.terminology.TerminologyCodeWithArchetypeTerm in project archetype-languageserver by nedap.
the class ArchetypeHoverInfo method getTerms.
private List<TerminologyCodeWithArchetypeTerm> getTerms(CTerminologyCode cTermCode, DocumentSymbol terminologyCode, Archetype archetypeForTerms) {
List<TerminologyCodeWithArchetypeTerm> result = new ArrayList();
ArchetypeTerminology terminology = archetypeForTerms.getTerminology(cTermCode);
String language = ArchieLanguageConfiguration.getMeaningAndDescriptionLanguage();
String defaultLanguage = ArchieLanguageConfiguration.getDefaultMeaningAndDescriptionLanguage();
String constraint = terminologyCode.getName();
if (constraint.startsWith("at")) {
ArchetypeTerm termDefinition = terminology.getTermDefinition(language, constraint);
if (termDefinition == null) {
termDefinition = terminology.getTermDefinition(defaultLanguage, constraint);
}
if (termDefinition != null) {
result.add(new TerminologyCodeWithArchetypeTerm(constraint, termDefinition));
}
} else if (constraint.startsWith("ac")) {
ValueSet acValueSet = terminology.getValueSets().get(constraint);
if (acValueSet != null) {
for (String atCode : acValueSet.getMembers()) {
ArchetypeTerm termDefinition = terminology.getTermDefinition(language, atCode);
if (termDefinition == null) {
termDefinition = terminology.getTermDefinition(defaultLanguage, atCode);
}
if (termDefinition != null) {
result.add(new TerminologyCodeWithArchetypeTerm(atCode, termDefinition));
}
}
}
}
return result;
}
use of com.nedap.archie.aom.terminology.TerminologyCodeWithArchetypeTerm in project archetype-languageserver by nedap.
the class ArchetypeHoverInfo method extractHoverInfo.
private void extractHoverInfo(DocumentInformation documentInformation, CTerminologyCode object, Archetype archetypeForTerms) {
// get the closest to an actual location
DocumentSymbol documentSymbol = documentInformation.lookupCObjectOrAttribute(object.path(), true);
// the document symbol tree does not contain terminology codes. So use the separate index
// perhaps better to add two versions of the tree, one for internal and one for external use?
// anyway, this works and is fast.
DocumentSymbol terminologyCodeSymbol = documentInformation.getcTerminologyCodes().getFirstMatchAfter(documentSymbol.getSelectionRange().getStart(), d -> object.getConstraint().contains(d.getName()));
if (terminologyCodeSymbol == null) {
System.err.println("COULD NOT FIND DOCUMENT SYMBOL FOR CTERMINOLOGY CODE");
return;
}
List<TerminologyCodeWithArchetypeTerm> terms = getTerms(object, terminologyCodeSymbol, archetypeForTerms);
if (terms != null) {
StringBuilder content = new StringBuilder();
if (object.getConstraint() != null && object.getConstraint().size() == 1 && AOMUtils.isValueSetCode(object.getConstraint().get(0))) {
ArchetypeTerm valueSetTerm = archetypeForTerms.getTerm(object, object.getConstraint().get(0), language);
if (valueSetTerm != null) {
content.append("## ");
content.append(valueSetTerm.getText());
content.append("\n");
content.append(valueSetTerm.getDescription());
content.append("\n\n### Members:");
}
}
for (TerminologyCodeWithArchetypeTerm term : terms) {
content.append("\n\n");
content.append(term.getCode());
content.append(": ");
if (term.getTerm() != null) {
content.append("__");
content.append(term.getTerm().getText());
content.append("__");
content.append("\n\t");
content.append(term.getTerm().getDescription());
}
}
Hover hover = new Hover();
hover.setContents(new MarkupContent(MARKDOWN, content.toString()));
Range range = terminologyCodeSymbol.getRange();
hoverRanges.addRange(range, hover);
}
}
Aggregations