feat(iit): Implement event-level QC architecture V3.1 with dynamic rule filtering, report deduplication and AI intent enhancement
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
115
backend/update-skill-applicable-forms.ts
Normal file
115
backend/update-skill-applicable-forms.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* 更新 Skill 配置:为规则添加 applicableForms
|
||||
*
|
||||
* 确保规则只在包含对应表单的事件中执行
|
||||
*/
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log('='.repeat(60));
|
||||
console.log('📋 更新 Skill 配置:添加 applicableForms');
|
||||
console.log('='.repeat(60));
|
||||
|
||||
// 1. 获取项目
|
||||
const project = await prisma.iitProject.findFirst({
|
||||
where: { name: { contains: 'test0207' } },
|
||||
});
|
||||
|
||||
if (!project) {
|
||||
console.log('❌ 未找到项目');
|
||||
await prisma.$disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`\n✅ 项目: ${project.name} (${project.id})`);
|
||||
|
||||
// 2. 获取当前 Skill 配置
|
||||
const skill = await prisma.iitSkill.findFirst({
|
||||
where: { projectId: project.id, isActive: true },
|
||||
});
|
||||
|
||||
if (!skill) {
|
||||
console.log('❌ 未找到激活的 Skill');
|
||||
await prisma.$disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`\n📋 当前 Skill: ${skill.name} (${skill.id})`);
|
||||
|
||||
const config = skill.config as any;
|
||||
const rules = config?.rules || [];
|
||||
|
||||
console.log(`\n当前规则配置 (共 ${rules.length} 条):`);
|
||||
for (const rule of rules) {
|
||||
console.log(` - ${rule.name}`);
|
||||
console.log(` field: ${rule.field}`);
|
||||
console.log(` applicableForms: ${JSON.stringify(rule.applicableForms || '(未设置)')}`);
|
||||
}
|
||||
|
||||
// 3. 定义规则-表单映射
|
||||
// 根据规则检查的字段,确定应该在哪个表单中检查
|
||||
const ruleFormMapping: Record<string, string[]> = {
|
||||
'年龄范围检查': ['basic_demography_form'],
|
||||
'出生日期范围检查': ['basic_demography_form'],
|
||||
'月经周期规律性检查': ['medical_history_and_diagnosis'],
|
||||
'VAS 评分检查': ['cmss'], // 或者 mcgill_sfmpq,根据实际字段确定
|
||||
'知情同意书签署检查': ['informed_consent'],
|
||||
};
|
||||
|
||||
// 4. 更新规则配置
|
||||
console.log('\n' + '='.repeat(60));
|
||||
console.log('📝 更新规则配置');
|
||||
console.log('='.repeat(60));
|
||||
|
||||
const updatedRules = rules.map((rule: any) => {
|
||||
const applicableForms = ruleFormMapping[rule.name];
|
||||
if (applicableForms) {
|
||||
console.log(`\n ✅ ${rule.name}`);
|
||||
console.log(` 添加 applicableForms: ${JSON.stringify(applicableForms)}`);
|
||||
return {
|
||||
...rule,
|
||||
applicableForms,
|
||||
};
|
||||
} else {
|
||||
console.log(`\n ⚠️ ${rule.name} - 未找到映射,保持不变`);
|
||||
return rule;
|
||||
}
|
||||
});
|
||||
|
||||
// 5. 保存更新后的配置
|
||||
const updatedConfig = {
|
||||
...config,
|
||||
rules: updatedRules,
|
||||
};
|
||||
|
||||
await prisma.iitSkill.update({
|
||||
where: { id: skill.id },
|
||||
data: { config: updatedConfig },
|
||||
});
|
||||
|
||||
console.log('\n' + '='.repeat(60));
|
||||
console.log('✅ 配置更新完成');
|
||||
console.log('='.repeat(60));
|
||||
|
||||
// 6. 验证更新结果
|
||||
const verifySkill = await prisma.iitSkill.findUnique({
|
||||
where: { id: skill.id },
|
||||
});
|
||||
|
||||
const verifyConfig = verifySkill?.config as any;
|
||||
console.log('\n更新后的规则配置:');
|
||||
for (const rule of verifyConfig?.rules || []) {
|
||||
console.log(` - ${rule.name}`);
|
||||
console.log(` applicableForms: ${JSON.stringify(rule.applicableForms || '(未设置)')}`);
|
||||
}
|
||||
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
|
||||
main().catch(async (error) => {
|
||||
console.error('❌ 脚本出错:', error);
|
||||
await prisma.$disconnect();
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user