Class: DeidRegistry
The corpus-level consistency handle. Construct it with createDeidRegistry. It holds the consumer's key in a module-private registry - the handle exposes no secret field and redacts itself through every stringify channel.
Example
import { createDeidRegistry } from "@cosyte/deid";
const registry = createDeidRegistry({ key: "secret" });
// Same patient across documents shifts by the same offset:
const a = registry.forPatient("patient-1");
const b = registry.forPatient("patient-1");
a === b; // => true (memoized - same handle, same offset)
Constructors
Constructor
new DeidRegistry():
DeidRegistry
Internal
Use createDeidRegistry.
Returns
DeidRegistry
Methods
forPatient()
forPatient(
patientKey):DeidContext
Return the DeidContext scoped to patientKey, minting and memoizing it on first use. The
same key always yields the same context - hence the same deterministic date-shift offset - so a
patient's dates shift consistently across every document in the corpus. Pass this context as
DeidOptions.context to deidentify (or a per-format adapter) for that patient's documents.
Parameters
patientKey
string
A stable per-patient key (an MRN, an enterprise patient id - the consumer's choice, provided it is the same across that patient's documents).
Returns
The patient-scoped, self-redacting context.
Example
import { createDeidRegistry } from "@cosyte/deid";
const registry = createDeidRegistry({ key: "secret" });
const ctx = registry.forPatient("patient-1");
pseudonym()
pseudonym(
id):string
Map an identifier to its corpus-wide consistent pseudonym - a keyed-HMAC surrogate that is the same for the same input everywhere and not reversible without the key. Patient-independent: the same MRN maps to the same token regardless of which patient scope processes it, so records link.
Parameters
id
string
The identifier to pseudonymize (MRN, beneficiary number, account number).
Returns
string
The consistent lowercase-hex surrogate.
Example
import { createDeidRegistry } from "@cosyte/deid";
const registry = createDeidRegistry({ key: "secret" });
registry.pseudonym("MRN-1") === registry.pseudonym("MRN-1"); // => true (consistent)
remapUid()
remapUid(
uid):string
Map an opaque unique identifier (a DICOM study/series/instance UID, a GUID) to its corpus-wide
consistent surrogate, so cross-document UID linkage survives de-identification. Domain-separated
from pseudonym, so a UID and an identifier with the same text never share a surrogate. This
is the format-agnostic linkage primitive; a format that owns UID validity (DICOM UIDs must be a
valid 0.… OID) handles that in its own adapter.
Parameters
uid
string
The unique identifier to remap.
Returns
string
The consistent lowercase-hex surrogate.
Example
import { createDeidRegistry } from "@cosyte/deid";
const registry = createDeidRegistry({ key: "secret" });
registry.remapUid("1.2.840.113619.2.55") === registry.remapUid("1.2.840.113619.2.55"); // => true
toJSON()
toJSON():
string
Redacts through JSON.stringify.
Returns
string
toString()
toString():
string
Redacts through String(...) and template interpolation.
Returns
string