Skip to content

Commit

Permalink
Latest server changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pmanko committed May 1, 2024
1 parent cef8c6d commit a3e7963
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 35 deletions.
3 changes: 3 additions & 0 deletions build-dev-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /usr/bin/env bash

docker-compose -f debug.docker-compose.yml build
2 changes: 1 addition & 1 deletion src/lib/kafkaConsumerUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
100 changes: 71 additions & 29 deletions src/workflows/botswana/IpmsWorkflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ export async function handleAdtFromIpms(adtMessage: string): Promise<any> {
.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) {
Expand Down Expand Up @@ -292,53 +292,42 @@ export async function handleAdtFromIpms(adtMessage: string): Promise<any> {
}
}

export async function handleOruFromIpms(translatedBundle: R4.IBundle): Promise<R4.IBundle> {
export async function handleOruFromIpms(message: any): Promise<R4.IBundle> {
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 = <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 = <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 = <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 = <R4.IBundle>(
await got
Expand Down Expand Up @@ -421,3 +410,56 @@ export async function handleOruFromIpms(translatedBundle: R4.IBundle): Promise<R

return translatedBundle
}

function processIpmsPatient(patient: R4.IPatient): any {
// TODO: Figure out how IPMS stores bcn and ppn
let omang, bcn, ppn

const omangEntry = patient.identifier?.find(
i => 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}
}
4 changes: 2 additions & 2 deletions src/workflows/botswana/hl7Workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/workflows/botswana/workflowHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 = ''
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a3e7963

Please sign in to comment.