OpenMRS sample bug

From OpenHatch wiki
Jump to navigation Jump to search

OpenMRS bug walkthrough[edit]

Talk to Chris Hay and Katherine Ye if you have any questions.

The code being used for this bug walkthrough can be found here: https://github.com/hypotext/openmrs-core

We'll be walking you through fixing this bug, testing changes in the webapp, writing tests, and submitting a pull request!

Your First OpenMRS Ticket[edit]

In this workshop, you will work through the full development process involved in contributing to OpenMRS. To contribute to the project, one first needs to pick a sub-project to work on. In the open source community, this means claiming a ticket to work on. A ticket provides an overview of an issue that needs to be fixed or a new feature to be added, and is how work is divided up among contributors. In this workshop, you will pick a ticket to work on and hopefully fix the issue or create the new feature. Below is a list of starter tickets that will allow you to make a real contribution to the project. If you'd like to ease your way into this process, we also have a sample ticket that you can work on. The sample ticket is a real ticket, but is one that has already been completed. This allows you to work through a ticket similar to the starter tickets provided, but with a guide and provided solution there to assist you when needed.


Or, you can choose to work on the sample ticket here: https://issues.openmrs.org/browse/TRUNK-3780 Talk to Chris and Katherine about this. The sections below will cover the process of fixing the prefix bug.

Analyzing a Ticket[edit]

After clicking on one of the links above, you'll come to a page that lists the details for an issue/feature that needs work. Ideally, it'll provide descriptions of the current behavior, the desired behavior, and areas of interest that might help fix the issue. Make sure to read through the comments section to get a feel for the progress that's already been made.


For the sample ticket, please initially only read below the line saying "###DEPRECATED (this was the previous description)". This is what was originally provided when the ticket was created and was all that was given to work off of. Everything above the line was added by Chris and Katherine while they were in the process of fixing the issue, so only read this after analyzing the ticket yourself.

The issues at hand: patient search doesn't do prefix search for 2 character searches but does work for 3+ character searches. So it seems that somewhere it must be manually defined to only do prefix search with 3+ characters. How could this be used to create the desired behavior and fix the bug?

Replicate the Issue[edit]

After familiarizing yourself with the ticket, you then need to replicate the error. This will help provide additional context/error logs about the issue and will also ensure that you will be able to test whatever changes you make. To do this, you'll likely need to start the webapp. Help in doing that can be found here (if using the VM setup, the webapp should already be running).

Sample ticket: Start the server and go to the webapp. Login using admin/Admin123 (try admin/test if that doesn't work). Navigate to the patient search and try searching for the names described in the ticket. Can you reproduce the bug? You may need to make some test data in the webapp.

Looking Through the Code Base[edit]

Once you can replicate the error, try to find and open the files related to the areas of interest (if provided). One way you can do this is by opening up the OpenMRS project's folder in Sublime and clicking on Find->Find in Files. Another is to use the built in search function on the openmrs repo in Github. Then simply search for whatever might seem relevant to the issue.

If you prefer to work from the command line (using emacs, vim, nano, for example), navigate to openmrs-core. Then you can search for code with grep -r "STRING HERE" . (don't forget the quotes and the period at the end -- it tells grep to look in the current directory.

Sample ticket: Search for PatientSearchCriteria, PatientServiceImpl, HibernatePatientDAO, and DWRPatientService. Ctrl-f or grep through these to try to find something that might specify a minimum length string as a search requirement. Afterwards, look for similar variables via the Find in Files method. In our case, for TRUNK-3780, the same change was needed to be done in 2 files (since the java backend and javascript front end are separate).

Testing Your Changes[edit]

After making your changes, test them by trying to replicate the original issue once more. You can do that by following the instructions to get the webapp up and running (making sure to RE-COMPILE and DELETE OLD DATA), then testing searching for users' names. You can also run tests you've added to the code by doing `mvn clean install` in the top-level openmrs-core directory. Check the output to see which tests fail and pass.

If your compilation fails because of failed tests, check to see if those tests are still necessary. If the desired behavior should cause them to fail, comment them out temporarily or make them work for the new code and try to compile again. If you now get the desired behavior, then you're almost done! Now you just need to add more unit tests.

This is important because if you submit a pull request to a project, the maintainer will almost certainly ask you to write tests.

Sample Project: Follow the above and if you get stuck and would like additional help finding the changes that need to be made, take a look at the commit summary for the accepted solution: https://github.com/openmrs/openmrs-core/pull/865/files

Making Unit Tests[edit]

Once you've fixed the bug or added the new feature, you want to make sure that others don't break it. To do this, find existing tests in the code base that relate to your ticket. (We won't tell you exactly where to find them, but if you're stuck, you can refer to the TRUNK-3780 merged pull request.)

Modify existing tests so that they properly test for the new behavior. Then add any additional tests you find necessary to ensure that your changes are kept when future contributors start messing with the code. Once this is done, re-compile and re-test your changes to make sure everything works.

You can run tests by doing `mvn clean install` in the top-level openmrs-core directory. Check the output to see which tests fail and pass.

Submitting the Pull Request[edit]

First, compare your solution to what other students have done. Also take a look at the existing pull requests that might touch the same areas of code, and make sure they don't clash (optional).

Ask Chris or Katherine to help you submit your changes.

Submit your pull request here: https://github.com/hypotext/openmrs-core