diff --git a/src/domain/usecases/GetDiseaseOutbreakWithOptionsUseCase.ts b/src/domain/usecases/GetDiseaseOutbreakWithOptionsUseCase.ts deleted file mode 100644 index aab268c3..00000000 --- a/src/domain/usecases/GetDiseaseOutbreakWithOptionsUseCase.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { FutureData } from "../../data/api-futures"; -import { - DataSource, - DiseaseOutbreakEventBaseAttrs, -} from "../entities/disease-outbreak-event/DiseaseOutbreakEvent"; -import { DiseaseOutbreakEventWithOptions } from "../entities/disease-outbreak-event/DiseaseOutbreakEventWithOptions"; -import { Future } from "../entities/generic/Future"; -import { Id } from "../entities/Ref"; -import { DiseaseOutbreakEventRepository } from "../repositories/DiseaseOutbreakEventRepository"; -import { OptionsRepository } from "../repositories/OptionsRepository"; -import { TeamMemberRepository } from "../repositories/TeamMemberRepository"; - -export class GetDiseaseOutbreakWithOptionsUseCase { - constructor( - private options: { - diseaseOutbreakEventRepository: DiseaseOutbreakEventRepository; - optionsRepository: OptionsRepository; - teamMemberRepository: TeamMemberRepository; - } - ) {} - - public execute(id?: Id): FutureData { - if (id) { - return this.options.diseaseOutbreakEventRepository - .get(id) - .flatMap(diseaseOutbreakEventBase => { - return this.getDiseaseOutbreakEventWithOptions(diseaseOutbreakEventBase); - }); - } else { - return this.getDiseaseOutbreakEventWithOptions(); - } - } - - private getDiseaseOutbreakEventWithOptions( - diseaseOutbreakEventBase?: DiseaseOutbreakEventBaseAttrs - ): FutureData { - return Future.joinObj({ - dataSources: this.options.optionsRepository.getDataSources(), - hazardTypes: this.options.optionsRepository.getHazardTypes(), - mainSyndromes: this.options.optionsRepository.getMainSyndromes(), - suspectedDiseases: this.options.optionsRepository.getSuspectedDiseases(), - notificationSources: this.options.optionsRepository.getNotificationSources(), - incidentStatus: this.options.optionsRepository.getIncidentStatus(), - incidentManagers: this.options.teamMemberRepository.getIncidentManagers(), - }).flatMap( - ({ - dataSources, - hazardTypes, - mainSyndromes, - suspectedDiseases, - notificationSources, - incidentStatus, - incidentManagers, - }) => { - const diseaseOutbreakEventWithOptions: DiseaseOutbreakEventWithOptions = { - diseaseOutbreakEvent: diseaseOutbreakEventBase, - options: { - dataSources, - incidentManagers, - hazardTypes, - mainSyndromes, - suspectedDiseases, - notificationSources, - incidentStatus, - }, - // TODO: Get labels from Datastore used in mapEntityToInitialFormState to create initial form state - labels: { - errors: { - field_is_required: "This field is required", - field_is_required_na: "This field is required when not applicable", - }, - }, - // TODO: Get rules from Datastore used in applyRulesInFormState - rules: [ - { - type: "toggleSectionsVisibilityByFieldValue", - fieldId: "dataSource", - fieldValue: DataSource.RTSL_ZEB_OS_DATA_SOURCE_EBS, - sectionIds: ["hazardType_section"], - }, - { - type: "toggleSectionsVisibilityByFieldValue", - fieldId: "dataSource", - fieldValue: DataSource.RTSL_ZEB_OS_DATA_SOURCE_IBS, - sectionIds: ["mainSyndrome_section", "suspectedDisease_section"], - }, - ], - }; - return Future.success(diseaseOutbreakEventWithOptions); - } - ); - } -} diff --git a/src/webapp/components/form/form-summary/useFormSummary.ts b/src/webapp/components/form/form-summary/useFormSummary.ts deleted file mode 100644 index 24732b5b..00000000 --- a/src/webapp/components/form/form-summary/useFormSummary.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { useEffect, useState } from "react"; -import { useAppContext } from "../../../contexts/app-context"; -import { Id } from "../../../../domain/entities/Ref"; -import { - DataSource, - DiseaseOutbreakEvent, -} from "../../../../domain/entities/disease-outbreak-event/DiseaseOutbreakEvent"; -import { User } from "../../user-selector/UserSelector"; - -import { Maybe } from "../../../../utils/ts-utils"; -import { - getDateAsLocaleDateTimeString, - getDateAsMonthYearString, -} from "../../../../data/repositories/utils/DateTimeHelper"; -import { mapTeamMemberToUser } from "../../../pages/form-page/mapEntityToFormState"; - -const EventTypeLabel = "Event type"; -const DiseaseLabel = "Disease"; -type LabelWithValue = { - label: string; - value: string; -}; - -type FormSummary = { - subTitle: string; - summary: LabelWithValue[]; - incidentManager: Maybe; - notes: string; -}; -export function useFormSummary(id: Id) { - const { compositionRoot } = useAppContext(); - const [formSummary, setFormSummary] = useState(); - const [summaryError, setSummaryError] = useState(); - - useEffect(() => { - compositionRoot.diseaseOutbreakEvent.get.execute(id).run( - diseaseOutbreakEvent => { - setFormSummary(mapDiseaseOutbreakEventToFormSummary(diseaseOutbreakEvent)); - }, - err => { - console.debug(err); - setSummaryError(`Event tracker with id: ${id} does not exist`); - } - ); - }, [compositionRoot.diseaseOutbreakEvent.get, id]); - - const mapDiseaseOutbreakEventToFormSummary = ( - diseaseOutbreakEvent: DiseaseOutbreakEvent - ): FormSummary => { - const dataSourceLabelValue: LabelWithValue = - diseaseOutbreakEvent.dataSource === DataSource.RTSL_ZEB_OS_DATA_SOURCE_EBS - ? { - label: EventTypeLabel, - value: diseaseOutbreakEvent.hazardType ?? "", - } - : { - label: DiseaseLabel, - value: diseaseOutbreakEvent.suspectedDisease?.name ?? "", - }; - return { - subTitle: diseaseOutbreakEvent.name, - summary: [ - { - label: "Last updated", - value: getDateAsLocaleDateTimeString(diseaseOutbreakEvent.lastUpdated), - }, - dataSourceLabelValue, - { - label: "Event ID", - value: diseaseOutbreakEvent.id, - }, - { - label: "Emergence date", - value: getDateAsMonthYearString(diseaseOutbreakEvent.emerged.date), - }, - { - label: "Detection date", - value: getDateAsMonthYearString(diseaseOutbreakEvent.detected.date), - }, - { - label: "Notification date", - value: getDateAsMonthYearString(diseaseOutbreakEvent.notified.date), - }, - ], - incidentManager: diseaseOutbreakEvent.incidentManager - ? mapTeamMemberToUser(diseaseOutbreakEvent.incidentManager) - : undefined, - notes: diseaseOutbreakEvent.notes ?? "", - }; - }; - - return { formSummary, summaryError }; -}