interface AuditEntry {
timestamp: string;
action: 'create' | 'read' | 'update' | 'delete' | 'access';
resource_type: 'session' | 'note' | 'transcript' | 'patient_summary';
resource_id: string;
actor: string;
ip_address: string;
success: boolean;
}
class HipaaAuditLogger {
private entries: AuditEntry[] = [];
log(entry: Omit<AuditEntry, 'timestamp'>): void {
const fullEntry: AuditEntry = {
...entry,
timestamp: new Date().toISOString(),
};
const serialized = JSON.stringify(fullEntry);
if (this.containsPhi(serialized)) {
console.error('CRITICAL: PHI detected in audit entry — entry blocked');
return;
}
this.entries.push(fullEntry);
console.log(`AUDIT: ${JSON.stringify(fullEntry)}`);
}
private containsPhi(text: string): boolean {
const phiPatterns = [
/\b\d{3}-\d{2}-\d{4}\b/,
/\b[A-Z]\d{8}\b/,
/\b\d{1,2}\/\d{1,2}\/\d{4}\b/,
];
return phiPatterns.some(p => p.test(text));
}
getRetentionPolicy(): { minYears: number; note: string } {
return {
minYears: 6,
note: 'HIPAA requires audit logs retained for minimum 6 years',
};
}
}
export { HipaaAuditLogger, AuditEntry };
type AbridgeRole = 'clinician' | 'nurse' | 'admin' | 'billing' | 'integration_service';
interface AbridgePermissions {
canCreateSession: boolean;
canViewNotes: boolean;
canViewPatientSummary: boolean;
canExportData: boolean;
canManageProviders: boolean;
canAccessBilling: boolean;
}
const ROLE_PERMISSIONS: Record<AbridgeRole, AbridgePermissions> = {
clinician: {
canCreateSession: true, canViewNotes: true, canViewPatientSummary: true,
canExportData: false, canManageProviders: false, canAccessBilling: false,
},
nurse: {
canCreateSession: true, canViewNotes: true, canViewPatientSummary: true,
canExportData: false, canManageProviders: false, canAccessBilling: false,
},
admin: {
canCreateSession: false, canViewNotes: false, canViewPatientSummary: false,
canExportData: true, canManageProviders: true, canAccessBilling: true,
},
billing: {
canCreateSession: false, canViewNotes: false, canViewPatientSummary: false,
canExportData: false, canManageProviders: false, canAccessBilling: true,
},
integration_service: {
canCreateSession: true, canViewNotes: true, canViewPatientSummary: false,
canExportData: false, canManageProviders: false, canAccessBilling: false,
},
};
function checkPermission(role: AbridgeRole, action: keyof AbridgePermissions): boolean {
return ROLE_PERMISSIONS[role]?.[action] ?? false;
}
async function loadAbridgeSecrets(): Promise<Record<string, string>> {
const { SecretManagerServiceClient } = await import('@google-cloud/secret-manager');
const client = new SecretManagerServiceClient();
const secrets: Record<string, string> = {};
const secretNames = ['abridge-client-secret', 'abridge-org-id', 'epic-client-secret'];
for (const name of secretNames) {
const [version] = await client.accessSecretVersion({
name: `projects/${process.env.GCP_PROJECT}/secrets/${name}/versions/latest`,
});
secrets[name] = version.payload?.data?.toString() || '';
}
return secrets;
}