From e6d392e53fa4dbc0cf208ecf53114686a4e787a9 Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Fri, 29 Sep 2023 16:39:26 +0200 Subject: [PATCH] fix(dashboard): edit medical file --- app/src/scenes/Persons/MedicalFile.js | 2 +- dashboard/src/scenes/person/components/EditModal.js | 6 +++--- dashboard/src/scenes/person/components/MedicalFilePrint.js | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/scenes/Persons/MedicalFile.js b/app/src/scenes/Persons/MedicalFile.js index 6df333827..bf23fd7fd 100644 --- a/app/src/scenes/Persons/MedicalFile.js +++ b/app/src/scenes/Persons/MedicalFile.js @@ -45,7 +45,7 @@ const MedicalFile = ({ navigation, person, personDB, onUpdatePerson, updating, e const treatments = useMemo(() => (allTreatments || []).filter((t) => t.person === personDB._id), [allTreatments, personDB._id]); - const medicalFileDB = useMemo(() => (allMedicalFiles || []).find((m) => m.person === personDB._id), [allMedicalFiles, personDB._id]); + const medicalFileDB = personDB.medicalFile; const [medicalFile, setMedicalFile] = useState(medicalFileDB); const [writingComment, setWritingComment] = useState(''); diff --git a/dashboard/src/scenes/person/components/EditModal.js b/dashboard/src/scenes/person/components/EditModal.js index 016f1a4ff..8f557830e 100644 --- a/dashboard/src/scenes/person/components/EditModal.js +++ b/dashboard/src/scenes/person/components/EditModal.js @@ -11,7 +11,7 @@ import { import { outOfBoundariesDate } from '../../../services/date'; import SelectTeamMultiple from '../../../components/SelectTeamMultiple'; import { currentTeamState, userState } from '../../../recoil/auth'; -import { useRecoilState, useRecoilValue } from 'recoil'; +import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'; import CustomFieldInput from '../../../components/CustomFieldInput'; import { useMemo, useState } from 'react'; import ButtonCustom from '../../../components/ButtonCustom'; @@ -31,8 +31,8 @@ export default function EditModal({ person, selectedPanel, onClose, isMedicalFil const team = useRecoilValue(currentTeamState); const [persons, setPersons] = useRecoilState(personsState); const customFieldsMedicalFile = useRecoilValue(customFieldsMedicalFileSelector); - const [allMedicalFiles, setAllMedicalFiles] = useRecoilState(medicalFileState); - const medicalFile = useMemo(() => (allMedicalFiles || []).find((m) => m.person === person._id), [allMedicalFiles, person._id]); + const setAllMedicalFiles = useSetRecoilState(medicalFileState); + const medicalFile = person.medicalFile; const customFieldsMedicalFileWithLegacyFields = useMemo(() => { const c = [...customFieldsMedicalFile]; diff --git a/dashboard/src/scenes/person/components/MedicalFilePrint.js b/dashboard/src/scenes/person/components/MedicalFilePrint.js index 1237b8e0f..e25b90607 100644 --- a/dashboard/src/scenes/person/components/MedicalFilePrint.js +++ b/dashboard/src/scenes/person/components/MedicalFilePrint.js @@ -7,14 +7,13 @@ import CustomFieldDisplay from '../../../components/CustomFieldDisplay'; import { sortActionsOrConsultations } from '../../../recoil/actions'; import { arrayOfitemsGroupedByConsultationSelector } from '../../../recoil/selectors'; import { treatmentsState } from '../../../recoil/treatments'; -import { medicalFileState, customFieldsMedicalFileSelector } from '../../../recoil/medicalFiles'; +import { customFieldsMedicalFileSelector } from '../../../recoil/medicalFiles'; import { useLocalStorage } from '../../../services/useLocalStorage'; export function MedicalFilePrint({ person }) { const organisation = useRecoilValue(organisationState); const allConsultations = useRecoilValue(arrayOfitemsGroupedByConsultationSelector); const allTreatments = useRecoilValue(treatmentsState); - const allMedicalFiles = useRecoilValue(medicalFileState); const team = useRecoilValue(currentTeamState); const [consultationTypes] = useLocalStorage('consultation-types', []); @@ -39,7 +38,7 @@ export function MedicalFilePrint({ person }) { const treatments = useMemo(() => (allTreatments || []).filter((t) => t.person === person._id), [allTreatments, person._id]); - const medicalFile = useMemo(() => (allMedicalFiles || []).find((m) => m.person === person._id), [allMedicalFiles, person._id]); + const medicalFile = person.medicalFile; return (