-
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 #747 from cbrianbet/feat/new-reporting-layer
added county apis to his deployment
- Loading branch information
Showing
8 changed files
with
199 additions
and
66 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
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
39 changes: 39 additions & 0 deletions
39
src/common/queries/handlers/get-facility-by-infrastructure-county.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,39 @@ | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { AllEmrSites } from '../../../care-treatment/common/entities/all-emr-sites.model'; | ||
import { GetFacilityByInfrastructureCountyQuery } from '../impl/get-facility-by-infrastructure-county.query'; | ||
|
||
@QueryHandler(GetFacilityByInfrastructureCountyQuery) | ||
export class GetFacilityByInfrastructureCountyHandler implements IQueryHandler<GetFacilityByInfrastructureCountyQuery> { | ||
constructor( | ||
@InjectRepository(AllEmrSites, 'mssql') | ||
private readonly repository: Repository<AllEmrSites>, | ||
) {} | ||
|
||
async execute(query: GetFacilityByInfrastructureCountyQuery): Promise<any> { | ||
const facilitiesInfrastructure = this.repository | ||
.createQueryBuilder('q') | ||
.select('COUNT(1) facilities, InfrastructureType, County') | ||
.where(`InfrastructureType is not null AND EMR_Status = 'Active'`); | ||
|
||
if (query.county) { | ||
facilitiesInfrastructure.andWhere('q.County IN (:...county)', { | ||
county: [query.county], | ||
}); | ||
} | ||
|
||
if (query.subCounty) { | ||
facilitiesInfrastructure.andWhere('q.SubCounty IN (:...subCounty)', { | ||
subCounty: [query.subCounty], | ||
}); | ||
} | ||
|
||
|
||
return await facilitiesInfrastructure | ||
.groupBy('q.InfrastructureType, County') | ||
.orderBy('County') | ||
.distinct(true) | ||
.getRawMany(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/common/queries/handlers/get-facility-status-by-county.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 { AllEmrSites } from '../../../care-treatment/common/entities/all-emr-sites.model'; | ||
import { GetFacilityStatusByCountyQuery } from '../impl/get-facility-status-by-county.query'; | ||
|
||
@QueryHandler(GetFacilityStatusByCountyQuery) | ||
export class GetFacilityStatusByCountyHandler implements IQueryHandler<GetFacilityStatusByCountyQuery> { | ||
constructor( | ||
@InjectRepository(AllEmrSites, 'mssql') | ||
private readonly repository: Repository<AllEmrSites>, | ||
) {} | ||
|
||
async execute(query: GetFacilityStatusByCountyQuery): Promise<any> { | ||
const facilitiesStatus = this.repository | ||
.createQueryBuilder('q') | ||
.select('COUNT(1) facilities, EMR_Status, County') | ||
.where('EMR_Status is not null'); | ||
|
||
if (query.county) { | ||
facilitiesStatus.andWhere('q.County IN (:...county)', { | ||
county: [query.county], | ||
}); | ||
} | ||
|
||
if (query.subCounty) { | ||
facilitiesStatus.andWhere('q.SubCounty IN (:...subCounty)', { | ||
subCounty: [query.subCounty], | ||
}); | ||
} | ||
|
||
return await facilitiesStatus | ||
.groupBy('q.EMR_Status, County') | ||
.orderBy('County') | ||
.distinct(true) | ||
.getRawMany(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/common/queries/impl/get-facility-by-infrastructure-county.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,7 @@ | ||
export class GetFacilityByInfrastructureCountyQuery { | ||
county?: string[]; | ||
subCounty?: string[]; | ||
facility?: string[]; | ||
partner?: string[]; | ||
agency?: string[]; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/common/queries/impl/get-facility-status-by-county.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,7 @@ | ||
export class GetFacilityStatusByCountyQuery { | ||
county?: string[]; | ||
subCounty?: string[]; | ||
facility?: string[]; | ||
partner?: string[]; | ||
agency?: 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