OpenMRS resources

Revision as of 18:40, 22 November 2014 by imported>Nquah

What is OpenMRS?

OpenMRS is an open-source electronic medical records platform often used in developing countries. ThoughtWorks contributes to it as part of their Humanitarian Software Program.

It might look like there's an intimidatingly large amount of stuff to do below, but

  • you only have to set things up once!
  • it'll be second nature to you in no time
  • learning this workflow will serve you very well when contributing to other open source projects, or even just working on a team of software engineers.

Here is a screenshot! (please ignore the French)

What to install before the workshop

If your computer has at least 10 GB of hard disk space free and at least 3 GB of RAM, it's recommended to download and install the following:

Install VirtualBox: https://www.virtualbox.org/wiki/Downloads

and Vagrant: http://downloads.vagrantup.com/


This allows you to use a virtual machine at the workshop that already has everything set up. Otherwise, you'll need to perform a manual installation. The manual installation guide can be found here: https://wiki.openmrs.org/display/docs/Getting+Started+as+a+Developer, but will be covered in more depth at the workshop.

Getting OpenMRS up and running on your computer

The short version:

  • Install git and IRC.
  • Manual setup (clone the code from GitHub) OR VM setup (follow VM instructions).
    • VM setup is highly recommended.
  • Review the workflow of getting your code merged
  • Configure your git remotes. (if manual setup)
  • Compile the code.
  • Start the web server.
  • Go through the web app set up process. (if manual setup)
  • You should now have a running local version of OpenMRS on your machine!
  • If you want to get a feel for how one would fix a bug in the code, GOTO "OpenMRS bug walkthrough." If you want to fix an actual bug in the code, GOTO "new beginner tasks."

Here are all the relevant links:

See steps below.

Git setup

See here.

OpenMRS setup

1) Partial Virtual Machine Setup

  • This quick setup allows you to communicate with a virtual machine (VM) that has all OpenMRS related setup requirements already installed. You will be working in your machine and running/testing the code by using the command line to control the VM.
  • Pros: Quickest and easiest to do.
  • Cons: Harder to debug and less stable if you continue working on OpenMRS (if future releases complicate the setup, it'll be much harder to fix yourself)
  • Requirements: 10GB of hard disk space and 3GB RAM. Requires you to install VirtualBox and Vagrant.
  • Once VirtualBox and Vagrant are installed, follow the rest of the setup in the README here: https://github.com/cpschuster/OpenMRS-dev-setup. Issue this command to clone it to your machine:
  git clone -b express-setup https://github.com/cpschuster/OpenMRS-dev-setup   

Then follow the "Happy Path Usage Instructions" in the README at https://github.com/cpschuster/OpenMRS-dev-setup/tree/express-setup

Note: If you've ever used the express setup before, you'll want to do

  vagrant box remove OpenMRS-dev-setup-clone 

before issuing "vagrant up".

2) Full Virtual Machine Setup

  • This setup uses a virtual machine that has the full OpenMRS setup fully configured for you. You will be using the virtual machine to both write code and to run/test it. Features snapshots of the VM that allow you to very quickly skip to various stages of this demo in case you get stuck. Simply install VirtualBox and copy over the VM's file from a provided flash drive. Then simply run the machine in VirtualBox and begin working.
  • Pros: Quick and easy to do. You don't need to install anything on your machine (other than the VM) to work on the project.
  • Cons: In order to not need anything else configured on your machine, you'll be using the setup in the VM, which may have a slight learning curve.
  • Requirements: 10GB hard disk space and 3GB RAM (preferably 4+GB). Requires you to install VirtualBox and to download/copy over the VM.

3) Manual Setup

  • This setup fully configures your machine to be able to contribute to OpenMRS.
  • Pros: Lowest hardware requirements
  • Cons: Slowest and most error prone setup (especially if you run Windows)

It's highly recommended you choose one of the VM based setups. If that's not possible or if you'd simply prefer to do the manual setup, follow the guide here: https://wiki.openmrs.org/display/docs/Getting+Started+as+a+Developer and make sure to talk to Nicole and Danni about this setup.

Workflow

See here.

git: version control system. GitHub: visual interface for git. Lets you view repositories, pull requests (requests from other people to add original code), etc. online.

  • First, clone the "official version" from GitHub (happens only once): https://github.com/openmrs/openmrs-core
  • Set up your remotes so you get new code and push your original code to the right places
  • Pull new changes from upstream (the "official" version of OpenMRS on GitHub, linked above)
  • Make local changes on your machine
  • Push to origin (your "fork" of OpenMRS on your GitHub account). e.g. here is mine
  • When done, make a pull request on upstream, which will be reviewed. Current OpenMRS pull requests
  • Repeat
  • Hopefully get your pull request merged into upstream! Looks like this.

OpenMRS bug walkthrough

Talk to Chris Hay and Katherine Ye.

Check out code from 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

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.

You can choose from a list of starter tickets here:

If you're working on one of these, please edit the wiki and put your name next to it! Also, talk to Danni Yu and Nicole Quah (ThoughtWorks).

  • TRUNK-3895 Filter daemon user from user-related API methods
  • TRUNK-3479 Concept Validator should ignore short names
  • TRUNK-3274 Voided person addresses and names should be ignored by the short patient form validator
  • TRUNK-2660 Validate field lengths of domain objects in management pages
  • TRUNK-4539 Support validation in the UI for the database characters set for a field or column
  • TRUNK-3849 Move Address and Name layout support classes from web layer to api layer
  • TRUNK-2941 Find+Move mediawiki archive pages in confluence
  • TRUNK-3709 Secret answer should be encrypted

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

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 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

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.

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

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. 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

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

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

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.

Ask Chris or Katherine to help you submit your changes.

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

New beginner tasks

Talk to Danni Yu and Nicole Quah (ThoughtWorks).

  • Pair programming is great!
  • Have Vagrant and VirtualBox installed with at least 10 GB of hard disk space.

If you're working on one of these, please edit the wiki and put your name next to it!

  • TRUNK-3895 Filter daemon user from user-related API methods
  • TRUNK-3479 Concept Validator should ignore short names
  • TRUNK-3274 Voided person addresses and names should be ignored by the short patient form validator
  • TRUNK-2660 Validate field lengths of domain objects in management pages
  • TRUNK-4539 Support validation in the UI for the database characters set for a field or column
  • TRUNK-3849 Move Address and Name layout support classes from web layer to api layer
  • TRUNK-2941 Find+Move mediawiki archive pages in confluence
  • TRUNK-3709 Secret answer should be encrypted