Wire physician memories/templates into all AI generation routes
Previously only well-visit and sick-visit used saved physician templates. Now HPI encounter, HPI dictation, SOAP, and hospital course all fetch getUserMemoryContext() and pass physicianMemories to the backend so the AI learns from saved templates/preferences.
This commit is contained in:
parent
eb63d9973d
commit
6e1b6ca3d7
7 changed files with 98 additions and 66 deletions
|
|
@ -134,23 +134,28 @@
|
||||||
|
|
||||||
showLoading('Generating hospital course...');
|
showLoading('Generating hospital course...');
|
||||||
|
|
||||||
fetch('/api/generate-hospital-course', {
|
var memoriesPromise = (typeof getUserMemoryContext === 'function') ? getUserMemoryContext() : Promise.resolve('');
|
||||||
method: 'POST',
|
|
||||||
headers: getAuthHeaders(),
|
memoriesPromise.then(function(memCtx) {
|
||||||
body: JSON.stringify({
|
return fetch('/api/generate-hospital-course', {
|
||||||
notes: notes,
|
method: 'POST',
|
||||||
edNote: edNote,
|
headers: getAuthHeaders(),
|
||||||
hAndP: hAndP,
|
body: JSON.stringify({
|
||||||
labs: labs,
|
notes: notes,
|
||||||
patientAge: document.getElementById('hc-age').value,
|
edNote: edNote,
|
||||||
patientGender: document.getElementById('hc-gender').value,
|
hAndP: hAndP,
|
||||||
pmh: document.getElementById('hc-pmh').value,
|
labs: labs,
|
||||||
setting: document.getElementById('hc-setting').value,
|
patientAge: document.getElementById('hc-age').value,
|
||||||
los: document.getElementById('hc-los').value,
|
patientGender: document.getElementById('hc-gender').value,
|
||||||
formatPreference: document.getElementById('hc-format').value,
|
pmh: document.getElementById('hc-pmh').value,
|
||||||
additionalInstructions: document.getElementById('hc-instructions').value,
|
setting: document.getElementById('hc-setting').value,
|
||||||
model: getSelectedModel()
|
los: document.getElementById('hc-los').value,
|
||||||
})
|
formatPreference: document.getElementById('hc-format').value,
|
||||||
|
additionalInstructions: document.getElementById('hc-instructions').value,
|
||||||
|
physicianMemories: memCtx || null,
|
||||||
|
model: getSelectedModel()
|
||||||
|
})
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then(function(r) { return r.json(); })
|
.then(function(r) { return r.json(); })
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
|
|
|
||||||
|
|
@ -137,16 +137,21 @@
|
||||||
if (!text) { showToast('No transcript', 'error'); return; }
|
if (!text) { showToast('No transcript', 'error'); return; }
|
||||||
showLoading('Generating HPI...');
|
showLoading('Generating HPI...');
|
||||||
|
|
||||||
fetch('/api/generate-hpi-encounter', {
|
var memoriesPromise = (typeof getUserMemoryContext === 'function') ? getUserMemoryContext() : Promise.resolve('');
|
||||||
method: 'POST',
|
|
||||||
headers: getAuthHeaders(),
|
memoriesPromise.then(function(memCtx) {
|
||||||
body: JSON.stringify({
|
return fetch('/api/generate-hpi-encounter', {
|
||||||
transcript: text,
|
method: 'POST',
|
||||||
patientAge: document.getElementById('enc-age').value,
|
headers: getAuthHeaders(),
|
||||||
patientGender: document.getElementById('enc-gender').value,
|
body: JSON.stringify({
|
||||||
setting: document.getElementById('enc-setting').value,
|
transcript: text,
|
||||||
model: getSelectedModel()
|
patientAge: document.getElementById('enc-age').value,
|
||||||
})
|
patientGender: document.getElementById('enc-gender').value,
|
||||||
|
setting: document.getElementById('enc-setting').value,
|
||||||
|
physicianMemories: memCtx || null,
|
||||||
|
model: getSelectedModel()
|
||||||
|
})
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then(function(r) { return r.json(); })
|
.then(function(r) { return r.json(); })
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
|
|
|
||||||
|
|
@ -90,17 +90,22 @@
|
||||||
|
|
||||||
showLoading('Generating SOAP note...');
|
showLoading('Generating SOAP note...');
|
||||||
|
|
||||||
fetch('/api/generate-soap', {
|
var memoriesPromise = (typeof getUserMemoryContext === 'function') ? getUserMemoryContext() : Promise.resolve('');
|
||||||
method: 'POST',
|
|
||||||
headers: getAuthHeaders(),
|
memoriesPromise.then(function(memCtx) {
|
||||||
body: JSON.stringify({
|
return fetch('/api/generate-soap', {
|
||||||
transcript: text,
|
method: 'POST',
|
||||||
patientAge: document.getElementById('soap-age').value,
|
headers: getAuthHeaders(),
|
||||||
patientGender: document.getElementById('soap-gender').value,
|
body: JSON.stringify({
|
||||||
type: document.getElementById('soap-type').value,
|
transcript: text,
|
||||||
additionalInstructions: document.getElementById('soap-instructions').value,
|
patientAge: document.getElementById('soap-age').value,
|
||||||
model: getSelectedModel()
|
patientGender: document.getElementById('soap-gender').value,
|
||||||
})
|
type: document.getElementById('soap-type').value,
|
||||||
|
additionalInstructions: document.getElementById('soap-instructions').value,
|
||||||
|
physicianMemories: memCtx || null,
|
||||||
|
model: getSelectedModel()
|
||||||
|
})
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then(function(r) { return r.json(); })
|
.then(function(r) { return r.json(); })
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
|
|
|
||||||
|
|
@ -134,29 +134,34 @@
|
||||||
var outputType = document.getElementById('dict-output-type').value;
|
var outputType = document.getElementById('dict-output-type').value;
|
||||||
var endpoint, bodyData;
|
var endpoint, bodyData;
|
||||||
|
|
||||||
if (outputType === 'soap-full' || outputType === 'soap-subjective') {
|
|
||||||
endpoint = '/api/generate-soap';
|
|
||||||
bodyData = {
|
|
||||||
transcript: text,
|
|
||||||
patientAge: document.getElementById('dict-age').value,
|
|
||||||
patientGender: document.getElementById('dict-gender').value,
|
|
||||||
type: outputType === 'soap-full' ? 'full' : 'subjective',
|
|
||||||
model: getSelectedModel()
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
endpoint = '/api/generate-hpi-dictation';
|
|
||||||
bodyData = {
|
|
||||||
transcript: text,
|
|
||||||
patientAge: document.getElementById('dict-age').value,
|
|
||||||
patientGender: document.getElementById('dict-gender').value,
|
|
||||||
setting: document.getElementById('dict-setting').value,
|
|
||||||
model: getSelectedModel()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
showLoading('Generating...');
|
showLoading('Generating...');
|
||||||
|
|
||||||
fetch(endpoint, { method: 'POST', headers: getAuthHeaders(), body: JSON.stringify(bodyData) })
|
var memoriesPromise = (typeof getUserMemoryContext === 'function') ? getUserMemoryContext() : Promise.resolve('');
|
||||||
|
|
||||||
|
memoriesPromise.then(function(memCtx) {
|
||||||
|
if (outputType === 'soap-full' || outputType === 'soap-subjective') {
|
||||||
|
endpoint = '/api/generate-soap';
|
||||||
|
bodyData = {
|
||||||
|
transcript: text,
|
||||||
|
patientAge: document.getElementById('dict-age').value,
|
||||||
|
patientGender: document.getElementById('dict-gender').value,
|
||||||
|
type: outputType === 'soap-full' ? 'full' : 'subjective',
|
||||||
|
physicianMemories: memCtx || null,
|
||||||
|
model: getSelectedModel()
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
endpoint = '/api/generate-hpi-dictation';
|
||||||
|
bodyData = {
|
||||||
|
transcript: text,
|
||||||
|
patientAge: document.getElementById('dict-age').value,
|
||||||
|
patientGender: document.getElementById('dict-gender').value,
|
||||||
|
setting: document.getElementById('dict-setting').value,
|
||||||
|
physicianMemories: memCtx || null,
|
||||||
|
model: getSelectedModel()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return fetch(endpoint, { method: 'POST', headers: getAuthHeaders(), body: JSON.stringify(bodyData) });
|
||||||
|
})
|
||||||
.then(function(r) { return r.json(); })
|
.then(function(r) { return r.json(); })
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ router.post('/generate-hospital-course', authMiddleware, async (req, res) => {
|
||||||
los, // length of stay
|
los, // length of stay
|
||||||
model,
|
model,
|
||||||
formatPreference, // 'auto' | 'prose' | 'dayByDay' | 'organSystem'
|
formatPreference, // 'auto' | 'prose' | 'dayByDay' | 'organSystem'
|
||||||
additionalInstructions
|
additionalInstructions,
|
||||||
|
physicianMemories
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
if (!notes || notes.length === 0) {
|
if (!notes || notes.length === 0) {
|
||||||
|
|
@ -80,6 +81,8 @@ router.post('/generate-hospital-course', authMiddleware, async (req, res) => {
|
||||||
prompt += `\n\nADDITIONAL INSTRUCTIONS FROM PHYSICIAN:\n${additionalInstructions}`;
|
prompt += `\n\nADDITIONAL INSTRUCTIONS FROM PHYSICIAN:\n${additionalInstructions}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (physicianMemories) clinicalData += '\n\n' + physicianMemories;
|
||||||
|
|
||||||
const result = await callAI([
|
const result = await callAI([
|
||||||
{ role: 'system', content: prompt },
|
{ role: 'system', content: prompt },
|
||||||
{ role: 'user', content: clinicalData }
|
{ role: 'user', content: clinicalData }
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,17 @@ const { authMiddleware } = require('../middleware/auth');
|
||||||
// HPI from encounter
|
// HPI from encounter
|
||||||
router.post('/generate-hpi-encounter', authMiddleware, async (req, res) => {
|
router.post('/generate-hpi-encounter', authMiddleware, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { transcript, patientAge, patientGender, model, setting } = req.body;
|
const { transcript, patientAge, patientGender, model, setting, physicianMemories } = req.body;
|
||||||
if (!transcript || !transcript.trim()) return res.status(400).json({ error: 'Transcript empty' });
|
if (!transcript || !transcript.trim()) return res.status(400).json({ error: 'Transcript empty' });
|
||||||
|
|
||||||
const prompt = setting === 'inpatient' ? PROMPTS.hpiInpatient : PROMPTS.hpiEncounter;
|
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' + physicianMemories;
|
||||||
|
|
||||||
const result = await callAI([
|
const result = await callAI([
|
||||||
{ role: 'system', content: prompt },
|
{ role: 'system', content: prompt },
|
||||||
{ role: 'user', content: `Patient: ${patientAge || 'Unknown'}, ${patientGender || 'Unknown'}\nSetting: ${setting || 'outpatient'}\n\nTRANSCRIPT:\n${transcript}` }
|
{ role: 'user', content: context }
|
||||||
], { model });
|
], { model });
|
||||||
|
|
||||||
res.json({ success: true, hpi: result.content, model: result.model });
|
res.json({ success: true, hpi: result.content, model: result.model });
|
||||||
|
|
@ -26,14 +29,17 @@ router.post('/generate-hpi-encounter', authMiddleware, async (req, res) => {
|
||||||
// HPI from dictation
|
// HPI from dictation
|
||||||
router.post('/generate-hpi-dictation', authMiddleware, async (req, res) => {
|
router.post('/generate-hpi-dictation', authMiddleware, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { transcript, patientAge, patientGender, model, setting } = req.body;
|
const { transcript, patientAge, patientGender, model, setting, physicianMemories } = req.body;
|
||||||
if (!transcript || !transcript.trim()) return res.status(400).json({ error: 'Dictation empty' });
|
if (!transcript || !transcript.trim()) return res.status(400).json({ error: 'Dictation empty' });
|
||||||
|
|
||||||
const prompt = setting === 'inpatient' ? PROMPTS.hpiInpatient : PROMPTS.hpiDictation;
|
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' + physicianMemories;
|
||||||
|
|
||||||
const result = await callAI([
|
const result = await callAI([
|
||||||
{ role: 'system', content: prompt },
|
{ role: 'system', content: prompt },
|
||||||
{ role: 'user', content: `Patient: ${patientAge || 'Unknown'}, ${patientGender || 'Unknown'}\nSetting: ${setting || 'outpatient'}\n\nDICTATION:\n${transcript}` }
|
{ role: 'user', content: context }
|
||||||
], { model });
|
], { model });
|
||||||
|
|
||||||
res.json({ success: true, hpi: result.content, model: result.model });
|
res.json({ success: true, hpi: result.content, model: result.model });
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ const { authMiddleware } = require('../middleware/auth');
|
||||||
|
|
||||||
router.post('/generate-soap', authMiddleware, async (req, res) => {
|
router.post('/generate-soap', authMiddleware, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { transcript, patientAge, patientGender, model, type, additionalInstructions } = req.body;
|
const { transcript, patientAge, patientGender, model, type, additionalInstructions, physicianMemories } = req.body;
|
||||||
if (!transcript || !transcript.trim()) return res.status(400).json({ error: 'Empty input' });
|
if (!transcript || !transcript.trim()) return res.status(400).json({ error: 'Empty input' });
|
||||||
|
|
||||||
let prompt;
|
let prompt;
|
||||||
|
|
@ -20,9 +20,12 @@ router.post('/generate-soap', authMiddleware, async (req, res) => {
|
||||||
prompt += `\n\nADDITIONAL INSTRUCTIONS:\n${additionalInstructions}`;
|
prompt += `\n\nADDITIONAL INSTRUCTIONS:\n${additionalInstructions}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var context = `Patient: ${patientAge || 'Unknown'}, ${patientGender || 'Unknown'}\n\nINPUT:\n${transcript}`;
|
||||||
|
if (physicianMemories) context += '\n\n' + physicianMemories;
|
||||||
|
|
||||||
const result = await callAI([
|
const result = await callAI([
|
||||||
{ role: 'system', content: prompt },
|
{ role: 'system', content: prompt },
|
||||||
{ role: 'user', content: `Patient: ${patientAge || 'Unknown'}, ${patientGender || 'Unknown'}\n\nINPUT:\n${transcript}` }
|
{ role: 'user', content: context }
|
||||||
], { model });
|
], { model });
|
||||||
|
|
||||||
res.json({ success: true, soap: result.content, model: result.model });
|
res.json({ success: true, soap: result.content, model: result.model });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue