Skip to content

Commit

Permalink
chore: merge with development
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Dec 21, 2023
2 parents 1954ae1 + 9d25631 commit 9cebde1
Show file tree
Hide file tree
Showing 19 changed files with 366 additions and 101 deletions.
12 changes: 9 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: 2023-12-12T06:06:24.698Z\n"
"PO-Revision-Date: 2023-12-12T06:06:24.698Z\n"
"POT-Creation-Date: 2023-12-12T09:57:09.880Z\n"
"PO-Revision-Date: 2023-12-12T09:57:09.881Z\n"

msgid "WHO privacy policy"
msgstr ""
Expand Down Expand Up @@ -64,7 +64,7 @@ msgstr ""
msgid "FUTURE"
msgstr ""

msgid "NONE"
msgid "ALL"
msgstr ""

msgid "SUPRANATIONAL"
Expand Down Expand Up @@ -109,6 +109,12 @@ msgstr ""
msgid "Action"
msgstr ""

msgid "Survey deleted!"
msgstr ""

msgid "Error deleting the survery"
msgstr ""

msgid "Yes"
msgstr ""

Expand Down
10 changes: 8 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: 2023-11-28T10:56:14.436Z\n"
"POT-Creation-Date: 2023-12-12T09:57:09.880Z\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 @@ -61,7 +61,7 @@ msgstr ""
msgid "FUTURE"
msgstr ""

msgid "NONE"
msgid "ALL"
msgstr ""

msgid "SUPRANATIONAL"
Expand Down Expand Up @@ -100,6 +100,12 @@ msgstr ""
msgid "Action"
msgstr ""

msgid "Survey deleted!"
msgstr ""

msgid "Error deleting the survery"
msgstr ""

msgid "Yes"
msgstr ""

Expand Down
2 changes: 2 additions & 0 deletions src/CompositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { SaveFormDataUseCase } from "./domain/usecases/SaveFormDataUseCase";
import { GetAllSurveysUseCase } from "./domain/usecases/GetAllSurveysUseCase";
import { GetPopulatedSurveyUseCase } from "./domain/usecases/GetPopulatedSurveyUseCase";
import { NonAdminUserTestRepository } from "./data/repositories/testRepositories/NonAdminUserTestRepository";
import { DeleteSurveyUseCase } from "./domain/usecases/DeleteSurveyUseCase";

export type CompositionRoot = ReturnType<typeof getCompositionRoot>;

Expand Down Expand Up @@ -54,6 +55,7 @@ function getCompositionRoot(repositories: Repositories) {
getPopulatedForm: new GetPopulatedSurveyUseCase(repositories.surveyFormRepository),
saveFormData: new SaveFormDataUseCase(repositories.surveyFormRepository),
getSurveys: new GetAllSurveysUseCase(repositories.surveyFormRepository),
deleteSurvey: new DeleteSurveyUseCase(repositories.surveyFormRepository),
},
};
}
Expand Down
91 changes: 80 additions & 11 deletions src/data/repositories/SurveyFormD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
D2TrackerEnrollmentAttribute,
} from "@eyeseetea/d2-api/api/trackerEnrollments";
import { GLOBAL_OU_ID } from "../../domain/usecases/SaveFormDataUseCase";
import { PaginatedReponse } from "../../domain/entities/TablePagination";

//PPS Program Ids
export const PPS_SURVEY_FORM_ID = "OGOw5Kt3ytv";
Expand Down Expand Up @@ -421,7 +422,7 @@ export class SurveyD2Repository implements SurveyRepository {
text: formName, //formName
type: "boolean",
storeFalse: false,
value: dataValue ? (dataValue === "true" ? true : false) : false,
value: dataValue ? (dataValue === "true" ? true : undefined) : undefined,
isVisible: hiddenFields.some(field => field === formName) ? false : true,
};
return boolQ;
Expand Down Expand Up @@ -728,18 +729,28 @@ export class SurveyD2Repository implements SurveyRepository {
getSurveys(
surveyFormType: SURVEY_FORM_TYPES,
programId: Id,
orgUnitId: Id
): FutureData<Survey[]> {
orgUnitId: Id,
parentWardRegisterId: Id | undefined,
page: number,
pageSize: number
): FutureData<PaginatedReponse<Survey[]>> {
return this.isTrackerProgram(programId)
? this.getTrackerProgramSurveys(surveyFormType, programId, orgUnitId)
: this.getEventProgramSurveys(surveyFormType, programId, orgUnitId);
: this.getEventProgramSurveys(
surveyFormType,
programId,
orgUnitId,
parentWardRegisterId,
page,
pageSize
);
}

getTrackerProgramSurveys(
surveyFormType: SURVEY_FORM_TYPES,
programId: Id,
orgUnitId: Id
): FutureData<Survey[]> {
): FutureData<PaginatedReponse<Survey[]>> {
return apiToFuture(
this.api.tracker.trackedEntities.get({
fields: { $all: true },
Expand Down Expand Up @@ -771,15 +782,25 @@ export class SurveyD2Repository implements SurveyRepository {
return survey;
});

return Future.success(surveys);
return Future.success({
pager: {
page: -1,
pageSize: -1,
total: -1,
},
objects: surveys,
});
});
}

getEventProgramSurveys(
surveyFormType: SURVEY_FORM_TYPES,
programId: Id,
orgUnitId: Id
): FutureData<Survey[]> {
orgUnitId: Id,
parentWardRegisterId: Id | undefined,
page: number,
pageSize: number
): FutureData<PaginatedReponse<Survey[]>> {
const ouMode =
orgUnitId !== "" &&
(programId === PPS_WARD_REGISTER_ID ||
Expand All @@ -793,9 +814,18 @@ export class SurveyD2Repository implements SurveyRepository {
program: programId,
orgUnit: orgUnitId,
ouMode: ouMode,
// Testing the API filter for now to see how the filtering performs
...(surveyFormType === "PPSPatientRegister" && {
page: page + 1,
pageSize,
totalPages: true,
filter: `${WARD_ID_DATAELEMENT_ID}:eq:${parentWardRegisterId}`,
}),
})
).flatMap(events => {
const surveys = events.instances.map(event => {
).flatMap(response => {
const events = response.instances;

const surveys = events.map(event => {
let startDateString,
surveyType = "",
surveyCompleted,
Expand Down Expand Up @@ -871,7 +901,16 @@ export class SurveyD2Repository implements SurveyRepository {
});
});

return Future.sequential(surveys);
return Future.sequential(surveys).map(surveys => {
return {
pager: {
page: response.page,
pageSize: response.pageSize,
total: response.total,
},
objects: surveys,
};
});
});
}

Expand Down Expand Up @@ -923,4 +962,34 @@ export class SurveyD2Repository implements SurveyRepository {
.flatMapError(_err => Future.success(""));
else return Future.success("");
}

deleteSurvey(eventId: Id, orgUnitId: Id, programId: Id): FutureData<void> {
const event: D2TrackerEvent = {
event: eventId,
orgUnit: orgUnitId,
program: programId,
// status doesn't play a part in deleting but is required
status: "ACTIVE",
occurredAt: "",
dataValues: [],
};
return apiToFuture(
this.api.tracker.postAsync({ importStrategy: "DELETE" }, { events: [event] })
).flatMap(response => {
return apiToFuture(
// eslint-disable-next-line testing-library/await-async-utils
this.api.system.waitFor("TRACKER_IMPORT_JOB", response.response.id)
).flatMap(result => {
if (result && result.status !== "ERROR") {
return Future.success(undefined);
} else {
return Future.error(
new Error(
`Error: ${result?.validationReport?.errorReports?.at(0)?.message} `
)
);
}
});
});
}
}
65 changes: 43 additions & 22 deletions src/data/repositories/testRepositories/SurveyFormTestRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Survey } from "../../../domain/entities/Survey";
import { SurveyRepository } from "../../../domain/repositories/SurveyRepository";
import { FutureData } from "../../api-futures";
import { PPS_SURVEY_FORM_ID } from "../SurveyFormD2Repository";
import { PaginatedReponse } from "../../../domain/entities/TablePagination";

export class SurveyTestRepository implements SurveyRepository {
getSurveyNameFromId(id: string): FutureData<string | undefined> {
Expand Down Expand Up @@ -60,31 +61,46 @@ export class SurveyTestRepository implements SurveyRepository {
else return Future.error(new Error("An error occured while saving the survey"));
}

getSurveys(programId: string, orgUnitId: string): FutureData<Survey[]> {
getSurveys(programId: string, orgUnitId: string): FutureData<PaginatedReponse<Survey[]>> {
if (programId === PPS_SURVEY_FORM_ID)
return Future.success([
{
name: "TestSurvey1",
id: "1",
startDate: new Date(),
status: "ACTIVE",
assignedOrgUnit: { id: orgUnitId, name: "OU1" },
surveyType: "SUPRANATIONAL",
rootSurvey: { id: "1", name: "TestSurvey1", surveyType: "" },
surveyFormType: "PPSSurveyForm",
return Future.success({
pager: {
page: 0,
pageSize: 2,
total: 2,
},
{
name: "TestSurvey2",
id: "2",
startDate: new Date(),
status: "COMPLETED",
assignedOrgUnit: { id: "OU1234", name: "OU2" },
surveyType: "NATIONAL",
rootSurvey: { id: "2", name: "TestSurvey1", surveyType: "" },
surveyFormType: "PPSSurveyForm",
objects: [
{
name: "TestSurvey1",
id: "1",
startDate: new Date(),
status: "ACTIVE",
assignedOrgUnit: { id: orgUnitId, name: "OU1" },
surveyType: "SUPRANATIONAL",
rootSurvey: { id: "1", name: "TestSurvey1", surveyType: "" },
surveyFormType: "PPSSurveyForm",
},
{
name: "TestSurvey2",
id: "2",
startDate: new Date(),
status: "COMPLETED",
assignedOrgUnit: { id: "OU1234", name: "OU2" },
surveyType: "NATIONAL",
rootSurvey: { id: "2", name: "TestSurvey1", surveyType: "" },
surveyFormType: "PPSSurveyForm",
},
],
});
else
return Future.success({
pager: {
page: 0,
pageSize: 0,
total: 0,
},
]);
else return Future.success([]);
objects: [],
});
}
getSurveyById(eventId: string): FutureData<D2TrackerEvent> {
if (eventId) {
Expand All @@ -104,4 +120,9 @@ export class SurveyTestRepository implements SurveyRepository {
return Future.error(new Error("Error in getSurveyById"));
}
}

deleteSurvey(orgUnitId: Id, eventId: Id, programId: Id): FutureData<void> {
if (orgUnitId && eventId && programId) return Future.success(undefined);
else return Future.error(new Error("An error occured while deleting the survey"));
}
}
11 changes: 11 additions & 0 deletions src/domain/entities/TablePagination.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface PaginatedReponse<T> {
pager: Pager;
objects: T;
}

export interface Pager {
page: number;
total?: number;
pageSize: number;
pageCount?: number;
}
4 changes: 4 additions & 0 deletions src/domain/entities/generic/ActionOutcome.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ActionOutcome {
status: "success" | "error";
message: string;
}
9 changes: 7 additions & 2 deletions src/domain/repositories/SurveyRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ImportStrategy } from "../entities/Program";
import { Questionnaire } from "../entities/Questionnaire";
import { Id } from "../entities/Ref";
import { Survey, SURVEY_FORM_TYPES } from "../entities/Survey";
import { PaginatedReponse } from "../entities/TablePagination";

export interface SurveyRepository {
getForm(programId: Id, eventId: Id | undefined): FutureData<Questionnaire>;
Expand All @@ -16,8 +17,12 @@ export interface SurveyRepository {
getSurveys(
surveyFormType: SURVEY_FORM_TYPES,
programId: Id,
orgUnitId: Id
): FutureData<Survey[]>;
orgUnitId: Id,
parentWardRegisterId: Id | undefined,
page: number,
pageSize: number
): FutureData<PaginatedReponse<Survey[]>>;
getPopulatedSurveyById(eventId: Id, programId: Id): FutureData<Questionnaire>;
getSurveyNameFromId(id: Id): FutureData<string | undefined>;
deleteSurvey(eventId: Id, orgUnitId: Id, programId: Id): FutureData<void>;
}
19 changes: 19 additions & 0 deletions src/domain/usecases/DeleteSurveyUseCase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { FutureData } from "../../data/api-futures";
import { SURVEY_FORM_TYPES } from "../entities/Survey";
import { Id } from "../entities/Ref";

import { SurveyRepository } from "../repositories/SurveyRepository";
import { getProgramId } from "../utils/PPSProgramsHelper";

export class DeleteSurveyUseCase {
constructor(private surveyReporsitory: SurveyRepository) {}

public execute(
surveyFormType: SURVEY_FORM_TYPES,
orgUnitId: Id,
eventId: Id
): FutureData<void> {
const programId = getProgramId(surveyFormType);
return this.surveyReporsitory.deleteSurvey(eventId, orgUnitId, programId);
}
}
Loading

0 comments on commit 9cebde1

Please sign in to comment.