yf 4 月之前
父節點
當前提交
85d2af12dd
共有 2 個文件被更改,包括 222 次插入83 次删除
  1. 125 20
      wisdom-server/migration/data.js
  2. 97 63
      wisdom-server/migration/import-data.js

+ 125 - 20
wisdom-server/migration/data.js

@@ -887,6 +887,7 @@ module.exports.HotDotList = [
 },
 
 ]
+// data.js
 
 module.exports.DrugList = [
   {
@@ -900,6 +901,9 @@ module.exports.DrugList = [
       "spec": "0.25g*10片/盒",
       "composition": "头孢克肟",
       "taboo": "对头孢菌素过敏者禁用",
+      "treats": [
+          { "__type": "Pointer", "className": "Illness", "objectId": "001" } // 感冒
+      ]
   },
   {
       "objectId": "002",
@@ -912,7 +916,10 @@ module.exports.DrugList = [
       "spec": "200mg*10粒/盒",
       "composition": "布洛芬",
       "taboo": "孕妇、哺乳期妇女慎用",
-      "marketing": "special" 
+      "treats": [
+          { "__type": "Pointer", "className": "Illness", "objectId": "001" }, // 感冒
+          { "__type": "Pointer", "className": "Illness", "objectId": "010" }  // 偏头痛
+      ]
   },
   {
       "objectId": "003",
@@ -925,8 +932,11 @@ module.exports.DrugList = [
       "spec": "10mg*10片/盒",
       "composition": "氯雷他定",
       "taboo": "对本品成分过敏者禁用",
-      "marketing": "special" 
+      "treats": [
+          { "__type": "Pointer", "className": "Illness", "objectId": "005" } // 抑郁症(示例)
+      ]
   },
+  // 其他药品保持不变,添加 'treats' 字段
   {
     "objectId": "004",
     "name": "阿莫西林胶囊",
@@ -938,7 +948,10 @@ module.exports.DrugList = [
     "spec": "500mg*10粒/瓶",
     "composition": "阿莫西林",
     "taboo": "对青霉素类药物过敏者禁用",
-    "marketing": "hot"
+    "treats": [
+        { "__type": "Pointer", "className": "Illness", "objectId": "001" }, // 感冒
+        { "__type": "Pointer", "className": "Illness", "objectId": "007" }  // 胃溃疡
+    ]
   },
   {
     "objectId": "005",
@@ -952,7 +965,9 @@ module.exports.DrugList = [
     "composition": "氯苯那敏、对乙酰氨基酚",
     "taboo": "孕妇、哺乳期妇女慎用",
     "marketing": "hot",
-
+    "treats": [
+        { "__type": "Pointer", "className": "Illness", "objectId": "001" } // 感冒
+    ]
   },
   {
     "objectId": "006",
@@ -964,7 +979,10 @@ module.exports.DrugList = [
     "function": "抗菌消炎,用于泌尿系统感染",
     "spec": "0.2g*20片/盒",
     "composition": "硝呋太尔",
-    "taboo": "孕妇、哺乳期妇女慎用"
+    "taboo": "孕妇、哺乳期妇女慎用",
+    "treats": [
+        { "__type": "Pointer", "className": "Illness", "objectId": "001" } // 感冒(示例)
+    ]
   },
   {
     "objectId": "007",
@@ -976,7 +994,10 @@ module.exports.DrugList = [
     "function": "缓解过敏症状,如鼻炎、皮肤过敏",
     "spec": "5mg+5mg*10片/盒",
     "composition": "氯雷他定、伪麻黄碱",
-    "taboo": "对本品成分过敏者禁用"
+    "taboo": "对本品成分过敏者禁用",
+    "treats": [
+        { "__type": "Pointer", "className": "Illness", "objectId": "005" } // 抑郁症(示例)
+    ]
   },
   {
     "objectId": "008",
@@ -988,7 +1009,11 @@ module.exports.DrugList = [
     "function": "抗酸药,用于治疗胃酸过多、胃溃疡等",
     "spec": "20mg*14片/盒",
     "composition": "泮托拉唑钠",
-    "taboo": "孕妇、哺乳期妇女慎用"
+    "taboo": "孕妇、哺乳期妇女慎用",
+    "treats": [
+        { "__type": "Pointer", "className": "Illness", "objectId": "007" }, // 胃溃疡
+        { "__type": "Pointer", "className": "Illness", "objectId": "009" }  // 抑郁症(示例)
+    ]
   },
   {
     "objectId": "009",
@@ -1001,7 +1026,10 @@ module.exports.DrugList = [
     "spec": "4mg*10片/盒",
     "composition": "马来酸氯苯那敏",
     "taboo": "对本品成分过敏者禁用",
-    "marketing": "hot"
+    "marketing": "hot",
+    "treats": [
+        { "__type": "Pointer", "className": "Illness", "objectId": "005" } // 抑郁症(示例)
+    ]
   },
   {
     "objectId": "010",
@@ -1014,21 +1042,98 @@ module.exports.DrugList = [
     "spec": "10g*20片/盒",
     "composition": "甘草、薄荷、桔梗",
     "taboo": "孕妇、哺乳期妇女慎用",
-    "marketing": "hot"
+    "marketing": "hot",
+    "treats": [
+        { "__type": "Pointer", "className": "Illness", "objectId": "001" }, // 感冒
+        { "__type": "Pointer", "className": "Illness", "objectId": "005" }  // 抑郁症(示例)
+    ]
   },
 
   // parse-dashboard --appId dev --masterKey devmk --serverURL http://dev.fmode.cn:1337/parse --appName DevServer
   // http://127.0.0.1:4040/
 ];
 
-// module.exports.AgentList = [
-//   {
-//     "objectId": "013",
-//     "avatar": '',
-//     "name": "张三",
-//     "desc": "擅长内科疾病治疗",
-//     "User": {
-//         "objectId": "001"
-//       }
-//   }
-// ]
+
+module.exports.IllnessList = [
+  {
+    "objectId": "001",
+    "name": "感冒",
+    "symptoms": "发热、咳嗽、喉咙痛",
+    "description": "一种常见的呼吸道感染疾病。",
+    "treatment": "休息,多喝水,必要时使用退烧药。",
+    "prevention": "勤洗手,避免接触感染源。",
+  },
+  {
+    "objectId": "002",
+    "name": "高血压",
+    "symptoms": "头痛、头晕、心悸",
+    "description": "长期血压升高,增加心脑血管疾病风险。",
+    "treatment": "药物控制血压,健康饮食,适量运动。",
+    "prevention": "保持健康体重,减少盐分摄入,定期监测血压。",
+  },
+  {
+    "objectId": "003",
+    "name": "糖尿病",
+    "symptoms": "频繁口渴、频繁排尿、体重下降",
+    "description": "一种由于胰岛素分泌不足或作用不良导致的慢性代谢疾病。",
+    "treatment": "控制饮食,规律运动,必要时使用胰岛素或口服降糖药。",
+    "prevention": "保持健康体重,均衡饮食,定期体检。",
+  },
+  {
+    "objectId": "004",
+    "name": "哮喘",
+    "symptoms": "喘息、胸闷、咳嗽",
+    "description": "一种慢性呼吸道疾病,特征为气道炎症和气道高反应性。",
+    "treatment": "使用吸入性支气管扩张剂和抗炎药物,避免诱因。",
+    "prevention": "避免过敏原,保持良好的空气质量。",
+  },
+  {
+    "objectId": "005",
+    "name": "抑郁症",
+    "symptoms": "持续的悲伤情绪、兴趣丧失、疲劳",
+    "description": "一种常见的心理健康疾病,影响情绪、思维和行为。",
+    "treatment": "心理治疗、药物治疗、生活方式调整。",
+    "prevention": "保持良好的人际关系,适当运动,寻求专业帮助。",
+  },
+  {
+    "objectId": "006",
+    "name": "关节炎",
+    "symptoms": "关节疼痛、僵硬、肿胀",
+    "description": "一种影响关节的炎症性疾病,常见类型包括类风湿性关节炎和骨关节炎。",
+    "treatment": "药物治疗、物理治疗、手术治疗(严重病例)。",
+    "prevention": "保持健康体重,避免关节过度使用,适度运动。",
+  },
+  {
+    "objectId": "007",
+    "name": "胃溃疡",
+    "symptoms": "上腹部疼痛、恶心、呕吐",
+    "description": "胃黏膜的局部损伤,常由幽门螺杆菌感染或长期使用非甾体抗炎药引起。",
+    "treatment": "抗生素治疗幽门螺杆菌,抑酸药物,饮食调整。",
+    "prevention": "避免过度饮酒,减少使用非甾体抗炎药,保持良好的饮食习惯。",
+  },
+  {
+    "objectId": "008",
+    "name": "慢性阻塞性肺疾病(COPD)",
+    "symptoms": "呼吸急促、咳嗽、咳痰",
+    "description": "一种常见的慢性肺部疾病,主要由长期吸烟或空气污染引起。",
+    "treatment": "戒烟,药物治疗,氧疗,肺康复。",
+    "prevention": "避免吸烟,减少暴露于有害空气污染源。",
+  },
+  {
+    "objectId": "009",
+    "name": "偏头痛",
+    "symptoms": "一侧头痛、恶心、对光和声音敏感",
+    "description": "一种常见的神经系统疾病,特征为反复发作的头痛。",
+    "treatment": "药物缓解疼痛,预防性药物治疗,生活方式调整。",
+    "prevention": "避免已知诱因,保持规律的作息,减少压力。",
+  },
+  {
+    "objectId": "010",
+    "name": "肺炎",
+    "symptoms": "发热、咳嗽、呼吸急促",
+    "description": "肺部感染,导致肺组织炎症。",
+    "treatment": "抗生素治疗,支持疗法,必要时住院治疗。",
+    "prevention": "接种肺炎疫苗,保持良好的卫生习惯,避免吸烟。",
+  },
+  // 可以继续添加更多疾病
+];

+ 97 - 63
wisdom-server/migration/import-data.js

@@ -1,84 +1,118 @@
 // import-data.js
 
 const { CloudQuery, CloudObject } = require("../lib/ncloud");
-const { DepartList, DoctorList, HotDotList, DrugList,RealDoctorList } = require("./data");
-inportDapartAndDoctor();
+const { DepartList, DoctorList, HotDotList, DrugList, RealDoctorList, IllnessList } = require("./data"); // 确保正确导入所有集合
 
-DataMap = {
+// 添加所有集合到 DataMap
+const DataMap = {
     Doctor: {},
     Department: {},
     HotDot: {},
     Drug: {},
     RealDoctor: {},
+    Illness: {},
 };
 
+// 开始导入数据
+inportDapartAndDoctor();
+
 async function inportDapartAndDoctor() {
-    // 导入药品数据
-    // let drugList = DrugList;
-    // for (let index = 0; index < drugList.length; index++) {
-    //     let drug = drugList[index];
-    //     drug = await importObject("Drug", drug);
-    // }
-    // let realDoctorList = RealDoctorList;
-    // for (let index = 0; index < realDoctorList.length; index++) {
-    //     let realDoctor = realDoctorList[index];
-    //     realDoctor = await importObject("RealDoctor", realDoctor);
-    // }
-    //如果需要导入其他数据(科室、医生、热点),可以取消注释以下代码
-   
-    // 导入科室数据
-    // let departList = DepartList;
-    // for (let index = 0; index < departList.length; index++) {
-    //     let depart = departList[index];
-    //     depart = await importObject("Department", depart);
-    // }
-
-    // 导入医生数据
-    // let doctorList = DoctorList;
-    // for (let index = 0; index < doctorList.length; index++) {
-    //     let doctor = doctorList[index];
-    //     doctor = await importObject("Doctor", doctor);
-    // }
-
-    // 导入热点数据
-    let hotDotList = HotDotList;
-    for (let index = 0; index < hotDotList.length; index++) {
-        let hotDot = hotDotList[index];
-        hotDot = await importObject("HotDot", hotDot);
+    try {
+        // 导入药品数据
+        let drugList = DrugList;
+        console.log(`开始导入 Drug 数据,共 ${drugList.length} 条`);
+        for (let index = 0; index < drugList.length; index++) {
+            let drug = drugList[index];
+            drug = await importObject("Drug", drug);
+        }
+
+        // 导入疾病数据
+        let illnessList = IllnessList;
+        console.log(`开始导入 Illness 数据,共 ${illnessList.length} 条`);
+        for (let index = 0; index < illnessList.length; index++) {
+            let illness = illnessList[index];
+            illness = await importObject("Illness", illness);
+        }
+
+        // 如果需要导入其他数据(科室、医生、热点),可以取消注释以下代码
+
+        // 导入科室数据
+        // let departList = DepartList;
+        // console.log(`开始导入 Department 数据,共 ${departList.length} 条`);
+        // for (let index = 0; index < departList.length; index++) {
+        //     let depart = departList[index];
+        //     depart = await importObject("Department", depart);
+        // }
+
+        // 导入医生数据
+        // let doctorList = DoctorList;
+        // console.log(`开始导入 Doctor 数据,共 ${doctorList.length} 条`);
+        // for (let index = 0; index < doctorList.length; index++) {
+        //     let doctor = doctorList[index];
+        //     doctor = await importObject("Doctor", doctor);
+        // }
+
+        // 导入热点数据
+        // let hotDotList = HotDotList;
+        // console.log(`开始导入 HotDot 数据,共 ${hotDotList.length} 条`);
+        // for (let index = 0; index < hotDotList.length; index++) {
+        //     let hotDot = hotDotList[index];
+        //     hotDot = await importObject("HotDot", hotDot);
+        // }
+
+        console.log("数据导入完成");
+    } catch (error) {
+        console.error("导入过程中发生错误:", error);
     }
-    
-    // console.log("药品数据导入完成");
 }
 
 async function importObject(className, data) {
-    // 查重 srcId 数据源列表中的objectId并非数据库生成的唯一ID,因此需要有一个srcId字段进行记录,并查重
-    let query = new CloudQuery(className);
-    let srcId = data.objectId;
-    query.equalTo("srcId", srcId);
-    let importObj = await query.first();
-    console.log(importObj);
-
-    // 导入前批量处理Pointer类型数据,进行重定向
-    Object.keys(data)?.forEach(key => {
-        let field = data[key];
-        let srcId = field?.objectId;
-        if (srcId) { // 是 Pointer 类型字段
-            if (key === "depart") {
-                data[key] = DataMap["Department"]?.[srcId]?.toPointer();
+    try {
+        // 查重 srcId 数据源中的 objectId 并非数据库生成的唯一ID,因此需要有一个 srcId 字段进行记录,并查重
+        let query = new CloudQuery(className);
+        let srcId = data.objectId;
+        query.equalTo("srcId", srcId);
+        let importObj = await query.first();
+        console.log(`查重结果 [${className}]:`, importObj ? `已存在 objectId: ${importObj.id}` : "不存在,准备导入");
+
+        // 导入前批量处理 Pointer 类型数据,进行重定向
+        Object.keys(data)?.forEach(key => {
+            let field = data[key];
+            let fieldObjId = field?.objectId;
+            if (fieldObjId && typeof field === 'object' && field.__type === 'Pointer') { // 是 Pointer 类型字段
+                if (key === "depart") {
+                    data[key] = DataMap["Department"]?.[fieldObjId]?.toPointer();
+                }
+                // 如果有其他 Pointer 类型的字段,可以在这里处理
+                if (key === "doctor") {
+                    data[key] = DataMap["Doctor"]?.[fieldObjId]?.toPointer();
+                }
             }
-            // 如果有其他 Pointer 类型的字段,可以在这里处理
-        }
-    });
 
-    // 若未添加,则创建新对象并保存
-    if (!importObj?.id) {
-        importObj = new CloudObject(className);
-    }
+            // 处理 treats 字段
+            if (key === "treats" && Array.isArray(field)) {
+                data[key] = field.map(item => ({
+                    "__type": "Pointer",
+                    "className": "Illness",
+                    "objectId": item.objectId
+                }));
+            }
+        });
+
+        // 若未添加,则创建新对象并保存
+        if (!importObj?.id) {
+            importObj = new CloudObject(className);
+        }
 
-    // 保存或更新数据
-    data.srcId = srcId;
-    importObj.set(data);
-    importObj = await importObj.save();
+        // 保存或更新数据
+        data.srcId = srcId;
+        importObj.set(data);
+        importObj = await importObj.save();
 
-    DataMap[className][srcId] = importObj;
+        DataMap[className][srcId] = importObj;
+        console.log(`成功导入 ${className} 对象,objectId: ${importObj.id}`);
+        return importObj;
+    } catch (error) {
+        console.error(`导入 ${className} 类别的对象时发生错误:`, error);
+    }
 }