-
Notifications
You must be signed in to change notification settings - Fork 11
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 #742 from cbrianbet/feat/new-reporting-layer
Get Facility Keph level Txcurr api
- Loading branch information
Showing
4 changed files
with
78 additions
and
1 deletion.
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
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
38 changes: 38 additions & 0 deletions
38
src/common/queries/handlers/get-facility-txcurr.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,38 @@ | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { GetFacilityTxcurrQuery } from '../impl/get-facility-txcurr.query'; | ||
import { LinelistFACTART } from '../../../care-treatment/common/entities/linelist-fact-art.model'; | ||
|
||
@QueryHandler(GetFacilityTxcurrQuery) | ||
export class GetFacilityTxcurrHandler implements IQueryHandler<GetFacilityTxcurrQuery> { | ||
constructor( | ||
@InjectRepository(LinelistFACTART, 'mssql') | ||
private readonly repository: Repository<LinelistFACTART>, | ||
) {} | ||
|
||
async execute(query: GetFacilityTxcurrQuery): Promise<any> { | ||
const facilities = this.repository | ||
.createQueryBuilder('q') | ||
.select('count (*) TxCurr, KEPH_Level') | ||
.leftJoin('all_EMRSites', 'e', 'e.MFLCode = q.SiteCode') | ||
.where(`ARTOutcomeDescription='Active'`); | ||
|
||
if (query.county) { | ||
facilities.andWhere('q.County IN (:...county)', { | ||
county: [query.county], | ||
}); | ||
} | ||
|
||
if (query.subCounty) { | ||
facilities.andWhere('q.SubCounty IN (:...subCounty)', { | ||
subCounty: [query.subCounty], | ||
}); | ||
} | ||
|
||
|
||
return await facilities | ||
.groupBy('KEPH_Level') | ||
.getRawMany(); | ||
} | ||
} |
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,7 @@ | ||
export class GetFacilityTxcurrQuery { | ||
county?: string[]; | ||
subCounty?: string[]; | ||
facility?: string[]; | ||
partner?: string[]; | ||
agency?: string[]; | ||
} |