Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLAT-623 sync/async receiver openhim import #180

Merged
merged 9 commits into from
Dec 1, 2022
2 changes: 1 addition & 1 deletion client-registry-jempi/docker-compose.combined.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.9'

services:
jempi-async-receiver:
image: jembi/jempi-async-receiver:${JEMPI_AJEMPI_SYNC_RECEIVER_IMAGE_TAG}
image: jembi/jempi-async-receiver:${JEMPI_ASYNC_RECEIVER_IMAGE_TAG}
deploy:
replicas: 1
resources:
Expand Down
33 changes: 33 additions & 0 deletions client-registry-jempi/importer/openhim/docker-compose.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3.9'

services:
jempi-openhim-config-importer:
image: node:erbium-alpine
deploy:
restart_policy:
condition: none
environment:
OPENHIM_CORE_SERVICE_NAME: openhim-core
OPENHIM_MEDIATOR_API_PORT: 8080
nour-borgi marked this conversation as resolved.
Show resolved Hide resolved
OPENHIM_API_USERNAME: [email protected]
OPENHIM_API_PASSWORD: ${JEMPI_OPENHIM_PASSWORD}
NODE_TLS_REJECT_UNAUTHORIZED: 0
command: sh -c "node openhimConfig.js"
configs:
- source: openhim-config-importer-openhimConfig.js
target: /openhimConfig.js
- source: openhim-config-importer-openhim-import.json
target: /openhim-import.json

configs:
openhim-config-importer-openhimConfig.js:
file: ./openhimConfig.js
name: openhim-config-importer-openhimConfig.js-${openhim_config_importer_openhimConfig_js_DIGEST:?err}
labels:
name: openhim
openhim-config-importer-openhim-import.json:
file: ./openhim-import.json
name: openhim-config-importer-openhim-import.json-${openhim_config_importer_openhim_import_js_DIGEST:?err}
labels:
name: openhim

106 changes: 106 additions & 0 deletions client-registry-jempi/importer/openhim/openhim-import.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"Channels": [
{
"methods": ["POST"],
"type": "http",
"allow": ["instant"],
"whitelist": [],
"authType": "private",
"matchContentTypes": [],
"properties": [],
"txViewAcl": [],
"txViewFullAcl": [],
"txRerunAcl": [],
"status": "enabled",
"rewriteUrls": false,
"addAutoRewriteRules": true,
"autoRetryEnabled": false,
"autoRetryPeriodMinutes": 60,
"routes": [
{
"type": "http",
"status": "enabled",
"forwardAuthHeader": false,
"name": "JeMPI Sync Receiver",
"secured": false,
"host": "jempi-sync-reciever",
"port": 50000,
"path": "",
"pathTransform": "",
"primary": true,
"username": "",
"password": ""
}
],
"requestBody": true,
"responseBody": true,
"rewriteUrlsConfig": [],
"name": "JeMPI Sync Receiver",
"urlPattern": "^/fhir/Patient.*$",
"priority": 10,
"matchContentRegex": null,
"matchContentXpath": null,
"matchContentValue": null,
"matchContentJson": null,
"pollingSchedule": null,
"tcpHost": null,
"tcpPort": null,
"updatedBy": {
"id": "605c8ddd9e66da001494935e",
"name": "Super User"
},
"alerts": []
},
{
"methods": ["POST"],
"type": "http",
"allow": ["instant"],
"whitelist": [],
"authType": "private",
"matchContentTypes": [],
"properties": [],
"txViewAcl": [],
"txViewFullAcl": [],
"txRerunAcl": [],
"status": "enabled",
"rewriteUrls": false,
"addAutoRewriteRules": true,
"autoRetryEnabled": false,
"autoRetryPeriodMinutes": 60,
"routes": [
{
"type": "http",
"status": "enabled",
"forwardAuthHeader": false,
"name": "JeMPI Async Receiver",
"secured": false,
"host": "jempi-async-reciever",
"port": 50000,
"path": "",
"pathTransform": "",
"primary": true,
"username": "",
"password": ""
}
],
"requestBody": true,
"responseBody": true,
"rewriteUrlsConfig": [],
"name": "JeMPI Async Receiver",
"urlPattern": "^/async/fhir/Patient/?$",
"priority": 1,
"matchContentRegex": null,
"matchContentXpath": null,
"matchContentValue": null,
"matchContentJson": null,
"pollingSchedule": null,
"tcpHost": null,
"tcpPort": null,
"updatedBy": {
"id": "605c8ddd9e66da001494935e",
"name": "Super User"
},
"alerts": []
}
]
}
52 changes: 52 additions & 0 deletions client-registry-jempi/importer/openhim/openhimConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"use strict";

const fs = require("fs");
const https = require("https");
const path = require("path");

const OPENHIM_CORE_SERVICE_NAME = process.env.OPENHIM_CORE_SERVICE_NAME;
const OPENHIM_API_PASSWORD = process.env.OPENHIM_API_PASSWORD;
const OPENHIM_MEDIATOR_API_PORT = process.env.OPENHIM_MEDIATOR_API_PORT;
const OPENHIM_API_USERNAME = process.env.OPENHIM_API_USERNAME;

const authHeader = new Buffer.from(
`${OPENHIM_API_USERNAME}:${OPENHIM_API_PASSWORD}`
).toString("base64");

const jsonData = JSON.parse(
fs.readFileSync(path.resolve(__dirname, "openhim-import.json"))
);

const data = JSON.stringify(jsonData);

const options = {
protocol: "https:",
hostname: OPENHIM_CORE_SERVICE_NAME,
port: OPENHIM_MEDIATOR_API_PORT,
path: "/metadata",
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": data.length,
Authorization: `Basic ${authHeader}`,
},
};

const req = https.request(options, (res) => {
if (res.statusCode == 401) {
throw new Error(`Incorrect OpenHIM API credentials`);
}

if (res.statusCode != 201) {
throw new Error(`Failed to import OpenHIM config: ${res.statusCode}`);
}

console.log("Successfully imported OpenHIM config");
});

req.on("error", (error) => {
console.error("Failed to import OpenHIM config: ", error);
});

req.write(data);
req.end();
7 changes: 4 additions & 3 deletions client-registry-jempi/package-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A patient matching and deduplicater for the platform",
"type": "infrastructure",
"version": "0.0.1",
"dependencies": [],
"dependencies": ["interoperability-layer-openhim"],
"environmentVariables": {
"STATEFUL_NODES": "single",
"JEMPI_KAFKA_01_MEMORY_LIMIT": "3G",
Expand Down Expand Up @@ -43,12 +43,13 @@
"JEMPI_API_MEMORY_RESERVE": "500M",
"JEMPI_KAFKA_TOPICS": "JeMPI-async-preprocessor,JeMPI-patient-controller,JeMPI-patient-em,JeMPI-patient-linker,JeMPI-mu-linker,JeMPI-notifications",
"JEMPI_KAFKA_DEBUG": false,
"JEMPI_AJEMPI_SYNC_RECEIVER_IMAGE_TAG": "0.1.0",
"JEMPI_ASYNC_RECEIVER_IMAGE_TAG": "0.1.0",
"JEMPI_SYNC_RECEIVER_IMAGE_TAG": "0.1.0",
"JEMPI_PRE_PROCESSOR_IMAGE_TAG": "0.1.0",
"JEMPI_CONTROLLER_IMAGE_TAG": "0.1.0",
"JEMPI_EM_CALCULATOR_IMAGE_TAG": "0.1.0",
"JEMPI_LINKER_IMAGE_TAG": "0.1.0",
"JEMPI_API_IMAGE_TAG": "0.1.0"
rcrichton marked this conversation as resolved.
Show resolved Hide resolved
"JEMPI_API_IMAGE_TAG": "0.1.0",
"JEMPI_OPENHIM_PASSWORD": "instant101"
}
}
16 changes: 16 additions & 0 deletions client-registry-jempi/swarm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ main() {

docker::await_service_ready jempi-api

if docker service ps -q instant_openhim-core &>/dev/null; then
config::set_config_digests "${COMPOSE_FILE_PATH}"/importer/openhim/docker-compose.config.yml

try "docker stack deploy -c ${COMPOSE_FILE_PATH}/importer/openhim/docker-compose.config.yml instant" "Failed to deploy jempi-openhim-config-importer"

log info "Waiting to give JeMPI Openhim config importer time to run before cleaning up service"

config::remove_config_importer jempi-openhim-config-importer
config::await_service_removed instant_jempi-openhim-config-importer
else
log warn "Service 'interoperability-layer-openhim' does not appear to be running... skipping configuring of async/sync JeMPI channels"
fi

docker::deploy_sanity "${service_names[@]}"
elif [[ "${ACTION}" == "down" ]]; then
log info "Scaling down client-registry-jempi"
Expand All @@ -124,6 +137,9 @@ main() {
docker::service_destroy "$service_name"
done

docker::service_destroy jempi-kafka-config-importer
docker::service_destroy jempi-openhim-config-importer

docker::try_remove_volume jempi-kafka-01-data
docker::try_remove_volume jempi-kafka-02-data
docker::try_remove_volume jempi-kafka-03-data
Expand Down