Files
his/test_fix.js

72 lines
2.2 KiB
JavaScript
Raw 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 testFix() {
try {
console.log('=== 测试手术安排关联修复 ===\n');
// 1. 测试新的 JOIN 条件
const result = await pool.query(`
SELECT
os.schedule_id,
os.oper_code,
os.apply_id,
cs.id as surgery_id,
cs.surgery_no,
cs.apply_dept_name,
cs.main_surgeon_name,
CASE
WHEN cs.id IS NOT NULL THEN '✅ 关联成功'
ELSE '❌ 未找到关联'
END as status
FROM hisdev.op_schedule os
LEFT JOIN hisdev.cli_surgery cs
ON os.oper_code = cs.surgery_no AND cs.delete_flag = '0'
WHERE os.delete_flag = '0'
ORDER BY os.create_time DESC
LIMIT 10
`);
console.log('手术安排与手术申请关联情况(使用 oper_code = surgery_no');
console.table(result.rows);
// 2. 统计关联成功率
const stats = await pool.query(`
SELECT
COUNT(*) as total,
COUNT(CASE WHEN cs.id IS NOT NULL THEN 1 END) as matched,
COUNT(CASE WHEN cs.id IS NULL THEN 1 END) as unmatched,
ROUND(COUNT(CASE WHEN cs.id IS NOT NULL THEN 1 END) * 100.0 / COUNT(*), 2) as match_rate
FROM hisdev.op_schedule os
LEFT JOIN hisdev.cli_surgery cs
ON os.oper_code = cs.surgery_no AND cs.delete_flag = '0'
WHERE os.delete_flag = '0'
`);
console.log('\n=== 关联统计 ===');
console.log(`总计: ${stats.rows[0].total}`);
console.log(`关联成功: ${stats.rows[0].matched}`);
console.log(`未找到关联: ${stats.rows[0].unmatched}`);
console.log(`关联成功率: ${stats.rows[0].match_rate}%`);
if (parseInt(stats.rows[0].matched) > 0) {
console.log('\n✅ 修复成功!手术安排现在能正确关联到手术申请,申请科室和主刀医生可以正常显示。');
} else {
console.log('\n⚠ 没有关联成功的记录,请检查数据。');
}
} catch (err) {
console.error('测试失败:', err.message);
} finally {
pool.end();
}
}
testFix();