Skip to content

Commit

Permalink
Merge branch 'master' into POC-654
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqedme authored Feb 15, 2024
2 parents 775ede9 + a312ebe commit c557bd6
Show file tree
Hide file tree
Showing 24 changed files with 1,568 additions and 3 deletions.
45 changes: 45 additions & 0 deletions src/app/clinic-dashboard/hiv/ahd-report/ahd-report.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Component, OnInit } from '@angular/core';
import { AhdReportBaseComponent } from 'src/app/hiv-care-lib/ahd-monthly-report/ahd-report-base/ahd-report-base.component';
import { Router, ActivatedRoute } from '@angular/router';
import { AhdResourceService } from 'src/app/etl-api/ahd-resource.service';
import * as Moment from 'moment';
@Component({
selector: 'ahd-reports',
templateUrl:
'../../../hiv-care-lib/ahd-monthly-report/ahd-report-base/ahd-report-base.component.html'
})
export class AhdReportComponent
extends AhdReportBaseComponent
implements OnInit {
constructor(
public router: Router,
public route: ActivatedRoute,
public ahdReport: AhdResourceService
) {
super(router, route, ahdReport);
}
public params: any;
public prepReportSummaryData: any = [];
public columnDefs: any = [];

public statusError = false;
public errorMessage = '';
public showInfoMessage = false;
public isLoading = false;
ngOnInit() {
this.params = { _month: Moment().format('YYYY-MM-DD') };
this.route.queryParams.subscribe(
(params: any) => {
if (params && params.month) {
this.isLoading = true;
this.params = params;
this.generateReport();
}
},
(error) => {
console.error('Error', error);
this.showInfoMessage = true;
}
);
}
}
2 changes: 2 additions & 0 deletions src/app/clinic-dashboard/hiv/hiv-program.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { BsDatepickerModule } from 'ngx-bootstrap';
import { ClinicDashboardRetentionReportComponent } from './retention-report/clinic-dashboard-retention-report.component';
import { ClinicDashboardCaseManagementComponent } from './case-management/clinic-dashboard-case-management.component';
import { PrepReportComponent } from './prep-report/prep-report.component';
import { AhdReportComponent } from './ahd-report/ahd-report.component';
import { ClinicDashboardHeiReportComponent } from './clinic-dashboard-hei-indicators-report/clinic-dashboard-hei-report.component';
import { ClinicDashboardPmtctRriReportComponent } from './clinic-dashboard-pmtct-rri-report/clinic-dashboard-pmtct-rri-report.component';

Expand Down Expand Up @@ -178,6 +179,7 @@ import { PlhivNcdV2ReportComponent } from './plhiv-ncd-v2-report/plhiv-ncd-v2-re
ClinicDashboardRetentionReportComponent,
ClinicDashboardCaseManagementComponent,
PrepReportComponent,
AhdReportComponent,
ClinicDashboardHeiReportComponent,
ClinicDashboardPmtctRriReportComponent,
HIVListsMicroFrontendComponent,
Expand Down
15 changes: 15 additions & 0 deletions src/app/clinic-dashboard/hiv/hiv-program.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { ChartAbstractionPatientlistComponent } from 'src/app/hiv-care-lib/dqa-r
import { ClinicDashboardCaseManagementComponent } from './case-management/clinic-dashboard-case-management.component';
import { PrepReportComponent } from './prep-report/prep-report.component';
import { PrepReportPatientListComponent } from 'src/app/hiv-care-lib/prep-report/prep-report-patient-list/prep-report-patient-list.component';
import { AhdReportComponent } from './ahd-report/ahd-report.component';
import { AhdMonthlyReportPatientlistComponent } from 'src/app/hiv-care-lib/ahd-monthly-report/ahd-monthly-report-patientlist/ahd-monthly-report-patientlist.component';
import { MonthlyReportComponent } from 'src/app/hiv-care-lib/monthly-report/monthly-report.component';
// tslint:disable-next-line: max-line-length
import { ClinicDashboardGainsAndLossesComponent } from './patient-gain-and-loses-report/clinic-dashboard-gains-and-losses.component';
Expand Down Expand Up @@ -487,6 +489,19 @@ const routes: Routes = [
component: PlhivNcdV2ReportPatientListComponent
}
]
},
{
path: 'ahd-monthly-report',
children: [
{
path: '',
component: AhdReportComponent
},
{
path: 'patient-list',
component: AhdMonthlyReportPatientlistComponent
}
]
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Router, ActivatedRoute } from '@angular/router';
import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common';
import { take } from 'rxjs/operators';
import * as rison from 'rison-node';
import * as Moment from 'moment';

import { AhdReportBaseComponent } from 'src/app/hiv-care-lib/ahd-monthly-report/ahd-report-base/ahd-report-base.component';
import { DataAnalyticsDashboardService } from '../../services/data-analytics-dashboard.services';
import { AhdResourceService } from 'src/app/etl-api/ahd-resource.service';

@Component({
selector: 'ahd-report',
templateUrl:
'../../../hiv-care-lib/ahd-monthly-report/ahd-report-base/ahd-report-base.component.html'
})
export class AhdReportComponent
extends AhdReportBaseComponent
implements OnInit {
public enabledControls = 'locationControl,monthControl';

constructor(
public router: Router,
public route: ActivatedRoute,
public ahdReport: AhdResourceService,
private dataAnalyticsDashboardService: DataAnalyticsDashboardService,
private location: Location
) {
super(router, route, ahdReport);
}

public ngOnInit() {
this.loadReportParamsFromUrl();
}

public generateReport() {
this.setSelectedLocation();
this.storeParamsInUrl();

if (Array.isArray(this.locationUuids) && this.locationUuids.length > 0) {
this.params = {
locationUuids: this.getSelectedLocations(this.locationUuids),
month: this._month
};
super.generateReport();
super.showDraftReportAlert(this._month);
} else {
this.errorMessage = 'Locations are required!';
}
}

public storeParamsInUrl() {
const state = {
locationUuids: this.getSelectedLocations(this.locationUuids),
month: this._month
};
const stateUrl = rison.encode(state);
const path = this.router.parseUrl(this.location.path());
path.queryParams = {
state: stateUrl
};

this.location.replaceState(path.toString());
}

public loadReportParamsFromUrl() {
const path = this.router.parseUrl(this.location.path());
if (path.queryParams['state']) {
const state = rison.decode(path.queryParams['state']);
this.locationUuids = state.locations;
this.month = state.month;
}

if (path.queryParams['state']) {
this.generateReport();
}
}

public setSelectedLocation() {
this.dataAnalyticsDashboardService
.getSelectedLocations()
.pipe(take(1))
.subscribe((data) => {
if (data) {
this.locationUuids = data.locations;
}
});
}

private getSelectedLocations(locationUuids: Array<any>): string {
return locationUuids.map((location) => location.value).join(',');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { TxNewReportComponent } from './datim-reports/tx-new-report/tx-new-repor
import { TxCurrReportComponent } from './datim-reports/tx-curr-report.component';
import { TxMmdReportComponent } from './datim-reports/tx-mmd-report.component';
import { TxRttReportComponent } from './datim-reports/tx-rtt-report.component';
import { AhdReportComponent } from './ahd-report/ahd-report.component';
import { PlhivNcdV2ReportComponent } from './plhiv-ncd-v2-report/plhiv-ncd-v2-report.component';

@NgModule({
Expand Down Expand Up @@ -95,7 +96,8 @@ import { PlhivNcdV2ReportComponent } from './plhiv-ncd-v2-report/plhiv-ncd-v2-re
TxCurrReportComponent,
TxMmdReportComponent,
TxRttReportComponent,
PlhivNcdV2ReportComponent
PlhivNcdV2ReportComponent,
AhdReportComponent
],
providers: [
DataAnalyticsDashboardService,
Expand Down
15 changes: 15 additions & 0 deletions src/app/data-analytics-dashboard/hiv/data-analytics-hiv.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import { TxMmdReportPatientListComponent } from 'src/app/hiv-care-lib/tx-mmd-rep
import { TxMmdReportComponent } from './datim-reports/tx-mmd-report.component';
import { TxRttReportComponent } from './datim-reports/tx-rtt-report.component';
import { TxRttReportPatientListComponent } from 'src/app/hiv-care-lib/tx-rtt-report/tx-rtt-report-patient-list/tx-rtt-report-patient-list.component';
import { AhdReportComponent } from './ahd-report/ahd-report.component';
import { AhdMonthlyReportPatientlistComponent } from 'src/app/hiv-care-lib/ahd-monthly-report/ahd-monthly-report-patientlist/ahd-monthly-report-patientlist.component';
import { PlhivNcdV2ReportPatientListComponent } from 'src/app/hiv-care-lib/plhiv-ncd-v2-report/plhiv-ncd-v2-report-patient-list/plhiv-ncd-v2-report-patient-list.component';
import { PlhivNcdV2ReportComponent } from './plhiv-ncd-v2-report/plhiv-ncd-v2-report.component';

Expand Down Expand Up @@ -267,6 +269,19 @@ const routes: Routes = [
component: PlhivNcdV2ReportPatientListComponent
}
]
},
{
path: 'ahd-monthly-report',
children: [
{
path: '',
component: AhdReportComponent
},
{
path: 'patient-list',
component: AhdMonthlyReportPatientlistComponent
}
]
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export class DataAnalyticsMonthlyReportComponent implements OnInit {
description: '',
url: 'plhiv-ncd-v2-monthly-report',
icon: 'fa'
},
{
title: 'AHD Monthly Report',
description: '',
url: 'ahd-monthly-report',
icon: 'fa'
}
];
}
Expand Down
109 changes: 109 additions & 0 deletions src/app/etl-api/ahd-resource.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { Injectable } from '@angular/core';
import { AppSettingsService } from '../app-settings/app-settings.service';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import * as Moment from 'moment';
import { catchError, map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class AhdResourceService {
public get url(): string {
return this.appSettingsService.getEtlRestbaseurl().trim();
}
constructor(
public http: HttpClient,
public appSettingsService: AppSettingsService
) {}
public getAhdMonthlyReport(params: any): Observable<any> {
// tslint:disable-next-line: max-line-length

const stardDate = this.getDates(params.month).currentMonthFirstDate;
return this.http
.get(
`${this.url}ahd-monthly-summary?endDate=${params.month}&startDate=${stardDate}&locationUuids=${params.locationUuids}`
)
.pipe(
catchError((err: any) => {
const error: any = err;
const errorObj = {
error: error.status,
message: error.statusText
};
return Observable.of(errorObj);
}),
map((response: Response) => {
return response;
})
);
}
public getDates(currentEndDate) {
// Convert the currentEndDate string to a Date object
const currentDate = new Date(currentEndDate);

// Get the current month and year
const currentMonth = currentDate.getMonth();
const currentYear = currentDate.getFullYear();

// Calculate the previous month's last date
const previousMonthLastDate = new Date(
currentYear,
currentMonth,
0
).getDate();

// Calculate the current month's end date
const currentMonthEndDate = new Date(
currentYear,
currentMonth + 1,
0
).getDate();

// Calculate the current month's first date
const currentMonthFirstDate = new Date(currentYear, currentMonth, 1);

// Format the dates as strings in the "YYYY-MM-DD" format
const previousMonthLastDateString =
currentYear +
'-' +
currentMonth.toString().padStart(2, '0') +
'-' +
previousMonthLastDate.toString().padStart(2, '0');

const currentMonthEndDateString = currentEndDate;
const currentMonthFirstDateString =
currentMonthFirstDate.getFullYear() +
'-' +
(currentMonthFirstDate.getMonth() + 1).toString().padStart(2, '0') +
'-' +
currentMonthFirstDate.getDate().toString().padStart(2, '0');

// Return the formatted dates
return {
currentMonthFirstDate: currentMonthFirstDateString
};
}

public getAhdPatientList(params: any, locationUuid: string): Observable<any> {
// tslint:disable-next-line: max-line-length
const stardDate = this.getDates(params.month).currentMonthFirstDate;

return this.http
.get(
`${this.url}ahd-monthly-summary-patient-list?indicators=${params.indicators}&startDate=${stardDate}&endDate=${params.month}&locationUuids=${params.locationUuids}`
)
.pipe(
catchError((err: any) => {
const error: any = err;
const errorObj = {
error: error.status,
message: error.statusText
};
return Observable.of(errorObj);
}),
map((response: Response) => {
return response;
})
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div>
<button class="btn btn-primary" (click)="goBack()">
<span class="glyphicon glyphicon-arrow-left"></span>
<span>Go back to report view</span>
</button>
</div>
<div class="loader" *ngIf="isLoading">
<span><i class="fa fa-spinner fa-spin"></i>Loading...</span>
</div>
<h3>
<b>{{ selectedIndicatorGender }} {{ selectedIndicator }}</b> patient list
</h3>
<hr />
<patient-list
[extraColumns]="extraColumns"
[overrideColumns]="overrideColumns"
[data]="patientData"
></patient-list>

<div *ngIf="hasLoadedAll">
<p class="bg-info" style="padding: 4px">
<b>
<span style="color: green" class="glyphicon glyphicon-ok"
>All records loaded {{ '[ ' + patientData.length + ' ]' }}</span
></b
>
</p>

<p></p>
</div>

<div *ngIf="hasError">
<p class="alert-error alert">Error loading patient list.</p>
</div>
Loading

0 comments on commit c557bd6

Please sign in to comment.