mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
feat(02-12): add scoped profile summary
- expose bounded read-only profile facts for shared records\n- keep profile navigation separate from Settings mutations
This commit is contained in:
1 parent
e2d308ec31
commit
9eab70f032
7 files changed
+233
-2
No files matched your search
@@ -36,6 +36,7 @@ import { mentalHealthKeys } from "./mental-health";
|
||||
import { moodKeys } from "./mood";
|
||||
import { nutrientKeys } from "./nutrients";
|
||||
import { recordSettingsKeys } from "./record-settings";
|
||||
import { profileKeys } from "./profile";
|
||||
import { settingsKeys } from "./settings";
|
||||
import { sharingKeys } from "./sharing";
|
||||
import { workoutKeys } from "./workouts";
|
||||
@@ -65,6 +66,7 @@ export const queryKeys = {
|
||||
...customMetrics,
|
||||
...nutrientKeys,
|
||||
...recordSettingsKeys,
|
||||
...profileKeys,
|
||||
...sharingKeys,
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
/** Query keys for the bounded, read-only profile summary surface. */
|
||||
export const profileKeys = {
|
||||
profileSummary: () => ["profile", "summary"] as const,
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
import { prisma } from "@/lib/db";
|
||||
import { readHealthProfileFacts } from "@/lib/profile/health-facts";
|
||||
|
||||
export interface ProfileSummaryPayload {
|
||||
allergies: Array<{ substance: string; category: string }>;
|
||||
familyHistory: Array<{ condition: string; relationship: string }>;
|
||||
facts: Array<{ label: string; value: string }>;
|
||||
}
|
||||
|
||||
/**
|
||||
* The shared profile surface deliberately carries only the bounded, structured
|
||||
* facts a record viewer needs. It does not load settings, AI configuration, or
|
||||
* any encrypted free-text field.
|
||||
*/
|
||||
export async function readProfileSummary(
|
||||
userId: string,
|
||||
): Promise<ProfileSummaryPayload> {
|
||||
const [allergies, familyHistory, healthFacts] = await Promise.all([
|
||||
prisma.allergy.findMany({
|
||||
where: { userId, deletedAt: null },
|
||||
orderBy: { createdAt: "desc" },
|
||||
take: 25,
|
||||
select: { substance: true, category: true },
|
||||
}),
|
||||
prisma.familyHistoryEntry.findMany({
|
||||
where: { userId, deletedAt: null },
|
||||
orderBy: { createdAt: "desc" },
|
||||
take: 25,
|
||||
select: { condition: true, relationship: true },
|
||||
}),
|
||||
readHealthProfileFacts(userId),
|
||||
]);
|
||||
|
||||
return {
|
||||
allergies,
|
||||
familyHistory,
|
||||
facts: Object.values(healthFacts.current).flatMap((fact) =>
|
||||
fact?.value && !fact.unreadable
|
||||
? [{ label: fact.kind, value: fact.value }]
|
||||
: [],
|
||||
),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user