Skip to content

Commit

Permalink
initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
sainingo committed Nov 4, 2024
1 parent d60b7f7 commit 8a32b23
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/app/etl-api/khis-air-resource.service.ts
Original file line number Diff line number Diff line change
@@ -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<any> | null {
if (!payload) {
return null;
}
return this.http.post(this.getMoh731KHisToAirUrl(), payload);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ <h4 *ngIf="!statusError">
[sectionDefs]="sectionsDef"
(indicatorSelected)="onIndicatorSelected($event)"
[rowData]="data"
[startDate]="startDate"
[endDate]="endDate"
[isReleased]="isReleased"
></moh-731-tabular>
</p-tabPanel>
Expand Down
12 changes: 12 additions & 0 deletions src/app/hiv-care-lib/moh-731-report/moh-731-tabular.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@
[gridOptions]="gridOptions"
>
</ag-grid-angular>

<div class="row" style="margin-top: 8px; margin-right: 8px; padding: 0px">
<button
type="button"
*ngIf="!parentIsBusy"
class="btn btn-primary pull-right"
(click)="getCombinedData()"
>
Sync Data
</button>
</div>

65 changes: 64 additions & 1 deletion src/app/hiv-care-lib/moh-731-report/moh-731-tabular.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -17,13 +20,20 @@ export class Moh731TabularComponent implements OnInit {
public gridOptions: any = {
columnDefs: []
};
public headerTitles = [];

@Output() public indicatorSelected = new EventEmitter<any>();

// tslint:disable-next-line:no-input-rename
@Input('rowData')
public data: Array<any> = [];

@Input('startDate')
public startDate: any;

@Input('endDate')
public endDate: any;

@ViewChild('agGrid')
public agGrid: AgGridNg2;

Expand All @@ -40,7 +50,9 @@ export class Moh731TabularComponent implements OnInit {

@Input() public isReleased: boolean;

constructor() {}
constructor(
private khisAirModuleResourceService: KhisAirModuleResourceService
) {}

public ngOnInit() {
this.setCellSelection();
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
);
}
}
}

0 comments on commit 8a32b23

Please sign in to comment.