Skip to content

Commit

Permalink
iSantePlus setup for custom modules and LNSP mock (#86)
Browse files Browse the repository at this point in the history
* Updating iSantePlus setup for custom modules and mysql extraction

* network fix

* LNSP Mock and server fixes

* Mock work

* Retry work

* module update

* Agenda work

* Format and lint

* Finished LNSP mock work
  • Loading branch information
pmanko authored Nov 16, 2024
1 parent da4818c commit 9599dfb
Show file tree
Hide file tree
Showing 55 changed files with 9,134 additions and 601 deletions.
17 changes: 8 additions & 9 deletions mk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@


#reverse proxy
#./instant package remove -n reverse-proxy-nginx --env-file .env
# ./instant package init -n reverse-proxy-nginx --env-file .env -d
#./instant package down -n reverse-proxy-nginx --env-file .env
#./instant package up -n reverse-proxy-nginx --env-file .env
# ./instant package remove -n reverse-proxy-nginx --env-file .env
# ./instant package init -n reverse-proxy-nginx --env-file .env
# ./instant package down -n reverse-proxy-nginx --env-file .env
# ./instant package up -n reverse-proxy-nginx --env-file .env

#openhim

Expand All @@ -30,9 +30,8 @@
#./instant package init -n database-mysql --env-file .env

#isanteplus

./instant package remove -n emr-isanteplus --env-file .env
./instant package init -n emr-isanteplus --env-file .env
# ./instant package remove -n emr-isanteplus --env-file .env
# ./instant package init -n emr-isanteplus --env-file .env
# ./instant package down -n emr-isanteplus --env-file .env
# ./instant package up -n emr-isanteplus --env-file .env

Expand Down Expand Up @@ -93,8 +92,8 @@


# LNSP Mediator
#./instant package remove -n lnsp-mediator --env-file .env
#./instant package init -n lnsp-mediator --env-file .env -d
./instant package remove -n lnsp-mediator --env-file .env
./instant package init -n lnsp-mediator --env-file .env -d
# ./instant package down -n lnsp-mediator --env-file .env -d
# ./instant package up -n lnsp-mediator --env-file .env -d

Expand Down
Binary file not shown.
2 changes: 0 additions & 2 deletions packages/emr-isanteplus/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,5 @@ networks:
reverse-proxy:
name: reverse-proxy_public
external: true




2 changes: 1 addition & 1 deletion packages/lnsp-mediator/swarm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function initialize_package() {
# fi
# fi

docker::deploy_service $STACK "${COMPOSE_FILE_PATH}" "docker-compose.yml" "$xds_dev_compose_filename"
#docker::deploy_service $STACK "${COMPOSE_FILE_PATH}" "docker-compose.yml" "$xds_dev_compose_filename"
) ||
{
log error "Failed to deploy package"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# OpenHIM Core HTTP server config
server {
listen 8091;
client_max_body_size 10M;

location / {
resolver 127.0.0.11 valid=30s;
set $upstream_isanteplus isanteplus;
proxy_pass http://$upstream_isanteplus:8080;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 3 additions & 1 deletion projects/lnsp-mediator/.env.development
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DB_HOST=localhost
DB_PORT=27019
DB_NAME=nest
DB_NAME=nest
RETRY_INTERVAL=30
MAX_RETRIES=7
3 changes: 2 additions & 1 deletion projects/lnsp-mediator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@nestjs/mongoose": "^10.0.10",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.4.0",
"agenda": "^5.0.0",
"axios": "^1.7.4",
"body-parser": "^1.20.2",
"body-parser-xml": "^2.0.5",
Expand All @@ -53,7 +54,7 @@
"@types/express": "^4.17.17",
"@types/express-xml-bodyparser": "^0",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/node": "^22.9.0",
"@types/supertest": "^6.0.0",
"@types/xml2js": "^0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
Expand Down
9 changes: 6 additions & 3 deletions projects/lnsp-mediator/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ export class AppController {
} else if (bodyString.includes('ns2:GetMessages')) {
serviceResponse =
await this.labResultService.handleGetLabResultsByFacility(body);
} else if (bodyString.includes('http://docs.oasis-open.org/wsn/bw2/NotificationProducer/SubscribeRequest')) {
} else if (
bodyString.includes(
'http://docs.oasis-open.org/wsn/bw2/NotificationProducer/SubscribeRequest',
)
) {
serviceResponse =
await this.subscriptionService.handleSubscription(body);
} else
{
} else {
serviceResponse =
await this.labResultService.handleCreateLabResult(body);
}
Expand Down
1 change: 1 addition & 0 deletions projects/lnsp-mediator/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CoreModule } from './core/core.module';
import { FeaturesModule } from './features/features.module';
import { Hl7Module } from './core/hl7/hl7.module';
import { ConfigModule } from '@nestjs/config';

import * as fs from 'fs';
import * as path from 'path';

Expand Down
64 changes: 64 additions & 0 deletions projects/lnsp-mediator/src/core/agenda/agenda.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Module, Global, Inject, OnModuleDestroy } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import Agenda from 'agenda';
import { Logger } from '@nestjs/common';

const logger = new Logger('Agenda');

@Global()
@Module({
providers: [
{
provide: 'AGENDA_INSTANCE',
useFactory: async (configService: ConfigService) => {
const host = configService.get<string>('DB_HOST');
const port = configService.get<number>('DB_PORT');
const name = configService.get<string>('DB_NAME');

const uri = `mongodb://${host}:${port}/${name}`;
logger.log(`Agenda connecting to MongoDB at ${uri}`);

const agenda = new Agenda({
db: { address: uri, collection: 'agendaJobs' },
});

// Set up event logging here
agenda.on('start', (job) => {
console.log(
`Job ${job.attrs.name} started at ${new Date(
job.attrs.lastRunAt,
).toISOString()}`,
);
});

agenda.on('complete', (job) => {
console.log(
`Job ${job.attrs.name} completed at ${new Date(
job.attrs.lastFinishedAt,
).toISOString()}`,
);
});

agenda.on('fail', (error, job) => {
console.error(
`Job ${job.attrs.name} failed with error: ${error.message}`,
);
});
logger.log('Starting Agenda');
await agenda.start();
logger.log('Agenda started');

return agenda;
},
inject: [ConfigService],
},
],
exports: ['AGENDA_INSTANCE'],
})
export class AgendaModule implements OnModuleDestroy {
constructor(@Inject('AGENDA_INSTANCE') private readonly agenda: Agenda) {}

async onModuleDestroy() {
await this.agenda.stop(); // Gracefully stop Agenda
}
}
2 changes: 2 additions & 0 deletions projects/lnsp-mediator/src/core/core.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Module } from '@nestjs/common';
import { DatabaseModule } from './database/database.module';
import { Hl7Module } from './hl7/hl7.module';
import { AgendaModule } from './agenda/agenda.module';

@Module({
imports: [
DatabaseModule,
AgendaModule,
Hl7Module.forRoot({
mapping: false,
profiling: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class LabOrderController {
}

@Get()
async getAll() {
async getAll(): Promise<any> {
return this.labOrderService.findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LabOrderDAO } from './lab-order.dao';
import { NotificationService } from '../notification/notification.service';
import { Hl7Service } from 'src/core/hl7/hl7.service';

/*
const example_message = `------=_Part_59239_818160219.1723569579332
Content-Type: application/xop+xml; charset=utf-8; type="application/soap+xml"
Expand Down Expand Up @@ -50,6 +51,7 @@ ORC|NW|11221685923|||||^^^20240813131934||20240813131934|||11221^Demo^Provider||
OBR||11221685923||VLCVR|||20240813131934||||O|||||11221^Demo^Provider|||||||||||^^^20240813131934
------=_Part_59239_818160219.1723569579332--`;
*/

const documentSubmissionSuccessTemplate = `------=_Part_60435_1628391534.1724167510003
Content-Type: application/xop+xml; charset=utf-8; type="application/soap+xml"
Expand Down Expand Up @@ -215,7 +217,8 @@ export class LabOrderService {
let responseBody;
let status;

const contentType = 'multipart/related;boundary="----=_Part_59239_818160219.1723569579332"; type="application/xop+xml"; start-info="application/soap+xml";charset=UTF-8'
const contentType =
'multipart/related;boundary="----=_Part_59239_818160219.1723569579332"; type="application/xop+xml"; start-info="application/soap+xml";charset=UTF-8';
//const contentType = 'multipart/related;start="<rootpart*[email protected]>";type="application/xop+xml";boundary="uuid:59239_818160219.1723569579332";start-info="application/soap+xml;action="urn:ihe:iti:2007:RetrieveDocumentSet""';

if (result && result.length === 1) {
Expand Down
15 changes: 3 additions & 12 deletions projects/lnsp-mediator/src/features/lab-result/lab-result.dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,11 @@ export class LabResultDAO extends DAO<LabResultDocument> {
super(model);
}

async findByFacilityId(
facilityId: string,
limit: number = 100,
//afterDateTime?: Date,
) {
async findByFacilityId(facilityId: string, sinceDate: Date) {
const query = this.model
.find({ facilityId })
.sort({ createdAt: -1 })
.limit(limit);

// TODO: Figure out why can't filter by Date
// if (afterDateTime) {
// query.where('createdAt').gte(afterDateTime);
// }
.where({ createdAt: { $gte: sinceDate } })
.sort({ createdAt: -1 });

return query.exec();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class LabResultService {
const parsedData = await this.parseLabResultRequest(xmlPayload);
const resultList = await this.findAllByFacilityId(
parsedData.facilityId,
parsedData.maxNumber,
parsedData.sinceDate,
);

let responseBody;
Expand All @@ -119,6 +119,7 @@ export class LabResultService {

if (resultList.length === 0) {
status = HttpStatus.NOT_FOUND;
responseBody = this.decorateResultList([]);
} else {
responseBody = this.decorateResultList(resultList);
status = HttpStatus.ACCEPTED;
Expand All @@ -139,9 +140,9 @@ export class LabResultService {

async findAllByFacilityId(
facilityId: string,
maxNumber: number = 100,
sinceDate: Date,
): Promise<LabResult[]> {
return this.labResultDAO.findByFacilityId(facilityId, maxNumber);
return this.labResultDAO.findByFacilityId(facilityId, sinceDate);
}

async parseLabResultDocument(xmlPayload: any): Promise<LabResult> {
Expand Down Expand Up @@ -225,24 +226,23 @@ export class LabResultService {

parseLabResultRequest(xmlPayload: any): {
facilityId: string;
maxNumber: number;
sinceDate: Date;
} {
try {
const facilityId =
xmlPayload['soap-env:envelope']['soap-env:body'][0][
'ns2:getmessages'
][0].$.facility;
const maxNumberString =
const sinceDate = new Date(
xmlPayload['soap-env:envelope']['soap-env:body'][0][
'ns2:getmessages'
][0]['ns2:maximumnumber'][0];

const maxNumber = parseInt(maxNumberString);
][0].$.since,
);

return { facilityId, maxNumber };
return { facilityId, sinceDate };
} catch (error) {
throw new Error(
'Could not parse facility ID and maximum number from request',
'Could not parse facility ID and since date from request',
);
}
}
Expand Down
Loading

0 comments on commit 9599dfb

Please sign in to comment.