fuyu 4 年之前
父節點
當前提交
6c5e256075
共有 3 個文件被更改,包括 58 次插入19 次删除
  1. 7 3
      src/modules/api/controller.js
  2. 10 6
      src/modules/api/router.js
  3. 41 10
      src/service/move.js

+ 7 - 3
src/modules/api/controller.js

@@ -2,10 +2,14 @@
  * @Author: fuyu
  * @Date: 2021-03-23 11:56:31
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-23 18:56:55
- * @FilePath: /202103/code/sql_merge/src/modules/api/controller.js
+ * @LastEditTime: 2021-03-24 15:12:09
+ * @FilePath: /sql_merge/src/modules/api/controller.js
  */
-import {moveAll} from '../../service/move'
+import {moveAll, movePacs} from '../../service/move'
 export async function move(ctx) {
   await moveAll()
 }
+
+export async function pacs(ctx) {
+  await movePacs()
+}

+ 10 - 6
src/modules/api/router.js

@@ -2,16 +2,20 @@
  * @Author: fuyu
  * @Date: 2021-02-26 17:17:47
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-23 11:59:01
- * @FilePath: /202103/code/sql_merge/src/modules/api/router.js
+ * @LastEditTime: 2021-03-24 15:12:18
+ * @FilePath: /sql_merge/src/modules/api/router.js
  */
 import * as api from './controller'
 
 export const baseUrl = '/api'
 
 export default [{
-    method: 'POST',
-    route: '/move',
-    handlers: [api.move]
-  }
+  method: 'POST',
+  route: '/move',
+  handlers: [api.move]
+},{
+  method: 'POST',
+  route: '/pacs',
+  handlers: [api.pacs]
+}
 ]

+ 41 - 10
src/service/move.js

@@ -2,12 +2,16 @@
  * @Author: fuyu
  * @Date: 2021-03-23 12:00:09
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-24 14:48:50
+ * @LastEditTime: 2021-03-24 15:19:24
  * @FilePath: /sql_merge/src/service/move.js
  */
 
 import config from '../../config'
 const limit = config['limit']
+const FLAG_DELAULT = 0
+const FLAG_REPORT = 1
+const FLAG_PACS = 2
+
 import {logSum, logSingle} from './log'
 import {RemoteApplication as OldRemoteApplication, ApplicationProgressLog as OldApplicationProgressLog, Bbs as OldBbs, RemoteOrder as OldRemoteOrder, RemoteWater as OldRemoteWater, Register as OldRegister, Exams as OldExams, PatientInfos as OldPatientInfos, Studies as OldStudies, Series as OldSeries, Images as OldImages, Report as OldReport, ReportRecord as OldReportRecord, QualityControl as OldQualityControl, QualityCause as OldQualityCause} from '../dao_old'
 import {Institution,  RemoteApplication as NewRemoteApplication, ApplicationProgressLog as NewApplicationProgressLog, Bbs as NewBbs, RemoteOrder as NewRemoteOrder, RemoteWater as NewRemoteWater, Register as NewRegister, Exams as NewExams, PatientInfos as NewPatientInfos, Studies as NewStudies, Series as NewSeries, Images as NewImages, Report as NewReport, ReportRecord as NewReportRecord, QualityControl as NewQualityControl, QualityCause as NewQualityCause} from '../dao_new'
@@ -18,6 +22,36 @@ export async function moveAll() {
     await moveSingle(ids[i]['id'])
   }
 }
+
+export async function movePacs() {
+  const ids = await Institution.findAll({attributes: ['id']})
+  for(let i = 0; i < ids.length; i++) {
+    await moveSinglePacs(ids[i]['id'])
+  }
+}
+
+const moveSinglePacs = async institution_id => {
+  let count = limit, sum = 0
+  while(count === limit) {
+    count = await moveExamsPacs(institution_id)
+    sum += count
+  }
+  logSum('pacs-', institution_id, sum)
+}
+
+const moveExamsPacs = async (institution_id) => {
+  let exmas = await OldExams.findAll({where: {institution_id, flag: FLAG_REPORT}, limit})
+  for(let i = 0; i < exmas.length; i++) {
+    await moveExamPacs(exmas[i])
+  }
+  return exmas.length
+}
+
+const moveExamPacs = async (exam) => {
+  await fixPacs(exam.study_id, exam.patient_id)
+  await updateExamFlag(exam, FLAG_PACS)
+}
+
 const moveSingle = async institution_id => {
   let count = limit, sum = 0
   while(count === limit) {
@@ -28,10 +62,7 @@ const moveSingle = async institution_id => {
 }
 
 const moveExams = async (institution_id) => {
-  // offset: 5, limit: 5
-  console.log('limit',limit)
-  let exmas = await OldExams.findAll({where: {institution_id, flag: 0}, limit})
-
+  let exmas = await OldExams.findAll({where: {institution_id, flag: FLAG_DELAULT}, limit})
   for(let i = 0; i < exmas.length; i++) {
     await moveExam(exmas[i])
   }
@@ -44,7 +75,7 @@ const moveExam = async (exam) => {
 
 const fixExam = async(exam) => {
   // 同步PACS
-  await fixPacs(exam.study_id, exam.patient_id)
+  // await fixPacs(exam.study_id, exam.patient_id)
   // 同步报告
   await fixReports(exam.id)
   // 同步远程诊断
@@ -52,7 +83,7 @@ const fixExam = async(exam) => {
   // 同步登记
   await fixRegisters(exam.id)
   // 更新检查标识
-  await updateExamFlag(exam)
+  await updateExamFlag(exam, 1)
 }
 
 const fixCommon = async (NewClass, OldClass, where, cb) => {
@@ -142,12 +173,12 @@ const fixSerieChild = async serie => {
   await fixCommons(NewImages, OldImages, {series_id: serie.id})
 }
 
-const updateExamFlag = async exam => {
+const updateExamFlag = async (exam, flag) => {
   const old = await OldExams.findOne({where: {id: exam.id}})
-  old.flag = 1;
+  old.flag = flag;
   await old.save()
   const newExam = await NewExams.findOne({where: {id: exam.id}})
-  newExam.flag = 1;
+  newExam.flag = flag;
   await newExam.save()
   return true
 }