Best way to override pages in openmrs 1.x

Hi all

Someone asked me this question on linkedIn but did not know how to answer. Apparently they are using openmrs 1.9.11 for their implementation and they want to override some pages like the default patient registration form. And in openmrs 1.x the legacyui is still attached to the platform so what he was asking was the files to modify but I didn’t think it was a good idea for them to be messing with the platform code in a production environment for changes like that. I was hoping there is a cleaner way of overriding pages in 1.x via modules without touching the platform code. If so, what are the resources to that one can read to achieve this. I did some initial search and found this But I think that is for openmrs 2.x. What they are using is just platform 1.9.11


This is how the xforms module overrides the default patient registration form in legacyui without touching the platform:

Where patientReg is my controller bean as you can see here:

And the url mapping is configured here:

1 Like

Thanks @dkayiwa

@dkayiwa please help me understand something. What is the difference between using the SimpleUrlHandlerMapping above and simply having an an annotated controller with @RequestMapping("/admin/patients/newPatient.form") and if this done in more than one module, which one takes precedence?


You will get a runtime error of more than one controller with the same mapping. :slight_smile:

Ok thanks.

What about using an annotated controller with @RequestMapping("/admin/patients/newPatient.form") instead of the SimpleUrlHandleMapping. I’ve done some research and all I see is how to use the SimpleUrlHandlerMapping can’t find a resource that explains why I would choose it over and annotated controller.

You would get the same error with the annotated controller.

1 Like

hi @dkayiwa. I would like to so something similar. But for my case I would like to do the override from the find patient on home screen. In fact I want to move the whole patient registration to a new module. Would like to customize the forms to fit our use case and also add some custom javascript to those pages. It would have been easier if we used platform 2.0 because we’d not need to create a new module and just do the customizations inside the legacyui module. But we are still in openmrs 1.x and have not planned for an upgrade yet. The suggestions you gave are a little confusing for a newbie like me.

Btw, I tried that. I created controller that extends SimpleFormController and also implemented a URL handler mapping that was suppose to intercept requests to /openmrs/findPatient but when I test the application and to click on the find patient link, I still see the version of core interface.

If you read the thread again, you will notice that just having a controller will not work. You need to do all that i did in my post.

@jtabot and also just in case you had not seen this:

@dkayiwa thanks. I will go through the whole thread again and make sure I don’t skip a step and get back to you with feedback.

@dkayiwa how can I get some custom javascript into that page?

EDIT: I mean the patient registration form designed from the xforms module.

@dkayiwa how is is resolved to a view? I know that this line will resolve to the patientReg.jsp inside the webapp folder but not sure about how the success view resolves to any jsp file.

Also in the url handler mapping bean, I don’t see any relation between the handler mapping and patientReg controller or is that the only relationship they have is specified here ?

As for JavaScript, did you take a look at this?

@dkayiwa surprisenly I was able to override the patient registration page from within a custom module with just this,

public class CustomShortPatientFormController {

    protected static final String URL_MAPPING = "/admin/patients/shortPatientForm.form";

    private static final String VIEW = "/module/patientregistration/views/patientReg";

    private static final String PATIENT_DASHBOARD_URL = "/patientDashboard.form";

    @RequestMapping(method = RequestMethod.GET)
    public String onGet() {
	    return VIEW;

    @RequestMapping(method = RequestMethod.POST)
    public String onPost() {
	    return VIEW;

No SimpleFormController, no SimpleUrlHandlerMapping, no xml bean declaration. Is this supposed to happen? You said I’d get an error but I can see my custom view fine which means the default platform page was properly overridden. Should I rely on this or is this a bug?

1 Like

It could be that the annotations take preference to the xml mappings.

An annotated controller has higher predence than the xml based one

@dkayiwa @wyclif thanks. This simplifies my work.

There used to be documentation on this, I just can’t find the page, seems like it was removed.