package dk.silverbullet.telemed.questionnaire.node; import com.google.gson.annotations.Expose; import dk.silverbullet.telemed.questionnaire.Questionnaire; import dk.silverbullet.telemed.questionnaire.R; import dk.silverbullet.telemed.questionnaire.element.*; import dk.silverbullet.telemed.questionnaire.expression.Variable; import dk.silverbullet.telemed.questionnaire.expression.VariableLinkFailedException; import dk.silverbullet.telemed.utils.Util; import java.util.Map; public class UrineDeviceNode extends DeviceNode { @SuppressWarnings("unused") private static final String TAG = Util.getTag(UrineDeviceNode.class); @Expose private Variable<Integer> urine; @Expose String text; public UrineDeviceNode(Questionnaire questionnaire, String nodeName) { super(questionnaire, nodeName); } @Override public void enter() { setView(); super.enter(); } public void setView() { clearElements(); addElement(new TextViewElement(this, text)); if (hasHelp()) { addElement(new HelpTextElement(this, getHelpText(), getHelpImage())); } addElement(new TextViewElement(this, Util.getString(R.string.urine_enter_measurement, questionnaire))); RadioButtonElement<Integer> select = new RadioButtonElement<Integer>(this); { @SuppressWarnings("unchecked") // Arrays and generics don't mix. ValueChoice<Integer>[] choices = new ValueChoice[6]; int c = 0; choices[c++] = new ValueChoice<Integer>(0, Util.getString(R.string.urine_value_negative, questionnaire)); choices[c++] = new ValueChoice<Integer>(1, Util.getString(R.string.urine_value_plus_minus, questionnaire)); choices[c++] = new ValueChoice<Integer>(2, Util.getString(R.string.urine_value_plus_one, questionnaire)); choices[c++] = new ValueChoice<Integer>(3, Util.getString(R.string.urine_value_plus_two, questionnaire)); choices[c++] = new ValueChoice<Integer>(4, Util.getString(R.string.urine_value_plus_three, questionnaire)); choices[c++] = new ValueChoice<Integer>(5, Util.getString(R.string.urine_value_plus_four, questionnaire)); assert c == choices.length; select.setChoices(choices); } select.setOutputVariable(urine); addElement(select); TwoButtonElement be = new TwoButtonElement(this, Util.getString(R.string.default_omit, questionnaire), Util.getString(R.string.default_next, questionnaire)); be.setLeftNextNode(getNextFailNode()); be.setLeftSkipValidation(true); be.setRightNextNode(getNextNode()); addElement(be); } @Override public void linkVariables(Map<String, Variable<?>> variablePool) throws VariableLinkFailedException { super.linkVariables(variablePool); urine = Util.linkVariable(variablePool, urine); } @Override public void deviceLeave() { } public void setUrine(Variable<Integer> urine) { this.urine = urine; } }