const { Client } = require('pg'); const fs = require('fs'); const path = require('path'); const client = new Client({ host: '192.168.110.252', port: 15432, database: 'postgresql', user: 'postgresql', password: 'Jchl1528', }); async function main() { await client.connect(); await client.query('SET search_path TO healthlink_his'); // Get all department names const res = await client.query( "SELECT DISTINCT dept_name FROM sys_dept WHERE dept_name IS NOT NULL AND dept_name != '' ORDER BY dept_name" ); const names = res.rows.map(r => r.dept_name); fs.writeFileSync(path.join(__dirname, 'dept_names.json'), JSON.stringify(names, null, 2), 'utf8'); console.log('Total departments:', names.length); names.forEach(n => console.log(n)); await client.end(); } main().catch(e => { console.error(e.message); process.exit(1); });