pediatric-ai-scribe-v2/public/js/chartReview.js
ifedan-ed 1c2098d1dd v2.0.0: Pediatric AI Scribe
Features:
- Live encounter recording → HPI (outpatient/inpatient)
- Voice dictation → HPI / SOAP note
- Hospital course generator (prose/day-by-day/organ system/psych)
- Chart review / precharting (outpatient/subspecialty/ED)
- SOAP note generator (full/subjective only)
- Developmental milestones (AAP/Nelson) with narrative + 3-sentence summary
- AI refine & shorten for all outputs
- Ask AI what's missing (clarification)
- Authentication (email/password, email verification, 2FA)
- Nextcloud integration with auto date folders
- PWA support (installable on phone)
- 18+ AI models via OpenRouter
- HIPAA compliance guidance
- Docker support
2026-03-21 16:55:50 -04:00

117 lines
5.1 KiB
JavaScript

(function() {
var visitsContainer = document.getElementById('cr-visits-container');
var addVisitBtn = document.getElementById('cr-add-visit');
var labsContainer = document.getElementById('cr-labs-container');
var addLabBtn = document.getElementById('cr-add-lab');
var generateBtn = document.getElementById('cr-generate-btn');
var outputCard = document.getElementById('cr-output');
var reviewText = document.getElementById('cr-review-text');
var modelTag = document.getElementById('cr-model-tag');
var visitIndex = 1;
addVisitBtn.addEventListener('click', function() {
visitIndex++;
var card = document.createElement('div');
card.className = 'card visit-card';
card.innerHTML = '<div class="card-header"><h3><i class="fas fa-calendar"></i> Visit / Note #' + visitIndex + '</h3>' +
'<button class="btn-sm btn-ghost remove-visit-btn"><i class="fas fa-trash"></i></button></div>' +
'<div class="note-entry"><div class="note-meta">' +
'<input type="date" class="visit-date">' +
'<select class="visit-type"><option value="outpatient">Outpatient Visit</option><option value="subspecialty">Subspecialty Note</option><option value="ed">ED Visit</option></select>' +
'<input type="text" class="visit-specialist" placeholder="Specialist name">' +
'<input type="text" class="visit-specialty" placeholder="Specialty (e.g., Endocrinology)"></div>' +
'<div class="editable-box visit-content" contenteditable="true" data-placeholder="Paste note here..."></div>' +
'<input type="text" class="visit-labs" placeholder="Labs from this visit (optional)"></div>';
visitsContainer.appendChild(card);
card.querySelector('.remove-visit-btn').addEventListener('click', function() { card.remove(); });
});
document.querySelectorAll('.remove-visit-btn').forEach(function(btn) {
btn.addEventListener('click', function() { btn.closest('.visit-card').remove(); });
});
addLabBtn.addEventListener('click', function() {
var entry = document.createElement('div');
entry.className = 'lab-entry';
entry.innerHTML = '<input type="date" class="lab-date"><input type="text" class="lab-values" placeholder="Lab results...">' +
'<button class="btn-sm btn-ghost" onclick="this.parentElement.remove()"><i class="fas fa-trash"></i></button>';
labsContainer.appendChild(entry);
});
generateBtn.addEventListener('click', function() {
var type = document.getElementById('cr-type').value;
var visits = [];
var subspecialty = [];
var edVisits = [];
visitsContainer.querySelectorAll('.visit-card').forEach(function(card) {
var content = card.querySelector('.visit-content').innerText.trim();
if (!content) return;
var vType = card.querySelector('.visit-type').value;
var entry = {
date: card.querySelector('.visit-date').value || '',
content: content,
labs: card.querySelector('.visit-labs').value || ''
};
if (vType === 'subspecialty') {
entry.specialistName = card.querySelector('.visit-specialist').value || '';
entry.specialty = card.querySelector('.visit-specialty').value || '';
subspecialty.push(entry);
} else if (vType === 'ed') {
edVisits.push(entry);
} else {
entry.type = 'outpatient';
visits.push(entry);
}
});
var labs = [];
labsContainer.querySelectorAll('.lab-entry').forEach(function(entry) {
var vals = entry.querySelector('.lab-values').value.trim();
if (vals) labs.push({ date: entry.querySelector('.lab-date').value || '', values: vals });
});
if (visits.length === 0 && subspecialty.length === 0 && edVisits.length === 0) {
showToast('Add at least one visit/note', 'error');
return;
}
showLoading('Generating chart review...');
fetch('/api/generate-chart-review', {
method: 'POST',
headers: getAuthHeaders(),
body: JSON.stringify({
type: type,
visits: visits,
subspecialty: subspecialty,
edVisits: edVisits,
labs: labs,
patientAge: document.getElementById('cr-age').value,
patientGender: document.getElementById('cr-gender').value,
pmh: document.getElementById('cr-pmh').value,
additionalInstructions: document.getElementById('cr-instructions').value,
model: getSelectedModel()
})
})
.then(function(r) { return r.json(); })
.then(function(data) {
hideLoading();
if (data.success) {
reviewText.textContent = data.review;
modelTag.textContent = (data.model || '').split('/').pop();
outputCard.classList.remove('hidden');
outputCard.scrollIntoView({ behavior: 'smooth' });
showToast('Chart review generated!', 'success');
} else showToast(data.error || 'Failed', 'error');
})
.catch(function(err) { hideLoading(); showToast(err.message, 'error'); });
});
document.getElementById('cr-refine-btn').addEventListener('click', function() { refineDocument('cr-review-text', 'cr-refine-input'); });
document.getElementById('cr-shorten-btn').addEventListener('click', function() { shortenDocument('cr-review-text'); });
console.log('✅ Chart Review module loaded');
})();