Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add new admin report #68

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2022-09-16T08:44:53.398Z\n"
"PO-Revision-Date: 2022-09-16T08:44:53.398Z\n"
"POT-Creation-Date: 2022-11-07T09:57:24.113Z\n"
"PO-Revision-Date: 2022-11-07T09:57:24.113Z\n"

msgid "<No value>"
msgstr ""
Expand Down Expand Up @@ -89,6 +89,12 @@ msgstr ""
msgid "Approved value comment"
msgstr ""

msgid "Approve value"
msgstr ""

msgid "Error when trying to approve data values"
msgstr ""

msgid "Error when trying to check difference in data values"
msgstr ""

Expand Down Expand Up @@ -149,7 +155,10 @@ msgstr ""
msgid "Approve"
msgstr ""

msgid "Error when trying to approve data values"
msgid "Activate monitoring"
msgstr ""

msgid "Deactivate monitoring"
msgstr ""

msgid "Check Difference"
Expand Down Expand Up @@ -217,3 +226,30 @@ msgstr ""

msgid "Toggle filters"
msgstr ""

msgid "Uset 2FA info"
msgstr ""

msgid "uid"
msgstr ""

msgid "Name"
msgstr ""

msgid "Username"
msgstr ""

msgid "External auth"
msgstr ""

msgid "TwoFA"
msgstr ""

msgid "Email"
msgstr ""

msgid "Disabled"
msgstr ""

msgid "save"
msgstr ""
40 changes: 38 additions & 2 deletions i18n/es.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2022-09-16T08:44:53.398Z\n"
"POT-Creation-Date: 2022-11-07T09:57:24.113Z\n"
"PO-Revision-Date: 2018-10-25T09:02:35.143Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -89,6 +89,12 @@ msgstr ""
msgid "Approved value comment"
msgstr ""

msgid "Approve value"
msgstr ""

msgid "Error when trying to approve data values"
msgstr ""

msgid "Error when trying to check difference in data values"
msgstr ""

Expand Down Expand Up @@ -149,7 +155,10 @@ msgstr ""
msgid "Approve"
msgstr ""

msgid "Error when trying to approve data values"
msgid "Activate monitoring"
msgstr ""

msgid "Deactivate monitoring"
msgstr ""

msgid "Check Difference"
Expand Down Expand Up @@ -218,6 +227,33 @@ msgstr ""
msgid "Toggle filters"
msgstr ""

msgid "Uset 2FA info"
msgstr ""

msgid "uid"
msgstr ""

msgid "Name"
msgstr ""

msgid "Username"
msgstr ""

msgid "External auth"
msgstr ""

msgid "TwoFA"
msgstr ""

msgid "Email"
msgstr ""

msgid "Disabled"
msgstr ""

msgid "save"
msgstr ""

#~ msgid "Add"
#~ msgstr "Añadir"

Expand Down
8 changes: 8 additions & 0 deletions src/compositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ import { GenerateSortOrderUseCase } from "./domain/reports/mal-data-approval/use
import { GetMonitoringUseCase } from "./domain/reports/mal-data-approval/usecases/GetMonitoringUseCase";
import { SaveMonitoringUseCase } from "./domain/reports/mal-data-approval/usecases/SaveMonitoringUseCase";
import { DuplicateDataValuesUseCase } from "./domain/reports/mal-data-approval/usecases/DuplicateDataValuesUseCase";
import { UserInfoDefaultRepository } from "./data/reports/userInfo/UserInfoDefaultRepository";
import { GetUserInfoUseCase } from "./domain/reports/userinfo/usecases/GetUserInfoUseCase";
import { SaveUserInfoCsvUseCase } from "./domain/reports/userinfo/usecases/SaveUserInfoCsvUseCase";

export function getCompositionRoot(api: D2Api) {
const configRepository = new Dhis2ConfigRepository(api, getReportType());
const dataCommentsRepository = new NHWADataCommentsDefaultRepository(api);
const dataApprovalRepository = new NHWADataApprovalDefaultRepository(api);
const dataDuplicationRepository = new MalDataApprovalDefaultRepository(api);
const getUserInfoRepository = new UserInfoDefaultRepository(api);
const widpAdminDefaultRepository = new WIDPAdminDefaultRepository(api);
const orgUnitsRepository = new Dhis2OrgUnitsRepository(api);

Expand All @@ -53,6 +57,10 @@ export function getCompositionRoot(api: D2Api) {
saveColumns: new SaveApprovalColumnsUseCase(dataApprovalRepository),
updateStatus: new UpdateStatusUseCase(dataApprovalRepository),
}),
user2fa: getExecute({
get: new GetUserInfoUseCase(getUserInfoRepository),
save: new SaveUserInfoCsvUseCase(getUserInfoRepository),
}),
malDataApproval: getExecute({
get: new GetMalDataSetsUseCase(dataDuplicationRepository),
getDiff: new GetMalDataDiffUseCase(dataDuplicationRepository),
Expand Down
2 changes: 2 additions & 0 deletions src/data/common/clients/storage/Namespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type Namespace = typeof Namespaces[keyof typeof Namespaces];
export const Namespaces = {
NHWA_APPROVAL_STATUS_USER_COLUMNS: "nhwa-approval-status-user-columns",
MAL_APPROVAL_STATUS_USER_COLUMNS: "mal-approval-status-user-columns",
USER_2FA_STATUS: "user-2fa-auth-status",
MAL_DIFF_STATUS_USER_COLUMNS: "mal-diff-status-user-columns",
MAL_DIFF_NAMES_SORT_ORDER: "mal-diff-names-sort-order",
MONITORING: "monitoring",
Expand All @@ -15,6 +16,7 @@ export const NamespaceProperties: Record<Namespace, string[]> = {
[Namespaces.NHWA_APPROVAL_STATUS_USER_COLUMNS]: [],
[Namespaces.MAL_APPROVAL_STATUS_USER_COLUMNS]: [],
[Namespaces.MAL_DIFF_STATUS_USER_COLUMNS]: [],
[Namespaces.USER_2FA_STATUS]: [],
[Namespaces.MAL_DIFF_NAMES_SORT_ORDER]: [],
[Namespaces.MONITORING]: [],
};
111 changes: 56 additions & 55 deletions src/data/reports/mal-data-approval/MalDataApprovalDefaultRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import {
MalDataApprovalOptions,
MalDataApprovalRepository,
} from "../../../domain/reports/mal-data-approval/repositories/MalDataApprovalRepository";
import {
DataDiffItem,
DataDiffItemIdentifier
} from "../../../domain/reports/mal-data-approval/entities/DataDiffItem";
import { DataDiffItem, DataDiffItemIdentifier } from "../../../domain/reports/mal-data-approval/entities/DataDiffItem";
import { Namespaces } from "../../common/clients/storage/Namespaces";

export interface Pagination {
Expand Down Expand Up @@ -231,12 +228,12 @@ export class MalDataApprovalDefaultRepository implements MalDataApprovalReposito
paging_to_download
)
.getData();

const orgunits = config.currentUser.orgUnits ? config.currentUser.orgUnits.map(({ id }) => id) : [];
const { rows } = await sqlViews
.query<Variables, SqlField>(
getSqlViewId(config, SQL_VIEW_DATA_DUPLICATION_NAME),
{
orgUnitRoot: sqlViewJoinIds(config.currentUser.orgUnits.map(({ id }) => id)),
orgUnitRoot: sqlViewJoinIds(orgunits),
orgUnits: sqlViewJoinIds(orgUnitIds),
periods: sqlViewJoinIds(periods),
dataSets: sqlViewJoinIds(_.isEmpty(dataSetIds) ? allDataSetIds : dataSetIds),
Expand Down Expand Up @@ -466,44 +463,44 @@ export class MalDataApprovalDefaultRepository implements MalDataApprovalReposito
async duplicateDataValues(dataValues: DataDiffItemIdentifier[]): Promise<boolean> {
try {
const approvalDataSetId = process.env.REACT_APP_APPROVE_DATASET_ID ?? "fRrt4V8ImqD";
const uniqueDataSets = _.uniqBy(dataValues, 'dataSet');
const uniqueDataElementsNames = _.uniq(_.map(dataValues, 'dataElement'));
const uniqueDataSets = _.uniqBy(dataValues, "dataSet");
const uniqueDataElementsNames = _.uniq(_.map(dataValues, "dataElement"));

const DSDataElements: { dataSetElements: dataSetElementsType[] }[] = await promiseMap(uniqueDataSets, async item =>
this.api
.get<any>(`/dataSets/${item.dataSet}`, { fields: "dataSetElements[dataElement[id,name]]" })
.getData()
const DSDataElements: { dataSetElements: dataSetElementsType[] }[] = await promiseMap(
uniqueDataSets,
async item =>
this.api
.get<any>(`/dataSets/${item.dataSet}`, { fields: "dataSetElements[dataElement[id,name]]" })
.getData()
);

const dataValueSets: dataSetsValueType[] = await promiseMap(uniqueDataSets, async item =>
this.api.get<any>("/dataValueSets", {
dataSet: item.dataSet,
period: item.period,
orgUnit: item.orgUnit,
}).getData()
this.api
.get<any>("/dataValueSets", {
dataSet: item.dataSet,
period: item.period,
orgUnit: item.orgUnit,
})
.getData()
);

const ADSDataElementsRaw: { dataSetElements: dataSetElementsType[] } = await this.api
.get<any>(`/dataSets/${approvalDataSetId}`, { fields: "dataSetElements[dataElement[id,name]]" })
.getData();

const ADSDataElements: dataElementsType[] = ADSDataElementsRaw.dataSetElements.map(
(element) => {
return {
id: element.dataElement.id,
name: element.dataElement.name,
};
}
);
const ADSDataElements: dataElementsType[] = ADSDataElementsRaw.dataSetElements.map(element => {
return {
id: element.dataElement.id,
name: element.dataElement.name,
};
});

const dataElementsMatchedArray: { [key: string]: any }[] = DSDataElements.flatMap(DSDataElement => {
return DSDataElement.dataSetElements.flatMap((element) => {
return DSDataElement.dataSetElements.flatMap(element => {
const dataElement = element.dataElement;
if (uniqueDataElementsNames.includes(dataElement.name)) {
const othername = dataElement.name + "-APVD";
const ADSDataElement = ADSDataElements.find(
(DataElement) => DataElement.name === othername
);
const ADSDataElement = ADSDataElements.find(DataElement => DataElement.name === othername);
return {
origId: dataElement?.id,
destId: ADSDataElement?.id,
Expand All @@ -513,24 +510,22 @@ export class MalDataApprovalDefaultRepository implements MalDataApprovalReposito
return [];
}
});
})
});

const apvdDataValues = dataValueSets.flatMap(dataValueSet => {
if (dataValueSet.dataValues) {
const data = dataValueSet.dataValues.flatMap(
(dataValue) => {
const data = { ...dataValue };
const destId = dataElementsMatchedArray.find(
dataElementsMatchedObj => dataElementsMatchedObj.origId === dataValue.dataElement
)?.destId;
data.dataElement = destId;
data.dataSet = approvalDataSetId;
delete data.lastUpdated;
delete data.comment;

return data.dataElement ? data : [];
}
);
const data = dataValueSet.dataValues.flatMap(dataValue => {
const data = { ...dataValue };
const destId = dataElementsMatchedArray.find(
dataElementsMatchedObj => dataElementsMatchedObj.origId === dataValue.dataElement
)?.destId;
data.dataElement = destId;
data.dataSet = approvalDataSetId;
delete data.lastUpdated;
delete data.comment;

return data.dataElement ? data : [];
});
return data;
} else {
return [];
Expand Down Expand Up @@ -558,7 +553,7 @@ export class MalDataApprovalDefaultRepository implements MalDataApprovalReposito
.post<any>("/dataValueSets.json", {}, { dataValues: _.reject(chunk, _.isEmpty) })
.getData();

copyResponse.push(response)
copyResponse.push(response);
}
return _.every(copyResponse, item => item.status === "SUCCESS");
} else {
Expand Down Expand Up @@ -586,7 +581,11 @@ export class MalDataApprovalDefaultRepository implements MalDataApprovalReposito
};

const revokeResponse = await this.api
.delete<any>("/dataApprovals", { ds: revokeData.dataSet, pe: revokeData.period, ou: revokeData.orgUnit })
.delete<any>("/dataApprovals", {
ds: revokeData.dataSet,
pe: revokeData.period,
ou: revokeData.orgUnit,
})
.getData();

return duplicateResponse && revokeResponse === "";
Expand Down Expand Up @@ -631,17 +630,19 @@ export class MalDataApprovalDefaultRepository implements MalDataApprovalReposito
try {
const response: any[] = [];
dataSets.forEach(async dataSet => {
const isApproved = await this.api.get<any>(
"/dataApprovals",
{ wf: dataSet.workflow, pe: dataSet.period, ou: dataSet.orgUnit }
).getData();
const isApproved = await this.api
.get<any>("/dataApprovals", { wf: dataSet.workflow, pe: dataSet.period, ou: dataSet.orgUnit })
.getData();

if (isApproved.state === "APPROVED_HERE") {
response.push(
await this.api.delete<any>(
"/dataApprovals",
{ wf: dataSet.workflow, pe: dataSet.period, ou: dataSet.orgUnit }
).getData()
await this.api
.delete<any>("/dataApprovals", {
wf: dataSet.workflow,
pe: dataSet.period,
ou: dataSet.orgUnit,
})
.getData()
);
}
});
Expand Down Expand Up @@ -727,7 +728,7 @@ type DataSetRow = Record<CsvField, string>;

function getISODate() {
const date = new Date().toISOString();
return date.slice(0, date.lastIndexOf(":"))
return date.slice(0, date.lastIndexOf(":"));
}

/* From the docs: "The variables must contain alphanumeric, dash, underscore and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ export class NHWADataApprovalDefaultRepository implements NHWADataApprovalReposi
const allDataSetIds = _.values(config.dataSets).map(ds => ds.id); // ?
const sqlViews = new Dhis2SqlViews(this.api);

const orgunits = config.currentUser.orgUnits ? config.currentUser.orgUnits.map(({ id }) => id) : [];
const { pager, rows } = await sqlViews
.query<Variables, SqlField>(
getSqlViewId(config, SQL_VIEW_DATA_APPROVAL_NAME),
{
orgUnitRoot: sqlViewJoinIds(config.currentUser.orgUnits.map(({ id }) => id)),
orgUnitRoot: sqlViewJoinIds(orgunits),
orgUnits: sqlViewJoinIds(orgUnitIds),
periods: sqlViewJoinIds(periods),
dataSets: sqlViewJoinIds(_.isEmpty(dataSetIds) ? allDataSetIds : dataSetIds),
Expand Down
Loading