109 lines
10 KiB
JavaScript
109 lines
10 KiB
JavaScript
// Fills a development instance with sample content. Never run against real data.
|
|
// node scripts/seed-demo.mjs [http://localhost:3726]
|
|
// Reads the admin password from ADMIN_PASSWORD (or .env).
|
|
try {
|
|
process.loadEnvFile('.env');
|
|
} catch {
|
|
/* optional */
|
|
}
|
|
const base = process.argv[2] ?? `http://localhost:${process.env.PORT ?? 3726}`;
|
|
const password = process.env.ADMIN_PASSWORD;
|
|
if (!password) throw new Error('Set ADMIN_PASSWORD (or put it in .env) to seed demo data.');
|
|
|
|
let cookie = '';
|
|
async function call(method, path, body, form) {
|
|
const res = await fetch(base + path, {
|
|
method,
|
|
headers: { 'X-Requested-With': 'studydesk', ...(cookie ? { cookie } : {}), ...(body && !form ? { 'content-type': 'application/json' } : {}) },
|
|
body: form ?? (body ? JSON.stringify(body) : undefined),
|
|
});
|
|
const set = res.headers.get('set-cookie');
|
|
if (set) cookie = set.split(';')[0];
|
|
const text = await res.text();
|
|
if (!res.ok) throw new Error(`${method} ${path} -> ${res.status} ${text}`);
|
|
return text ? JSON.parse(text) : null;
|
|
}
|
|
|
|
await call('POST', '/api/auth/login', { password });
|
|
|
|
const pharm = (await call('POST', '/api/classes', { name: 'Pharmacology', code: 'NUR 356', description: 'Drug classes, mechanisms, adverse effects and nursing considerations.' })).class;
|
|
const peds = (await call('POST', '/api/classes', { name: 'Pediatrics', code: 'NUR 410' })).class;
|
|
const medsurg = (await call('POST', '/api/classes', { name: 'Medical-Surgical Nursing', code: 'NUR 320' })).class;
|
|
const unit1 = (await call('POST', `/api/classes/${pharm.id}/folders`, { name: 'Unit 1: Cardiovascular' })).folder;
|
|
|
|
const q = (type, stem, options, rationale, topic, difficulty = 'medium') => ({ type, stem, options: options.map(([text, correct, why]) => ({ text, correct: Boolean(correct), why: why ?? '' })), rationale, topic, difficulty });
|
|
const cardiac = [
|
|
q('single', 'A client taking digoxin reports nausea, fatigue and seeing yellow halos around lights. Which action should the nurse take **first**?', [
|
|
['Hold the next dose and check the apical pulse and serum digoxin level', 1, 'Visual changes with GI upset are classic early toxicity; assess and hold before giving more.'],
|
|
['Administer the scheduled dose with food', 0, 'Giving more drug worsens toxicity.'],
|
|
['Reassure the client that these effects are expected', 0, 'These are signs of toxicity, not expected effects.'],
|
|
['Encourage oral fluids and reassess in 4 hours', 0, 'Delays recognition of a potentially life-threatening problem.'],
|
|
], 'Digoxin has a narrow therapeutic range (0.5 to 2 ng/mL). Early toxicity presents with **GI symptoms and visual disturbances**; dysrhythmias follow. Hold the drug, assess the apical pulse for a full minute, and obtain a level.', 'Cardiac glycosides'),
|
|
q('multi', 'A nurse is teaching a client who is starting furosemide. Which statements should be included? **Select all that apply.**', [
|
|
['Take the medication in the morning', 1, 'Prevents nocturia.'],
|
|
['Eat foods high in potassium, such as bananas and potatoes', 1, 'Loop diuretics waste potassium.'],
|
|
['Rise slowly from sitting or lying down', 1, 'Volume depletion causes orthostatic hypotension.'],
|
|
['Expect a weight gain of 1 kg per day', 0, 'Weight should fall or stay stable; a gain suggests fluid retention.'],
|
|
['Report ringing in the ears', 1, 'Ototoxicity is a known adverse effect.'],
|
|
], 'Furosemide is a loop diuretic. Key teaching: morning dosing, potassium intake, orthostatic precautions, daily weights, and reporting tinnitus or hearing changes.', 'Diuretics'),
|
|
q('single', 'Which laboratory value should the nurse review before administering lisinopril?', [
|
|
['Serum potassium', 1, 'ACE inhibitors reduce aldosterone and can cause hyperkalemia.'],
|
|
['Serum calcium', 0],
|
|
['Platelet count', 0],
|
|
['Serum amylase', 0],
|
|
], 'ACE inhibitors can cause **hyperkalemia** and a rise in creatinine. Review potassium and renal function, and monitor blood pressure.', 'ACE inhibitors', 'easy'),
|
|
q('single', 'A client receiving a heparin infusion has an aPTT of 120 seconds (control 30 seconds). Which action is appropriate?', [
|
|
['Stop the infusion and notify the provider', 1, 'The aPTT is four times control; the therapeutic goal is 1.5 to 2.5 times control.'],
|
|
['Increase the infusion rate per protocol', 0, 'Would increase bleeding risk.'],
|
|
['Continue the infusion and recheck in 6 hours', 0],
|
|
['Administer vitamin K', 0, 'Vitamin K reverses warfarin. Protamine sulfate reverses heparin.'],
|
|
], 'Therapeutic aPTT on heparin is about **1.5 to 2.5 times control**. A value of 120 seconds is supratherapeutic. The antidote is protamine sulfate.', 'Anticoagulants', 'hard'),
|
|
q('multi', 'Which findings indicate a therapeutic response to metoprolol? **Select all that apply.**', [
|
|
['Heart rate decreases from 104 to 78/min', 1],
|
|
['Blood pressure decreases from 162/94 to 134/82 mm Hg', 1],
|
|
['Client reports fewer episodes of chest pain', 1],
|
|
['Wheezing is heard on auscultation', 0, 'Bronchospasm is an adverse effect.'],
|
|
], 'Beta-1 blockade lowers heart rate, contractility and blood pressure, reducing myocardial oxygen demand.', 'Beta blockers'),
|
|
q('single', 'A client taking warfarin has an INR of 5.8 with no bleeding. Which prescription should the nurse anticipate?', [
|
|
['Hold warfarin and administer oral vitamin K', 1],
|
|
['Administer protamine sulfate', 0, 'Protamine reverses heparin.'],
|
|
['Increase the warfarin dose', 0],
|
|
['Administer fresh frozen plasma immediately', 0, 'Reserved for serious bleeding.'],
|
|
], 'The usual target INR is 2 to 3. For a markedly elevated INR without bleeding, hold warfarin and give low-dose oral vitamin K (phytonadione).', 'Anticoagulants'),
|
|
];
|
|
const cardiacQuiz = (await call('POST', '/api/quizzes', { classId: pharm.id, folderId: unit1.id, title: 'Cardiovascular medications', description: 'Glycosides, diuretics, ACE inhibitors, beta blockers and anticoagulants.', questions: cardiac })).quiz;
|
|
await call('POST', '/api/quizzes', { classId: pharm.id, title: 'Antibiotics check', questions: [
|
|
q('single', 'Which assessment is the priority before the first dose of IV penicillin?', [['Ask about previous allergic reactions', 1], ['Measure urine output', 0], ['Check blood glucose', 0], ['Assess deep tendon reflexes', 0]], 'Penicillins are a leading cause of drug anaphylaxis.', 'Antibiotics', 'easy'),
|
|
q('single', 'A client on gentamicin reports new ringing in the ears. The nurse should suspect:', [['Ototoxicity', 1], ['Hepatotoxicity', 0], ['Superinfection', 0], ['Photosensitivity', 0]], 'Aminoglycosides are ototoxic and nephrotoxic. Monitor peak and trough levels.', 'Antibiotics'),
|
|
] });
|
|
|
|
const cards = [
|
|
['Furosemide: class', '**Loop diuretic**'], ['Furosemide: key adverse effects', '- Hypokalemia\n- Ototoxicity\n- Orthostatic hypotension\n- Dehydration'],
|
|
['Digoxin: therapeutic range', '**0.5 to 2 ng/mL**'], ['Digoxin toxicity: early signs', 'Anorexia, nausea, vomiting, fatigue, **yellow-green halos**'],
|
|
['Antidote for heparin', 'Protamine sulfate'], ['Antidote for warfarin', 'Vitamin K (phytonadione)'],
|
|
['Lisinopril: suffix and class', '**-pril** = ACE inhibitor'], ['ACE inhibitor: classic adverse effects', 'Dry **cough**, hyperkalemia, angioedema, first-dose hypotension'],
|
|
['Metoprolol: hold when', 'Heart rate below **60/min** or systolic BP below 100 mm Hg (per protocol)'], ['Normal serum potassium', '3.5 to 5.0 mEq/L'],
|
|
['Therapeutic INR on warfarin', '2 to 3 (2.5 to 3.5 for mechanical valves)'], ['Spironolactone: class', 'Potassium-sparing diuretic (aldosterone antagonist)'],
|
|
].map(([front, back]) => ({ front, back }));
|
|
const deck = (await call('POST', '/api/decks', { classId: pharm.id, folderId: unit1.id, title: 'Cardiac drug cards', description: 'High-yield facts for exam 1.', cards })).deck;
|
|
await call('POST', '/api/decks', { classId: peds.id, title: 'Growth and development milestones', cards: [
|
|
{ front: 'Age an infant sits without support', back: 'About **6 to 8 months**' }, { front: 'Age of first words', back: 'About 12 months' }, { front: 'Erikson stage: toddler', back: 'Autonomy vs. shame and doubt' },
|
|
] });
|
|
|
|
await call('POST', '/api/notes', { classId: pharm.id, title: 'Exam 1 plan', content: '## Topics\n- Cardiac glycosides\n- Diuretics\n- Anticoagulants\n\n| Drug | Antidote |\n| --- | --- |\n| Heparin | Protamine sulfate |\n| Warfarin | Vitamin K |\n' });
|
|
await call('POST', '/api/documents/text', { classId: pharm.id, title: 'Lecture 3: Heart failure drugs', text: '# Heart failure pharmacology\n\n## ACE inhibitors\nACE inhibitors such as lisinopril block the conversion of angiotensin I to angiotensin II. They reduce afterload and preload and slow ventricular remodeling. Adverse effects include a dry cough, hyperkalemia, angioedema and first-dose hypotension. Monitor potassium and creatinine.\n\n## Beta blockers\nMetoprolol succinate, carvedilol and bisoprolol reduce mortality in heart failure with reduced ejection fraction. Start low and titrate slowly. Hold for a heart rate below 60 per minute.\n\n## Loop diuretics\nFurosemide relieves congestion by inhibiting sodium and chloride reabsorption in the loop of Henle. Monitor daily weights, intake and output, potassium, and hearing.\n\n## Digoxin\nDigoxin increases contractility and slows conduction through the AV node. The therapeutic range is 0.5 to 2 ng/mL. Hypokalemia increases the risk of toxicity. Early signs of toxicity are anorexia, nausea, vomiting and visual disturbances such as yellow halos.\n' });
|
|
|
|
// Some study history so dashboards have something to show.
|
|
const attempt = (await call('POST', '/api/attempts', { mode: 'practice', source: { type: 'quiz', quizId: cardiacQuiz.id }, shuffleQuestions: false, shuffleOptions: false })).attempt;
|
|
const answers = {};
|
|
attempt.questions.forEach((question, i) => {
|
|
const right = question.options.filter((o) => o.correct).map((o) => o.id);
|
|
const wrong = question.options.filter((o) => !o.correct).map((o) => o.id);
|
|
answers[question.id] = { selected: i === 1 ? right.slice(0, 2) : i === 3 ? wrong.slice(0, 1) : right, checked: true };
|
|
});
|
|
await call('PATCH', `/api/attempts/${attempt.id}`, { answers, elapsedSec: 312 });
|
|
await call('POST', `/api/attempts/${attempt.id}/complete`, { elapsedSec: 312 });
|
|
const queue = await call('GET', `/api/review/queue?deckId=${deck.id}`);
|
|
for (const [i, item] of queue.cards.slice(0, 7).entries()) await call('POST', '/api/review/answer', { cardId: item.card.id, rating: i % 4 === 0 ? 1 : 3 });
|
|
|
|
console.log(`Seeded demo data at ${base}: ${[pharm, peds, medsurg].map((c) => c.name).join(', ')}`);
|