Example app
One small Node.js program that receives and verifies Signals webhooks, creates a patient, posts a breaching reading and acknowledges the alert.
- Complexity
- 2/5
- Clients
- Node.js 22 or later
- Time
- 15 minutes
This app ties the tutorial together in one file. It verifies each delivery, creates a patient, posts a heart rate above the band, and acknowledges the alert when alert.triggered arrives.
It expects the band from Create a patient and a subscriber for your tunnel URL from Register a webhook.
Set upTerminal
npm init -y && npm install express standardwebhooksOVOK_MANAGER_ID=…
OVOK_MANAGER_SECRET=…
OVOK_SUBMITTER_ID=…
OVOK_SUBMITTER_SECRET=…
SIGNALS_SIGNING_SECRET=whsec_…Write the appServer-side
import express from 'express';
import { Webhook } from 'standardwebhooks';
const API = 'https://api.sandbox.ovok.com/v1/signals/api';
const env = process.env;
const basic = (id, secret) => `Basic ${Buffer.from(`${id}:${secret}`).toString('base64')}`;
const manager = basic(env.OVOK_MANAGER_ID, env.OVOK_MANAGER_SECRET);
const submitter = basic(env.OVOK_SUBMITTER_ID, env.OVOK_SUBMITTER_SECRET);
async function call(authorization, path, body) {
const response = await fetch(`${API}${path}`, {
method: 'POST',
headers: { authorization, 'content-type': 'application/json' },
body: JSON.stringify(body),
});
if (!response.ok) throw new Error(`${path} answered ${response.status}`);
}
const webhook = new Webhook(env.SIGNALS_SIGNING_SECRET);
const app = express();
app.post('/signals/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
let event;
try {
event = webhook.verify(req.body, req.headers);
} catch {
return res.sendStatus(400);
}
res.sendStatus(204);
console.log(event.type, event.data.patientRefId);
if (event.type === 'alert.triggered') {
await call(manager, `/alert/${event.data.id}/ack`, {
actor: { reference: 'Practitioner/123', display: 'Dr. Max Mustermann' },
});
}
});
app.listen(3000, async () => {
await call(manager, '/patient', { patients: [{ refId: 'resident-001', name: 'Resident 001' }] });
await call(submitter, '/observation', {
patientRefId: 'resident-001',
identifier: [{ system: 'urn:example:readings', value: `reading-${Date.now()}` }],
code: { coding: [{ system: 'http://loinc.org', code: '8867-4' }] },
valueQuantity: { value: 132, unit: '/min' },
effectiveDateTime: new Date().toISOString(),
});
});- Each run posts a new
identifier, so a rerun is not refused as a duplicate. - The receiver answers
204before it acknowledges, so a slow call never delays the delivery.
Run itTerminal
node --env-file=.env app.mjsVerify your integration
The log shows these lines, the first two in either order:
alert.triggered resident-001
episode.opened resident-001
alert.acknowledged resident-001If a line is missing, see Debugging.
See also
- Signals webhooks: every event and its payload
- Verify webhooks: signatures in more languages
- Mutual TLS: require client certificates
Last updated on
Send a reading
Post a heart rate above the band as the Submitter app, see the alert arrive at your webhook, then acknowledge it.
Signals with Ovok
Use Signals as part of an Ovok app: FHIR Observations go to Signals, and its alerts come back into FHIR as DetectedIssue, Flag and Observation interpretation.