/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ehr_editor.leafNodes;
import ehr_editor.ContainerPanel;
import java.awt.Color;
import java.util.List;
import java.util.Random;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import org.openehr.am.archetype.constraintmodel.CAttribute;
import org.openehr.am.archetype.constraintmodel.CComplexObject;
import org.openehr.am.archetype.constraintmodel.CObject;
import org.openehr.am.archetype.constraintmodel.CPrimitiveObject;
import org.openehr.am.archetype.constraintmodel.CSingleAttribute;
import org.openehr.am.archetype.constraintmodel.primitive.CDuration;
import org.openehr.am.openehrprofile.datatypes.text.CCodePhrase;
import org.openehr.rm.datastructure.history.IntervalEvent;
import terminology.EhrTerminology;
/**
*
* @author marek
*/
public class IntervalEventLeaf extends LeafNode {
private static Random generator = new Random();
CSingleAttribute mathFunctionCAttribute = null;
String mathFunctionTerminology = null;
CSingleAttribute widthCAttribute = null;
CSingleAttribute dataCAttribute = null;
CSingleAttribute stateCAttribute = null;
public IntervalEventLeaf(ContainerPanel parentPanel){
BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
this.setLayout(boxLayout);
Border border = new LineBorder(new Color(0, 0, 0, 0), 10);
this.setBorder(border);
this.setBackground(new Color(Math.abs(generator.nextInt()) % 128 + 128, Math.abs(generator.nextInt()) % 128 + 128, Math.abs(generator.nextInt()) % 128 + 128));
this.setSize(100, 30);
//this.setPreferredSize(new Dimension(100, 30));
//this.setMaximumSize(new Dimension(500, 30));
this.setVisible(true);
CAttribute attribute = parentPanel.getcAttribute();
CObject object = parentPanel.getCobject();
this.add(new JLabel(object.getClass().getSimpleName()));
CComplexObject complexObject = (CComplexObject)object;
List<CAttribute> attributes = complexObject.getAttributes();
for(CAttribute cAttribute : attributes){
if( cAttribute instanceof CSingleAttribute ){
CSingleAttribute cSingleAttribute = (CSingleAttribute)cAttribute;
switch(cSingleAttribute.getRmAttributeName()){
case "math_function":
mathFunctionCAttribute = cSingleAttribute;
break;
case "width":
widthCAttribute = cSingleAttribute;
break;
case "data":
dataCAttribute = cSingleAttribute;
break;
case "state":
stateCAttribute = cSingleAttribute;
break;
default:
throw new RuntimeException("Unknown IntervalEvent attribute");
}
} else {
throw new RuntimeException("IntervalEvent - unexpected CMultipleAttribute");
}
}
this.mathFunctionTerminology = this.parseMathFunctionTerminology();
this.parseWidth();
return;
}
private String parseMathFunctionTerminology(){
String terminology = "";
CCodePhrase cCodePhrase = (CCodePhrase)((CComplexObject)this.mathFunctionCAttribute.getChildren().get(0)).getAttributes().get(0).getChildren().get(0);
String terminologyID = cCodePhrase.getTerminologyId().getValue();
List<String> codes = cCodePhrase.getCodeList();
EhrTerminology ehrTerminology = new EhrTerminology();
for( String code : codes )
terminology += ehrTerminology.getRubricById(code)+", ";
return terminology;
}
private String parseWidth(){
String width = null;
CPrimitiveObject cPrimitiveObject = (CPrimitiveObject)((CComplexObject)this.widthCAttribute.getChildren().get(0)).getAttributes().get(0).getChildren().get(0);
CDuration cDuration = (CDuration)cPrimitiveObject.getItem();
return width;
}
}