72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
/**
|
|
* 调试脚本:检查 REDCap 实际数据和字段映射
|
|
*/
|
|
import { PrismaClient } from '@prisma/client';
|
|
import { RedcapAdapter } from './src/modules/iit-manager/adapters/RedcapAdapter.js';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('=== 调试 REDCap 数据 ===\n');
|
|
|
|
// 1. 获取项目配置
|
|
const project = await prisma.iitProject.findFirst({
|
|
where: { name: { contains: 'test0207' } },
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
redcapUrl: true,
|
|
redcapApiToken: true,
|
|
fieldMappings: true
|
|
}
|
|
});
|
|
|
|
if (!project) {
|
|
console.log('未找到项目');
|
|
await prisma.$disconnect();
|
|
return;
|
|
}
|
|
|
|
console.log('项目:', { id: project.id, name: project.name });
|
|
console.log('字段映射配置:', JSON.stringify(project.fieldMappings, null, 2));
|
|
|
|
// 2. 从 REDCap 获取 record_id=1 的实际数据
|
|
const adapter = new RedcapAdapter(project.redcapUrl, project.redcapApiToken);
|
|
|
|
try {
|
|
const record = await adapter.getRecordById('1');
|
|
console.log('\n=== REDCap Record ID=1 实际数据 ===');
|
|
console.log(JSON.stringify(record, null, 2));
|
|
|
|
// 特别检查年龄相关字段
|
|
console.log('\n=== 年龄相关字段 ===');
|
|
const ageFields = Object.entries(record || {}).filter(([key]) =>
|
|
key.toLowerCase().includes('age') ||
|
|
key.toLowerCase().includes('年龄') ||
|
|
key.toLowerCase().includes('birth') ||
|
|
key.toLowerCase().includes('出生')
|
|
);
|
|
console.log('年龄相关字段:', ageFields);
|
|
|
|
// 显示所有字段名
|
|
console.log('\n=== 所有字段名 ===');
|
|
console.log(Object.keys(record || {}).join(', '));
|
|
|
|
} catch (error: any) {
|
|
console.error('REDCap 查询失败:', error.message);
|
|
}
|
|
|
|
// 3. 检查字段映射表
|
|
const fieldMappings = await prisma.iitFieldMapping.findMany({
|
|
where: { projectId: project.id },
|
|
});
|
|
console.log('\n=== 字段映射表 ===');
|
|
for (const m of fieldMappings) {
|
|
console.log(` ${m.aliasName} -> ${m.actualName}`);
|
|
}
|
|
|
|
await prisma.$disconnect();
|
|
}
|
|
|
|
main().catch(console.error);
|