Skip to content

Commit

Permalink
chore: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
njogz committed Oct 29, 2024
2 parents 4ff49ac + dfe2107 commit 34ad8e3
Show file tree
Hide file tree
Showing 32 changed files with 1,201 additions and 409 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Test

on: [push, pull_request]
on: [push]

jobs:
unit:
Expand All @@ -20,6 +20,7 @@ jobs:
e2e-tests:
name: E2E Tests
runs-on: ubuntu-latest
if: false

steps:
- name: Login to Docker Hub
Expand Down
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ Conversely, to bring data into the CHT, OpenHIM is configured to route the updat

See more information on the [CHT interoperability](https://docs.communityhealthtoolkit.org/apps/concepts/interoperability/) page on the CHT documentation site.

### Services

Services are currently available at these URLs:

- **OpenHIM Admin Console** - [https://interoperability.dev.medicmobile.org](https://interoperability.dev.medicmobile.org).
- **OpenHIM Mediator** - [https://interoperability.dev.medicmobile.org:5001/mediator](https://interoperability.dev.medicmobile.org:5001/mediator).
- **CHT with LTFU configuration** - [https://interop-cht-test.dev.medicmobile.org/](https://interop-cht-test.dev.medicmobile.org/).

Credentials to the instances can be shared upon request.

[GitHub repository for the kubernetes configuration](https://github.com/medic/interoperability-kubernetes/).

### Workflow Sequence Diagram
Expand Down
6 changes: 0 additions & 6 deletions WORKFLOW.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ The document provided includes placeholders for URLs. Replacing these placeholde
- **OpenHIM Admin Console** - http://localhost:9000/
- **CHT with LTFU configuration** - http://localhost:5988/

### Live Test Instance

- **Mediator (`${MEDIATOR_ENDPOINT}`)** - [https://interoperability.dev.medicmobile.org:5001/mediator](https://interoperability.dev.medicmobile.org:5001/mediator)
- **OpenHIM Admin Console** - [https://interoperability.dev.medicmobile.org](https://interoperability.dev.medicmobile.org)
- **CHT with LTFU configuration** - [https://interop-cht-test.dev.medicmobile.org/](https://interop-cht-test.dev.medicmobile.org/)

## Steps

The following steps assume that you successfully logged in into OpenHIM and the CHT instances.
Expand Down
31 changes: 31 additions & 0 deletions docker/docker-compose.cht-couchdb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '3.9'

services:
couchdb:
image: public.ecr.aws/medic/cht-couchdb:4.1.0-alpha
volumes:
- couchdb-data:/opt/couchdb/data
- cht-credentials:/opt/couchdb/etc/local.d/
environment:
- "COUCHDB_USER=${COUCHDB_USER:-admin}"
- "COUCHDB_PASSWORD=${COUCHDB_PASSWORD:-password}"
- "COUCHDB_SECRET=${COUCHDB_SECRET:-secret}"
- "COUCHDB_UUID=${COUCHDB_UUID:-CC0C3BA1-88EE-4AE3-BFD3-6E0EE56ED534}"
- "SVC_NAME=${SVC_NAME:-couchdb}"
- "COUCHDB_LOG_LEVEL=${COUCHDB_LOG_LEVEL:-error}"
restart: always
logging:
driver: "local"
options:
max-size: "${LOG_MAX_SIZE:-50m}"
max-file: "${LOG_MAX_FILES:-20}"
networks:
cht-net:

volumes:
cht-credentials:
couchdb-data:

networks:
cht-net:
name: ${CHT_NETWORK:-cht-net}
2 changes: 1 addition & 1 deletion mediator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ docker run --network <openhim-network-name> --name mediator -rm -p 5005:5005 med
1. Run `npm dev` to start the mediator with watch mode. All code is in the `src` folder. The `dist` folder is generated by the build process.
1. Navigate to `/mediator` folder. Run `npm install` to install the dependencies.
1. Run `npm run unit-test` to run unit tests.
1. Run `npm run e2e-test` to run e2e tests. (When running subsequent e2e tests locally, be aware to delete `/cht-interoperability/docker/srv` directory created by the CHT.)
1. Run `npm run e2e-test` to run e2e tests.
16 changes: 10 additions & 6 deletions mediator/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as dotenv from 'dotenv';
dotenv.config();

export const PORT = process.env.PORT || 6000;
const REQUEST_TIMEOUT = Number(getEnvironmentVariable('REQUEST_TIMEOUT', '5000'));

export const OPENHIM = {
username: getEnvironmentVariable('OPENHIM_USERNAME', '[email protected]'),
Expand All @@ -11,27 +12,30 @@ export const OPENHIM = {
};

export const FHIR = {
url: getEnvironmentVariable('FHIR_URL', 'http://openhim-core:5001/fhir'),
url: getEnvironmentVariable('FHIR_URL', 'https://openhim-core:5001/fhir'),
username: getEnvironmentVariable('FHIR_USERNAME', 'interop-client'),
password: getEnvironmentVariable('FHIR_PASSWORD', 'interop-password'),
timeout: Number(getEnvironmentVariable('REQUEST_TIMEOUT', '5000'))
timeout: REQUEST_TIMEOUT
};

export const CHT = {
url: getEnvironmentVariable('CHT_URL', 'https://nginx'),
username: getEnvironmentVariable('CHT_USERNAME', 'admin'),
password: getEnvironmentVariable('CHT_PASSWORD', 'password'),
timeout: Number(getEnvironmentVariable('REQUEST_TIMEOUT', '5000'))
timeout: REQUEST_TIMEOUT
};

export const OPENMRS = {
url: getEnvironmentVariable('OPENMRS_CHANNEL_URL', 'http://openhim-core:5001/openmrs'),
url: getEnvironmentVariable('OPENMRS_CHANNEL_URL', 'https://openhim-core:5001/openmrs'),
username: getEnvironmentVariable('OPENMRS_CHANNEL_USERNAME', 'interop-client'),
password: getEnvironmentVariable('OPENMRS_CHANNEL_PASSWORD', 'interop-password'),
timeout: Number(getEnvironmentVariable('REQUEST_TIMEOUT', '5000'))
timeout: REQUEST_TIMEOUT
};

export const SYNC_INTERVAL = getEnvironmentVariable('SYNC_INTERVAL', '60000');
// how often in seconds the sync should run. hardcoded to 1 minute
export const SYNC_INTERVAL = '60';
// how far back should the sync look for new resources. Defaults to one hour
export const SYNC_PERIOD = getEnvironmentVariable('SYNC_PERIOD', '3600');

function getEnvironmentVariable(env: string, def: string) {
if (process.env.NODE_ENV === 'test') {
Expand Down
16 changes: 8 additions & 8 deletions mediator/config/openmrs_mediator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ export const openMRSMediatorConfig = {
description: 'A mediator to sync CHT data with OpenMRS',
defaultChannelConfig: [
{
name: 'OpenMRS Mediator',
urlPattern: '^/openmrs/.*$',
name: 'OpenMRS Sync',
urlPattern: '^/trigger$',
routes: [
{
name: 'OpenMRS Mediator',
name: 'OpenMRS polling Mediator',
host: 'mediator',
pathTransform: 's/\\/openmrs/',
path: '/openmrs/sync',
port: 6000,
primary: true,
type: 'http',
},
],
allow: ['interop'],
methods: ['GET', 'POST', 'PUT', 'DELETE'],
type: 'http',
type: 'polling',
pollingSchedule: '1 minute'
},
],
endpoints: [
{
name: 'OpenMRS Mediator',
host: 'openmrs',
path: '/',
host: 'mediator',
path: '/openmrs/sync',
port: '6000',
primary: true,
type: 'http',
Expand Down
23 changes: 7 additions & 16 deletions mediator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { mediatorConfig } from './config/mediator';
import { openMRSMediatorConfig } from './config/openmrs_mediator';
import { logger } from './logger';
import bodyParser from 'body-parser';
import {PORT, OPENHIM, SYNC_INTERVAL, OPENMRS} from './config';
import {PORT, OPENHIM, OPENMRS} from './config';
import patientRoutes from './src/routes/patient';
import serviceRequestRoutes from './src/routes/service-request';
import encounterRoutes from './src/routes/encounter';
import organizationRoutes from './src/routes/organization';
import endpointRoutes from './src/routes/endpoint';
import chtRoutes from './src/routes/cht';
import openMRSRoutes from './src/routes/openmrs';
import { registerMediatorCallback } from './src/utils/openhim';
import { syncPatients, syncEncounters } from './src/utils/openmrs_sync'
import os from 'os';

const {registerMediator} = require('openhim-mediator-utils');
Expand All @@ -21,7 +21,7 @@ const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

app.get('*', (_: Request, res: Response) => {
app.get('/', (_: Request, res: Response) => {
const osUptime = os.uptime();
const processUptime = process.uptime();
res.send({status: 'success', osuptime: osUptime, processuptime: processUptime});
Expand All @@ -34,30 +34,21 @@ app.use('/encounter', encounterRoutes);
app.use('/organization', organizationRoutes);
app.use('/endpoint', endpointRoutes);

// routes for cht docs
// routes for CHT docs
app.use('/cht', chtRoutes);

// routes for OpenMRS
app.use('/openmrs', openMRSRoutes);

if (process.env.NODE_ENV !== 'test') {
app.listen(PORT, () => logger.info(`Server listening on port ${PORT}`));

// TODO => inject the 'port' and 'http scheme' into 'mediatorConfig'
registerMediator(OPENHIM, mediatorConfig, registerMediatorCallback);

// if OPENMRS is specified, register its mediator
// and start the sync background task
if (OPENMRS.url) {
registerMediator(OPENHIM, openMRSMediatorConfig, registerMediatorCallback);
// start patient and ecnounter sync in the background
setInterval(async () => {
try {
const startTime = new Date();
startTime.setHours(startTime.getHours() - 1);
await syncPatients(startTime);
await syncEncounters(startTime);
} catch (error: any) {
logger.error(error);
}
}, Number(SYNC_INTERVAL));
}
}

Expand Down
6 changes: 3 additions & 3 deletions mediator/src/controllers/cht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function createPatient(chtPatientDoc: any) {

export async function updatePatientIds(chtFormDoc: any) {
// first, get the existing patient from fhir server
const response = await getFHIRPatientResource(chtFormDoc.external_id);
const response = await getFHIRPatientResource(chtFormDoc.doc.external_id);

if (response.status != 200) {
return { status: 500, data: { message: `FHIR responded with ${response.status}`} };
Expand All @@ -37,10 +37,10 @@ export async function updatePatientIds(chtFormDoc: any) {
}

const fhirPatient = response.data.entry[0].resource;
addId(fhirPatient, chtPatientIdentifierType, chtFormDoc.patient_id);
addId(fhirPatient, chtPatientIdentifierType, chtFormDoc.doc.patient_id);

// now, we need to get the actual patient doc from cht...
const patient_uuid = await getPatientUUIDFromSourceId(chtFormDoc._id);
const patient_uuid = await getPatientUUIDFromSourceId(chtFormDoc.doc._id);
if (patient_uuid){
addId(fhirPatient, chtDocumentIdentifierType, patient_uuid);
return updateFhirResource({ ...fhirPatient, resourceType: 'Patient' });
Expand Down
18 changes: 18 additions & 0 deletions mediator/src/controllers/openmrs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { logger } from '../../logger';
import { syncPatients, syncEncounters } from '../utils/openmrs_sync'
import { SYNC_PERIOD } from '../../config'

export async function sync() {
try {
let now = Date.now();
let syncPeriod = parseInt(SYNC_PERIOD, 10);
let startTime = new Date(now - syncPeriod);

await syncPatients(startTime);
await syncEncounters(startTime);
return { status: 200, data: { message: `OpenMRS sync completed successfully`} };
} catch(error: any) {
logger.error(error);
return { status: 500, data: { message: `Error during OpenMRS Sync`} };
}
}
Loading

0 comments on commit 34ad8e3

Please sign in to comment.