Skip to content

Commit

Permalink
Fix issue of incorrect appointments count in appointments overview (#121
Browse files Browse the repository at this point in the history
)
  • Loading branch information
maikofelix47 authored Sep 23, 2022
1 parent 5347f46 commit f0ffb33
Showing 1 changed file with 59 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ import * as moment_ from 'moment';

const moment = moment_;

interface DailyScheduled {
date: string;
count: {
scheduled: number;
};
}
interface WeeeklyScheduleReport {
reports: {
attended: any;
hasNotReturned: any;
scheduled: any;
};
results: DailyScheduled[];
totals: {
attended: number;
hasNotReturned: number;
scheduled: number;
};
}
interface DayCount {
date: string;
count: number;
}

@Component({
selector: 'appointments-overview',
templateUrl: './appointments-overview.component.html',
Expand Down Expand Up @@ -55,49 +79,53 @@ export class AppointmentsOverviewComponent implements OnInit, OnChanges {
.subtract(1, 'day')
.format('YYYY-MM-DD');
this.today = moment(v).format('DD-MM-YYYY');
// create 5 week days
const _data = [];
const programTypes = [
'781d85b0-1359-11df-a1f1-0026b9348838',
'781d897a-1359-11df-a1f1-0026b9348838',
'96047aaf-7ab3-45e9-be6a-b61810fe617d',
'c19aec66-1a40-4588-9b03-b6be55a8dd1d',
'f7793d42-11ac-4cfd-9b35-e0a21a7a7c31',
'334c9e98-173f-4454-a8ce-f80b20b7fdf0',
'96ba279b-b23b-4e78-aba9-dcbd46a96b7b',
'781d8880-1359-11df-a1f1-0026b9348838'
];
const programTypeParams = programTypes.join();
for (let i = 1; i <= 5; i++) {
_data.push({
date: moment(v)
.startOf('week')
.add(i, 'day')
.format('DD-MM-YYYY'),
count: 0
});
}
dataSource
.getMonthlySchedule({
startDate: startDate,
endDate: endDate,
limit: 5,
locationUuids: locationUuid,
programType: programTypeParams
department: 'HIV',
groupBy: 'groupByPerson,groupByAttendedDate,groupByRtcDate'
})
.subscribe(
(data) => {
(data: WeeeklyScheduleReport) => {
const _data: DayCount[] = [];
const weeklyMap = new Map();
// create the weeks schedule with zero appointments
for (let i = 0; i < 5; i++) {
const scheduleDate = moment(v)
.startOf('week')
.add(i, 'day')
.format('YYYY-MM-DD');
const scheduledObj: DailyScheduled = {
date: scheduleDate,
count: {
scheduled: 0
}
};
weeklyMap.set(scheduleDate, scheduledObj);
}

const results: DailyScheduled[] = data.results || [];
// replace placeholder schedules with actual schedules in the map obj
results.forEach((scheduled: DailyScheduled) => {
weeklyMap.set(scheduled.date, scheduled);
});
// retrieve scheduled obj from map to data array
weeklyMap.forEach((value: DailyScheduled, key: string) => {
const dayCount: DayCount = {
date: key,
count: value.count.scheduled || 0
};
_data.push(dayCount);
});
this.appointmentsLoaded = true;
this.loadingAppointments = false;
_data.map((appointment, index) => {
appointment.count =
data.results[index] !== undefined
? data.results[index].count.scheduled
: 0;
});

this.appointments = _data;
},
(error) => {
(error: any) => {
this.loadingAppointments = false;
this.errorLoadingAppointments = true;
this.showAppointments = false;
Expand Down

0 comments on commit f0ffb33

Please sign in to comment.