From a3e79636eefa97420c27d13b1e7f2a523747fe84 Mon Sep 17 00:00:00 2001 From: Piotr Mankowski Date: Thu, 2 May 2024 01:11:48 +0200 Subject: [PATCH] Latest server changes --- build-dev-image.sh | 3 + src/lib/kafkaConsumerUtil.ts | 2 +- src/workflows/botswana/IpmsWorkflows.ts | 100 +++++++++++++++------- src/workflows/botswana/hl7Workflows.ts | 4 +- src/workflows/botswana/workflowHandler.ts | 6 +- yarn.lock | 8 ++ 6 files changed, 88 insertions(+), 35 deletions(-) create mode 100755 build-dev-image.sh diff --git a/build-dev-image.sh b/build-dev-image.sh new file mode 100755 index 0000000..4a6c18a --- /dev/null +++ b/build-dev-image.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash + +docker-compose -f debug.docker-compose.yml build \ No newline at end of file diff --git a/src/lib/kafkaConsumerUtil.ts b/src/lib/kafkaConsumerUtil.ts index 00610cc..9bbcd6d 100644 --- a/src/lib/kafkaConsumerUtil.ts +++ b/src/lib/kafkaConsumerUtil.ts @@ -77,7 +77,7 @@ export class KafkaConsumerUtil { await heartbeat() break // Break the loop if processing succeeds } } else { - logger.error(`Workflow result did not succeed: ${res.result}`) + logger.error(`Workflow result did not succeed: ${JSON.stringify(res.result)}`) } } catch (error) { logger.error(`Error processing message ${message.offset}: ${error}`) diff --git a/src/workflows/botswana/IpmsWorkflows.ts b/src/workflows/botswana/IpmsWorkflows.ts index afb337f..46385fb 100644 --- a/src/workflows/botswana/IpmsWorkflows.ts +++ b/src/workflows/botswana/IpmsWorkflows.ts @@ -240,8 +240,8 @@ export async function handleAdtFromIpms(adtMessage: string): Promise { .filter( e => e.resource && - e.resource.resourceType == 'Task' && - e.resource.status == TaskStatusKind._received, + e.resource.resourceType == 'Task' // && + // e.resource.status == TaskStatusKind._received, ) .sort((a, b) => { if (a.resource && b.resource) { @@ -292,53 +292,42 @@ export async function handleAdtFromIpms(adtMessage: string): Promise { } } -export async function handleOruFromIpms(translatedBundle: R4.IBundle): Promise { +export async function handleOruFromIpms(message: any): Promise { + let translatedBundle: R4.IBundle = { resourceType: 'Bundle'} + // Get Patient By Omang // Get ServiceRequests by status and code // Match Results to Service Requests try { + if(!message) + throw new Error('No message provided!') + + if(!message.bundle) + message = JSON.parse(message) + + translatedBundle = message.bundle + if (translatedBundle && translatedBundle.entry) { const patient: IPatient = ( - translatedBundle.entry.find(e => e.resource && e.resource.resourceType == 'Patient')! + translatedBundle.entry.find((e: any) => e.resource && e.resource.resourceType == 'Patient')! .resource! ) const dr: IDiagnosticReport = ( - translatedBundle.entry.find( - e => e.resource && e.resource.resourceType == 'DiagnosticReport', - )!.resource! + translatedBundle.entry.find((e: any) => e.resource && e.resource.resourceType == 'DiagnosticReport')!.resource! ) const obs: IObservation = ( - translatedBundle.entry.find(e => e.resource && e.resource.resourceType == 'Observation')! + translatedBundle.entry.find((e: any) => e.resource && e.resource.resourceType == 'Observation')! .resource! ) const drCode = dr.code && dr.code.coding && dr.code.coding.length > 0 ? dr.code.coding[0].code : '' - let omang - const omangEntry = patient.identifier?.find( - i => i.system && i.system == config.get('bwConfig:omangSystemUrl'), - ) - - if (omangEntry) { - omang = omangEntry.value! - } else { - omang = '' - } - - const options = { - timeout: config.get('bwConfig:requestTimeout'), - searchParams: {}, - } - - // Find all active service requests with dr code with this Omang. - options.searchParams = { - identifier: `${config.get('bwConfig:omangSystemUrl')}|${omang}`, - _revinclude: ['ServiceRequest:patient', 'Task:patient'], - } + + const {omang, bcn, ppn, options} = processIpmsPatient(patient) const patientBundle = ( await got @@ -421,3 +410,56 @@ export async function handleOruFromIpms(translatedBundle: R4.IBundle): Promise i.system && i.system == config.get('bwConfig:omangSystemUrl'), + ) + const bcnEntry = patient.identifier?.find( + i => i.system && i.system == config.get('bwConfig:bdrsSystemUrl'), + ) + + const ppnEntry = patient.identifier?.find( + i => i.system && i.system == config.get('bwConfig:immigrationSystemUrl'), + ) + + const identifierQuery = [] + + if (omangEntry) { + omang = omangEntry.value! + identifierQuery.push(`${config.get('bwConfig:omangSystemUrl')}|${omang}`) + } else { + omang = '' + } + + if (bcnEntry) { + bcn = bcnEntry.value! + identifierQuery.push(`${config.get('bwConfig:bdrsSystemUrl')}|${bcn}`) + } else { + bcn = '' + } + + if(ppnEntry) { + ppn = ppnEntry.value! + identifierQuery.push(`${config.get('bwConfig:immigrationSystemUrl')}|${ppn}`) + } else { + ppn = '' + } + + const identifierQueryString = identifierQuery.join(',') + + const options = { + timeout: config.get('bwConfig:requestTimeout'), + searchParams: {}, + } + + options.searchParams = { + identifier: identifierQueryString, + _revinclude: ['ServiceRequest:patient', 'Task:patient'], + } + + return {omang: omang, bcn: bcn, ppn: ppn, options: options} +} diff --git a/src/workflows/botswana/hl7Workflows.ts b/src/workflows/botswana/hl7Workflows.ts index 0a10c17..67fe477 100644 --- a/src/workflows/botswana/hl7Workflows.ts +++ b/src/workflows/botswana/hl7Workflows.ts @@ -69,8 +69,8 @@ export default class Hl7WorkflowsBw { } static async translateBundle(hl7Msg: string, templateConfigKey: string) { - let maxRetries = config.get('retryConfig:translatorMaxRetries') || 5; - let delay = config.get('retryConfig:translatorRetryDelay') || 2000; + const maxRetries = config.get('retryConfig:translatorMaxRetries') || 5; + const delay = config.get('retryConfig:translatorRetryDelay') || 2000; // The errorCheck function defines the criteria for retrying based on the operation's result const errorCheck = (result: R4.IBundle) => result === this.errorBundle; diff --git a/src/workflows/botswana/workflowHandler.ts b/src/workflows/botswana/workflowHandler.ts index a176acc..da2126e 100644 --- a/src/workflows/botswana/workflowHandler.ts +++ b/src/workflows/botswana/workflowHandler.ts @@ -178,7 +178,7 @@ export class WorkflowHandler { case topicList.HANDLE_ORU_FROM_IPMS: { hl7Message = val - response = await handleOruFromIpms(val) + const oruRes = await handleOruFromIpms(val) break } @@ -261,8 +261,8 @@ export class WorkflowHandler { maxRetries?: number, retryDelay?: number, ) { - let myMaxRetries = maxRetries || config.get('retryConfig:kafkaMaxRetries') || 5 - let myRetryDelay = retryDelay || config.get('retryConfig:kafkaRetryDelay') || 2000 + const myMaxRetries = maxRetries || config.get('retryConfig:kafkaMaxRetries') || 5 + const myRetryDelay = retryDelay || config.get('retryConfig:kafkaRetryDelay') || 2000 await this.initKafkaProducer() let val = '' diff --git a/yarn.lock b/yarn.lock index 0d25c49..a6ab83b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7500,6 +7500,7 @@ __metadata: typescript: ^4.0.3 urijs: ^1.19.11 uuid: ^3.3.3 + uuid4: ^1.1.4 winston: ^3.2.1 winston-daily-rotate-file: ^4.4.2 languageName: unknown @@ -8348,6 +8349,13 @@ __metadata: languageName: node linkType: hard +"uuid4@npm:^1.1.4": + version: 1.1.4 + resolution: "uuid4@npm:1.1.4" + checksum: 1a1c91651fa99ca7b9bd3453bd5f061838dc9861ea901c5c5f28c1939081c428a7476f24c4cdd1a78dad82987d8433782fb417fc4b2ef9a3b5c3ddfe5139d578 + languageName: node + linkType: hard + "uuid@npm:^3.3.3": version: 3.4.0 resolution: "uuid@npm:3.4.0"