Skip to content

Commit

Permalink
Merge pull request #732 from cbrianbet/feat/new-reporting-layer
Browse files Browse the repository at this point in the history
His deployment backend
  • Loading branch information
cbrianbet authored May 28, 2024
2 parents 834558e + 25cbadb commit 6717916
Show file tree
Hide file tree
Showing 15 changed files with 461 additions and 0 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

169 changes: 169 additions & 0 deletions src/common/common.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { GetPartnersQuery } from './queries/impl/get-partners.query';
import { GetAgenciesQuery } from './queries/impl/get-agencies.query';
import { GetProjectsQuery } from './queries/impl/get-projects.query';
import { GetSitesQuery } from './queries/impl/get-sites.query';
import { GetFacilityStatusQuery } from './queries/impl/get-facility-status.query';
import { GetFacilityStatusByPartnerQuery } from './queries/impl/get-facility-status-by-partner.query';
import { GetFacilityLevelByOwnershipPartnerQuery } from './queries/impl/get-facility-level-by-ownership-partner.query';
import { GetFacilityLevelByOwnershipCountyQuery } from './queries/impl/get-facility-level-by-ownership-county.query';
import { GetFacilityByInfrastructureQuery } from './queries/impl/get-facility-by-infrastructure.query';
import { GetFacilityLinelistQuery } from './queries/impl/get-facility-linelist.query';

@Controller('common')
export class CommonController {
Expand Down Expand Up @@ -198,6 +204,169 @@ export class CommonController {
return this.queryBus.execute(query);
}

@Get('facilityStatus')
async getFacilityStatus(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
): Promise<any> {
const query = new GetFacilityStatusQuery();
if(county) {
query.county = county;
}
if(subCounty) {
query.subCounty = subCounty;
}
if(facility) {
query.facility = facility;
}
if(partner) {
query.partner = partner;
}
if(agency) {
query.agency = agency;
}
return this.queryBus.execute(query);
}

@Get('facilityStatusByPartner')
async getFacilityStatusByPartner(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
): Promise<any> {
const query = new GetFacilityStatusByPartnerQuery();
if(county) {
query.county = county;
}
if(subCounty) {
query.subCounty = subCounty;
}
if(facility) {
query.facility = facility;
}
if(partner) {
query.partner = partner;
}
if(agency) {
query.agency = agency;
}
return this.queryBus.execute(query);
}

@Get('facilityLevelByOwnershipPartner')
async getFacilityLevelByOwnershipPartner(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
): Promise<any> {
const query = new GetFacilityLevelByOwnershipPartnerQuery();
if(county) {
query.county = county;
}
if(subCounty) {
query.subCounty = subCounty;
}
if(facility) {
query.facility = facility;
}
if(partner) {
query.partner = partner;
}
if(agency) {
query.agency = agency;
}
return this.queryBus.execute(query);
}

@Get('facilityLevelByOwnershipCounty')
async getFacilityLevelByOwnershipCounty(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
): Promise<any> {
const query = new GetFacilityLevelByOwnershipCountyQuery();
if(county) {
query.county = county;
}
if(subCounty) {
query.subCounty = subCounty;
}
if(facility) {
query.facility = facility;
}
if(partner) {
query.partner = partner;
}
if(agency) {
query.agency = agency;
}
return this.queryBus.execute(query);
}

@Get('facilityByInfrastructure')
async getFacilityByInfrastructure(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
): Promise<any> {
const query = new GetFacilityByInfrastructureQuery();
if(county) {
query.county = county;
}
if(subCounty) {
query.subCounty = subCounty;
}
if(facility) {
query.facility = facility;
}
if(partner) {
query.partner = partner;
}
if(agency) {
query.agency = agency;
}
return this.queryBus.execute(query);
}


@Get('facilityLinelist')
async getFacilityLinelist(
@Query('county') county,
@Query('subCounty') subCounty,
@Query('facility') facility,
@Query('partner') partner,
@Query('agency') agency,
): Promise<any> {
const query = new GetFacilityLinelistQuery();
if(county) {
query.county = county;
}
if(subCounty) {
query.subCounty = subCounty;
}
if(facility) {
query.facility = facility;
}
if(partner) {
query.partner = partner;
}
if(agency) {
query.agency = agency;
}
return this.queryBus.execute(query);
}

@Get('sites')
async getSites(): Promise<any> {
return this.queryBus.execute(new GetSitesQuery());
Expand Down
12 changes: 12 additions & 0 deletions src/common/common.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { GetFacilitiesHandler } from './queries/handlers/get-facilities.handler'
import { GetPartnersHandler } from './queries/handlers/get-partners.handler';
import { GetAgenciesHandler } from './queries/handlers/get-agencies.handler';
import { GetSitesHandler } from './queries/handlers/get-sites.handler';
import { GetFacilityStatusHandler } from './queries/handlers/get-facility-status.handler';
import { GetFacilityStatusByPartnerHandler } from './queries/handlers/get-facility-status-by-partner.handler';
import { GetFacilityLevelByOwnershipPartnerHandler } from './queries/handlers/get-facility-level-by-ownership-partner.handler';
import { GetFacilityLevelByOwnershipCountyHandler } from './queries/handlers/get-facility-level-by-ownership-county.handler';
import { GetFacilityByInfrastructureHandler } from './queries/handlers/get-facility-by-infrastructure.handler';
import { GetFacilityLinelistHandler } from './queries/handlers/get-facility-linelist.handler';
import { CommonController } from './common.controller';
import { AllEmrSites } from '../care-treatment/common/entities/all-emr-sites.model';

Expand All @@ -24,6 +30,12 @@ import { AllEmrSites } from '../care-treatment/common/entities/all-emr-sites.mod
GetPartnersHandler,
GetAgenciesHandler,
GetSitesHandler,
GetFacilityStatusHandler,
GetFacilityStatusByPartnerHandler,
GetFacilityLevelByOwnershipPartnerHandler,
GetFacilityLevelByOwnershipCountyHandler,
GetFacilityByInfrastructureHandler,
GetFacilityLinelistHandler,
],
controllers: [CommonController],
})
Expand Down
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 { GetFacilityByInfrastructureQuery } from '../impl/get-facility-by-infrastructure.query';

@QueryHandler(GetFacilityByInfrastructureQuery)
export class GetFacilityByInfrastructureHandler implements IQueryHandler<GetFacilityByInfrastructureQuery> {
constructor(
@InjectRepository(AllEmrSites, 'mssql')
private readonly repository: Repository<AllEmrSites>,
) {}

async execute(query: GetFacilityByInfrastructureQuery): Promise<any> {
const projects = this.repository
.createQueryBuilder('q')
.select('COUNT(1) facilities, InfrastructureType, PartnerName')
.where('InfrastructureType is not null');

if (query.county) {
projects.andWhere('q.County IN (:...county)', {
county: [query.county],
});
}

if (query.subCounty) {
projects.andWhere('q.SubCounty IN (:...subCounty)', {
subCounty: [query.subCounty],
});
}


return await projects
.groupBy('q.InfrastructureType, PartnerName')
.orderBy('PartnerName')
.distinct(true)
.getRawMany();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 { GetFacilityLevelByOwnershipCountyQuery } from '../impl/get-facility-level-by-ownership-county.query';

@QueryHandler(GetFacilityLevelByOwnershipCountyQuery)
export class GetFacilityLevelByOwnershipCountyHandler implements IQueryHandler<GetFacilityLevelByOwnershipCountyQuery> {
constructor(
@InjectRepository(AllEmrSites, 'mssql')
private readonly repository: Repository<AllEmrSites>,
) {}

async execute(query: GetFacilityLevelByOwnershipCountyQuery): Promise<any> {
const projects = this.repository
.createQueryBuilder('q')
.select('COUNT(1) facilities, County, Keph_level')
.where('Keph_level is not null');

if (query.county) {
projects.andWhere('q.County IN (:...county)', {
county: [query.county],
});
}

if (query.subCounty) {
projects.andWhere('q.SubCounty IN (:...subCounty)', {
subCounty: [query.subCounty],
});
}


return await projects
.groupBy('q.County, Keph_level')
.orderBy('Keph_level')
.orderBy('County')
.distinct(true)
.getRawMany();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 { GetFacilityLevelByOwnershipPartnerQuery } from '../impl/get-facility-level-by-ownership-partner.query';

@QueryHandler(GetFacilityLevelByOwnershipPartnerQuery)
export class GetFacilityLevelByOwnershipPartnerHandler implements IQueryHandler<GetFacilityLevelByOwnershipPartnerQuery> {
constructor(
@InjectRepository(AllEmrSites, 'mssql')
private readonly repository: Repository<AllEmrSites>,
) {}

async execute(query: GetFacilityLevelByOwnershipPartnerQuery): Promise<any> {
const projects = this.repository
.createQueryBuilder('q')
.select('COUNT(1) facilities, PartnerName, Keph_level')
.where('Keph_level is not null');

if (query.county) {
projects.andWhere('q.County IN (:...county)', {
county: [query.county],
});
}

if (query.subCounty) {
projects.andWhere('q.SubCounty IN (:...subCounty)', {
subCounty: [query.subCounty],
});
}


return await projects
.groupBy('q.PartnerName, Keph_level')
.orderBy('Keph_level')
.orderBy('PartnerName')
.distinct(true)
.getRawMany();
}
}
41 changes: 41 additions & 0 deletions src/common/queries/handlers/get-facility-linelist.handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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 { GetFacilityLinelistQuery } from '../impl/get-facility-linelist.query';

@QueryHandler(GetFacilityLinelistQuery)
export class GetFacilityLinelistHandler implements IQueryHandler<GetFacilityLinelistQuery> {
constructor(
@InjectRepository(AllEmrSites, 'mssql')
private readonly repository: Repository<AllEmrSites>,
) {}

async execute(query: GetFacilityLinelistQuery): Promise<any> {
const projects = this.repository
.createQueryBuilder('q')
.select(
`MFLCode, FacilityName, SubCounty, County,
[PartnerName], [AgencyName],[EMR_Status],[EMR]
,[owner],[InfrastructureType], [KEPH_Level]`
);

if (query.county) {
projects.andWhere('q.County IN (:...county)', {
county: [query.county],
});
}

if (query.subCounty) {
projects.andWhere('q.SubCounty IN (:...subCounty)', {
subCounty: [query.subCounty],
});
}


return await projects
.orderBy('MFLCode')
.distinct(true)
.getRawMany();
}
}
Loading

0 comments on commit 6717916

Please sign in to comment.