Skip to content

Commit

Permalink
POC-581: Develop Defaulter tracing register in POC
Browse files Browse the repository at this point in the history
  • Loading branch information
henrykorir committed Mar 25, 2024
1 parent ca10afe commit 933c666
Show file tree
Hide file tree
Showing 15 changed files with 1,271 additions and 637 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { TestBed, inject } from '@angular/core/testing';

import { DefaulterTracingRegisterResourceService } from './defaulter-tracing-register-resource.service';

describe('DefaulterTracingRegisterResourceService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [DefaulterTracingRegisterResourceService]
});
});

it('should be created', inject(
[DefaulterTracingRegisterResourceService],
(service: DefaulterTracingRegisterResourceService) => {
expect(service).toBeTruthy();
}
));
});
63 changes: 63 additions & 0 deletions src/app/etl-api/defaulter-tracing-register-resource.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AppSettingsService } from '../app-settings/app-settings.service';
import { catchError, map } from 'rxjs/operators';
import { Observable } from 'rxjs';

@Injectable({
providedIn: 'root'
})
export class DefaulterTracingRegisterResourceService {
public get url(): string {
return this.appSettingsService.getEtlRestbaseurl().trim();
}

constructor(
public http: HttpClient,
public appSettingsService: AppSettingsService
) {}

public getDefaulterTracingRegisterMonthlyRegister(
params: any
): Observable<any> {
console.log('params2etl: ', params);
// tslint:disable-next-line: max-line-length
return this.http
.get(
`${this.url}defaulter-tracing-register?&month=${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;
})
);
}
public getDefaulterTracingRegisterPatientList(params: any): Observable<any> {
// tslint:disable-next-line: max-line-length
return this.http
.get(
`${this.url}defaulter-tracing-register-patient-list?startDate=${params.startDate}&endDate=${params.month}&locationUuids=${params.locationUuids}&indicators=${params.indicators}&currentView=${params.currentView}`
)
.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,30 @@
<div>
<button class="btn btn-primary" (click)="goBack()">
<span class="glyphicon glyphicon-arrow-left"></span>
<span> Back</span>
</button>
</div>
<div class="loader" *ngIf="isLoading">
<span><i class="fa fa-spinner fa-spin"></i>Loading...</span>
</div>
<h3>Defaulter Tracing Register patient list</h3>
<hr />
<patient-list
[extraColumns]="extraColumns"
[overrideColumns]="overrideColumns"
[data]="patientData"
></patient-list>
<div *ngIf="patientData">
<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { DefaulterPatientListComponent } from './defaulter-patient-list.component';

describe('DefaulterPatientListComponent', () => {
let component: DefaulterPatientListComponent;
let fixture: ComponentFixture<DefaulterPatientListComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DefaulterPatientListComponent]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DefaulterPatientListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Location } from '@angular/common';
import { DefaulterTracingRegisterResourceService } from 'src/app/etl-api/defaulter-tracing-register-resource.service';

@Component({
selector: 'app-defaulter-patient-list',
templateUrl: './defaulter-patient-list.component.html',
styleUrls: ['./defaulter-patient-list.component.css']
})
export class DefaulterPatientListComponent implements OnInit {
public params: any;
public patientData: any;
public extraColumns: Array<any> = [];
public isLoading = true;
public overrideColumns: Array<any> = [];
public selectedIndicator: string;
public selectedIndicatorGender: string;
public hasLoadedAll = false;
public hasError = false;
public selectedMonth: String;

constructor(
private router: Router,
private route: ActivatedRoute,
private _location: Location,
public dtrResourceService: DefaulterTracingRegisterResourceService
) {}

ngOnInit() {
this.route.queryParams.subscribe(
(params) => {
if (params && params.month) {
this.params = params;
this.selectedIndicator = params.indicatorHeader;
this.selectedIndicatorGender = params.indicatorGender;
this.getPatientList(params);
}
},
(error) => {
console.error('Error', error);
}
);
this.addExtraColumns();
}

private getPatientList(params: any) {
this.dtrResourceService
.getDefaulterTracingRegisterPatientList(params)
.subscribe((data) => {
this.isLoading = false;
this.patientData = data.results.results;
this.hasLoadedAll = true;
});
}

public addExtraColumns() {
const extraColumns = {
phone_number: 'Phone',
enrollment_date: 'Enrolment Date',
last_appointment: 'Last Appointment',
latest_rtc_date: 'Latest RTC Date',
days_since_rtc_date: 'Days since RTC',
arv_first_regimen: 'ARV first regimen',
arv_first_regimen_start_date: 'First ARV start date',
cur_meds: 'Current Regimen',
cur_arv_line: 'Current ARV Line',
arv_start_date: 'ARV Start Date',
latest_vl: 'Latest VL',
vl_category: 'VL Category',
latest_vl_date: 'Latest VL Date',
previous_vl: 'Previous VL',
previous_vl_date: 'Previous VL Date',
ovcid_id: 'OVCID'
};

const status = this.selectedIndicatorGender.split(' - ')[0];
if (status === 'Died') {
Object.assign(extraColumns, {
death_date: 'Death Date',
cause_of_death: 'Cause of Death'
});
} else if (status === 'Transferred Out') {
Object.assign(extraColumns, {
transfer_out_date_v1: 'Transfer out date'
});
}
for (const indicator in extraColumns) {
if (indicator) {
this.extraColumns.push({
headerName: extraColumns[indicator],
field: indicator
});
}
}

this.overrideColumns.push(
{
field: 'identifiers',
cellRenderer: (column) => {
return (
'<a href="javascript:void(0);" title="Identifiers">' +
column.value +
'</a>'
);
}
},
{
field: 'last_appointment',
width: 200
},
{
field: 'cur_prep_meds_names',
width: 160
}
);
}

public goBack() {
this._location.back();
}
}
Loading

0 comments on commit 933c666

Please sign in to comment.