-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from koskedk/dev
Dev
- Loading branch information
Showing
23 changed files
with
509 additions
and
7,948 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
STATS_PORT = 4720 | ||
|
||
STATS_RABBITMQ_URI = amqp://guest:[email protected].3:5672/spot | ||
STATS_RABBITMQ_URI = amqp://guest:[email protected].4:5672/spot | ||
STATS_RABBITMQ_EXCHANGE = stats.exchange | ||
STATS_RABBITMQ_EXCHANGE_TYPE = direct | ||
STATS_RABBITMQ_ROUTES = manifest.route|stats.route|metric.route | ||
STATS_RABBITMQ_QUEUES = manifest.queue|stats.queue|metric.queue | ||
STATS_RABBITMQ_ROUTES = manifest.route|stats.route|metric.route|syncstats.route | ||
STATS_RABBITMQ_QUEUES = manifest.queue|stats.queue|metric.queue|syncstats.queue | ||
|
||
GLOBE_RABBITMQ_URI = amqp://guest:[email protected].3:5672/spot | ||
GLOBE_RABBITMQ_URI = amqp://guest:[email protected].4:5672/spot | ||
GLOBE_RABBITMQ_EXCHANGE = globe.exchange | ||
GLOBE_RABBITMQ_EXCHANGE_TYPE = direct | ||
GLOBE_RABBITMQ_ROUTES = practice.route | ||
GLOBE_RABBITMQ_QUEUES = practice.queue | ||
|
||
STATS_MONGODB_URI = mongodb://192.168.100.3/dwapiStats | ||
STATS_MONGODB_URI = mongodb://192.168.100.4/dwapiStats | ||
STATS_KEY = koskedk.com+5-key.pem | ||
STATS_CERT = koskedk.com+5.pem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/server/src/application/transfers/commands/handlers/request-stats.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { Inject, Logger } from '@nestjs/common'; | ||
import { IManifestRepository } from '../../../../domain/transfers/manifest-repository.interface'; | ||
import { RequestStatsCommand } from '../request-stats.command'; | ||
import { MessagingService } from '../../../../infrastructure/messging/messaging.service'; | ||
import { ConfigService } from '../../../../config/config.service'; | ||
|
||
@CommandHandler(RequestStatsCommand) | ||
export class RequestStatsHandler | ||
implements ICommandHandler<RequestStatsCommand> { | ||
constructor( | ||
@Inject('IManifestRepository') | ||
private readonly manifestRepository: IManifestRepository, | ||
private readonly client: MessagingService, | ||
private readonly config: ConfigService, | ||
) {} | ||
|
||
async execute(command: RequestStatsCommand): Promise<any> { | ||
let manifests = []; | ||
manifests = await this.manifestRepository.getCurrentMissing(); | ||
if (command.facilityCodes && command.facilityCodes.length > 0) { | ||
manifests = manifests.filter((x) => | ||
command.facilityCodes.includes(x.code), | ||
); | ||
} | ||
for (const manifest of manifests) { | ||
try { | ||
const result = await this.client.publish( | ||
JSON.stringify({ | ||
label: RequestStatsCommand.name, | ||
body: { | ||
id: manifest.mId, | ||
code: manifest.code, | ||
docket: manifest.docket, | ||
}, | ||
}), | ||
this.config.QueueStatsExchange, | ||
this.config.getRoute('syncstats.route'), | ||
); | ||
} catch (e) { | ||
Logger.error(`PUBLISH`, e); | ||
} | ||
} | ||
return manifests; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
packages/server/src/application/transfers/commands/handlers/sync-stats.handler.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { CommandBus } from '@nestjs/cqrs'; | ||
import { Logger } from '@nestjs/common'; | ||
import { TestDbHelper } from '../../../../../test/test-db.helper'; | ||
import { | ||
getDockets, | ||
getFacilities, | ||
getMasterFacs, | ||
getUpdateStatsCommands, | ||
} from '../../../../../test/test.data'; | ||
import { | ||
Docket, | ||
Facility, | ||
IFacilityRepository, | ||
MasterFacility, | ||
} from '../../../../domain'; | ||
import { TransfersModule } from '../../transfers.module'; | ||
import { CourtsInfrastructureModule } from '../../../../infrastructure/courts'; | ||
import { UpdateStatsCommand } from '../update-stats.command'; | ||
import { UpdateStatsHandler } from './update-stats.handler'; | ||
import { plainToClass } from 'class-transformer'; | ||
import { LogManifestCommand } from '../log-manifest.command'; | ||
import { SyncStatsCommand } from '../sync-stats.command'; | ||
import { SyncStatsHandler } from './sync-stats.handler'; | ||
|
||
describe('Sync Stats Command Tests', () => { | ||
let module: TestingModule; | ||
let commandBus: CommandBus; | ||
|
||
let dockets: Docket[]; | ||
let masterFacilities: MasterFacility[]; | ||
let facilities: Facility[]; | ||
let syncStatsCommands: SyncStatsCommand[]; | ||
|
||
const dbHelper = new TestDbHelper(); | ||
let facilityRepository: IFacilityRepository; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
imports: [ | ||
MongooseModule.forRoot(dbHelper.url, dbHelper.options), | ||
TransfersModule, | ||
CourtsInfrastructureModule, | ||
], | ||
}).compile(); | ||
dockets = await getDockets(); | ||
masterFacilities = await getMasterFacs(); | ||
facilities = await getFacilities(); | ||
syncStatsCommands = await getUpdateStatsCommands(); | ||
await dbHelper.initConnection(); | ||
await dbHelper.seedDb( | ||
'facilities', | ||
facilities.filter((x) => x.code === 12618), | ||
); | ||
const handler = module.get<SyncStatsHandler>(SyncStatsHandler); | ||
facilityRepository = module.get<IFacilityRepository>('IFacilityRepository'); | ||
commandBus = module.get<CommandBus>(CommandBus); | ||
commandBus.bind(handler, SyncStatsCommand.name); | ||
}); | ||
|
||
afterAll(async () => { | ||
await dbHelper.clearDb(); | ||
await dbHelper.closeConnection(); | ||
}); | ||
|
||
it('should Sync Facility Stats', async () => { | ||
const existingFacility = facilities.find((x) => x.code === 12618); | ||
const syncStats = syncStatsCommands.filter((x) => x.facilityCode === 12618); | ||
for (const command of syncStats) { | ||
const result = await commandBus.execute(command); | ||
expect(result).not.toBeNull(); | ||
|
||
const findresult = await facilityRepository.get(existingFacility._id); | ||
const facility = plainToClass(Facility, findresult); | ||
command.stats.forEach((stat) => { | ||
expect( | ||
facility.getStats(command.docket.name, stat.name).recieved, | ||
).toEqual(stat.recieved); | ||
}); | ||
} | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
packages/server/src/application/transfers/commands/handlers/sync-stats.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { CommandHandler, EventPublisher, ICommandHandler } from '@nestjs/cqrs'; | ||
import { LogManifestCommand } from '../log-manifest.command'; | ||
import { Inject, Logger } from '@nestjs/common'; | ||
import { | ||
Facility, | ||
IDocketRepository, | ||
IFacilityRepository, | ||
IMasterFacilityRepository, | ||
} from '../../../../domain'; | ||
import { UpdateStatsCommand } from '../update-stats.command'; | ||
import { plainToClass } from 'class-transformer'; | ||
import { IManifestRepository } from '../../../../domain/transfers/manifest-repository.interface'; | ||
import { SyncStatsCommand } from '../sync-stats.command'; | ||
|
||
@CommandHandler(SyncStatsCommand) | ||
export class SyncStatsHandler implements ICommandHandler<SyncStatsCommand> { | ||
constructor( | ||
@Inject('IDocketRepository') | ||
private readonly docketRepository: IDocketRepository, | ||
@Inject('IFacilityRepository') | ||
private readonly facilityRepository: IFacilityRepository, | ||
@Inject('IManifestRepository') | ||
private readonly manifestRepository: IManifestRepository, | ||
private readonly publisher: EventPublisher, | ||
) {} | ||
|
||
async execute(command: SyncStatsCommand): Promise<any> { | ||
let facility = await this.facilityRepository.findByCode( | ||
command.facilityCode, | ||
); | ||
if (facility) { | ||
facility = plainToClass(Facility, facility); | ||
facility.updateSummary(command.docket, command.stats, command.updated); | ||
|
||
const updatedFacility = await this.facilityRepository.update(facility); | ||
this.publisher.mergeObjectContext(facility).commit(); | ||
Logger.log(`Updated Stats ${facility.name}`); | ||
|
||
const manifest = await this.manifestRepository.getCurrentDocket( | ||
facility._id, | ||
command.docket.name, | ||
); | ||
if (manifest) { | ||
const recieved = facility.getPatientSummary(command.docket.name); | ||
if (recieved) { | ||
manifest.recievedCount = recieved; | ||
await this.manifestRepository.update(manifest); | ||
} | ||
} | ||
return updatedFacility; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/server/src/application/transfers/commands/request-stats.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class RequestStatsCommand { | ||
constructor(public facilityCodes?: number[]) {} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/server/src/application/transfers/commands/sync-stats.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class SyncStatsCommand { | ||
constructor( | ||
public facilityCode: number, | ||
public docket: any, | ||
public stats: any, | ||
public updated: Date, | ||
public manifestId?: string, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/server/src/application/transfers/queries/get-misssing-stats.query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export class GetMisssingStatsQuery {} |
59 changes: 59 additions & 0 deletions
59
packages/server/src/application/transfers/queries/handlers/get-missing-stats.handler.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { QueryBus } from '@nestjs/cqrs'; | ||
import { Logger } from '@nestjs/common'; | ||
import { TestDbHelper } from '../../../../../test/test-db.helper'; | ||
import { | ||
getTestFacilities, | ||
getTestStatsData, | ||
} from '../../../../../test/test.data'; | ||
import { TransfersModule } from '../../transfers.module'; | ||
import { CourtsInfrastructureModule } from '../../../../infrastructure/courts'; | ||
import { GetMisssingStatsQuery } from '../get-misssing-stats.query'; | ||
import { GetMisssingStatsHandler } from './get-missing-stats.handler'; | ||
|
||
describe('Get Manifests Stats', () => { | ||
let module: TestingModule; | ||
const { dockets, masterfacilities } = getTestStatsData(); | ||
const { facilities, manifests } = getTestFacilities(); | ||
const dbHelper = new TestDbHelper(); | ||
const liveData = facilities[0]; | ||
liveData.summaries = []; | ||
let queryBus: QueryBus; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
imports: [ | ||
MongooseModule.forRoot(dbHelper.url, dbHelper.options), | ||
TransfersModule, | ||
CourtsInfrastructureModule, | ||
], | ||
}).compile(); | ||
|
||
await dbHelper.initConnection(); | ||
await dbHelper.seedDb('dockets', dockets); | ||
await dbHelper.seedDb('masterfacilities', masterfacilities); | ||
liveData.code = masterfacilities[0].code; | ||
await dbHelper.seedDb('facilities', [liveData]); | ||
await dbHelper.seedDb('manifests', manifests); | ||
|
||
const handler = module.get<GetMisssingStatsHandler>( | ||
GetMisssingStatsHandler, | ||
); | ||
|
||
queryBus = module.get<QueryBus>(QueryBus); | ||
queryBus.bind(handler, GetMisssingStatsQuery.name); | ||
}); | ||
|
||
afterAll(async () => { | ||
await dbHelper.clearDb(); | ||
await dbHelper.closeConnection(); | ||
}); | ||
|
||
it('should get Manifest Missing Stats', async () => { | ||
const query = new GetMisssingStatsQuery(); | ||
const result = await queryBus.execute<GetMisssingStatsQuery, any>(query); | ||
expect(result.length).toBeGreaterThan(0); | ||
result.forEach((c) => Logger.debug(`${c}`)); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
packages/server/src/application/transfers/queries/handlers/get-missing-stats.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
import { Inject } from '@nestjs/common'; | ||
import { IManifestRepository } from '../../../../domain/transfers/manifest-repository.interface'; | ||
import { GetStatsQuery } from '../get-stats.query'; | ||
import { GetMisssingStatsQuery } from '../get-misssing-stats.query'; | ||
|
||
@QueryHandler(GetMisssingStatsQuery) | ||
export class GetMisssingStatsHandler | ||
implements IQueryHandler<GetMisssingStatsQuery, any> { | ||
constructor( | ||
@Inject('IManifestRepository') | ||
private readonly repository: IManifestRepository, | ||
) {} | ||
async execute(query: GetMisssingStatsQuery): Promise<any> { | ||
return await this.repository.getCurrentMissing(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.