Files
his/check_surgery_save.js

68 lines
2.1 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { Pool } = require('pg');
const pool = new Pool({
host: '47.116.196.11',
port: 15432,
database: 'postgresql',
user: 'postgresql',
password: 'Jchl1528'
});
async function checkLatestSurgery() {
try {
console.log('=== 检查最近创建的手术安排 ===\n');
// 1. 查询最近创建的手术安排
const latestSchedule = await pool.query(`
SELECT
os.schedule_id,
os.oper_code,
os.oper_name,
os.apply_id,
os.create_time,
cs.apply_dept_id,
cs.apply_dept_name,
cs.main_surgeon_id,
cs.main_surgeon_name,
cs.surgery_no
FROM hisdev.op_schedule os
LEFT JOIN hisdev.cli_surgery cs ON os.apply_id = cs.id
WHERE os.delete_flag = '0'
ORDER BY os.create_time DESC
LIMIT 5
`);
console.log('最近5条手术安排');
console.table(latestSchedule.rows);
// 2. 检查是否有空值
const nullCheck = await pool.query(`
SELECT
COUNT(*) as total,
COUNT(CASE WHEN cs.apply_dept_name IS NULL OR cs.apply_dept_name = '' THEN 1 END) as null_apply_dept,
COUNT(CASE WHEN cs.main_surgeon_name IS NULL OR cs.main_surgeon_name = '' THEN 1 END) as null_surgeon
FROM hisdev.op_schedule os
LEFT JOIN hisdev.cli_surgery cs ON os.apply_id = cs.id
WHERE os.delete_flag = '0'
AND os.create_time > NOW() - INTERVAL '1 hour'
`);
console.log('\n=== 最近1小时内创建的手术安排 ===');
console.log(`总计: ${nullCheck.rows[0].total}`);
console.log(`申请科室为空的: ${nullCheck.rows[0].null_apply_dept}`);
console.log(`主刀医生为空的: ${nullCheck.rows[0].null_surgeon}`);
if (parseInt(nullCheck.rows[0].null_apply_dept) === 0 && parseInt(nullCheck.rows[0].null_surgeon) === 0) {
console.log('\n✅ 所有字段都已正确保存!');
} else {
console.log('\n⚠ 仍有部分字段为空,请检查后端代码是否已部署');
}
} catch (err) {
console.error('查询失败:', err.message);
} finally {
pool.end();
}
}
checkLatestSurgery();