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

[Fix] risk and iap fixes #39

Merged
merged 14 commits into from
Nov 27, 2024
Merged
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
12 changes: 6 additions & 6 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: 2024-11-08T16:32:23.115Z\n"
"PO-Revision-Date: 2024-11-08T16:32:23.115Z\n"
"POT-Creation-Date: 2024-11-22T15:21:43.931Z\n"
"PO-Revision-Date: 2024-11-22T15:21:43.931Z\n"

msgid "Low"
msgstr ""
Expand Down Expand Up @@ -135,9 +135,6 @@ msgstr ""
msgid "Dashboard"
msgstr ""

msgid "Respond, alert, watch"
msgstr ""

msgid "Select duration"
msgstr ""

Expand Down Expand Up @@ -165,7 +162,10 @@ msgstr ""
msgid "Create Risk Assessment"
msgstr ""

msgid "Add new Assessment"
msgid "Edit Risk Assessment"
msgstr ""

msgid "Add new Grade"
msgstr ""

msgid "Risk assessment incomplete"
Expand Down
10 changes: 5 additions & 5 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: 2024-11-08T16:32:23.115Z\n"
"POT-Creation-Date: 2024-11-22T15:21:43.931Z\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 @@ -134,9 +134,6 @@ msgstr ""
msgid "Dashboard"
msgstr ""

msgid "Respond, alert, watch"
msgstr ""

msgid "Select duration"
msgstr ""

Expand Down Expand Up @@ -164,7 +161,10 @@ msgstr ""
msgid "Create Risk Assessment"
msgstr ""

msgid "Add new Assessment"
msgid "Edit Risk Assessment"
msgstr ""

msgid "Add new Grade"
msgstr ""

msgid "Risk assessment incomplete"
Expand Down
9 changes: 8 additions & 1 deletion src/CompositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ import { ConfigurationsRepository } from "./domain/repositories/ConfigurationsRe
import { ConfigurationsD2Repository } from "./data/repositories/ConfigurationsD2Repository";
import { ConfigurationsTestRepository } from "./data/repositories/test/ConfigurationsTestRepository";
import { CompleteEventTrackerUseCase } from "./domain/usecases/CompleteEventTrackerUseCase";
import { UserGroupD2Repository } from "./data/repositories/UserGroupD2Repository";
import { UserGroupRepository } from "./domain/repositories/UserGroupRepository";
import { UserGroupTestRepository } from "./data/repositories/test/UserGroupTestRepository";

export type CompositionRoot = ReturnType<typeof getCompositionRoot>;

Expand All @@ -87,6 +90,7 @@ type Repositories = {
chartConfigRepository: ChartConfigRepository;
systemRepository: SystemRepository;
configurationsRepository: ConfigurationsRepository;
userGroupRepository: UserGroupRepository;
};

function getCompositionRoot(repositories: Repositories) {
Expand All @@ -105,7 +109,8 @@ function getCompositionRoot(repositories: Repositories) {
),
getConfigurations: new GetConfigurationsUseCase(
repositories.configurationsRepository,
repositories.teamMemberRepository
repositories.teamMemberRepository,
repositories.userGroupRepository
),
complete: new CompleteEventTrackerUseCase(repositories),
},
Expand Down Expand Up @@ -160,6 +165,7 @@ export function getWebappCompositionRoot(api: D2Api) {
chartConfigRepository: new ChartConfigD2Repository(dataStoreClient),
systemRepository: new SystemD2Repository(api),
configurationsRepository: new ConfigurationsD2Repository(api),
userGroupRepository: new UserGroupD2Repository(api),
};

return getCompositionRoot(repositories);
Expand All @@ -182,6 +188,7 @@ export function getTestCompositionRoot() {
chartConfigRepository: new ChartConfigTestRepository(),
systemRepository: new SystemTestRepository(),
configurationsRepository: new ConfigurationsTestRepository(),
userGroupRepository: new UserGroupTestRepository(),
};

return getCompositionRoot(repositories);
Expand Down
12 changes: 9 additions & 3 deletions src/data/repositories/IncidentActionD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ import {
mapDataElementsToIncidentResponseActions,
mapIncidentActionToDataElements,
} from "./utils/IncidentActionMapper";
import { ActionPlanFormData, ResponseActionFormData } from "../../domain/entities/ConfigurableForm";
import {
ActionPlanFormData,
ResponseActionFormData,
SingleResponseActionFormData,
} from "../../domain/entities/ConfigurableForm";
import { getProgramStage } from "./utils/MetadataHelper";
import { Future } from "../../domain/entities/generic/Future";
import { Status, Verification } from "../../domain/entities/incident-action-plan/ResponseAction";
import { assertOrError } from "./utils/AssertOrError";
import { D2TrackerEvent } from "@eyeseetea/d2-api/api/trackerEvents";
import { statusCodeMap, verificationCodeMap } from "./consts/IncidentActionConstants";
import { FormType } from "../../webapp/pages/form-page/FormPage";

export const incidentActionPlanIds = {
iapType: "wr1I51WTHhl",
Expand Down Expand Up @@ -128,7 +133,7 @@ export class IncidentActionD2Repository implements IncidentActionRepository {
}

saveIncidentAction(
formData: ActionPlanFormData | ResponseActionFormData,
formData: ActionPlanFormData | ResponseActionFormData | SingleResponseActionFormData,
diseaseOutbreakId: Id
): FutureData<void> {
const programStageId = this.getProgramStageByFormType(formData.type);
Expand Down Expand Up @@ -242,10 +247,11 @@ export class IncidentActionD2Repository implements IncidentActionRepository {
});
}

private getProgramStageByFormType(formType: string) {
private getProgramStageByFormType(formType: FormType): Id {
switch (formType) {
case "incident-action-plan":
return RTSL_ZEBRA_INCIDENT_ACTION_PLAN_PROGRAM_STAGE_ID;
case "incident-response-actions":
case "incident-response-action":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is quite confusing, change "incident-response-action" to "single-incident-response-action" .

Make the change in the next PR for v2, so that we are not blocking release for this code review comment.

return RTSL_ZEBRA_INCIDENT_RESPONSE_ACTION_PROGRAM_STAGE_ID;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/data/repositories/TeamMemberD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { apiToFuture, FutureData } from "../api-futures";
import { assertOrError } from "./utils/AssertOrError";
import { Future } from "../../domain/entities/generic/Future";

const RTSL_ZEBRA_INCIDENTMANAGER = "RTSL_ZEBRA_INCIDENTMANAGER";
export const RTSL_ZEBRA_INCIDENTMANAGER = "RTSL_ZEBRA_INCIDENTMANAGER";
const RTSL_ZEBRA_RISKASSESSOR = "RTSL_ZEBRA_RISKASSESSOR";
const RTSL_ZEBRA_INCIDENT_MANAGEMENT_TEAM_MEMBERS = "RTSL_ZEBRA_INCIDENT_MANAGEMENT_TEAM_MEMBERS";
const RTSL_ZEBRA_INCIDENT_RESPONSE_OFFICERS = "RTSL_ZEBRA_INCIDENT_RESPONSE_OFFICERS";
Expand Down
29 changes: 29 additions & 0 deletions src/data/repositories/UserGroupD2Repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { D2Api } from "@eyeseetea/d2-api/2.36";
import { UserGroupRepository } from "../../domain/repositories/UserGroupRepository";
import { apiToFuture, FutureData } from "../api-futures";
import { assertOrError } from "./utils/AssertOrError";
import { UserGroup } from "../../domain/entities/UserGroup";
import { RTSL_ZEBRA_INCIDENTMANAGER } from "./TeamMemberD2Repository";

export class UserGroupD2Repository implements UserGroupRepository {
constructor(private api: D2Api) {}

getIncidentManagerUserGroupByCode(): FutureData<UserGroup> {
return apiToFuture(
this.api.metadata.get({
userGroups: {
fields: {
id: true,
},
filter: {
code: { eq: RTSL_ZEBRA_INCIDENTMANAGER },
},
},
})
)
.flatMap(response =>
assertOrError(response.userGroups[0], `User group ${RTSL_ZEBRA_INCIDENTMANAGER}`)
)
.map(userGroup => userGroup);
}
}
8 changes: 4 additions & 4 deletions src/data/repositories/consts/IncidentActionConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export const statusCodeMap: Record<ResponseActionStatusType, string> = {
Complete: "RTSL_ZEB_OS_STATUS_COMPLETE",
} as const;

export function getStatusTypeByCode(iapTypeCode: string): Maybe<ResponseActionStatusType> {
export function getStatusTypeByCode(statusCode: string): Maybe<ResponseActionStatusType> {
return (Object.keys(statusCodeMap) as ResponseActionStatusType[]).find(
key => statusCodeMap[key] === iapTypeCode
key => statusCodeMap[key] === statusCode
);
}

Expand All @@ -94,10 +94,10 @@ export const verificationCodeMap: Record<ResponseActionVerificationType, string>
};

export function getVerificationTypeByCode(
iapTypeCode: string
verificationCode: string
): Maybe<ResponseActionVerificationType> {
return (Object.keys(verificationCodeMap) as ResponseActionVerificationType[]).find(
key => verificationCodeMap[key] === iapTypeCode
key => verificationCodeMap[key] === verificationCode
);
}

Expand Down
12 changes: 12 additions & 0 deletions src/data/repositories/test/UserGroupTestRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Future } from "../../../domain/entities/generic/Future";
import { UserGroup } from "../../../domain/entities/UserGroup";
import { UserGroupRepository } from "../../../domain/repositories/UserGroupRepository";
import { FutureData } from "../../api-futures";

export class UserGroupTestRepository implements UserGroupRepository {
getIncidentManagerUserGroupByCode(): FutureData<UserGroup> {
return Future.success({
id: "1",
});
}
}
91 changes: 60 additions & 31 deletions src/data/repositories/utils/IncidentActionMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Maybe } from "../../../utils/ts-utils";
import {
ActionPlanFormData,
ResponseActionFormData,
SingleResponseActionFormData,
} from "../../../domain/entities/ConfigurableForm";
import { D2ProgramStageDataElementsMetadata } from "./RiskAssessmentMapper";
import { ActionPlanAttrs } from "../../../domain/entities/incident-action-plan/ActionPlan";
Expand All @@ -29,6 +30,7 @@ import {
Status,
Verification,
} from "../../../domain/entities/incident-action-plan/ResponseAction";
import _c from "../../../domain/entities/generic/Collection";

export function mapDataElementsToIncidentActionPlan(
id: Id,
Expand Down Expand Up @@ -101,7 +103,7 @@ export function mapDataElementsToIncidentResponseActions(
}

export function mapIncidentActionToDataElements(
formData: ActionPlanFormData | ResponseActionFormData,
formData: ActionPlanFormData | ResponseActionFormData | SingleResponseActionFormData,
programStageId: Id,
teiId: Id,
enrollmentId: Id,
Expand All @@ -118,6 +120,7 @@ export function mapIncidentActionToDataElements(
formData.entity,
programStageDataElementsMetadata
);
case "incident-response-actions":
case "incident-response-action":
return mapIncidentResponseActionToDataElements(
programStageId,
Expand Down Expand Up @@ -164,40 +167,66 @@ export function mapIncidentResponseActionToDataElements(
programStageId: Id,
teiId: Id,
enrollmentId: Id,
incidentResponseActions: ResponseAction[],
incidentResponseActions: ResponseAction | ResponseAction[],
programStageDataElementsMetadata: D2ProgramStageDataElementsMetadata[]
): D2TrackerEvent[] {
return incidentResponseActions.map(incidentResponseAction => {
const dataElementValues: Record<ResponseActionCodes, string> =
getValueFromIncidentResponseAction(incidentResponseAction);

const dataValues: DataValue[] = programStageDataElementsMetadata
.filter(
programStageDataElement =>
programStageDataElement.dataElement.id !== incidentResponseActionsIds.timeLine
)
.map(programStage => {
if (!isStringInIncidentResponseActionCodes(programStage.dataElement.code)) {
throw new Error(
`DataElement code ${programStage.dataElement.code} not found in Incident Action Plan Codes`
);
}
const typedCode: IncidentResponseActionKeyCode = programStage.dataElement.code;

return getPopulatedDataElement(
programStage.dataElement.id,
dataElementValues[typedCode]
return Array.isArray(incidentResponseActions)
? incidentResponseActions.map(incidentResponseAction => {
return buildDataValuesFromResponseAction(
programStageId,
teiId,
enrollmentId,
incidentResponseAction,
programStageDataElementsMetadata
);
})
: [
buildDataValuesFromResponseAction(
programStageId,
teiId,
enrollmentId,
incidentResponseActions,
programStageDataElementsMetadata
),
];
}

function buildDataValuesFromResponseAction(
programStageId: Id,
teiId: Id,
enrollmentId: Id,
responseAction: ResponseAction,
programStageDataElementsMetadata: D2ProgramStageDataElementsMetadata[]
): D2TrackerEvent {
const dataElementValues: Record<ResponseActionCodes, string> =
getValueFromIncidentResponseAction(responseAction);

const dataValues: DataValue[] = programStageDataElementsMetadata
.filter(
programStageDataElement =>
programStageDataElement.dataElement.id !== incidentResponseActionsIds.timeLine
)
.map(programStage => {
if (!isStringInIncidentResponseActionCodes(programStage.dataElement.code)) {
throw new Error(
`DataElement code ${programStage.dataElement.code} not found in Incident Action Plan Codes`
);
});
}
const typedCode: IncidentResponseActionKeyCode = programStage.dataElement.code;

return getIncidentActionTrackerEvent(
programStageId,
incidentResponseAction.id,
enrollmentId,
dataValues,
teiId
);
});
return getPopulatedDataElement(
programStage.dataElement.id,
dataElementValues[typedCode]
);
});

return getIncidentActionTrackerEvent(
programStageId,
responseAction.id,
enrollmentId,
dataValues,
teiId
);
}

function getPopulatedDataElement(dataElement: Id, value: Maybe<string>): DataValue {
Expand Down
2 changes: 2 additions & 0 deletions src/domain/entities/AppConfigurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Capability1,
Capability2,
} from "./risk-assessment/RiskAssessmentGrading";
import { UserGroup } from "./UserGroup";

export type SelectableOptions = {
eventTrackerConfigurations: DiseaseOutbreakEventOptions;
Expand All @@ -43,6 +44,7 @@ export type SelectableOptions = {
incidentResponseActionConfigurations: IncidentResponseActionOptions;
};
export type Configurations = {
incidentManagerUserGroup: UserGroup;
selectableOptions: SelectableOptions;
teamMembers: {
all: TeamMember[];
Expand Down
10 changes: 9 additions & 1 deletion src/domain/entities/ConfigurableForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,19 @@ export type ActionPlanFormData = BaseFormData & {
};

export type ResponseActionFormData = BaseFormData & {
type: "incident-response-action";
type: "incident-response-actions";
eventTrackerDetails: DiseaseOutbreakEvent;
entity: ResponseAction[];
options: IncidentResponseActionOptions;
};

export type SingleResponseActionFormData = BaseFormData & {
type: "incident-response-action";
eventTrackerDetails: DiseaseOutbreakEvent;
entity: ResponseAction;
options: IncidentResponseActionOptions;
};

export type IncidentManagementTeamRoleOptions = {
roles: Role[];
teamMembers: TeamMember[];
Expand All @@ -135,4 +142,5 @@ export type ConfigurableForm =
| RiskAssessmentQuestionnaireFormData
| ActionPlanFormData
| ResponseActionFormData
| SingleResponseActionFormData
| IncidentManagementTeamMemberFormData;
Loading
Loading