From 490b38bc0f36dc961f9f45680f6d76d094ac9a14 Mon Sep 17 00:00:00 2001 From: mark-labuschagne Date: Fri, 25 Nov 2022 11:05:28 +0200 Subject: [PATCH 1/7] register sync/async channels for JeMPI PLAT-623 --- .../openhim/docker-compose.config.yml | 33 ++++++ .../importer/openhim/openhim-import.json | 106 ++++++++++++++++++ .../importer/openhim/openhimConfig.js | 54 +++++++++ client-registry-jempi/package-metadata.json | 5 +- client-registry-jempi/swarm.sh | 16 +++ 5 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 client-registry-jempi/importer/openhim/docker-compose.config.yml create mode 100644 client-registry-jempi/importer/openhim/openhim-import.json create mode 100644 client-registry-jempi/importer/openhim/openhimConfig.js diff --git a/client-registry-jempi/importer/openhim/docker-compose.config.yml b/client-registry-jempi/importer/openhim/docker-compose.config.yml new file mode 100644 index 00000000..af000aa9 --- /dev/null +++ b/client-registry-jempi/importer/openhim/docker-compose.config.yml @@ -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 + OPENHIM_API_USERNAME: root@openhim.org + 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 + diff --git a/client-registry-jempi/importer/openhim/openhim-import.json b/client-registry-jempi/importer/openhim/openhim-import.json new file mode 100644 index 00000000..c1439d7b --- /dev/null +++ b/client-registry-jempi/importer/openhim/openhim-import.json @@ -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": "^/csv/?$", + "priority": 1, + "matchContentRegex": null, + "matchContentXpath": null, + "matchContentValue": null, + "matchContentJson": null, + "pollingSchedule": null, + "tcpHost": null, + "tcpPort": null, + "updatedBy": { + "id": "605c8ddd9e66da001494935e", + "name": "Super User" + }, + "alerts": [] + } + ] +} diff --git a/client-registry-jempi/importer/openhim/openhimConfig.js b/client-registry-jempi/importer/openhim/openhimConfig.js new file mode 100644 index 00000000..4932ef06 --- /dev/null +++ b/client-registry-jempi/importer/openhim/openhimConfig.js @@ -0,0 +1,54 @@ +'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 || 'openhim-core' +const OPENHIM_API_PASSWORD = + process.env.OPENHIM_API_PASSWORD || 'openhim-password' +const OPENHIM_MEDIATOR_API_PORT = process.env.OPENHIM_MEDIATOR_API_PORT || 8080 +const OPENHIM_API_USERNAME = + process.env.OPENHIM_API_USERNAME || 'root@openhim.org' + +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() diff --git a/client-registry-jempi/package-metadata.json b/client-registry-jempi/package-metadata.json index 67cb5994..a82a1bda 100644 --- a/client-registry-jempi/package-metadata.json +++ b/client-registry-jempi/package-metadata.json @@ -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", @@ -49,6 +49,7 @@ "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" + "JEMPI_API_IMAGE_TAG": "0.1.0", + "JEMPI_OPENHIM_PASSWORD": "instant101" } } diff --git a/client-registry-jempi/swarm.sh b/client-registry-jempi/swarm.sh index 6b301b1c..02d34518 100644 --- a/client-registry-jempi/swarm.sh +++ b/client-registry-jempi/swarm.sh @@ -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 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" @@ -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 From 85f36e59b8302953cac58b68cd30b5c7c7e02864 Mon Sep 17 00:00:00 2001 From: Mark-Labuschagne <78809924+Mark-Labuschagne@users.noreply.github.com> Date: Tue, 29 Nov 2022 12:04:44 +0200 Subject: [PATCH 2/7] Update client-registry-jempi/importer/openhim/openhimConfig.js Co-authored-by: Nour Borgi <48720958+nour-borgi@users.noreply.github.com> --- client-registry-jempi/importer/openhim/openhimConfig.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client-registry-jempi/importer/openhim/openhimConfig.js b/client-registry-jempi/importer/openhim/openhimConfig.js index 4932ef06..ba86cd8b 100644 --- a/client-registry-jempi/importer/openhim/openhimConfig.js +++ b/client-registry-jempi/importer/openhim/openhimConfig.js @@ -43,7 +43,7 @@ const req = https.request(options, res => { throw new Error(`Failed to import OpenHIM config: ${res.statusCode}`) } - console.log('Successfully Imported OpenHIM Config') + console.log('Successfully imported OpenHIM config') }) req.on('error', error => { From d83242490e3ba3affb02f0bfade049783a02613c Mon Sep 17 00:00:00 2001 From: Mark-Labuschagne <78809924+Mark-Labuschagne@users.noreply.github.com> Date: Tue, 29 Nov 2022 12:04:58 +0200 Subject: [PATCH 3/7] Update client-registry-jempi/swarm.sh Co-authored-by: Nour Borgi <48720958+nour-borgi@users.noreply.github.com> --- client-registry-jempi/swarm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client-registry-jempi/swarm.sh b/client-registry-jempi/swarm.sh index 02d34518..7080c479 100644 --- a/client-registry-jempi/swarm.sh +++ b/client-registry-jempi/swarm.sh @@ -120,7 +120,7 @@ main() { 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 running... skipping configuring of async/sync JeMPI channels" + 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[@]}" From 524e64a1204df02d4de6d1774133653cb67a08e1 Mon Sep 17 00:00:00 2001 From: mark-labuschagne Date: Tue, 29 Nov 2022 12:12:29 +0200 Subject: [PATCH 4/7] removed obselete defaults the defaults there would never be accessed, and should always have set values in their docker-compose files PLAT-623 --- client-registry-jempi/importer/openhim/openhimConfig.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client-registry-jempi/importer/openhim/openhimConfig.js b/client-registry-jempi/importer/openhim/openhimConfig.js index ba86cd8b..8dd6ef1f 100644 --- a/client-registry-jempi/importer/openhim/openhimConfig.js +++ b/client-registry-jempi/importer/openhim/openhimConfig.js @@ -4,12 +4,12 @@ const fs = require('fs') const https = require('https') const path = require('path') -const OPENHIM_CORE_SERVICE_NAME = process.env.OPENHIM_CORE_SERVICE_NAME || 'openhim-core' +const OPENHIM_CORE_SERVICE_NAME = process.env.OPENHIM_CORE_SERVICE_NAME const OPENHIM_API_PASSWORD = - process.env.OPENHIM_API_PASSWORD || 'openhim-password' -const OPENHIM_MEDIATOR_API_PORT = process.env.OPENHIM_MEDIATOR_API_PORT || 8080 + 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 || 'root@openhim.org' + process.env.OPENHIM_API_USERNAME const authHeader = new Buffer.from( `${OPENHIM_API_USERNAME}:${OPENHIM_API_PASSWORD}` From 6093a508bd86244d6dde86a5e920d17c46301f54 Mon Sep 17 00:00:00 2001 From: mark-labuschagne Date: Tue, 29 Nov 2022 12:20:12 +0200 Subject: [PATCH 5/7] linting --- .../importer/openhim/openhimConfig.js | 62 +++++++++---------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/client-registry-jempi/importer/openhim/openhimConfig.js b/client-registry-jempi/importer/openhim/openhimConfig.js index 8dd6ef1f..b475407d 100644 --- a/client-registry-jempi/importer/openhim/openhimConfig.js +++ b/client-registry-jempi/importer/openhim/openhimConfig.js @@ -1,54 +1,52 @@ -'use strict' +"use strict"; -const fs = require('fs') -const https = require('https') -const path = require('path') +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 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') +).toString("base64"); const jsonData = JSON.parse( - fs.readFileSync(path.resolve(__dirname, 'openhim-import.json')) -) + fs.readFileSync(path.resolve(__dirname, "openhim-import.json")) +); -const data = JSON.stringify(jsonData) +const data = JSON.stringify(jsonData); const options = { - protocol: 'https:', + protocol: "https:", hostname: OPENHIM_CORE_SERVICE_NAME, port: OPENHIM_MEDIATOR_API_PORT, - path: '/metadata', - method: 'POST', + path: "/metadata", + method: "POST", headers: { - 'Content-Type': 'application/json', - 'Content-Length': data.length, - Authorization: `Basic ${authHeader}` - } -} + "Content-Type": "application/json", + "Content-Length": data.length, + Authorization: `Basic ${authHeader}`, + }, +}; -const req = https.request(options, res => { +const req = https.request(options, (res) => { if (res.statusCode == 401) { - throw new Error(`Incorrect OpenHIM API credentials`) + throw new Error(`Incorrect OpenHIM API credentials`); } if (res.statusCode != 201) { - throw new Error(`Failed to import OpenHIM config: ${res.statusCode}`) + throw new Error(`Failed to import OpenHIM config: ${res.statusCode}`); } - console.log('Successfully imported OpenHIM config') -}) + console.log("Successfully imported OpenHIM config"); +}); -req.on('error', error => { - console.error('Failed to import OpenHIM config: ', error) -}) +req.on("error", (error) => { + console.error("Failed to import OpenHIM config: ", error); +}); -req.write(data) -req.end() +req.write(data); +req.end(); From 02674d979b43bbdd16a90907516bd06b4aabcf46 Mon Sep 17 00:00:00 2001 From: mark-labuschagne Date: Wed, 30 Nov 2022 10:54:04 +0200 Subject: [PATCH 6/7] fixed typo in client-registry-jempi env var PLAT-623 --- client-registry-jempi/docker-compose.combined.yml | 2 +- client-registry-jempi/package-metadata.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client-registry-jempi/docker-compose.combined.yml b/client-registry-jempi/docker-compose.combined.yml index 445965c1..9fba7f5d 100644 --- a/client-registry-jempi/docker-compose.combined.yml +++ b/client-registry-jempi/docker-compose.combined.yml @@ -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: diff --git a/client-registry-jempi/package-metadata.json b/client-registry-jempi/package-metadata.json index a82a1bda..500bf8e9 100644 --- a/client-registry-jempi/package-metadata.json +++ b/client-registry-jempi/package-metadata.json @@ -43,7 +43,7 @@ "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", From d6618f3b34f54085634288340b643166cf71718e Mon Sep 17 00:00:00 2001 From: mark-labuschagne Date: Wed, 30 Nov 2022 10:57:08 +0200 Subject: [PATCH 7/7] fixed async fhir patient endpoint PLAT-623 --- client-registry-jempi/importer/openhim/openhim-import.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client-registry-jempi/importer/openhim/openhim-import.json b/client-registry-jempi/importer/openhim/openhim-import.json index c1439d7b..0a782e86 100644 --- a/client-registry-jempi/importer/openhim/openhim-import.json +++ b/client-registry-jempi/importer/openhim/openhim-import.json @@ -87,7 +87,7 @@ "responseBody": true, "rewriteUrlsConfig": [], "name": "JeMPI Async Receiver", - "urlPattern": "^/csv/?$", + "urlPattern": "^/async/fhir/Patient/?$", "priority": 1, "matchContentRegex": null, "matchContentXpath": null,