Skip to content

Commit

Permalink
fix(app,dashboard): fix temporaire des duplicatas de dossier médical
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Oct 7, 2023
1 parent 3d4ced0 commit e592325
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
28 changes: 26 additions & 2 deletions app/src/recoil/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions dashboard/src/recoil/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e592325

Please sign in to comment.