diff --git a/src/app/etl-api/khis-air-resource.service.ts b/src/app/etl-api/khis-air-resource.service.ts new file mode 100644 index 000000000..645399e42 --- /dev/null +++ b/src/app/etl-api/khis-air-resource.service.ts @@ -0,0 +1,27 @@ +import { Injectable } from '@angular/core'; +import { AppSettingsService } from '../app-settings/app-settings.service'; +import { Observable } from 'rxjs'; +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; + +@Injectable({ + providedIn: 'root' +}) +export class KhisAirModuleResourceService { + constructor( + private http: HttpClient, + private appSettingsService: AppSettingsService + ) {} + + private getMoh731KHisToAirUrl(): string { + return ( + this.appSettingsService.getEtlRestbaseurl().trim() + 'extract-moh-731' + ); + } + + public postMOH731ExtractedData(payload: any): Observable | null { + if (!payload) { + return null; + } + return this.http.post(this.getMoh731KHisToAirUrl(), payload); + } +} diff --git a/src/app/hiv-care-lib/moh-731-report/moh-731-report-base.component.html b/src/app/hiv-care-lib/moh-731-report/moh-731-report-base.component.html index 6017cf522..a45f7977e 100644 --- a/src/app/hiv-care-lib/moh-731-report/moh-731-report-base.component.html +++ b/src/app/hiv-care-lib/moh-731-report/moh-731-report-base.component.html @@ -64,6 +64,8 @@

[sectionDefs]="sectionsDef" (indicatorSelected)="onIndicatorSelected($event)" [rowData]="data" + [startDate]="startDate" + [endDate]="endDate" [isReleased]="isReleased" > diff --git a/src/app/hiv-care-lib/moh-731-report/moh-731-tabular.component.html b/src/app/hiv-care-lib/moh-731-report/moh-731-tabular.component.html index 26dd38450..a8bcfd0ae 100644 --- a/src/app/hiv-care-lib/moh-731-report/moh-731-tabular.component.html +++ b/src/app/hiv-care-lib/moh-731-report/moh-731-tabular.component.html @@ -10,3 +10,15 @@ [gridOptions]="gridOptions" > + +
+ +
+ diff --git a/src/app/hiv-care-lib/moh-731-report/moh-731-tabular.component.ts b/src/app/hiv-care-lib/moh-731-report/moh-731-tabular.component.ts index 5fd57b309..7ef3ad13d 100644 --- a/src/app/hiv-care-lib/moh-731-report/moh-731-tabular.component.ts +++ b/src/app/hiv-care-lib/moh-731-report/moh-731-tabular.component.ts @@ -7,7 +7,10 @@ import { ViewChild, EventEmitter } from '@angular/core'; +import { ColDef, ColGroupDef } from 'ag-grid'; import { AgGridNg2 } from 'ag-grid-angular'; +import { KhisAirModuleResourceService } from 'src/app/etl-api/khis-air-resource.service'; +// import {KhisAirModuleResourceService} from "" @Component({ selector: 'moh-731-tabular', templateUrl: 'moh-731-tabular.component.html' @@ -17,6 +20,7 @@ export class Moh731TabularComponent implements OnInit { public gridOptions: any = { columnDefs: [] }; + public headerTitles = []; @Output() public indicatorSelected = new EventEmitter(); @@ -24,6 +28,12 @@ export class Moh731TabularComponent implements OnInit { @Input('rowData') public data: Array = []; + @Input('startDate') + public startDate: any; + + @Input('endDate') + public endDate: any; + @ViewChild('agGrid') public agGrid: AgGridNg2; @@ -40,7 +50,9 @@ export class Moh731TabularComponent implements OnInit { @Input() public isReleased: boolean; - constructor() {} + constructor( + private khisAirModuleResourceService: KhisAirModuleResourceService + ) {} public ngOnInit() { this.setCellSelection(); @@ -68,6 +80,7 @@ export class Moh731TabularComponent implements OnInit { created.children.push(child); } defs.push(created); + this.headerTitles.push(section.sectionTitle); } this.gridOptions.columnDefs = defs; @@ -87,4 +100,54 @@ export class Moh731TabularComponent implements OnInit { this.indicatorSelected.emit(selectedIndicator); }; } + + public cleanHeaderTitles(titles: string[]): string[] { + return titles.map((title) => title.replace(/^\d+\.\s*/, '').trim()); + } + + public getCombinedData() { + const headerTitles = this.cleanHeaderTitles(this.headerTitles); + const month = new Date(this.startDate).toLocaleString('default', { + month: 'long' + }); + + if (this.agGrid && this.agGrid.api && this.agGrid.columnApi) { + // Get all rows data + const rowData: any[] = []; + this.agGrid.api.forEachNode((node: any) => rowData.push(node.data)); + + // Get column definitions + const allColumns = this.agGrid.columnApi.getAllColumns(); + const columnDefs = allColumns.map((col) => col.getColDef()); + + // Combine data and columns + const combinedData = rowData.map((row) => { + const rowDataWithColumns = {}; + columnDefs.forEach((colDef: ColDef) => { + rowDataWithColumns[colDef.headerName] = row[colDef.field]; + }); + return { + month: month, + // headerTitles, + Location: row.location, + ...rowDataWithColumns + // rowDataWithColumns: { + // ...rowDataWithColumns + // } + }; + }); + + this.khisAirModuleResourceService + .postMOH731ExtractedData(combinedData) + .subscribe( + (response: any) => { + console.log('API Response:', response); + // Handle successful response here + }, + (error: any) => { + console.error('API Error:', error); + } + ); + } + } }