Skip to content

Commit

Permalink
POC-737: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred-Mutai committed Oct 25, 2024
1 parent dd81d59 commit ab8cf0d
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 783 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { Component, OnInit, Output } from '@angular/core';
import { DatePipe } from '@angular/common';
import {
Component,
ElementRef,
OnInit,
Output,
ViewChild
} from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import * as _ from 'lodash';
import * as Moment from 'moment';
import { DataAnalyticsDashboardService } from 'src/app/data-analytics-dashboard/services/data-analytics-dashboard.services';
import { ANCRegisterResourceService } from 'src/app/etl-api/anc-register-resource.service';
import * as html2canvas from 'html2canvas';
import * as jsPDF from 'jspdf';
@Component({
selector: 'app-anc-register',
templateUrl: './anc-register.component.html',
Expand All @@ -12,26 +23,28 @@ export class AncRegisterComponent implements OnInit {
public params: any;
public indicators: string;
public selectedIndicators = [];
public txnewReportSummaryData: any = [];
public ancRegisterData: any = [];
public columnDefs: any = [];
public reportName = 'ANC Register';
public reportName = 'AnteNatal (ANC) Register MOH 405';
public currentView = 'monthly';
public currentViewBelow = 'pdf';
public month: string;
public year: number;
public quarter: string;
public eDate: string;
public sDate: string;
public jointLocationUuids: string;

public statusError = false;
public errorMessage = '';
public showInfoMessage = false;
public isLoading = false;
public reportHead: any;
public enabledControls = 'locationControl,monthControl';
public enabledControls = 'locationControl,dayControl';
public pinnedBottomRowData: any = [];
public _month: string;
public isReleased = true;
@ViewChild('cntdarcontentToSnapshot') contentToSnapshot!: ElementRef;

public _locationUuids: any = [];
public get locationUuids(): Array<string> {
Expand All @@ -48,13 +61,16 @@ export class AncRegisterComponent implements OnInit {
this._locationUuids = locationUuids;
}

constructor(public router: Router, public route: ActivatedRoute) {
constructor(
public router: Router,
public route: ActivatedRoute,
public ancRegisterService: ANCRegisterResourceService,
private datePipe: DatePipe,
private dataAnalyticsDashboardService: DataAnalyticsDashboardService
) {
this.route.queryParams.subscribe((data) => {
data.month === undefined
? (this._month = Moment()
.subtract(1, 'M')
.endOf('month')
.format('YYYY-MM-DD'))
? (this._month = Moment().format('YYYY-MM-DD'))
: (this._month = data.month);

this.showDraftReportAlert(this._month);
Expand All @@ -64,56 +80,62 @@ export class AncRegisterComponent implements OnInit {
ngOnInit() {}

public onMonthChange(value): any {
this._month = Moment(value).endOf('month').format('YYYY-MM-DD');
this._month = Moment(value).format('YYYY-MM-DD');
}

public generateReport(): any {
this.dataAnalyticsDashboardService
.getSelectedLocations()
.subscribe((data) => {
const locationValues = data.locations.map(
(location) => `'${location.value}'`
);
this.jointLocationUuids = locationValues.join(', ');
});

this.route.parent.parent.params.subscribe((params: any) => {
this.storeParamsInUrl(params.location_uuid);
this.storeParamsInUrl();
});
this.txnewReportSummaryData = [];
// this.getTxNewReport(this.params);
this.ancRegisterData = [];
this.getANCRegisterData(this.params);
}

public storeParamsInUrl(param) {
public storeParamsInUrl() {
this.params = {
locationUuids: param,
_month: Moment(this._month).endOf('month').format('YYYY-MM-DD'),
month: Moment(this._month).endOf('month').format('YYYY-MM-DD'),
reportName: this.reportName,
_date: Moment(this._month).format('DD-MM-YYYY')
locationUuids: this.jointLocationUuids,
month: Moment(this._month).format('YYYY-MM-DD')
};
this.router.navigate([], {
relativeTo: this.route,
queryParams: this.params
});
}

// public getTxNewReport(params: any) {
// this.isLoading = true;
// this.txnewReport.getTxNewReport(params).subscribe((data) => {
// if (data.error) {
// this.showInfoMessage = true;
// this.errorMessage = `There has been an error while loading the report, please retry again`;
// this.isLoading = false;
// } else {
// this.showInfoMessage = false;
// this.columnDefs = data.sectionDefinitions;
// this.txnewReportSummaryData = data.result;
// this.calculateTotalSummary();
// this.isLoading = false;
// this.showDraftReportAlert(this._month);
// }
// });
// }
public getANCRegisterData(params: any) {
this.isLoading = true;
this.ancRegisterService.getANCRegisterRegister(params).subscribe((data) => {
if (data.error) {
this.showInfoMessage = true;
this.errorMessage = `There has been an error while loading the report, please retry again`;
this.isLoading = false;
} else {
this.showInfoMessage = false;
this.columnDefs = data.sectionDefinitions;
this.ancRegisterData = data;
this.calculateTotalSummary();
this.isLoading = false;
this.showDraftReportAlert(this._month);
}
});
}

public calculateTotalSummary() {
const totalsRow = [];
if (this.txnewReportSummaryData.length > 0) {
if (this.ancRegisterData.length > 0) {
const totalObj = {
location: 'Totals'
};
_.each(this.txnewReportSummaryData, (row) => {
_.each(this.ancRegisterData, (row) => {
Object.keys(row).map((key) => {
if (Number.isInteger(row[key]) === true) {
if (totalObj[key]) {
Expand Down Expand Up @@ -152,10 +174,27 @@ export class AncRegisterComponent implements OnInit {
}

public showDraftReportAlert(date) {
if (date != null && date >= Moment().endOf('month').format('YYYY-MM-DD')) {
if (date != null && date >= Moment().format('YYYY-MM-DD')) {
this.isReleased = false;
} else {
this.isReleased = true;
}
}

transformDate(date: string): string | null {
return this.datePipe.transform(date, 'dd/MM/yyyy');
}

public takeSnapshotAndExport() {
const elementToSnapshot = this.contentToSnapshot.nativeElement;

html2canvas(elementToSnapshot).then((canvas) => {
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF('p', 'mm', 'a4');
const imgWidth = 210; // A4 width in mm
const imgHeight = (canvas.height * imgWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, imgWidth, imgHeight);
pdf.save('MOH 405 ANC Register.pdf');
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ <h4 class="component-title text-success">
<p-tabPanel header="Monthly" leftIcon="fa-calendar-o">
<report-filters
[enabledControls]="enabledControls"
[monthString]="_month"
(onMonthChange)="onMonthChange($event)"
(startDateChange)="onMonthChange($event)"
[startDate]="_month"
[reportName]="reportName"
(generateReport)="generateReport()"
>
Expand All @@ -31,10 +31,6 @@ <h4 *ngIf="!statusError">
<small>{{ errorMessage }}</small>
</p>
</div>
<div *ngIf="!isReleased" class="alert alert-warning">
<strong>Viewing a Draft Version of the Report for the chosen month. </strong>
This report is likely to change without warning.
</div>

<div
class="btn-group pull-left"
Expand Down Expand Up @@ -199,16 +195,13 @@ <h4 *ngIf="!statusError">
>
<tr>
<td rowspan="2">{{ a + 1 }}</td>
<td colspan="2" rowspan="2">{{ data.DATE }}</td>
<td colspan="3">{{ data.National_ID }}</td>
<td colspan="2" rowspan="2">{{ data.date | date:'dd/MM/yyyy' }}</td>
<td colspan="3">{{ data.national_id_number }}</td>
<td colspan="3" rowspan="2">
{{ data.CCC_Number }}
{{ data.ccc_number }}
</td>
<td rowspan="2">{{ data.Age }}</td>
<td rowspan="2"></td>
<td rowspan="2"></td>
<td rowspan="2"></td>
<td rowspan="2"></td>
<td rowspan="2">{{ data.age }}</td>
<td rowspan="2">{{data.started_on_art}}</td>
<td rowspan="2"></td>
<td rowspan="2"></td>
<td rowspan="2"></td>
Expand All @@ -222,8 +215,11 @@ <h4 *ngIf="!statusError">
<td rowspan="2"></td>
<td rowspan="2"></td>
<td rowspan="2"></td>
<td rowspan="2">{{data.screened_for_tb}}</td>
<td rowspan="2"></td>
<td rowspan="2">{{data.started_on_tpt}}</td>
<td rowspan="2"></td>
<td rowspan="2">{{data.current_on_art}}</td>
<td rowspan="2"></td>
<td rowspan="2"></td>
<td rowspan="2"></td>
Expand All @@ -237,9 +233,9 @@ <h4 *ngIf="!statusError">
<td rowspan="2"></td>
<td rowspan="2"></td>
<td rowspan="2"></td>
<td colspan="2" rowspan="2"></td>
<td colspan="2" rowspan="2"></td>
<td colspan="4" rowspan="2"></td>
<td colspan="2" rowspan="2">{{data.dsd_status}}</td>
<td colspan="2" rowspan="2">{{data.dsd_type}}</td>
<td colspan="4" rowspan="2">{{data.remarks}}</td>
</tr>
<tr>
<td colspan="3">{{ data.NUPI }}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class CntdailyRegisterComponent implements OnInit {
public showInfoMessage = false;
public isLoading = false;
public reportHead: any;
public enabledControls = 'locationControl,monthControl';
public enabledControls = 'locationControl,dayControl';
public pinnedBottomRowData: any = [];
public _month: string;
public isReleased = true;
Expand Down Expand Up @@ -70,10 +70,7 @@ export class CntdailyRegisterComponent implements OnInit {
) {
this.route.queryParams.subscribe((data) => {
data.month === undefined
? (this._month = Moment()
.subtract(1, 'M')
.endOf('month')
.format('YYYY-MM-DD'))
? (this._month = Moment().format('YYYY-MM-DD'))
: (this._month = data.month);

this.showDraftReportAlert(this._month);
Expand All @@ -83,7 +80,7 @@ export class CntdailyRegisterComponent implements OnInit {
ngOnInit() {}

public onMonthChange(value): any {
this._month = Moment(value).endOf('month').format('YYYY-MM-DD');
this._month = Moment(value).format('YYYY-MM-DD');
}

public generateReport(): any {
Expand All @@ -106,7 +103,7 @@ export class CntdailyRegisterComponent implements OnInit {
public storeParamsInUrl() {
this.params = {
locationUuids: this.jointLocationUuids,
month: Moment(this._month).endOf('month').format('YYYY-MM-DD')
month: Moment(this._month).format('YYYY-MM-DD')
};
this.router.navigate([], {
relativeTo: this.route,
Expand Down Expand Up @@ -180,7 +177,7 @@ export class CntdailyRegisterComponent implements OnInit {
}

public showDraftReportAlert(date) {
if (date != null && date >= Moment().endOf('month').format('YYYY-MM-DD')) {
if (date != null && date >= Moment().format('YYYY-MM-DD')) {
this.isReleased = false;
} else {
this.isReleased = true;
Expand Down
Loading

0 comments on commit ab8cf0d

Please sign in to comment.