Thanks to the magic of Docker Compose, you can put this docker-compose.yml file into a folder:
version: "2.1"
services:
openmrs-referenceapplication-mysql:
restart: "always"
image: mysql:5.6
command: "mysqld --character-set-server=utf8 --collation-server=utf8_general_ci"
environment:
MYSQL_DATABASE: ${MYSQL_DB:-openmrs}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-Admin123}
MYSQL_USER: ${MYSQL_USER:-openmrs}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-Admin123}
healthcheck:
test: "exit 0"
volumes:
# - ./dbdump:/docker-entrypoint-initdb.d #uncomment this if you need to use a backup sql to initialize the databse
- openmrs-referenceapplication-mysql-data:/var/lib/mysql
openmrs-referenceapplication:
restart: "always"
image: openmrs/openmrs-reference-application-distro:demo
# image: openmrs/openmrs-reference-application-distro:demo
depends_on:
- openmrs-referenceapplication-mysql
ports:
- "127.0.0.1:8080:8080" #when using without nginx use 8080:8080 instead
environment:
DB_DATABASE: ${MYSQL_DB:-openmrs}
DB_HOST: openmrs-referenceapplication-mysql
DB_USERNAME: ${MYSQL_USER:-openmrs}
DB_PASSWORD: ${MYSQL_PASSWORD:-Admin123}
DB_CREATE_TABLES: "true"
DB_AUTO_UPDATE: "true"
MODULE_WEB_ADMIN: "true"
_JAVA_OPTIONS: -Xmx1g -Xms1g # change this depending on the server config
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/openmrs/"]
timeout: 20s
volumes:
- openmrs-referenceapplication-data:/usr/local/tomcat/.OpenMRS/
- /usr/local/tomcat/.OpenMRS/modules/ # do not store modules in data
- /usr/local/tomcat/.OpenMRS/owa/ # do not store owa in data
volumes:
openmrs-referenceapplication-mysql-data:
openmrs-referenceapplication-data:
and you can have a demo OpenMRS running at http://localhost:8080 with a single comand:
$ docker-compose up -d
The first time you bring up OpenMRS, it can take while for the database to be initialized. In my case, it takes at least 4-5 minutes each time it’s started.
To improve startup time from a given state, I created a couple bash scripts, one to backup named values and another to restore them:
backup-volumes.sh#!/bin/bash
docker-compose pause
dirname=${PWD##*/}
for nv in `docker volume ls -q`
do
if [[ $nv = ${dirname}* ]]; then
f=${nv//${dirname}_/}
echo -n "Backing up $f ..."
docker run -it --rm \
-v $nv:/data -v $PWD:/backup alpine \
tar -cjf /backup/$f.tar.bz2 -C /data ./
echo "done"
fi
done
docker-compose unpause
restore-volumes.sh#!/bin/bash
dirname=${PWD##*/}
for f in `ls *.tar.bz2`
do
nv="${dirname}_${f%.tar.bz2}"
echo -n "Restoring $nv ..."
docker run -it --rm \
-v $nv:/data -v $PWD:/backup alpine \
sh -c "rm -rf /data/* /data/..?* /data/.[!.]* ; tar -C /data/ -xjf /backup/$f"
echo "done"
done
Using the backup script to take a “snapshot” of OpenMRS, I’m able to restore that state with the restore script and start OpenMRS in about have the time (~2 minutes).
./backup-volumes.shdocker-compose down -v)./restore-volumes.shdocker-compose (not docker deploy), which prepends named volumes with the current directory name..tar.bz. If you are working in a local copy of a git repo, you might want to add *.tar.bz to your .gitignore… and you shouldn’t create any other archives ending in .tar.bz in the project folder if you don’t want the restore script to turn them into named volumes.I got an email this morning from Luis in Düsseldorf about a suggestion to improve OpenMRS. I help Luis with his ticket and bring it to the attention of the OpenMRS Google Code-In team. Teenagers from Cameroon, Uruguay, and New Jersey discuss the ticket with a mentor in Indianapolis. No doubt, one of these bright young students will submit a pull request soon.
It’s a small, wonderful world full of awesome people!
Another typical day in the OpenMRS community… 🙂
At the recent OpenMRS Worldwide Summit #OMRS15, I was helping out with the Saptarshi’s introductory tutorial and realized that the OpenMRS Standalone requires Java 7, meaning that it fails to run on Java 8. Yikes! But my Mac runs Java 8. How do I get Java 7 on my laptop without making a mess of things?
jenv to the rescue! jenv provides an easy way to manage multiple Java versions. Not only can you easily switch between Java versions, but you can configure different folders to run specific versions of Java. So, for example, you can run Java 7 for the OpenMRS Standalone and run Java 8 everywhere else.
Step zero. Install Homebrew. I already had this installed. I used to use Macports to install utilities on my Mac, but it was fairly invasive. Homebrew installs most everything under your user account, so it doesn’t mess with Mac’s view of the world and rarely, if ever, requires the use of sudo.
Step one. Install jenv.
brew install jenv
Step two. Install Java 7.
Grab the latest version of Java 7 SDK from Oracle’s Java 7 archive. For me, this meant navigating to the Java SE Development Kit 7u80 downloads, accepting the license agreement, and then downloading and installing from the dmg package for Mac OS X x64.
Step three. Tell jenv about Java 7.
jenv add /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/
If your version number differs, then your command may differ slightly. You can always navigate into /Library/Java/JavaVirtualMachines/ to find your installed version folders.
Done!
Now you can navigate into your OpenMRS Standalone folder, set the preferred Java version with a command like:
jenv local oracle64-1.7.0.80
and then execute the standalone with:
jenv exec java -jar openmrs-standalone.jar
In the OpenMRS community, we often hear reference to “core devs.” Who are these people? What make them “core devs” anyway?
OpenMRS is used all over the world with more than 115,000 downloads across more than 200 countries. As of February 2015, there are 1263 subscriptions to the OpenMRS Developers Mailing List. The initial release of OpenMRS 1.9 was thanks to substantive contributions from more than 70 devs. GitHub shows 930 forks and over 140 contributors to OpenMRS Core for openmrs-core. As of the OpenMRS Implementers Meeting in Maputo (#MOZ15), we introduced Developer Stages, both to recognize & empower developers based on their level of expertise and community engagement and to adopt a more scalable approach. If you listen to Yehuda Katz’s great discussion Indie OSS, it’s not healthy to make a distinction between “the core team” and community. So, why are we referring to a few developers as “core devs” and labeling the 99.9% as non-core?
As a community, we need to evolve beyond using distinctions like “core” vs. “non-core” developers toward a more scalable approach: Developer Stages. So, if you see me (or anyone in the OpenMRS community who agrees with me), calling someone out in the future for using the term “core devs,” please understand it’s not for a lack of respect & appreciation for the awesome contributions from those who have been attributed as such; rather, it’s out of an appreciation for all the awesome developers around the world in past & future, including the “core devs,” who have contributed and will contribute to saving lives through coding for OpenMRS.
From now on when you feel the urge to say “core devs,” try substituting it with “/dev/5’s” or “available /dev/4’s & /dev/5’s.” As a community, we will be working to make this attribution easier to see and understand, so, in the future, when someone refers to the “available /dev/5’s”, they’ll be referring to far more than a three people. 🙂
During the OpenMRS Leadership Camp 2014, we talked about ways to empower and scale the OpenMRS Developer Community. While our approach to collaborative development has gotten us far, we don’t have a clear process for developers to grow in responsibilities. The fact that OpenMRS has approximately the same number of developers doing code review or pushing to core as it had five years ago is a significant failure on our part. We’ve been talking about ways to be more inclusive for a while, but haven’t put these desires into something actionable… until now.
With the help from several folks in the community, I was able to come up with a draft process for recognizing the stages of a developer within the OpenMRS community:
| Stage | Description |
|---|---|
| /dev/null
“Community”
|
Criteria
Expectations
Privileges
|
| /dev/1
“Learning”
|
Criteria
Expectations
Privileges
|
| /dev/2
“Contributing”
|
Criteria
Expectations
Privileges
|
| /dev/3
“Cooperating”
|
Criteria
Expectations
Privileges
|
| /dev/4
“Collaborating”
|
Criteria
Expectations
Privileges
|
| /dev/5
“Leading”
|
Criteria
Expectations
Privileges
|
The goals of defining a process like this are:
Our goal would be to fully automate the transition from /dev/null to /dev/1 – i.e., anyone in the community should be able to transition to /dev/1 without requiring manual review from anyone else in the community. Realistically, transitioning through later stages of development would require some manual review, but our hope would be to keep things as objective as possible, so any developer would know what she needed to do in order to advance to the next stage of development.
Next steps:
While I could spend more time revising this blog post, it’s primary purpose is to share the work in progress, so I’m going to stop editing and let it go warts ‘n’ all. 🙂
You can see the actual OpenMRS Developer Stages wiki page here.
I recently sent an email to the OpenMRS Implements Mailing List describing the evolution of OpenMRS between 2012 and 2015. While writing the email, I thought it might be easier to describe in an image:

Our goal is to get to a UI-less platform (providing API & web services) used by an OpenMRS with a new and agile UI framework that meets or exceeds the needs of existing implementations. Currently, we have several implementations working in the 2.x UI, but the majority of implementations are still using the the 1.x UI. To achieve our goal, we will not only need to reach OpenMRS 2.3 with comparable or greater functionality than OpenMRS 1.9, but also find a way to ease the burden for implementations to migrate from 1.x to 2.x (e.g., migration tools, converting key modules to run in 2.x, possibly find a way to run most 1.x modules within the 2.x framework, etc.).
There are many ways to capture feedback from users & testers, from feedback buttons built into the app to issue trackers and tools like JIRA Capture. Another method we have been using, especially for upcoming releases or new features or widgets, within the OpenMRS community is a side-by-side feedback page.
The application is on the left and an etherpad on the right. While I am not suggesting this as an approach for issue tracking, but we have found it to be a quick & easy way of collecting community feedback. The combination of a link taking them directly to the product to be tested along with the near-zero activation energy required by etherpad makes it a handy combination. It’s also nice to be able to throw a brief intro into the etherpad to direct people on what to test and how to report feedback. And lastly, there’s a nice side effect of people seeing each other’s activity in real time. When combined with a developer responding to feedback and re-deploying fixes in real time, it can be incredibly powerful.
Anyway, the main reason I decided to blog on this is because I tweaked our side-by-side tool a bit and wanted to throw my one-page feedback HTML in here for the next time I need it. Here it is:
Feedback
Ever since the beginnings of OpenMRS, we’ve used the data model as a reference and as a teaching tool. As the number of tables has grown, it has become harder to keep the data model diagram updated. I also wanted an easy way to search for tables, columns, or foreign keys. So, I created dbtohtml to generate an easily browsable, standalone, singe-page HTML view of the data model.
I recently described the @should taglet created by OpenMRS that helped the community adopt and sustain better testing practices. Mário asked a good question about test-driven development (TDD):
While I don’t think we’re doing much TDD in the OpenMRS Community at this point, it would be great to evolve this direction. The real question is: will the @should tags that helped us start testing our code become an impediment to TDD? I don’t think so.
Let’s try a simple example to see how we could be TDD-ish with @should tags. Imagine that we want to be able to get the age in years of a person:
class Person {
Integer getAge(Date onDate) {
return 0; // TODO: return age
}
}
Before we write any code, we describe the expected behavior. To keep the example brief, I’ll just describe a couple expected behaviors:
class Person {
/**
* Returns person's age in years.
* @should return null for date before birthdate
* @should not round up age
*/
Integer getAge(Date onDate) {
return 0; // TODO: return age
}
}
Next, we invoke the Behavior Test Generator plugin to automatically do the busy work of generating the skeleton for our unit tests.
class PersonTest {
void getAge_shouldReturnNullForDateBeforeBirthdate() {
// TODO: write unit test
}
void getAge_shouldNotRoundUpAge() {
// TODO: write unit test
}
}
So, now we can write our unit tests and see them fail, like any newborn tests in TDD would do. Granted, in this example, you don’t technically start with the test code, but you can start with describing behavior (using @should tags) prior to writing code and using those tests to drive development. So, yes, we start with @should tags; however, @should tags, can precede any actual code, since they are effectively shorthand for the tests we are writing before coding.
In 2008, when OpenMRS was struggling to adopt better test-driven development practices, I was lucky enough to read Dan North’s Introducing BDD. As Dan says:
How true! For example, it’s common to see something like this when you start creating unit tests:
public class PatientTest {
public void testPatient() {
// test stuff here
}
}
The next question is, what gets tested in a method called “testPatient”? I suppose the only wrong answer is “nothing.” But the problem is there are an infinite number of right answers… because “testPatient” doesn’t say anything about the behavior. As Dan points out, simply replacing the word “test” with the word “should” is a game changer. Let’s try again, except this time we will use “should” in our method name:
public class PatientTest {
public void addIdentifier_shouldNotAddIdentifierThatIsInListAlready() {
// make sure an identifier isn't duplicated
}
}
It’s much easier to guess what will be tested inside that unit test’s method. That’s good… but it gets better. Dan’s suggestion of “should” not only places the focus on behavior, it also automagically forces testing to be scoped to a specific behavior, since any developer who sees a method name wrapping onto its third line instantly knows she is going about testing the wrong way and will look for help. Dan gives a great justification for this approach… but he had me at should.
Given Dan’s insight into using “should” instead of “test” to drive BDD, the trick was figuring out how we could engrain this approach within the OpenMRS community. After some discussion, we came up with an idea that I’m still proud of today and I believe has helped us adopt a better testing culture. Here’s what we did…
Testing is often filled with cookie-cutter code and requires additional effort that is difficult to sustain. We wanted to find a way to overcome both of these challenges. What we needed was a trivially easy way to generate behavior-focused tests. So, we invented the @should Javadoc tag to allow developers to describe expected behaviors within the Javadoc and then we paid someone to develop an IDE plugin to auto-generate the test methods from existing method names.
Now that we have the @should tag, let’s take on more stab at testing. Imagine you are writing some code for the Patient object…
public class Patient {
public void addIdentifier(PatientIdentifier patientIdentifier) {
// ...
}
}
You know that an identifier shouldn’t be added twice for the same patient, so you simply state that behavior in the Javadoc:
public class Patient {
/**
* @should not add identifier that is in list already
*/
public void addIdentifier(PatientIdentifier patientIdentifier) {
// ...
}
}
That’s it. You’re already doing BDD! Now, you tell your IDE to generate any missing unit tests for Patient and it automatically generates this method stub for you in the appropriate location:
public class PatientTest {
public void addIdentifier_shouldNotAddIdentifierThatIsInListAlready) {
// write your test here
}
}
The IDE plugin automatically derives the proper location and method name from your @should tag and the associated method. Now you can focus on testing that specific behavior without having to worry about any cookie-cutter code and adopting BDD is as simple as writing a Javadoc comment.
Low threshold to start testing behavior: just write a brief sentence starting with @should in your Javadoc.We still have a long way to go down the road to full BDD, but I was very happy with our first step. Over the years, the @should tag has become a handy tool for establishing a behavior-driven culture of testing; in fact, it has helped us adopt testing in general. For any Java-shop that is wondering “How do we get our developers to start testing their code?”, I would strongly encourage you to read Dan North’s writings and consider adopting the @should Javadoc tag.