Skip to content

Commit

Permalink
Document offline first
Browse files Browse the repository at this point in the history
  • Loading branch information
garethbowen committed Feb 23, 2022
1 parent 840b56d commit 88b2621
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 45 deletions.
4 changes: 2 additions & 2 deletions content/en/apps/_index.md
Expand Up @@ -11,15 +11,15 @@ description: >
This section provides an introduction to CHT Applications, provides some sample CHT Applications, and provides guides and reference materials for those wanting to build a CHT Application or deploy an existing one.
{{% /pageinfo %}}

Community Health Toolkit (CHT) Applications are digital health tools built using the [CHT Core Framework]({{< ref "core" >}}). The Core Framework provides a foundation on which custom CHT Applications are built. Since all CHT Applications share the same foundation, they also share capabilities and attributes. For example, all CHT Applications share a similar user-interface and share the same look-and-feel. All CHT Applications can be built to scale, can run across a variety of devices, support offline-first experiences, and support most languages. These baseline capabilities are foundational across all CHT Applications. Read more about this in [Why the CHT?]({{< ref "why-the-cht" >}}).
Community Health Toolkit (CHT) Applications are digital health tools built using the [CHT Core Framework]({{< ref "core" >}}). The Core Framework provides a foundation on which custom CHT Applications are built. Since all CHT Applications share the same foundation, they also share capabilities and attributes. For example, all CHT Applications share a similar user-interface and share the same look-and-feel. All CHT Applications can be built to scale, can run across a variety of devices, support [Offline-First]({{< ref "core/overview/offline-first" >}}) experiences, and support most languages. These baseline capabilities are foundational across all CHT Applications. Read more about this in [Why the CHT?]({{< ref "why-the-cht" >}}).

To create a digital health tool using the Community Health Toolkit, you'll need to build a CHT Application or re-use an existing CHT Application.

CHT Applications have been built to support a range of health interventions including antenatal care, postnatal care, family planning, integrated community case management of childhood illness, malnutrition, immunization, and epidemic response. CHT Applications have been built to support users at all levels of the community health system including patients, CHWs, CHW supervisors, nurses, health facility staff, program staff, researchers, and policy makers. Beyond the community-level, data from CHT Applications can integrate with the broader health system through integrations with software such as OpenMRS, DHIS2, and RapidPro.

## What skills are required

Building a CHT Application or altering an existing app is a technical undertaking requiring a technical skillset.
Building a CHT Application or altering an existing app is a technical undertaking requiring a technical skillset.

### To Build an App

Expand Down
2 changes: 1 addition & 1 deletion content/en/apps/guides/database/_index.md
Expand Up @@ -55,7 +55,7 @@ This is the standard CouchDB database used to configure user authentication and

## PouchDB

Used to store documents on the client device to allow for offline-first access. Bidirectional replication is done on the "medic" and "medic-user-{username}-meta" databases. The "medic" database is only partially replicated so the user stores only a subset of the entire CouchDB database for performance and security reasons.
Used to store documents on the client device to allow for [Offline-First]({{< ref "core/overview/offline-first" >}}) access. Bidirectional replication is done on the "medic" and "medic-user-{username}-meta" databases. The "medic" database is only partially replicated so the user stores only a subset of the entire CouchDB database for performance and security reasons.

{{< see-also page="apps/guides/performance/replication" >}}

Expand Down
24 changes: 12 additions & 12 deletions content/en/apps/guides/hosting/offline.md
Expand Up @@ -6,15 +6,15 @@ description: >
Deploying and hosting CHT Core server instances without Internet connectivity
---

{{% alert title="Note" %}} This guide is not meant for a production CHT instance. Support may be added in the future an offline CHT server in a production environment. Please see the "Considerations" section below.
{{% alert title="Note" %}} This guide is not meant for a production CHT instance. Support may be added in the future an offline CHT server in a production environment. Please see the "Considerations" section below.

Proceed only if you have staff familiar with DNS, TLS Certs, DHCP, LAN topology and Linux in general. This is a complex deployment where mistakes are easy to make unless proper training is in place. {{% /alert %}}

## Introduction

The CHT is built as an offline first application. This applies to clients, either browsers or Android applications, connecting to the CHT server. The server itself assumes it has Internet connectivity to provide services such as DNS, software updates and general use connectivity. This document explores what it looks like when the CHT server is offline without these services available.
The CHT is built as an [Offline-First]({{< ref "core/overview/offline-first" >}}) application. This applies to clients, either browsers or Android applications, connecting to the CHT server. The server itself assumes it has Internet connectivity to provide services such as DNS, software updates and general use connectivity. This document explores what it looks like when the CHT server is offline without these services available.

Running a CHT server offline requires no modifications to the CHT itself. Instead, supporting services normally found online are replicated locally.
Running a CHT server offline requires no modifications to the CHT itself. Instead, supporting services normally found online are replicated locally.

## Considerations

Expand All @@ -37,20 +37,20 @@ Browsers might allow you to connect to a server with an invalid TLS certificate

It is common to use [Let's Encrypt](https://en.wikipedia.org/wiki/Let%27s_encrypt) to acquire certificates because they provide free certificates. Let's Encrypt certificates expire after 90 days, so the server will need to be constantly updated with a new certificate. Other CAs provide certificates that expire after a year, so this concern will always apply.

After acquiring the certificate, if you are running a Docker-based CHT deployment, see [TLS instructions for Docker]({{< relref "/apps/guides/hosting/ssl-cert-install" >}}) to install the certificate.
After acquiring the certificate, if you are running a Docker-based CHT deployment, see [TLS instructions for Docker]({{< relref "/apps/guides/hosting/ssl-cert-install" >}}) to install the certificate.

### Domain Name Server

In order to match the static IP of the web server to the CN in the certificate, a Domain Name Server (DNS) must be used. This will allow any client on the LAN to easily connect to your CHT server without needing anything more than the domain name.
In order to match the static IP of the web server to the CN in the certificate, a Domain Name Server (DNS) must be used. This will allow any client on the LAN to easily connect to your CHT server without needing anything more than the domain name.

Most LANs will defer to the Internet Service Provider (ISP) to provide DNS, but there is no ISP in an offline scenario. Instead, one must be provided. This DNS server will then be configured to have an `A` record (or `AAAA` in the case of IPv6) to point to the CHT server.

### Dynamic Host Configuration Protocol
### Dynamic Host Configuration Protocol

Any new client that connects to a network will get an IP address from a Dynamic Host Configuration Protocol (DHCP) server. It is critical that the DHCP server for the LAN the CHT is on instructs all clients to use the DNS server configured above.
Any new client that connects to a network will get an IP address from a Dynamic Host Configuration Protocol (DHCP) server. It is critical that the DHCP server for the LAN the CHT is on instructs all clients to use the DNS server configured above.


### Wi-Fi AP
### Wi-Fi AP

A Wi-FI Access Point (AP) needs to be deployed on the LAN so Android devices can connect to the CHT. This can be an AP included with the router or a standalone AP. If the AP is standalone, check that any DHCP or DNS servers that could conflict with the one above are disabled.

Expand All @@ -62,9 +62,9 @@ An offline deployment may consider substituting some requirements above with the

When an offline solution is deployed, traffic stays 100% local, whereas when using either [your own reverse proxy]({{< relref "/secure-sharing-of-developer-instance" >}}) or a third party provider like [ngrok](https://ngrok.com/), traffic may traverse 100s or 1,000s of kilometers to ultimately reach the CHT server which is 10 meters away. This can help when Internet connectivity is very slow, very expensive per megabyte, or both.

### local-ip.co
### local-ip.co

[local-ip.co](http://local-ip.co/) offers both the TLS certificate and private key for `*.my.local-ip.co`. Additionally, the service has a DNS server that dynamically maps any IP you pass in the sub-sub-domain to the real world IP such that `192-168-0-1.my.local-ip.co` would resolve to `192.168.0.1`. This can make it very handy to deploy a development instance where all HTTP traffic remains local (unlike `ngrok` above).
[local-ip.co](http://local-ip.co/) offers both the TLS certificate and private key for `*.my.local-ip.co`. Additionally, the service has a DNS server that dynamically maps any IP you pass in the sub-sub-domain to the real world IP such that `192-168-0-1.my.local-ip.co` would resolve to `192.168.0.1`. This can make it very handy to deploy a development instance where all HTTP traffic remains local (unlike `ngrok` above).

As the DNS traffic still needs to leave your network and return, it is not a viable solution for a truly offline CHT deployment.

Expand All @@ -76,6 +76,6 @@ This may only work on certain, older version of Android as well.

### No DHCP or DNS Server

To avoid installing both the DHCP and DNS servers, an Android app that enables custom DNS entries, like [DNS Changer](https://play.google.com/store/apps/details?id=com.burakgon.dnschanger) or [Daedalus](https://play.google.com/store/apps/details?id=org.itxtech.daedalus) could be used. As [seen here](https://stackoverflow.com/questions/6370017/mapping-a-hostname-to-an-ip-address-on-android), on each Android device you could install this and add custom DNS entries to reach the TLS certificate on the CHT.
To avoid installing both the DHCP and DNS servers, an Android app that enables custom DNS entries, like [DNS Changer](https://play.google.com/store/apps/details?id=com.burakgon.dnschanger) or [Daedalus](https://play.google.com/store/apps/details?id=org.itxtech.daedalus) could be used. As [seen here](https://stackoverflow.com/questions/6370017/mapping-a-hostname-to-an-ip-address-on-android), on each Android device you could install this and add custom DNS entries to reach the TLS certificate on the CHT.

Like the self-signed certificate solution, this is hard to scale and would need to be complimented by editing `/etc/hosts` files on desktop browsers.
12 changes: 6 additions & 6 deletions content/en/apps/tutorials/local-setup.md
Expand Up @@ -23,11 +23,11 @@ By the end of the tutorial you should be able to:

## Brief Overview of Key Concepts

*CHT Core Framework* The Core Framework makes it faster to build full-featured, scalable digital health apps by providing a foundation developers can build on. These apps can support most languages, are offline-first, and work on basic phones (via SMS), smartphones, tablets, and computers.
*CHT Core Framework* The Core Framework makes it faster to build full-featured, scalable digital health apps by providing a foundation developers can build on. These apps can support most languages, are [Offline-First]({{< ref "core/overview/offline-first" >}}), and work on basic phones (via SMS), smartphones, tablets, and computers.

*CHT Project Configurer* a.k.a ***cht-conf*** is command-line interface tool to manage and configure CHT apps.

*Docker* is a tool designed to make it easier to create, deploy, and run applications by using containers.
*Docker* is a tool designed to make it easier to create, deploy, and run applications by using containers.

*Containers* allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package.

Expand All @@ -50,7 +50,7 @@ Now that you have the dependent tools and software installed, you are ready to s

### 1. Install the Core Framework

Check out the [cht-core respository](https://github.com/medic/cht-core) to your local machine. This can be done either by using the [Github Desktop app](https://desktop.github.com/) or by running the following command in the directory where you want the CHT code: `git clone https://github.com/medic/cht-core.git`. Checking out the repo will create a `cht-core` directory.
Check out the [cht-core respository](https://github.com/medic/cht-core) to your local machine. This can be done either by using the [Github Desktop app](https://desktop.github.com/) or by running the following command in the directory where you want the CHT code: `git clone https://github.com/medic/cht-core.git`. Checking out the repo will create a `cht-core` directory.

Open your terminal and navigate to the `cht-core` directory, where you should see the `docker-compose.yml` file. Run the command:

Expand Down Expand Up @@ -100,7 +100,7 @@ By default, the CHT will have the [Maternal & Newborn Health Reference Applicati
- Navigate your terminal to the `cht-core/config/default` directory. This is where the reference application is stored.
- Run the following `cht-conf` command to compile and upload default test data to your local instance:

```shell
```shell
cht --url=https://medic:password@localhost --accept-self-signed-certs csv-to-docs upload-docs`.
```

Expand Down Expand Up @@ -147,7 +147,7 @@ Once you have run the above command it should complete with the message: `INFO A

*****

### 5. Optional: Install Valid TLS Certificate
### 5. Optional: Install Valid TLS Certificate

{{< figure src="local-ip.TLS.png" link="local-ip.TLS.png" class="right col-6 col-lg-8" >}}

Expand All @@ -159,7 +159,7 @@ To install a valid certificate, open a terminal in the `cht-core` directory. Ens
./scripts/add-local-ip-certs-to-docker.sh
```
To see what a before and after looks like, note the screenshot to the left which uses `curl` to test the certificate validity.
To see what a before and after looks like, note the screenshot to the left which uses `curl` to test the certificate validity.
The output of `add-local-ip-certs-to-docker.sh` looks like this:
Expand Down
2 changes: 1 addition & 1 deletion content/en/core/_index.md
Expand Up @@ -10,7 +10,7 @@ description: >
This section provides an overview and reference for development of the Core Framework of the Community Health Toolkit (CHT).
{{% /pageinfo %}}

The Core Framework makes it faster to build full-featured, scalable digital health apps by providing a foundation developers can build on. These apps can support most languages, are offline-first, and work on basic phones (via SMS), smartphones, tablets, and computers.
The Core Framework makes it faster to build full-featured, scalable digital health apps by providing a foundation developers can build on. These apps can support most languages, are [Offline-First]({{< ref "core/overview/offline-first" >}}), and work on basic phones (via SMS), smartphones, tablets, and computers.

App developers are able to define health system roles, permissions and reporting hierarchies, and make use of five highly configurable areas of functionality: messaging, task and schedule management, decision support workflows, longitudinal person profiles, and analytics.

Expand Down

0 comments on commit 88b2621

Please sign in to comment.