if (causeOfDeathWidget != null) {
if (context.getMode() == FormEntryContext.Mode.VIEW) {
if (obsList != null && obsList.size() == 1) {
Obs obs = obsList.get(0);
if (obs.getValueCoded().getConceptId().equals(patientDiedConcept.getConceptId())) {
sb.append(causeOfDeathWidget.generateHtml(context));
}
} else if (obsList != null && obsList.size() == 0) {
// this state may not be happen often, but in case that there is no exit from case
// observation, but however patient is dead, we are displaying cause of death then
if (obsDeath != null && obsDeath.size() == 1) {
sb.append(causeOfDeathWidget.generateHtml(context));
}
}
} else {
sb.append(causeOfDeathWidget.generateHtml(context));
}
if (context.getMode() != FormEntryContext.Mode.VIEW) {
sb.append(causeOfDeathErrorWidget.generateHtml(context));
}
// only show causeOfDeathWidget if there is an initial value, else hide it
if (context.getMode() == FormEntryContext.Mode.ENTER) {
sb.append("<script>");
sb.append("$j(document).ready(function(){");
sb.append(" if($j(\"#" + causeWidgetId + "\").val() != \"\" && "
+ "$j(\"#" + reasonWidgetId + "\").val() == \"" + patientDiedConId + "\"){\n");
sb.append(" $j(\"#" + causeWidgetId + "\").show();}\n");
sb.append(" if($j(\"#" + causeWidgetId + "\").val() == \"\"){\n");
sb.append(" $j(\"#" + causeWidgetId + "\").hide();}\n");
sb.append("});");
sb.append("</script>");
}
if (context.getMode() == FormEntryContext.Mode.EDIT) {
sb.append("<script>");
sb.append("$j(document).ready(function(){");
sb.append("var cVal = $j(\"#" + causeWidgetId + "\").val();");
sb.append("if (cVal == \"" + otherNonCodedConId + "\")\n"
+ " { $j(\"#" + otherTextWidgetId + "\").show();}\n"
+ "if (cVal != \"" + otherNonCodedConId + "\")\n"
+ " { $j(\"#" + otherTextWidgetId + "\").val(\"\"); $j(\"#" + otherTextWidgetId + "\").hide();}");
sb.append("});");
sb.append("</script>");
}
}
// adding a jquery event handler to causeOfDeathWidget
sb.append("<script>");
sb.append("$j(\"#" + causeWidgetId + "\").change(function(){");
sb.append("var causeVal = $j(\"#" + causeWidgetId + "\").val();");
sb.append("if (causeVal == \"" + otherNonCodedConId + "\")\n"
+ " { $j(\"#" + otherTextWidgetId + "\").show();}\n"
+ "if (causeVal != \"" + otherNonCodedConId + "\")\n"
+ " { $j(\"#" + otherTextWidgetId + "\").val(\"\"); $j(\"#" + otherTextWidgetId + "\").hide();}");
sb.append("});");
sb.append("</script>");
// providing a blank space between the widgets
sb.append(" ");
if (otherReasonWidget != null) {
if (context.getMode() == FormEntryContext.Mode.VIEW) {
if (obsDeath != null && obsDeath.size() == 1) {
Obs obs = obsDeath.get(0);
if (obsList != null && obsList.size() == 0) {
if (obs.getValueCoded().getConceptId().equals(otherNonCodedConcept.getConceptId())) {
sb.append(otherReasonWidget.generateHtml(context));
}
} else if (obsList != null && obsList.size() == 1) {
Obs exitObs = obsList.get(0);
if (exitObs.getValueCoded().getConceptId().equals(patientDiedConcept.getConceptId())
&& obs.getValueCoded().getConceptId().equals(otherNonCodedConcept.getConceptId())) {
sb.append(otherReasonWidget.generateHtml(context));
}
}
}