Loading...
Loading...
Build HIPAA-compliant telemedicine apps with PubNub real-time messaging
npx skill4agent add pubnub/skills pubnub-telemedicinetelemedicine-setup.mdtelemedicine-features.mdtelemedicine-patterns.md| Reference | Purpose |
|---|---|
| telemedicine-setup.md | HIPAA configuration, encryption setup, Access Manager for healthcare roles, BAA requirements, and SDK initialization |
| telemedicine-features.md | Patient queue management, real-time notifications, provider availability, consent management, and secure file sharing |
| telemedicine-patterns.md | Consultation workflows, WebRTC video signaling, audit logging, multi-provider sessions, and emergency escalation |
import PubNub from 'pubnub';
const pubnub = new PubNub({
publishKey: process.env.PUBNUB_PUBLISH_KEY,
subscribeKey: process.env.PUBNUB_SUBSCRIBE_KEY,
secretKey: process.env.PUBNUB_SECRET_KEY, // Server-side only
userId: currentUser.id,
cryptoModule: PubNub.CryptoModule.aesCbcCryptoModule({
cipherKey: process.env.PUBNUB_CIPHER_KEY
}),
ssl: true,
logVerbosity: false // Disable in production to prevent PHI leaks in logs
});async function sendSecureMessage(channelId, message, senderRole) {
const payload = {
id: crypto.randomUUID(),
type: message.type,
content: message.content,
sender: {
id: message.senderId,
role: senderRole // 'provider' | 'patient' | 'nurse'
},
timestamp: new Date().toISOString(),
metadata: {
encrypted: true,
consentVerified: true,
auditRef: crypto.randomUUID()
}
};
try {
const result = await pubnub.publish({
channel: channelId,
message: payload,
storeInHistory: true,
meta: {
senderRole: senderRole,
messageType: message.type
}
});
await logAuditEvent('MESSAGE_SENT', channelId, payload.metadata.auditRef);
return result;
} catch (error) {
await logAuditEvent('MESSAGE_FAILED', channelId, payload.metadata.auditRef);
throw new Error(`Secure message delivery failed: ${error.message}`);
}
}async function grantProviderAccess(providerId, consultationChannelId, ttlMinutes = 60) {
const token = await pubnub.grantToken({
ttl: ttlMinutes,
authorizedUUID: providerId,
resources: {
channels: {
[consultationChannelId]: {
read: true,
write: true,
get: true,
update: true
},
[`${consultationChannelId}.files`]: {
read: true,
write: true
}
}
},
patterns: {
channels: {
[`consultation.${providerId}.*`]: {
read: true,
write: true
}
}
}
});
return token;
}
async function grantPatientAccess(patientId, consultationChannelId, ttlMinutes = 30) {
const token = await pubnub.grantToken({
ttl: ttlMinutes,
authorizedUUID: patientId,
resources: {
channels: {
[consultationChannelId]: {
read: true,
write: true
}
}
}
});
return token;
}consultation.{providerId}.{patientId}