From be6e6700a16689d864d557a480a448fe36ccfec3 Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Mon, 11 Sep 2023 20:23:54 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20historique=20pour=20dossier=20m=C3=A9di?= =?UTF-8?q?cal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/scenes/Persons/MedicalFile.js | 16 ++++++- app/src/scenes/Persons/Person.js | 5 ++ dashboard/src/recoil/medicalFiles.ts | 2 +- .../src/scenes/person/components/EditModal.js | 39 +++++++++++++-- .../scenes/person/components/PersonHistory.js | 47 ++++++++++++++----- ...erson-full-test-migrated-from-jest.spec.ts | 3 +- 6 files changed, 93 insertions(+), 19 deletions(-) diff --git a/app/src/scenes/Persons/MedicalFile.js b/app/src/scenes/Persons/MedicalFile.js index 62f32cab5..6df333827 100644 --- a/app/src/scenes/Persons/MedicalFile.js +++ b/app/src/scenes/Persons/MedicalFile.js @@ -190,6 +190,20 @@ const MedicalFile = ({ navigation, person, personDB, onUpdatePerson, updating, e const onUpdateRequest = async (latestMedicalFile) => { if (!latestMedicalFile) latestMedicalFile = medicalFile; + + const historyEntry = { + date: new Date(), + user: user._id, + data: {}, + }; + for (const key in latestMedicalFile) { + if (!customFieldsMedicalFile.map((field) => field.name).includes(key)) continue; + if (latestMedicalFile[key] !== medicalFileDB[key]) { + historyEntry.data[key] = { oldValue: medicalFileDB[key], newValue: latestMedicalFile[key] }; + } + } + if (!!Object.keys(historyEntry.data).length) latestMedicalFile.history = [...(medicalFileDB.history || []), historyEntry]; + const response = await API.put({ path: `/medical-file/${medicalFileDB._id}`, body: prepareMedicalFileForEncryption(customFieldsMedicalFile)({ ...medicalFileDB, ...latestMedicalFile }), @@ -309,7 +323,7 @@ const MedicalFile = ({ navigation, person, personDB, onUpdatePerson, updating, e