Example Server

This is for understanding and learning purposes only. This file is not fit for a production system.

import express from 'express';
import cors from 'cors';

const app = express();
const PORT = process.env.PORT || 3201;

app.use(cors());
app.use(express.json());

const availableHooks = [
  {
    id: 'order-sign-service',
    hook: 'order-sign',
    title: 'Ocean Order Sign Hook',
    description: 'Provides clinical decision support hen signing orders',
    // This is where you specify what data you want from Ocean
    prefetch: {
      patient: 'Patient/
Command 'context.patientId' could not render: There is no placeholder called 'context.patientId'
'
, // Some other available pieces of data // questionnaireResponse: 'QuestionnaireResponse?encounter=
Command 'context.encounterId' could not render: There is no placeholder called 'context.encounterId'
'
// provider: '
Command 'context.userId' could not render: There is no placeholder called 'context.userId'
'
} } ]; // The Discovery Endpoint app.get('/cds-services', (req, res) => { res.json({ services: availableHooks }); }); // Service Endpoint app.post('/cds-services/order-sign-service', async (req, res) => { try { const hookRequest = req.body; const response = await handleOrderSign(hookRequest); res.json(response); } catch (error) { console.error('Error in order-sign hook:', error); res.status(500).json({ error: 'Internal server error' }); } }); app.listen(PORT, () => { console.log(`CDS Hooks server running on port ${PORT}`); console.log(`Discovery endpoint: http://localhost:${PORT}/cds-services`); console.log(`Order-sign hook: http://localhost:${PORT}/cds-services/order-sign-service`); }); export async function handleOrderSign(request) { const { prefetch } = request; // Extract the first QuestionnaireResponse from the prefetch bundle const patient = prefetch?.["patient"]; const cards = []; // Critical error on 50% of submissions if (Math.random() > 0.5) { cards.push({ summary: 'Tea break', detail: 'We are unable to process submissions right now. The computer is having tea. Please try again.', indicator: 'critical', source: { label: 'Ocean Example CDS Server' } }); } // Warning for duplicate orders - based on patient demographic // Would be connected to an internal request system if (hasPotentialDuplicate(patient)) { cards.push({ summary: 'Potential Duplicate Order', detail: 'A similar order may have been recently placed for this patient. Please review before signing.', indicator: 'warning', source: { label: 'Ocean Example CDS Server' } }); } // Informational card applied to all requests // Just a static 2 week wait. Should be connected to an internal wait time system const twoWeeksLater = new Date(); twoWeeksLater.setDate(twoWeeksLater.getDate() + 14); const twoWeeksLaterStr = twoWeeksLater.toISOString().split("T").at(0); cards.push({ summary: `Request Received! Please do not reach out to us before ${twoWeeksLaterStr}`, detail: `There are currently ${Math.floor(Math.random() * 20)} requests ahead of you.`, indicator: 'info', source: { label: 'Ocean Example CDS Server' } }); return { cards }; } function hasPotentialDuplicate(patient) { // Simplified duplicate check - would normally check against recent orders in FHIR server // Here we are just checking if the patient's name contains 'Dup' return JSON.stringify(patient?.name).includes('Dup'); }