Skip to content

Commit

Permalink
reafctor: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Aug 6, 2024
1 parent a16e103 commit 8e00ad0
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 34 deletions.
10 changes: 5 additions & 5 deletions src/data/repositories/OptionsD2Repository.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { D2Api } from "@eyeseetea/d2-api/2.36";
import { Id, NamedRef } from "../../domain/entities/Ref";
import { Code, Id, NamedRef } from "../../domain/entities/Ref";
import { apiToFuture, FutureData } from "../api-futures";
import { OptionsRepository } from "../../domain/repositories/OptionsRepository";
import { Future } from "../../domain/entities/generic/Future";

export class OptionsD2Repository implements OptionsRepository {
constructor(private api: D2Api) {}

get(id: Id): FutureData<NamedRef> {
if (!id) return Future.success({ id: "", name: "" });
get(code: Code): FutureData<NamedRef> {
if (!code) return Future.success({ id: "", name: "" });
return apiToFuture(
this.api.metadata.get({
options: { fields: { id: true, name: true }, filter: { id: { eq: id } } },
options: { fields: { code: true, name: true }, filter: { code: { eq: code } } },
})
).map(response => {
if (!response.options[0]) throw new Error("Option not found");
const option: NamedRef = {
id: response.options[0].id,
id: response.options[0].code,
name: response.options[0].name,
};
return option;
Expand Down
8 changes: 7 additions & 1 deletion src/data/repositories/TeamMemberD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ export class TeamMemberD2Repository implements TeamMemberRepository {
return apiToFuture(
this.api.metadata.get({
users: {
fields: { id: true, name: true, email: true, phoneNumber: true },
fields: {
id: true,
name: true,
email: true,
phoneNumber: true,
username: true,
},
filter: { username: { eq: id } },
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class DiseaseOutbreakEventTestRepository implements DiseaseOutbreakEventR
lastUpdated: new Date(),
createdByName: "createdByName",
hazardType: "Biological:Animal",
mainSyndromeId: "1",
suspectedDiseaseId: "1",
notificationSourceId: "1",
mainSyndromeCode: "1",
suspectedDiseaseCode: "1",
notificationSourceCode: "1",
areasAffectedDistrictIds: [],
areasAffectedProvinceIds: [],
incidentStatus: "Watch",
Expand Down
36 changes: 24 additions & 12 deletions src/data/repositories/utils/DiseaseOutbreakMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export function mapTrackedEntityAttributesToDiseaseOutbreak(
lastUpdated: trackedEntity.updatedAt ? new Date(trackedEntity.updatedAt) : new Date(),
createdByName: undefined,
hazardType: getValueFromMap("hazardType", trackedEntity) as HazardType,
mainSyndromeId: getValueFromMap("mainSyndrome", trackedEntity),
suspectedDiseaseId: getValueFromMap("suspectedDisease", trackedEntity),
mainSyndromeCode: getValueFromMap("mainSyndrome", trackedEntity),
suspectedDiseaseCode: getValueFromMap("suspectedDisease", trackedEntity),

notificationSourceId: getValueFromMap("notificationSource", trackedEntity),
notificationSourceCode: getValueFromMap("notificationSource", trackedEntity),

areasAffectedProvinceIds: [getValueFromMap("areasAffectedProvinces", trackedEntity)].filter(
ou => ou !== ""
Expand Down Expand Up @@ -82,10 +82,10 @@ export function mapTrackedEntityAttributesToDiseaseOutbreak(
},
initiatePublicHealthCounterMeasures: {
date: new Date(
getValueFromMap("initiatePublicHealthCounterMeasuresNA", trackedEntity)
getValueFromMap("initiatePublicHealthCounterMeasuresDate", trackedEntity)
),
na:
getValueFromMap("initiatePublicHealthCounterMeasuresDate", trackedEntity) ===
getValueFromMap("initiatePublicHealthCounterMeasuresNA", trackedEntity) ===
"true",
},
initiateRiskCommunication: {
Expand Down Expand Up @@ -183,11 +183,11 @@ function getValueFromDiseaseOutbreak(
}
break;
case "RTSL_ZEB_TEA_MAIN_SYNDROME":
return diseaseOutbreak.mainSyndromeId;
return diseaseOutbreak.mainSyndromeCode;
case "RTSL_ZEB_TEA_SUSPECTED_DISEASE":
return diseaseOutbreak.suspectedDiseaseId;
return diseaseOutbreak.suspectedDiseaseCode;
case "RTSL_ZEB_TEA_NOTIFICATION_SOURCE":
return diseaseOutbreak.notificationSourceId;
return diseaseOutbreak.notificationSourceCode;
case "RTSL_ZEB_TEA_AREAS_AFFECTED_PROVINCES":
return diseaseOutbreak.areasAffectedProvinceIds[0] ?? ""; //TO DO : Handle multiple provinces once metadata change is done
case "RTSL_ZEB_TEA_AREAS_AFFECTED_DISTRICTS":
Expand All @@ -213,21 +213,33 @@ function getValueFromDiseaseOutbreak(
case "RTSL_ZEB_TEA_LABORATORY_CONFIRMATION":
return diseaseOutbreak.earlyResponseActions.laboratoryConfirmation.na ? "true" : "";
case "RTSL_ZEB_TEA_SPECIFY_DATE1":
return diseaseOutbreak.earlyResponseActions.laboratoryConfirmation.date.toISOString();
return (
diseaseOutbreak.earlyResponseActions.laboratoryConfirmation.date?.toISOString() ??
""
);
case "RTSL_ZEB_TEA_APPROPRIATE_CASE_MANAGEMENT":
return diseaseOutbreak.earlyResponseActions.appropriateCaseManagement.na ? "true" : "";
case "RTSL_ZEB_TEA_SPECIFY_DATE2":
return diseaseOutbreak.earlyResponseActions.appropriateCaseManagement.date?.toISOString();
return (
diseaseOutbreak.earlyResponseActions.appropriateCaseManagement.date?.toISOString() ??
""
);
case "RTSL_ZEB_TEA_APPROPRIATE_PUBLIC_HEALTH":
return diseaseOutbreak.earlyResponseActions.initiatePublicHealthCounterMeasures.na
? "true"
: "";
case "RTSL_ZEB_TEA_SPECIFY_DATE3":
return diseaseOutbreak.earlyResponseActions.initiatePublicHealthCounterMeasures.date?.toISOString();
return (
diseaseOutbreak.earlyResponseActions.initiatePublicHealthCounterMeasures.date?.toISOString() ??
""
);
case "RTSL_ZEB_TEA_APPROPRIATE_RISK_COMMUNICATION":
return diseaseOutbreak.earlyResponseActions.initiateRiskCommunication.na ? "true" : "";
case "RTSL_ZEB_TEA_SPECIFY_DATE4":
return diseaseOutbreak.earlyResponseActions.initiateRiskCommunication.date?.toISOString();
return (
diseaseOutbreak.earlyResponseActions.initiateRiskCommunication.date?.toISOString() ??
""
);
case "RTSL_ZEB_TEA_ESTABLISH_COORDINATION_MECHANISM":
return diseaseOutbreak.earlyResponseActions.establishCoordination.toISOString();
case "RTSL_ZEB_TEA_RESPONSE_NARRATIVE":
Expand Down
1 change: 1 addition & 0 deletions src/domain/entities/Ref.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type Id = string;
export type Code = string;

export interface Ref {
id: Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type DateWithNarrative = {
};

type DateWithNA = {
date: Date;
date: Maybe<Date>;
na: Maybe<boolean>;
};

Expand All @@ -43,9 +43,9 @@ export type DiseaseOutbreakEventBaseAttrs = NamedRef & {
lastUpdated: Date;
createdByName: Maybe<string>;
hazardType: HazardType;
mainSyndromeId: Id;
suspectedDiseaseId: Id;
notificationSourceId: Id;
mainSyndromeCode: Id;
suspectedDiseaseCode: Id;
notificationSourceCode: Id;
areasAffectedProvinceIds: Id[];
areasAffectedDistrictIds: Id[];
incidentStatus: IncidentStatusType;
Expand Down
12 changes: 6 additions & 6 deletions src/domain/usecases/GetDiseaseOutbreakByIdUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ export class GetDiseaseOutbreakByIdUseCase {
public execute(id: Id): FutureData<DiseaseOutbreakEvent> {
return this.diseaseOutbreakRepository.get(id).flatMap(diseaseOutbreakEventBase => {
const {
mainSyndromeId,
suspectedDiseaseId,
notificationSourceId,
mainSyndromeCode,
suspectedDiseaseCode,
notificationSourceCode,
incidentManagerName,
areasAffectedDistrictIds,
areasAffectedProvinceIds,
} = diseaseOutbreakEventBase;

return Future.joinObj({
mainSyndrome: this.optionsRepository.get(mainSyndromeId),
suspectedDisease: this.optionsRepository.get(suspectedDiseaseId),
notificationSource: this.optionsRepository.get(notificationSourceId),
mainSyndrome: this.optionsRepository.get(mainSyndromeCode),
suspectedDisease: this.optionsRepository.get(suspectedDiseaseCode),
notificationSource: this.optionsRepository.get(notificationSourceCode),
incidentManager: incidentManagerName
? this.teamMemberRepository.get(incidentManagerName)
: Future.success(undefined),
Expand Down
6 changes: 3 additions & 3 deletions src/domain/usecases/SaveDiseaseOutbreakUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export class SaveDiseaseOutbreakUseCase {
lastUpdated: new Date(),
createdByName: "createdByName",
hazardType: "Biological:Animal",
mainSyndromeId: "",
suspectedDiseaseId: "",
notificationSourceId: "",
mainSyndromeCode: "",
suspectedDiseaseCode: "",
notificationSourceCode: "",
areasAffectedDistrictIds: ["oEBf29y8JP8"],
areasAffectedProvinceIds: ["AWn3s2RqgAN"],
incidentStatus: "Watch",
Expand Down

0 comments on commit 8e00ad0

Please sign in to comment.