Skip to content

Commit

Permalink
Merge pull request #63 from EyeSeeTea/development
Browse files Browse the repository at this point in the history
Malaria Data Approval Report
  • Loading branch information
ifoche authored Oct 6, 2022
2 parents f2ec66d + 456cd2c commit 9d32123
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 57 deletions.
4 changes: 4 additions & 0 deletions src/compositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { GetMalDataApprovalColumnsUseCase } from "./domain/reports/mal-data-appr
import { MalDataApprovalDefaultRepository } from "./data/reports/mal-data-approval/MalDataApprovalDefaultRepository";
import { GetSortOrderUseCase } from "./domain/reports/mal-data-approval/usecases/GetSortOrderUseCase";
import { GenerateSortOrderUseCase } from "./domain/reports/mal-data-approval/usecases/GenerateSortOrderUseCase";
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";

export function getCompositionRoot(api: D2Api) {
Expand Down Expand Up @@ -57,6 +59,8 @@ export function getCompositionRoot(api: D2Api) {
save: new SaveMalDataSetsUseCase(dataDuplicationRepository),
getColumns: new GetMalDataApprovalColumnsUseCase(dataDuplicationRepository),
saveColumns: new SaveMalDataApprovalColumnsUseCase(dataDuplicationRepository),
getMonitoring: new GetMonitoringUseCase(dataDuplicationRepository),
saveMonitoring: new SaveMonitoringUseCase(dataDuplicationRepository),
updateStatus: new UpdateMalApprovalStatusUseCase(dataDuplicationRepository),
duplicateValue: new DuplicateDataValuesUseCase(dataDuplicationRepository),
getSortOrder: new GetSortOrderUseCase(dataDuplicationRepository),
Expand Down
46 changes: 31 additions & 15 deletions src/data/common/Dhis2ConfigRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const base = {
dataSets: { namePrefix: "MAL - WMR Form", nameExcluded: /-APVD$/ },

sqlViewNames: [SQL_VIEW_DATA_DUPLICATION_NAME, SQL_VIEW_MAL_METADATA_NAME, SQL_VIEW_MAL_DIFF_NAME],
constantCode: "NHWA_COMMENTS",
constantCode: "",
approvalWorkflows: { namePrefix: "MAL" },
},
};
Expand All @@ -52,25 +52,41 @@ export class Dhis2ConfigRepository implements ConfigRepository {
return { ...acc, [sqlView.name]: sqlView };
}, {});

const constant = getNth(constants, 0, `Missing constant: ${base[this.type].constantCode}`);
const currentUser = await this.getCurrentUser();
const pairedDataElements = getPairedMapping(filteredDataSets);
const orgUnitList = getPairedOrgunitsMapping(filteredDataSets);
const constantData = JSON.parse(constant.description || "{}") as Constant;
const { sections, sectionsByDataSet } = getSectionsInfo(constantData);
const currentYear = new Date().getFullYear();
if (base[this.type].constantCode !== ""){
const constant = getNth(constants, 0, `Missing constant: ${base[this.type].constantCode}`);
const constantData = JSON.parse(constant.description || "{}") as Constant;
const { sections, sectionsByDataSet } = getSectionsInfo(constantData);

return {
dataSets: keyById(filteredDataSets),
currentUser,
sqlViews,
pairedDataElementsByDataSet: pairedDataElements,
orgUnits: orgUnitList,
sections: keyById(sections),
sectionsByDataSet,
years: _.range(currentYear - 10, currentYear + 1).map(n => n.toString()),
approvalWorkflow: dataApprovalWorkflows,
};
}else{

return {
dataSets: keyById(filteredDataSets),
currentUser,
sqlViews,
pairedDataElementsByDataSet: pairedDataElements,
orgUnits: orgUnitList,
sections: undefined,
sectionsByDataSet: undefined,
years: _.range(currentYear - 10, currentYear + 1).map(n => n.toString()),
approvalWorkflow: dataApprovalWorkflows,
};

return {
dataSets: keyById(filteredDataSets),
currentUser,
sqlViews,
pairedDataElementsByDataSet: pairedDataElements,
orgUnits: orgUnitList,
sections: keyById(sections),
sectionsByDataSet,
years: _.range(currentYear - 10, currentYear + 1).map(n => n.toString()),
approvalWorkflow: dataApprovalWorkflows,
};
}
}

getMetadata() {
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 @@ -8,11 +8,13 @@ export const Namespaces = {
MAL_APPROVAL_STATUS_USER_COLUMNS: "mal-approval-status-user-columns",
MAL_DIFF_STATUS_USER_COLUMNS: "mal-diff-status-user-columns",
MAL_DIFF_NAMES_SORT_ORDER: "mal-diff-names-sort-order",
MONITORING: "monitoring",
};

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.MAL_DIFF_NAMES_SORT_ORDER]: [],
[Namespaces.MONITORING]: [],
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import {
MalDataApprovalItem,
MalDataApprovalItemIdentifier,
Monitoring,
} from "../../../domain/reports/mal-data-approval/entities/MalDataApprovalItem";
import {
MalDataApprovalOptions,
Expand Down Expand Up @@ -156,10 +157,12 @@ const fieldMapping: Record<keyof MalDataApprovalItem, SqlField> = {

export class MalDataApprovalDefaultRepository implements MalDataApprovalRepository {
private storageClient: StorageClient;
private globalStorageClient: StorageClient;

constructor(private api: D2Api) {
const instance = new Instance({ url: this.api.baseUrl });
this.storageClient = new DataStoreStorageClient("user", instance);
this.globalStorageClient = new DataStoreStorageClient("global", instance);
}

async getDiff(options: MalDataApprovalOptions): Promise<PaginatedObjects<DataDiffItem>> {
Expand Down Expand Up @@ -659,6 +662,16 @@ export class MalDataApprovalDefaultRepository implements MalDataApprovalReposito
return this.storageClient.saveObject<string[]>(namespace, columns);
}

async getMonitoring(namespace: string): Promise<Monitoring[]> {
const monitoring = await this.globalStorageClient.getObject<Monitoring[]>(namespace);

return monitoring ?? [];
}

async saveMonitoring(namespace: string, monitoring: Monitoring[]): Promise<void> {
return await this.globalStorageClient.saveObject<Monitoring[]>(namespace, monitoring);
}

async getSortOrder(): Promise<string[]> {
const sortOrderArray = await this.storageClient.getObject<string[]>(Namespaces.MAL_DIFF_NAMES_SORT_ORDER);

Expand Down
6 changes: 3 additions & 3 deletions src/domain/common/entities/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { User } from "./User";

export interface Config {
dataSets: Record<Id, NamedRef>;
sections: Record<Id, NamedRef>;
sections: Record<Id, NamedRef> | undefined;
currentUser: User;
sqlViews: Record<string, NamedRef>;
pairedDataElementsByDataSet: {
[dataSetId: string]: Array<{ dataValueVal: Id; dataValueComment: Id }>;
};
orgUnits: string[];
sectionsByDataSet: {
[dataSetId: string]: NamedRef[];
};
[dataSetId: string]: NamedRef[]
}| undefined;
years: string[];
approvalWorkflow: NamedRef[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export interface MalDataApprovalItemIdentifier {
workflow: string;
}

export interface Monitoring {
orgUnit: string;
period: string;
monitoring: boolean;
}

export function getDataDuplicationItemId(dataSet: MalDataApprovalItem): string {
return [dataSet.dataSetUid, dataSet.approvalWorkflowUid, dataSet.period, dataSet.orgUnitUid].join("-");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Id } from "../../../common/entities/Base";
import { Config } from "../../../common/entities/Config";
import { PaginatedObjects, Paging, Sorting } from "../../../common/entities/PaginatedObjects";
import { DataDiffItem, DataDiffItemIdentifier } from "../entities/DataDiffItem";
import { MalDataApprovalItem, MalDataApprovalItemIdentifier } from "../entities/MalDataApprovalItem";
import { DataDiffItem } from "../entities/DataDiffItem";
import { MalDataApprovalItem, MalDataApprovalItemIdentifier, Monitoring } from "../entities/MalDataApprovalItem";
import { DataDiffItemIdentifier } from "../entities/DataDiffItem";

export interface MalDataApprovalRepository {
get(options: MalDataApprovalOptions): Promise<PaginatedObjects<MalDataApprovalItem>>;
Expand All @@ -17,6 +18,8 @@ export interface MalDataApprovalRepository {
unapprove(dataSets: MalDataApprovalItemIdentifier[]): Promise<boolean>;
getColumns(namespace: string): Promise<string[]>;
saveColumns(namespace: string, columns: string[]): Promise<void>;
getMonitoring(namespace: string): Promise<Monitoring[]>;
saveMonitoring(namespace: string, monitoring: Monitoring[]): Promise<void>;
getSortOrder(): Promise<string[]>;
generateSortOrder(): Promise<void>;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { UseCase } from "../../../../compositionRoot";
import { Monitoring } from "../entities/MalDataApprovalItem";
import { MalDataApprovalRepository } from "../repositories/MalDataApprovalRepository";

export class GetMonitoringUseCase implements UseCase {
constructor(private approvalRepository: MalDataApprovalRepository) {}

execute(namespace: string): Promise<Monitoring[]> {
return this.approvalRepository.getMonitoring(namespace);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { UseCase } from "../../../../compositionRoot";
import { Monitoring } from "../entities/MalDataApprovalItem";
import { MalDataApprovalRepository } from "../repositories/MalDataApprovalRepository";

export class SaveMonitoringUseCase implements UseCase {
constructor(private approvalRepository: MalDataApprovalRepository) {}

execute(namespace: string, monitoring: Monitoring[]): Promise<void> {
return this.approvalRepository.saveMonitoring(namespace, monitoring);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { MalDataApprovalItemIdentifier } from "../entities/MalDataApprovalItem";
import { Namespaces } from "../../../../data/common/clients/storage/Namespaces";
import { MalDataApprovalItemIdentifier, Monitoring } from "../entities/MalDataApprovalItem";
import { MalDataApprovalRepository } from "../repositories/MalDataApprovalRepository";

export class UpdateMalApprovalStatusUseCase {
constructor(private approvalRepository: MalDataApprovalRepository) {}

async execute(items: MalDataApprovalItemIdentifier[], action: UpdateAction): Promise<boolean> {
async execute(
items: MalDataApprovalItemIdentifier[],
action: UpdateAction
): Promise<boolean | Monitoring[] | void> {
switch (action) {
case "complete":
return this.approvalRepository.complete(items);
Expand All @@ -16,10 +20,14 @@ export class UpdateMalApprovalStatusUseCase {
return this.approvalRepository.unapprove(items);
case "incomplete":
return this.approvalRepository.incomplete(items);
case "activate":
return this.approvalRepository.getMonitoring(Namespaces.MONITORING);
case "deactivate":
return this.approvalRepository.saveMonitoring(Namespaces.MONITORING, []);
default:
return false;
}
}
}

type UpdateAction = "complete" | "approve" | "duplicate" | "incomplete" | "revoke";
type UpdateAction = "complete" | "approve" | "duplicate" | "incomplete" | "unapprove" | "activate" | "deactivate" | "revoke";
Loading

0 comments on commit 9d32123

Please sign in to comment.