package ch.elexis.core.findings.ui.views;

import org.eclipse.jface.viewers.LabelProvider;

import ch.elexis.core.findings.IObservation;

public class ObservationLabelProvider extends LabelProvider {
	
	@Override
	public String getText(Object element){
		if (element instanceof IObservation) {
			String text = ((IObservation) element).getText().orElse("");
			// remove observation name from text, is already displayed in column header
			int index = text.indexOf(" ");
			if (index != -1) {
				return text.substring(index);
			} else {
				return text;
			}
		}
		return super.getText(element);
	}
}

@@ -36,16 +36,89 @@
 views;%0A%0A
+import java.util.Optional;%0A%0Aimport org.apache.commons.lang3.StringUtils;%0A
 import o
@@ -190,27 +190,165 @@
 ndings.I
-Observation
+Coding;%0Aimport ch.elexis.core.findings.IObservation;%0Aimport ch.elexis.core.findings.codes.CodingSystem;%0Aimport ch.elexis.core.findings.util.ModelUtil
 ;%0A%0Apubli
@@ -505,22 +505,27 @@
 %0A%09%09%09
-String text = 
+return getLabelText
 ((IO
@@ -548,180 +548,545 @@
 ent)
-.getText().orElse(%22%22);%0A%09%09%09// remove observation name from text, is already displayed in column header%0A%09%09%09int index = text.indexOf(%22 %22)
+;%0A%09%09%7D%0A%09%09return super.getText(element);%0A%09%7D%0A%09%0A%09/**%0A%09 * Get text value of the observation without leading title.%0A%09 * %0A%09 * @param observation%0A%09 * @return%0A%09 */%0A%09private String getLabelText(IObservation observation)%7B%0A%09%09String ret = observation.getText().orElse(%22%22).trim();%0A%09%09%0A%09%09Optional%3CICoding%3E coding = ModelUtil.getCodeBySystem(observation.getCoding(),%0A%09%09%09CodingSystem.ELEXIS_LOCAL_CODESYSTEM);%0A%09%09String title = coding.isPresent() ? coding.get().getDisplay() : %22%22
 ;%0A
-%09
 %09%09if (
-index != -1
+StringUtils.isNotBlank(title) && ret.startsWith(title)
 ) %7B%0A%09%09%09
-%09
 ret
-urn tex
+ = re
 t.su
@@ -1097,85 +1097,152 @@
 ing(
-index);%0A%09%09%09%7D else %7B%0A%09%09%09%09return text;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return super.getText(element)
+title.length(), ret.length()).trim();%0A%09%09%09if (ret.startsWith(%22: %22)) %7B%0A%09%09%09%09ret = ret.substring(%22: %22.length(), ret.length());%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return ret
 ;%0A%09%7D

rework parsing observation value label from text