Users
ctx.USER is the users table for your organization. Every loop reads and writes the same rows, so a patient seen by one loop is known to the next.
Get a user
const user = await ctx.USER.getUser({ id: "pat_18" });id is your own id for the person, such as a patient number, email address, or phone number. The first call creates the row, and later calls return it. user.id is the platform’s id for the same row.
Metadata
Metadata is a JSON object you own. setMetadata replaces the whole object.
await user.setMetadata({ name: "Thandi", phoneNumber: "+27821234567" });
const { name } = await user.getMetadata<{ name: string }>();Memory
Memory is a running list of lines about the person. Add one line at a time, and read it back as one string.
await user.remember("Prefers WhatsApp to calls");
const memory = await user.getMemory();Scans
A user’s completed face scans, across every loop in the organization.
const scans = await user.getScans();
const latest = await user.getLatestScan();
const count = await user.getScanCount();Each scan is a pointer with its loopId, scanSessionId, and createdAt. A scan is added once it completes, when it was created with this user. See Facial scans.
Example: one scan a month
import { workflow } from "@loops/sdk";
type Request = { patientId: string };
export const monthlyScanWorkflow = workflow<Request>({
id: "monthly-scan",
execute: async ({ step, event }) => {
await step.do("Create the scan", async ({ ctx }) => {
const user = await ctx.USER.getUser({ id: event.body.patientId });
const count = await user.getScanCount();
await ctx.FACIAL_SCAN.create({
user,
status: count >= 1 ? "limit_reached" : "ready",
});
});
},
});Last updated on