diff --git a/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java b/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java index 085ba4e..8d9edda 100644 --- a/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java +++ b/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java @@ -1,8 +1,14 @@ package org.openmrs.module.htmlformentryui.page.controller.htmlform; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.List; + import org.apache.commons.lang.StringUtils; import org.openmrs.Encounter; import org.openmrs.api.AdministrationService; +import org.openmrs.messagesource.MessageSourceService; import org.openmrs.module.emrapi.patient.PatientDomainWrapper; import org.openmrs.module.htmlformentry.HtmlForm; import org.openmrs.module.htmlformentry.HtmlFormEntryService; @@ -11,9 +17,18 @@ import org.openmrs.ui.framework.annotation.InjectBeans; import org.openmrs.ui.framework.annotation.SpringBean; import org.openmrs.ui.framework.page.PageModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestParam; public class ViewEncounterWithHtmlFormPageController { + + private static final Log log = LogFactory.getLog(ViewEncounterWithHtmlFormPageController.class); + + @Autowired + private MessageSourceService messageSourceService; + + private String message; public void get(@RequestParam("encounter") Encounter encounter, @RequestParam(value = "showPatientHeader", defaultValue = "true") boolean showPatientHeader, @@ -24,6 +39,7 @@ public void get(@RequestParam("encounter") Encounter encounter, @SpringBean("htmlFormEntryService") HtmlFormEntryService htmlFormEntryService, @SpringBean("adminService") AdministrationService administrationService, UiUtils ui, + List errors, PageModel model) { patient.setPatient(encounter.getPatient()); @@ -52,8 +68,10 @@ public void get(@RequestParam("encounter") Encounter encounter, model.addAttribute("showPatientHeader", showPatientHeader); HtmlForm htmlForm = htmlFormEntryService.getHtmlFormByForm(encounter.getForm()); + if (htmlForm == null) { - throw new IllegalArgumentException("encounter.form is not an HTML Form: " + encounter.getForm()); + log.warn("encounter.form is not an HTML Form"); + errors.add("encounter.form is not an HTML Form:"+encounter.getForm()); } model.addAttribute("htmlForm", htmlForm); } @@ -65,5 +83,12 @@ public void get(@RequestParam("encounter") Encounter encounter, private String fixCase(String word) { return Character.toUpperCase(word.charAt(0)) + word.substring(1).toLowerCase(); } + + @ExceptionHandler(value= IllegalArgumentException.class) + public String HandleIllegalArgumentException(Exception e) { + log.warn("encounter.form is not an HTML Form"); + return "IllegalArgumentException"; + } + } diff --git a/omod/src/main/webapp/pages/htmlform/IllegalArgumentException.gsp b/omod/src/main/webapp/pages/htmlform/IllegalArgumentException.gsp new file mode 100644 index 0000000..b72438b --- /dev/null +++ b/omod/src/main/webapp/pages/htmlform/IllegalArgumentException.gsp @@ -0,0 +1,12 @@ + + +

Application has encountered an error. Please contact support on ...

+ <% out << "encounter.form is not an HTML Form" %> + + + \ No newline at end of file