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..b24a530 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,12 @@ package org.openmrs.module.htmlformentryui.page.controller.htmlform; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + 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 +15,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, @@ -52,8 +65,16 @@ public void get(@RequestParam("encounter") Encounter encounter, model.addAttribute("showPatientHeader", showPatientHeader); HtmlForm htmlForm = htmlFormEntryService.getHtmlFormByForm(encounter.getForm()); +// HttpSession session = request.getSession(); if (htmlForm == null) { - throw new IllegalArgumentException("encounter.form is not an HTML Form: " + encounter.getForm()); +// HttpSession session = request.getSession(); + message = messageSourceService.getMessage("encounter.form is not an HTML Form" +encounter.getForm()); + log.warn("Active drugs are not supported yet"); +// session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, message); +// throw new IllegalArgumentException("encounter.form is not an HTML Form: " + encounter.getForm()); + model.addAttribute("htmlForm", htmlForm); + + } model.addAttribute("htmlForm", htmlForm); } @@ -65,5 +86,11 @@ public void get(@RequestParam("encounter") Encounter encounter, private String fixCase(String word) { return Character.toUpperCase(word.charAt(0)) + word.substring(1).toLowerCase(); } + + @ExceptionHandler(value= NullPointerException.class) + public String HandleNullPointerException(Exception e) { + log.warn(message); + return "NullPointerException"; + } } diff --git a/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp b/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp new file mode 100644 index 0000000..e69de29