private static DvCodedText getResolvedCodedText(DvCodedText dvCT, Guide guide) {
CodePhrase cf = null;
List<TermMapping> mappings = new ArrayList<>();
if (guide.getOntology().getTermBindings() != null) {
for (Map.Entry<String, TermBinding> entry : guide.getOntology().getTermBindings().entrySet()) {
TermBinding termBinding = entry.getValue();
if (termBinding != null) {
Binding binding = termBinding.getBindings().get(dvCT.getDefiningCode().getCodeString());
if (binding != null && binding.getCodes() != null && !binding.getCodes().isEmpty()) {
cf = binding.getCodes().get(0);
for (CodePhrase codePhrase : binding.getCodes()) {
mappings.add(new TermMapping(codePhrase, Match.EQUIVALENT, null, null));
}
}
}
}
}
if (!mappings.isEmpty() && cf != null) {
return new DvCodedText(dvCT.getValue(), mappings, null, null, null, null, cf, null);
} else {
return dvCT;
}
}