if (dateWidget != null) {
exitDate = dateWidget.getValue(context, submission);
if (exitDate != null) {
if (OpenmrsUtil.compare(exitDate, new Date()) > 0) {
ret.add(new FormSubmissionError(context.getFieldName(dateErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.cannotBeInFuture")));
}
}
if (obsList != null && obsList.size() == 0) {
if (exitDate == null) {
if (reasonForExitWidget != null &&
HtmlFormEntryUtil.convertToType(reasonForExitWidget.getValue(context, submission).toString().trim(), Concept.class) != null) {
ret.add(new FormSubmissionError(context.getFieldName(dateErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.required")));
}
}
}
}
if (reasonForExitWidget != null) {
Object value = reasonForExitWidget.getValue(context, submission);
exitReasonAnswerConcept = (Concept) HtmlFormEntryUtil.convertToType(value.toString().trim(), Concept.class);
if (obsList != null && obsList.size() == 0) {
if (exitReasonAnswerConcept == null) {
if (dateWidget != null && dateWidget.getValue(context, submission) != null) {
ret.add(new FormSubmissionError(context.getFieldName(reasonForExitErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.required")));
}
} else if (exitReasonAnswerConcept != null && exitReasonAnswerConcept.getConceptId().equals(patientDiedConcept.getConceptId())) {
if (causeOfDeathWidget == null ||
HtmlFormEntryUtil.convertToType(causeOfDeathWidget.getValue(context, submission).toString().trim(), Concept.class) == null) {
ret.add(new FormSubmissionError(context.getFieldName(causeOfDeathErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.required")));
}
} else if (exitReasonAnswerConcept != null && !exitReasonAnswerConcept.getConceptId().equals(patientDiedConcept.getConceptId())) {
if (causeOfDeathWidget != null &&
HtmlFormEntryUtil.convertToType(causeOfDeathWidget.getValue(context, submission).toString().trim(), Concept.class) != null) {
ret.add(new FormSubmissionError(context.getFieldName(causeOfDeathErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.cannotEnterAValue")));
}
}
}
}
if (causeOfDeathWidget != null) {
Object value = causeOfDeathWidget.getValue(context, submission);
causeOfDeathAnswerConcept = (Concept) HtmlFormEntryUtil.convertToType(value.toString().trim(), Concept.class);
String valueString = otherReasonWidget.getValue(context, submission);
if (obsDeath != null && obsDeath.size() == 0) {
if (causeOfDeathAnswerConcept == null) {
if (otherReasonWidget != null && !valueString.equals("")) {
ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.cannotEnterAValue")));
}
} else if (causeOfDeathAnswerConcept != null && causeOfDeathAnswerConcept.getConceptId().equals(otherNonCodedConcept.getConceptId())) {
if (otherReasonWidget == null || valueString.equals("")) {
ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.required")));
}
} else if (causeOfDeathAnswerConcept != null && !causeOfDeathAnswerConcept.getConceptId().equals(otherNonCodedConcept.getConceptId())) {
if (otherReasonWidget != null && !valueString.equals("")) {
ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.cannotEnterAValue")));
}
}
}
}
// this validation is added to avoid user resetting the 'exit from care'
if (obsList != null && obsList.size() == 1) {
if (exitDate == null) {
ret.add(new FormSubmissionError(context.getFieldName(dateErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.required")));
} else if (exitReasonAnswerConcept == null) {
ret.add(new FormSubmissionError(context.getFieldName(reasonForExitErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.required")));
} else if (exitReasonAnswerConcept != null && exitReasonAnswerConcept.getConceptId().equals(patientDiedConcept.getConceptId())) {
if (causeOfDeathWidget == null ||
HtmlFormEntryUtil.convertToType(causeOfDeathWidget.getValue(context, submission).toString().trim(), Concept.class) == null) {
ret.add(new FormSubmissionError(context.getFieldName(causeOfDeathErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.required")));
}
} else if (exitReasonAnswerConcept != null && !exitReasonAnswerConcept.getConceptId().equals(patientDiedConcept.getConceptId())) {
if (causeOfDeathWidget != null &&
HtmlFormEntryUtil.convertToType(causeOfDeathWidget.getValue(context, submission).toString().trim(), Concept.class) != null) {
ret.add(new FormSubmissionError(context.getFieldName(causeOfDeathErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.cannotEnterAValue")));
}
}
}
// this validation is added to avoid user resetting the 'patient died' incident
String valueString = otherReasonWidget.getValue(context, submission);
if (obsDeath != null && obsDeath.size() == 1) {
if (causeOfDeathAnswerConcept != null && causeOfDeathAnswerConcept.getConceptId().equals(otherNonCodedConcept.getConceptId())) {
if (otherReasonWidget == null || valueString.equals("")) {
ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.required")));
}
} else if (causeOfDeathAnswerConcept != null && !causeOfDeathAnswerConcept.getConceptId().equals(otherNonCodedConcept.getConceptId())) {
if (otherReasonWidget != null && !valueString.equals("")) {
ret.add(new FormSubmissionError(context.getFieldName(otherReasonErrorWidget), Context.getMessageSourceService()
.getMessage("htmlformentry.error.cannotEnterAValue")));
}
}
}