These instructions should help you get setup to run or develop on Medic Mobile's Community Health Application Framework. For latest changes and release announcements see our release notes.
If you are interested in building community health applications using this framework a good place to start is the guide for developing community health apps.
Medic Mobile combines messaging, data collection, and analytics for health workers and health systems in hard-to-reach areas with or without internet connectivity.
The medic
repository is the core tool of the Medic Mobile stack. When health workers submit data — using text messages (SMS), our mobile applications, or our SIM applications — the web app confirms data submission, generates unique IDs, and schedules automated reminder messages based on user-defined configurations. All information submitted by mobile users can be viewed, filtered, verified, and exported using the reports tab in the web application.
The web app is fully responsive with a mobile-first design, and supports localization using any written language. It can be installed locally or in the cloud by setting up the individual components or as a Docker container.
Currently, we functionally support the latest versions of Chrome, Chrome for Android and Firefox. We do not support Safari (unreliable implementations of web APIs we need) and the generic android browser (unreliable implementations in general). Our webapp code, which includes any code written as configuration, is still ES5. Our exact support matrix (including older app versions) can be found in our docs.
For more information about Medic Mobile's tools, visit http://medicmobile.org/tools. For more information about Medic Mobile's architecture and how the pieces fit together, see Architecture Overview. For more information about the format of docs in the database, see Database Schema. For more information about the SMS exchange protocol between webapp and gateway, see Message States.
If you want to get up and running with no fuss, you can use Docker.
Once up and running you can create your own custom application, or set up the standard application by running the Medic Configurer on the ./config/standard directory.
If you want to develop against the underlying framework of Medic and set up components individually, follow the Development Setup below.
Before getting started, read about our development workflow and the architecture overview.
With the setup instructions below the tools will run directly on your machine, rather than via Docker.
Developers are actively using both Linux and MacOS, so both of those platforms are well supported for development.
We don't support Windows out of the box. However, you can try using the Windows Subsystem for Linux. See the Windows Subsystem for Linux notes for how the installation instructions differ.
You will need to install the following:
NB: multiple CouchDB nodes will be more complicated, but the general pattern outlined below will be the same.
git clone https://github.com/medic/medic
cd medic
npm ci
By default CouchDB runs in "admin party" mode, which means you do not need users to read or edit any data. This is great for some, but to use Medic safely we're going to disable this feature.
First, add an admin user. When prompted to create an admin during installation, use a strong username and password. Passwords can be changed via Fauxton. For more information see the CouchDB install doc.
Now that's done, we must configure some security settings on CouchDB:
COUCH_URL=http://myAdminUser:myAdminPass@localhost:5984/medic COUCH_NODE_NAME=couchdb@127.0.0.1 grunt secure-couchdb
After following these steps CouchDB should no longer allow unauthorised access:
curl http://myAdminUser:myAdminPass@localhost:5984 # should work
{"couchdb":"Welcome","version":"2.0.0","vendor":{"name":"The Apache Software Foundation"}}
curl http://localhost:5984 # should fail
{"error":"unauthorized","reason":"Authentication required."}
To be able to use Fauxton with authenticated users:
curl -X PUT "http://myAdminUser:myAdminPass@localhost:5984/_node/$COUCH_NODE_NAME/_config/httpd/WWW-Authenticate" \
-d '"Basic realm=\"administrator\""' -H "Content-Type: application/json"
Medic needs the following environment variables to be declared:
COUCH_URL
: the full authenticated url to themedic
DB. Locally this would behttp://myAdminUser:myAdminPass@localhost:5984/medic
COUCH_NODE_NAME
: the name of your CouchDB's node. This is likely to either becouchdb@127.0.0,1
ornoname@nohost
. You can find out by querying CouchDB's membership API- (optionally)
API_PORT
: the port API will run on. If not defined we use5988
- (optionally)
CHROME_BIN
: only required ifgrunt unit
orgrunt e2e
complain that they can't find Chrome.
How to permanently define environment variables depends on your OS and shell (e.g. for bash you can put them ~/.bashrc
). You can temporarily define them with export
:
export COUCH_NODE_NAME=couchdb@127.0.0.1
export COUCH_URL=http://myAdminUser:myAdminPass@localhost:5984/medic
Webapp code is stored in CouchDB. To compile and deploy the current code, use grunt
:
grunt
This will also watch for changes and redeploy as neccessary.
API is needed to access the application.
Either start it directly with node
:
cd ./api
node server.js
Or use grunt
to have it watch for changes and restart as neccessary:
grunt dev-api
Sentinel is reponsible for certain background tasks. It's not strictly required to access the application, but many features won't work without it.
Either start it directly with node
:
cd ./sentinel
node server.js
Or use grunt
to have it watch for changes and restart as neccessary:
grunt dev-sentinel
Navigate your browser to http://localhost:5988/medic/login
.
Follow the steps below to use an Android device with a development build of your application. This process is relevant when running v3.5.0 or greater of the Community Health Application Framework since it relies on service workers, which requires a valid HTTPS certificate. These steps will make your developer build accessible from your Android device by giving it a trusted URL created by ngrok.
- Create a ngrok account at https://ngrok.com/
- Follow instructions on downloading and linking your computer to your ngrok account.
- Start the webapp. This can be via docker, grunt, debug, horti, etc....
- Run ngrok and forward it towards the port you are running the webapp on.
- EX: For running webapp in docker locally using the docker instructions above
$ ./ngrok http 443
. This will forward the traffic from your ngrok url on https to 443 on your local machine. - EX: For running via horti, or grunt where the api starts on port 5988.
$ ./ngrok http 5988
This will forward the traffic from your ngrok url on https to 5988 on your local machine. - Example output from ngrok: Forwarding https://1661304e.ngrok.io -> http://localhost:5988
- EX: For running webapp in docker locally using the docker instructions above
- You can then enter the ngrok generated url(https://1661304e.ngrok.io) into our android app or browser and connect to your local dev environment.
To fill your app with generated data, you can batch-load messages from a CSV file, with the load_messages.js script.
Use curl
to submit a single message:
curl -i -u gateway:123qwe \
--data-urlencode 'message=Test One two' \
--data-urlencode 'from=+13125551212' \
--data-urlencode 'sent_timestamp=1403965605868' \
-X POST \
http://localhost:5988/api/v1/records
All text labels in the app are localized. See the translation documentation for more details on how to add new labels or modify existing ones.
Check out the Gruntfile for all the tests you can run.
They live in the tests
directories of each app. Run them with grunt: grunt unit-continuous
.
They live in tests. Run them with grunt: grunt e2e
.
grunt api-e2e
Travis runs grunt ci
every time some new code is pushed to github.
To build reference documentation into a local folder jsdoc-docs
: grunt build-documentation
This app is highly configurable and can be modified to suit your needs. Read the guide for developing community health applications if you would like to customize your application further.
We include the "standard" configuration in this repo, which can be a useful basis to start with. It is located at ./config/standard.
Configuration is performed using Medic Configurer. medic-conf
expects a particular structure (seen in the standard config above). It compiles forms and configuration into the required formats, as well as uploading that configuration and performing other tasks.
To import the standard configuration:
- Install medic-conf:
npm install -g medic-conf
- Navigate to the configuration you want to import:
cd <medic-repo>/config/standard
- Ensure the app/api is running. Specifically on localhost for these instructions.
- Import the config:
medic-conf --url=http://username:password@localhost:5988
Code is automatically published via Travis CI to the staging server.
At Medic Mobile we are the technical steward of the Community Health Toolkit. We welcome and appreciate contributions, and support new developers to use the tools whenever possible. If you have an idea or a question we'd love to hear from you! The easiest ways to get in touch are by raising issues in the medic Github repo or joining our Slack channel. For more info check out our contributor guidelines.
Builds brought to you courtesy of Travis CI.
Copyright 2013-2018 Medic Mobile, Inc. hello@medicmobile.org
The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.