Skip to content

Commit

Permalink
targets in target summary
Browse files Browse the repository at this point in the history
Signed-off-by: Diana Barsan <barsan@medic.org>
  • Loading branch information
dianabarsan committed Aug 29, 2024
1 parent d66140c commit b9c23ff
Show file tree
Hide file tree
Showing 33 changed files with 670 additions and 266 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,32 @@ let fields = [];
if (contact.type === 'person') {
// eslint-disable-next-line no-undef
fields = [{ label: 'test.pid', value: contact.patient_id, width: 3 }];
}
// eslint-disable-next-line no-undef
if (cht.v1.context.targetDocs[0]) {
// eslint-disable-next-line no-undef
const targetIdx = contact.type === 'person' ? 0 : 1;
// eslint-disable-next-line no-undef
const targetDoc = cht.v1.context.targetDocs[targetIdx];
const card = {
label: 'Activity this month',
fields: [],
};
// eslint-disable-next-line no-undef
card.fields.push({ label: 'Last updated', value: targetDoc.date_updated });
card.fields.push({ label: 'Reporting period', value: targetDoc.reporting_period });

// eslint-disable-next-line no-undef
if (targetDoc) {
const card = {
label: 'Activity this month',
fields: [],
};
// eslint-disable-next-line no-undef
card.fields.push({ label: 'Last updated', value: targetDoc.date_updated });
// eslint-disable-next-line no-undef
targetDoc.targets.forEach(target => {
let value;
if (target.type === 'percent') {
value = (target.value.total ? target.value.pass * 100 / target.value.total : 0) + '%';
} else {
value = target.value.pass;
}
card.fields.push({ label: target.title.en, value: value });
});
cards.push(card);
}
targetDoc.targets.forEach(target => {
let value;
if (target.type === 'percent') {
value = (target.value.total ? target.value.pass * 100 / target.value.total : 0) + '%';
} else {
value = target.value.pass;
}
card.fields.push({ label: target.title.en, value: value });
});
cards.push(card);
}
return {
fields: fields,
Expand Down
7 changes: 6 additions & 1 deletion webapp/src/ts/actions/global.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createAction, Store } from '@ngrx/store';

import { createSingleValueAction, createMultiValueAction } from '@mm-actions/actionUtils';
import { createMultiValueAction, createSingleValueAction } from '@mm-actions/actionUtils';

export const Actions = {
updateReplicationStatus: createSingleValueAction('UPDATE_REPLICATION_STATUS', 'replicationStatus'),
Expand Down Expand Up @@ -39,6 +39,7 @@ export const Actions = {
updateUnreadCount: createSingleValueAction('UPDATE_UNREAD_COUNT', 'unreadCount'),
setTranslationsLoaded: createAction('SET_TRANSLATIONS_LOADED'),
setUserFacilityId: createSingleValueAction('SET_USER_FACILITY_ID', 'userFacilityId'),
setUserContactId: createSingleValueAction('SET_USER_CONTACT_ID', 'userContactId'),
setTrainingCardFormId: createSingleValueAction('SET_TRAINING_CARD_FORM_ID', 'trainingCardFormId'),
};

Expand Down Expand Up @@ -245,6 +246,10 @@ export class GlobalActions {
return this.store.dispatch(Actions.setUserFacilityId(userFacilityId));
}

setUserContactId(userContactId) {
return this.store.dispatch(Actions.setUserContactId(userContactId));
}

setTrainingCardFormId(trainingCard) {
return this.store.dispatch(Actions.setTrainingCardFormId(trainingCard));
}
Expand Down
9 changes: 9 additions & 0 deletions webapp/src/ts/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { OLD_ACTION_BAR_PERMISSION } from '@mm-components/actionbar/actionbar.co
import { BrowserDetectorService } from '@mm-services/browser-detector.service';
import { BrowserCompatibilityComponent } from '@mm-modals/browser-compatibility/browser-compatibility.component';
import { PerformanceService } from '@mm-services/performance.service';
import { UserSettingsService } from '@mm-services/user-settings.service';

const SYNC_STATUS = {
inProgress: {
Expand Down Expand Up @@ -136,6 +137,7 @@ export class AppComponent implements OnInit, AfterViewInit {
private trainingCardsService: TrainingCardsService,
private matIconRegistry: MatIconRegistry,
private browserDetectorService: BrowserDetectorService,
private userSettingsService: UserSettingsService,
) {
this.globalActions = new GlobalActions(store);
this.analyticsActions = new AnalyticsActions(store);
Expand Down Expand Up @@ -282,6 +284,7 @@ export class AppComponent implements OnInit, AfterViewInit {
.then(() => this.chtDatasourceService.isInitialized())
.then(() => this.checkPrivacyPolicy())
.then(() => (this.initialisationComplete = true))
.then(() => this.initUser())
.then(() => this.initRulesEngine())
.then(() => this.initTransitions())
.then(() => this.initForms())
Expand All @@ -307,6 +310,12 @@ export class AppComponent implements OnInit, AfterViewInit {
this.initAnalyticsModules();
}

private async initUser() {
const userSettings:any = await this.userSettingsService.get();
this.globalActions.setUserContactId(userSettings.contact_id);
this.globalActions.setUserFacilityId(userSettings.facility_id);
}

ngAfterViewInit() {
this.enableOldActionBar();
this.subscribeToSideFilterStore();
Expand Down
32 changes: 18 additions & 14 deletions webapp/src/ts/effects/contacts.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ export class ContactsEffects {
selectContact = createEffect(() => {
return this.actions$.pipe(
ofType(ContactActionList.selectContact),
withLatestFrom(this.store.select(Selectors.getForms)),
exhaustMap(([{ payload: { id, silent } }, forms]) => {
withLatestFrom(
this.store.select(Selectors.getUserFacilityId),
this.store.select(Selectors.getUserContactId),
this.store.select(Selectors.getForms),
),
exhaustMap(([{ payload: { id, silent } }, userFacilityId, userContactId, forms]) => {
if (!id) {
return of(this.contactsActions.clearSelection());
}
Expand Down Expand Up @@ -83,7 +87,7 @@ export class ContactsEffects {
.then(() => this.setTitle())
.then(() => this.loadDescendants(id, trackName))
.then(() => this.loadReports(id, forms, trackName))
.then(() => this.loadTargetDoc(id, trackName))
.then(() => this.loadTargetDoc(id, userFacilityId, userContactId, trackName))
.then(() => this.loadContactSummary(id, trackName))
.then(() => this.loadTasks(id, trackName))
.catch(err => {
Expand Down Expand Up @@ -176,18 +180,18 @@ export class ContactsEffects {
});
}

private loadTargetDoc(contactId, trackName) {
private async loadTargetDoc(contactId, userFacilityId, userContactId, trackName) {
const trackPerformance = this.performanceService.track();
return this.targetAggregateService
.getCurrentTargetDoc(this.selectedContact)
.then(targetDoc => {
return this
.verifySelectedContactNotChanged(contactId)
.then(() => this.contactsActions.receiveSelectedContactTargetDoc(targetDoc));
})
.finally(() => {
trackPerformance?.stop({ name: [ ...trackName, 'load_targets' ].join(':') });
});

const targetDocs = await this.targetAggregateService.getTargetDocs(
this.selectedContact,
userFacilityId,
userContactId
);
await this.verifySelectedContactNotChanged(contactId);
this.contactsActions.receiveSelectedContactTargetDoc(targetDocs);

trackPerformance?.stop({ name: [ ...trackName, 'load_targets' ].join(':') });
}

private loadTasks(contactId, trackName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { combineLatest, Subscription, Subject } from 'rxjs';
import { combineLatest, Subject, Subscription } from 'rxjs';
import { Store } from '@ngrx/store';

import { Selectors } from '@mm-selectors/index';
Expand All @@ -9,6 +9,8 @@ import { TargetAggregatesService } from '@mm-services/target-aggregates.service'
import { GlobalActions } from '@mm-actions/global';
import { TranslateService } from '@mm-services/translate.service';

import { ReportingPeriod } from '@mm-modules/analytics/analytics-target-aggregates-sidebar-filter.component';

@Component({
selector: 'analytics-target-aggregates-detail',
templateUrl: './analytics-target-aggregates-detail.component.html'
Expand Down Expand Up @@ -106,7 +108,7 @@ export class AnalyticsTargetAggregatesDetailComponent implements OnInit, OnDestr
}

private getReportingPeriodText(aggregate) {
if (this.targetAggregatesService.isCurrentPeriod(aggregate.reportingPeriod)) {
if (aggregate.reportingPeriod === ReportingPeriod.CURRENT) {
return this.translateService.instant(this.selected.subtitle_translation_key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class AnalyticsTargetAggregatesComponent implements OnInit, OnDestroy {

aggregate.reportingMonth = reportingMonth;
aggregate.reportingPeriod = reportingPeriod;
if (this.targetAggregatesService.isPreviousPeriod(aggregate.reportingPeriod)) {
if (aggregate.reportingPeriod === ReportingPeriod.PREVIOUS) {
filtersToDisplay.push(aggregate.reportingMonth);
}
aggregate.filtersToDisplay = filtersToDisplay;
Expand Down
20 changes: 18 additions & 2 deletions webapp/src/ts/modules/contacts/contacts-report.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, OnDestroy, AfterViewInit, NgZone } from '@angular/core';
import { AfterViewInit, Component, NgZone, OnDestroy, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
import { combineLatest, Subscription } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
Expand Down Expand Up @@ -37,6 +37,9 @@ export class ContactsReportComponent implements OnInit, OnDestroy, AfterViewInit
errorTranslationKey;
contentError;
cancelCallback;
userFacilityId;
userContactId;


constructor(
private store: Store,
Expand Down Expand Up @@ -135,6 +138,7 @@ export class ContactsReportComponent implements OnInit, OnDestroy, AfterViewInit
const formContext = new EnketoFormContext('#contact-report', 'report', formDoc, { source: 'contact', contact });
formContext.editedListener = this.markFormEdited.bind(this);
formContext.valuechangeListener = this.resetFormError.bind(this);
formContext.setUserContext(this.userContactId, this.userFacilityId);

return this.formService.render(formContext);
})
Expand Down Expand Up @@ -163,12 +167,24 @@ export class ContactsReportComponent implements OnInit, OnDestroy, AfterViewInit
this.store.select(Selectors.getEnketoError),
this.store.select(Selectors.getEnketoEditedStatus),
this.store.select(Selectors.getCancelCallback),
).subscribe(([ enketoStatus, enketoSaving, enketoError, enketoEdited, cancelCallback]) => {
this.store.select(Selectors.getUserFacilityId),
this.store.select(Selectors.getUserContactId),
).subscribe(([
enketoStatus,
enketoSaving,
enketoError,
enketoEdited,
cancelCallback,
userFacilityId,
userContactId
]) => {
this.enketoStatus = enketoStatus;
this.enketoSaving = enketoSaving;
this.enketoError = enketoError;
this.enketoEdited = enketoEdited;
this.cancelCallback = cancelCallback;
this.userFacilityId = userFacilityId;
this.userContactId = userContactId;
});
this.subscription.add(reduxSubscription);
}
Expand Down
3 changes: 1 addition & 2 deletions webapp/src/ts/modules/contacts/contacts.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, OnDestroy, AfterViewInit } from '@angular/core';
import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core';
import { combineLatest, Subscription } from 'rxjs';
import { Store } from '@ngrx/store';
import { Router } from '@angular/router';
Expand Down Expand Up @@ -230,7 +230,6 @@ export class ContactsComponent implements OnInit, AfterViewInit, OnDestroy {
const facilityIds = this
.getUserFacilityId(userSettings)
.filter(id => !!id);
this.globalActions.setUserFacilityId(facilityIds);

let homePlaces = await this.getDataRecordsService.get(facilityIds);
homePlaces = homePlaces?.filter(place => !!place);
Expand Down
9 changes: 9 additions & 0 deletions webapp/src/ts/modules/reports/reports-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export class ReportsAddComponent implements OnInit, OnDestroy, AfterViewInit {
errorTranslationKey;
cancelCallback;
selectMode;
userFacilityId;
userContactId;

private geoHandle:any;
private globalActions: GlobalActions;
Expand All @@ -73,6 +75,8 @@ export class ReportsAddComponent implements OnInit, OnDestroy, AfterViewInit {
this.store.select(Selectors.getEnketoError),
this.store.select(Selectors.getCancelCallback),
this.store.select(Selectors.getSelectMode),
this.store.select(Selectors.getUserFacilityId),
this.store.select(Selectors.getUserContactId),
).subscribe(([
loadingContent,
selectedReport,
Expand All @@ -81,6 +85,8 @@ export class ReportsAddComponent implements OnInit, OnDestroy, AfterViewInit {
enketoError,
cancelCallback,
selectMode,
userFacilityId,
userContactId,
]) => {
this.selectedReport = selectedReport;
this.loadingContent = loadingContent;
Expand All @@ -90,6 +96,8 @@ export class ReportsAddComponent implements OnInit, OnDestroy, AfterViewInit {
this.enketoError = enketoError;
this.cancelCallback = cancelCallback;
this.selectMode = selectMode;
this.userFacilityId = userFacilityId;
this.userContactId = userContactId;
});
this.subscription.add(reduxSubscription);
}
Expand Down Expand Up @@ -233,6 +241,7 @@ export class ReportsAddComponent implements OnInit, OnDestroy, AfterViewInit {
formContext.editing = !!reportContent;
formContext.editedListener = this.markFormEdited.bind(this);
formContext.valuechangeListener = this.resetFormError.bind(this);
formContext.setUserContext(this.userContactId, this.userFacilityId);

try {
const form = await this.formService.render(formContext);
Expand Down
9 changes: 9 additions & 0 deletions webapp/src/ts/modules/tasks/tasks-content.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class TasksContentComponent implements OnInit, OnDestroy {
formId;
private cancelCallback;
errorTranslationKey;
userFacilityId;
userContactId;
private tasksList;
private geoHandle;
private enketoError;
Expand Down Expand Up @@ -92,6 +94,8 @@ export class TasksContentComponent implements OnInit, OnDestroy {
this.store.select(Selectors.getSelectedTask),
this.store.select(Selectors.getCancelCallback),
this.store.select(Selectors.getTasksList),
this.store.select(Selectors.getUserFacilityId),
this.store.select(Selectors.getUserContactId),
).subscribe(([
enketoStatus,
enketoError,
Expand All @@ -101,6 +105,8 @@ export class TasksContentComponent implements OnInit, OnDestroy {
selectedTask,
cancelCallback,
taskList,
userFacilityId,
userContactId,
]) => {
this.enketoStatus = enketoStatus;
this.enketoError = enketoError;
Expand All @@ -110,6 +116,8 @@ export class TasksContentComponent implements OnInit, OnDestroy {
this.selectedTask = selectedTask;
this.cancelCallback = cancelCallback;
this.tasksList = taskList;
this.userFacilityId = userFacilityId;
this.userContactId = userContactId;
});
this.subscription.add(subscription);
}
Expand Down Expand Up @@ -222,6 +230,7 @@ export class TasksContentComponent implements OnInit, OnDestroy {
const formContext = new EnketoFormContext('#task-report', 'task', formDoc, action.content);
formContext.editedListener = this.markFormEdited.bind(this);
formContext.valuechangeListener = this.resetFormError.bind(this);
formContext.setUserContext(this.userContactId, this.userFacilityId);

return this.formService
.render(formContext)
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/ts/reducers/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const initialState = {
snackbarContent: null as any,
translationsLoaded: false,
userFacilityId: null,
userContactId: null,
trainingCardFormId: null,
};

Expand Down Expand Up @@ -207,6 +208,7 @@ const _globalReducer = createReducer(
on(Actions.setUserFacilityId, (state, { payload: { userFacilityId }}) => {
return { ...state, userFacilityId };
}),
on(Actions.setUserContactId, (state, { payload: { userContactId }}) => ({ ...state, userContactId })),
on(Actions.setTrainingCardFormId, (state, { payload: { trainingCardFormId }}) => {
return { ...state, trainingCardFormId };
}),
Expand Down
1 change: 1 addition & 0 deletions webapp/src/ts/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const Selectors = {
getUnreadCount: createSelector(getGlobalState, (globalState) => globalState.unreadCount),
getTranslationsLoaded: createSelector(getGlobalState, (globalState) => globalState.translationsLoaded),
getUserFacilityId: createSelector(getGlobalState, (globalState) => globalState.userFacilityId),
getUserContactId: createSelector(getGlobalState, (globalState) => globalState.userContactId),
getTrainingCardFormId: createSelector(getGlobalState, (globalState) => globalState.trainingCardFormId),

// enketo
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/ts/services/calendar-interval.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class CalendarIntervalService {
return CalendarInterval.getCurrent(startDate);
}

getPrevious(startDate: number, referenceDate?: Date) {
return CalendarInterval.getPrevious(startDate, referenceDate);
getInterval(startDate, timestamp) {
return CalendarInterval.getInterval(startDate, timestamp);
}
}
Loading

0 comments on commit b9c23ff

Please sign in to comment.