From e5923255f32d7cb8c02377d4cb43e78b29284cce Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Sat, 7 Oct 2023 16:23:38 +0200 Subject: [PATCH] =?UTF-8?q?fix(app,dashboard):=20fix=20temporaire=20des=20?= =?UTF-8?q?duplicatas=20de=20dossier=20m=C3=A9dical?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/recoil/selectors.js | 28 ++++++++++++++++++++++++++-- dashboard/src/recoil/selectors.js | 21 ++++++++++++++++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/app/src/recoil/selectors.js b/app/src/recoil/selectors.js index 89afa40f26..af580f67fa 100644 --- a/app/src/recoil/selectors.js +++ b/app/src/recoil/selectors.js @@ -93,7 +93,7 @@ export const itemsGroupedByPersonSelector = selector({ const comments = get(commentsState); const consultations = get(consultationsState); const treatments = get(treatmentsState); - const medicalFiles = get(medicalFileState); + const medicalFiles = get(medicalFileState).sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)); const relsPersonPlace = get(relsPersonPlaceState); const places = get(placesObjectSelector); const rencontres = get(rencontresState); @@ -173,7 +173,31 @@ export const itemsGroupedByPersonSelector = selector({ } for (const medicalFile of medicalFiles) { if (!personsObject[medicalFile.person]) continue; - personsObject[medicalFile.person].medicalFile = medicalFile; + if (personsObject[medicalFile.person].medicalFile) { + const nextDocuments = {}; + const nextComments = {}; + const existingMedicalFile = personsObject[medicalFile.person].medicalFile; + for (const document of medicalFile.documents || []) { + nextDocuments[document._id] = document; + } + for (const document of existingMedicalFile.documents || []) { + nextDocuments[document._id] = document; + } + for (const comment of medicalFile.comments || []) { + nextComments[comment._id] = comment; + } + for (const comment of existingMedicalFile.comments || []) { + nextComments[comment._id] = comment; + } + personsObject[medicalFile.person].medicalFile = { + ...medicalFile, + ...personsObject[medicalFile.person].medicalFile, + documents: Object.values(nextDocuments), + comments: Object.values(nextComments), + }; + } else { + personsObject[medicalFile.person].medicalFile = medicalFile; + } } // we don't use passages in the app - no use, no load // but we keep it here just to be aware of that app specificity diff --git a/dashboard/src/recoil/selectors.js b/dashboard/src/recoil/selectors.js index 5f8634fafa..98ec57b3a0 100644 --- a/dashboard/src/recoil/selectors.js +++ b/dashboard/src/recoil/selectors.js @@ -122,7 +122,7 @@ export const itemsGroupedByPersonSelector = selector({ const comments = get(commentsState); const consultations = get(consultationsState); const treatments = get(treatmentsState); - const medicalFiles = get(medicalFileState); + const medicalFiles = get(medicalFileState).sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)); const passages = get(passagesState); const relsPersonPlace = get(relsPersonPlaceState); const places = get(placesObjectSelector); @@ -260,11 +260,26 @@ export const itemsGroupedByPersonSelector = selector({ for (const medicalFile of medicalFiles) { if (!personsObject[medicalFile.person]) continue; if (personsObject[medicalFile.person].medicalFile) { + const nextDocuments = {}; + const nextComments = {}; + const existingMedicalFile = personsObject[medicalFile.person].medicalFile; + for (const document of medicalFile.documents || []) { + nextDocuments[document._id] = document; + } + for (const document of existingMedicalFile.documents || []) { + nextDocuments[document._id] = document; + } + for (const comment of medicalFile.comments || []) { + nextComments[comment._id] = comment; + } + for (const comment of existingMedicalFile.comments || []) { + nextComments[comment._id] = comment; + } personsObject[medicalFile.person].medicalFile = { ...medicalFile, ...personsObject[medicalFile.person].medicalFile, - documents: [...(medicalFile?.documents || []), ...(personsObject[medicalFile.person].medicalFile?.documents || [])], - comments: [...(medicalFile?.comments || []), ...(personsObject[medicalFile.person].medicalFile?.comments || [])], + documents: Object.values(nextDocuments), + comments: Object.values(nextComments), }; } else { personsObject[medicalFile.person].medicalFile = medicalFile;