From c5233155fa534fc33db0bef282ae1dd63d318795 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Oct 2025 20:42:02 +0000 Subject: [PATCH 1/2] Initial plan From d25e2d85e74bd3109e60931195aa05fbd7da70d9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Oct 2025 20:48:55 +0000 Subject: [PATCH 2/2] Support clinician notifications when seeding specific userIds Co-authored-by: pauljohanneskraft <15239005+pauljohanneskraft@users.noreply.github.com> --- functions/src/functions/defaultSeed.test.ts | 44 +++++++++++++++++ functions/src/functions/defaultSeed.ts | 54 ++++++++++++++++----- 2 files changed, 85 insertions(+), 13 deletions(-) diff --git a/functions/src/functions/defaultSeed.test.ts b/functions/src/functions/defaultSeed.test.ts index ddcf2fb6..7303ddea 100644 --- a/functions/src/functions/defaultSeed.test.ts +++ b/functions/src/functions/defaultSeed.test.ts @@ -70,4 +70,48 @@ describeWithEmulators("function: defaultSeed", (env) => { .get(); expect(userSymptomScores.docs.length).toBeGreaterThanOrEqual(1); }, 30_000); + + it("seeds clinician messages for specific userIds", async () => { + // First seed all users + await _defaultSeed(env.factory, { + date: new Date(), + only: [DebugDataComponent.users], + staticData: undefined, + onlyUserCollections: [], + userData: [], + }); + + const users = await env.collections.users.get(); + const clinician = users.docs.find( + (userDoc) => userDoc.data().type === UserType.clinician, + ); + const patient = users.docs.find( + (userDoc) => userDoc.data().type === UserType.patient, + ); + expect(clinician).toBeDefined(); + expect(patient).toBeDefined(); + + if (clinician === undefined) fail("clinician is undefined"); + if (patient === undefined) fail("patient is undefined"); + + // Seed clinician messages for specific clinician userId + await _defaultSeed(env.factory, { + date: new Date(), + only: [], + staticData: undefined, + onlyUserCollections: [UserDebugDataComponent.messages], + userData: [ + { + userId: clinician.id, + only: [UserDebugDataComponent.messages], + }, + ], + }); + + // Verify clinician messages were seeded + const clinicianMessages = await env.collections + .userMessages(clinician.id) + .get(); + expect(clinicianMessages.docs.length).toBeGreaterThan(0); + }, 30_000); }); diff --git a/functions/src/functions/defaultSeed.ts b/functions/src/functions/defaultSeed.ts index 38704578..98b97425 100644 --- a/functions/src/functions/defaultSeed.ts +++ b/functions/src/functions/defaultSeed.ts @@ -168,19 +168,47 @@ export async function _defaultSeed( } } - for (const userData of data.userData) { - try { - await _seedPatientCollections({ - debugData: debugDataService, - trigger: triggerService, - userId: userData.userId, - components: userData.only, - date: data.date, - }); - } catch (error) { - logger.error( - `Failed to seed user data ${userData.userId}: ${String(error)}`, - ); + if (data.userData.length > 0) { + const userService = factory.user(); + const allPatients = await userService.getAllPatients(); + + for (const userData of data.userData) { + try { + const user = await userService.getUser(userData.userId); + if (user?.content.type === UserType.patient) { + await _seedPatientCollections({ + debugData: debugDataService, + trigger: triggerService, + userId: userData.userId, + components: userData.only, + date: data.date, + }); + } else if (user?.content.type === UserType.clinician) { + const clinicianPatients = allPatients.filter( + (patient) => patient.content.clinician === user.id, + ); + const patients = await Promise.all( + clinicianPatients.map(async (patient) => { + const patientAuth = await userService.getAuth(patient.id); + return { + name: patientAuth.displayName, + id: patient.id, + }; + }), + ); + await _seedClinicianCollections({ + debugData: debugDataService, + trigger: triggerService, + userId: userData.userId, + components: userData.only, + patients, + }); + } + } catch (error) { + logger.error( + `Failed to seed user data ${userData.userId}: ${String(error)}`, + ); + } } } }