pediatric-ai-scribe-v3/src/routes/hpi.js
Daniel Onyejesi 044c809ff3 v10: Local Whisper transcription, bigger text areas, flexible AI memory
- Add local Whisper (whisper.cpp / faster-whisper) as transcription provider
  Set TRANSCRIBE_PROVIDER=local with configurable model size and binary path
- Upgrade all refine/instruction inputs to resizable textareas across
  encounter, dictation, hospital course, chart review, well visit, sick visit
- Make AI memory injection flexible: physician preferences and corrections
  are now actively applied (not just "formatting reference"), while still
  overridable by current prompt instructions
2026-03-28 22:00:30 +00:00

51 lines
2.7 KiB
JavaScript

const express = require('express');
const router = express.Router();
const { callAI } = require('../utils/ai');
const PROMPTS = require('../utils/prompts');
const { authMiddleware } = require('../middleware/auth');
// HPI from encounter
router.post('/generate-hpi-encounter', authMiddleware, async (req, res) => {
try {
const { transcript, patientAge, patientGender, model, setting, physicianMemories } = req.body;
if (!transcript || !transcript.trim()) return res.status(400).json({ error: 'Transcript empty' });
const prompt = setting === 'inpatient' ? PROMPTS.hpiInpatient : PROMPTS.hpiEncounter;
var context = `Patient: ${patientAge || 'Unknown'}, ${patientGender || 'Unknown'}\nSetting: ${setting || 'outpatient'}\n\nTRANSCRIPT:\n${transcript}`;
if (physicianMemories) context += '\n\n[PHYSICIAN PREFERENCES & LEARNED PATTERNS — Apply these preferences to your output. These reflect how this physician writes notes, their preferred style, terminology, and corrections from past outputs. Adapt your response accordingly, but user instructions in the current prompt take priority if they conflict.]\n' + physicianMemories + '\n[END PREFERENCES]';
const result = await callAI([
{ role: 'system', content: prompt },
{ role: 'user', content: context }
], { model });
res.json({ success: true, hpi: result.content, model: result.model });
} catch (err) {
res.status(500).json({ error: err.message });
}
});
// HPI from dictation
router.post('/generate-hpi-dictation', authMiddleware, async (req, res) => {
try {
const { transcript, patientAge, patientGender, model, setting, physicianMemories } = req.body;
if (!transcript || !transcript.trim()) return res.status(400).json({ error: 'Dictation empty' });
const prompt = setting === 'inpatient' ? PROMPTS.hpiInpatient : PROMPTS.hpiDictation;
var context = `Patient: ${patientAge || 'Unknown'}, ${patientGender || 'Unknown'}\nSetting: ${setting || 'outpatient'}\n\nDICTATION:\n${transcript}`;
if (physicianMemories) context += '\n\n[PHYSICIAN PREFERENCES & LEARNED PATTERNS — Apply these preferences to your output. These reflect how this physician writes notes, their preferred style, terminology, and corrections from past outputs. Adapt your response accordingly, but user instructions in the current prompt take priority if they conflict.]\n' + physicianMemories + '\n[END PREFERENCES]';
const result = await callAI([
{ role: 'system', content: prompt },
{ role: 'user', content: context }
], { model });
res.json({ success: true, hpi: result.content, model: result.model });
} catch (err) {
res.status(500).json({ error: err.message });
}
});
module.exports = router;