300 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			Plaintext
		
	
	
			
		
		
	
	
			300 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			Plaintext
		
	
	
| import {
 | |
|   getRelatedVisitTask,
 | |
|   getTableAnswerRowInfoList,
 | |
|   getDicomReadingQuestionAnswer,
 | |
|   getReadingQuestionAndAnswer
 | |
| }
 | |
|   from '@/api/trials'
 | |
| import { getVisitStudyList } from '@/api/reading'
 | |
| const getDefaultState = () => {
 | |
|   return {
 | |
|     visitTaskList: [],
 | |
|     activeStack: []
 | |
| 
 | |
|   }
 | |
| }
 | |
| function getQuestions(questions) {
 | |
|   questions.forEach(item => {
 | |
|     if (item.Type === 'table' && item.TableQuestions && item.TableQuestions.Answers.length > 0) {
 | |
|       item.TableQuestions.Answers.forEach(answerObj => {
 | |
|         answerObj.loctation = getQuestionAnswer(item.TableQuestions.Questions, 6, answerObj)
 | |
|         answerObj.lesionLength = getQuestionAnswer(item.TableQuestions.Questions, 0, answerObj)
 | |
|         answerObj.lesionShort = getQuestionAnswer(item.TableQuestions.Questions, 1, answerObj)
 | |
|         var isLymphLesion = getQuestionAnswer(item.TableQuestions.Questions, 2, answerObj)
 | |
|         isLymphLesion = isLymphLesion ? parseInt(isLymphLesion) : null
 | |
|         answerObj.isLymphLesion = isLymphLesion
 | |
|         answerObj.isLesionSaved = true
 | |
|       })
 | |
|     }
 | |
|     if (item.Childrens.length > 0) {
 | |
|       getQuestions(item.Childrens)
 | |
|     }
 | |
|   })
 | |
|   return questions
 | |
| }
 | |
| function findQuestionAndRemoveLesion(questions, obj) {
 | |
|   for (var i = 0; i < questions.length; i++) {
 | |
|     if (questions[i].Type === 'table' && questions[i].TableQuestions && (questions[i].LesionType === obj.lesionType) && questions[i].TableQuestions.Answers.length > 0) {
 | |
|       var idx = questions[i].TableQuestions.Answers.findIndex(i => String(i.RowIndex) === String(obj.rowIndex))
 | |
|       if (idx > -1) {
 | |
|         questions[i].TableQuestions.Answers.splice(idx, 1)
 | |
|         break
 | |
|       }
 | |
|     }
 | |
|     if (questions[i].Childrens.length > 0) {
 | |
|       findQuestionAndRemoveLesion(questions[i].Childrens, obj)
 | |
|     }
 | |
|   }
 | |
|   return questions
 | |
| }
 | |
| function findQuestionAndUpdateLesion(questions, obj) {
 | |
|   for (var i = 0; i < questions.length; i++) {
 | |
|     var item = questions[i]
 | |
|     if (item.Type === 'table' && item.Id === obj.questionId) {
 | |
|       var idx = item.TableQuestions.Answers.findIndex(i => i.RowIndex === obj.rowIndex)
 | |
|       item.TableQuestions.Answers[idx].isLymphLesion = obj.isLymphLesion
 | |
|       item.TableQuestions.Answers[idx].loctation = obj.lesionOrgan
 | |
|       item.TableQuestions.Answers[idx].lesionLength = obj.lesionLength
 | |
|       item.TableQuestions.Answers[idx].lesionShort = obj.lesionShort
 | |
|       item.TableQuestions.Answers[idx].isLesionSaved = obj.isLesionSaved
 | |
|       for (const i in obj.anwsers) {
 | |
|         if (i === 'MeasureData' && obj.anwsers[i]) {
 | |
|           item.TableQuestions.Answers[idx].InstanceId = obj.anwsers[i].instanceId
 | |
|           item.TableQuestions.Answers[idx].SeriesId = obj.anwsers[i].seriesId
 | |
|           item.TableQuestions.Answers[idx][i] = JSON.stringify(obj.anwsers[i])
 | |
|         } else {
 | |
|           item.TableQuestions.Answers[idx][i] = String(obj.anwsers[i])
 | |
|         }
 | |
|       }
 | |
|       break
 | |
|     }
 | |
|     if (item.Childrens.length > 0) {
 | |
|       this.findQuestionAndUpdateLesion(item.Childrens, obj)
 | |
|     }
 | |
|   }
 | |
|   return questions
 | |
| }
 | |
| function findQuestionAndAddLesion(questions, obj) {
 | |
|   for (var i = 0; i < questions.length; i++) {
 | |
|     if (questions[i].Type === 'table' && questions[i].TableQuestions && (questions[i].LesionType === obj.lesionType)) {
 | |
|       var sourceObj = {}
 | |
|       questions[i].TableQuestions.Questions.forEach(item => {
 | |
|         sourceObj[item.Id] = ''
 | |
|       })
 | |
|       var targetObj = Object.assign(sourceObj, obj.lesionObj)
 | |
|       targetObj.IsCurrentTaskAdd = 'True'
 | |
|       questions[i].TableQuestions.Answers.push(targetObj)
 | |
|       break
 | |
|     }
 | |
|     if (questions[i].Childrens.length > 0) {
 | |
|       findQuestionAndAddLesion(questions[i].Childrens, obj)
 | |
|     }
 | |
|   }
 | |
|   return questions
 | |
| }
 | |
| function getQuestionAnswer(questions, questionMark, answers) {
 | |
|   var idx = questions.findIndex(i => i.QuestionMark === questionMark)
 | |
|   if (idx > -1) {
 | |
|     var questionId = questions[idx].Id
 | |
|     return answers[questionId]
 | |
|   } else {
 | |
|     return ''
 | |
|   }
 | |
| }
 | |
| const state = getDefaultState
 | |
| 
 | |
| const mutations = {
 | |
| }
 | |
| 
 | |
| const actions = {
 | |
|   getVisitTasks({ state }, visitTaskId) {
 | |
|     return new Promise(resolve => {
 | |
|       getRelatedVisitTask({ visitTaskId: visitTaskId }).then(res => {
 | |
|         state.visitTaskList = res.Result
 | |
|         resolve()
 | |
|       }).catch(() => { resolve() })
 | |
|     })
 | |
|   },
 | |
| 
 | |
|   getDicomReadingQuestionAnswer({ state }, obj) {
 | |
|     return new Promise(resolve => {
 | |
|       var index = state.visitTaskList.findIndex(i => i.VisitTaskId === obj.visitTaskId)
 | |
|       var params = {
 | |
|         trialId: obj.trialId,
 | |
|         visitTaskId: obj.visitTaskId
 | |
|       }
 | |
|       getDicomReadingQuestionAnswer(params).then(res => {
 | |
|         state.visitTaskList[index].Questions = res.Result
 | |
|         resolve()
 | |
|       }).catch(() => { resolve() })
 | |
|     })
 | |
|   },
 | |
|   getReadingQuestionAndAnswer({ state }, obj) {
 | |
|     return new Promise(resolve => {
 | |
|       var index = state.visitTaskList.findIndex(i => i.VisitTaskId === obj.visitTaskId)
 | |
|       var params = {
 | |
|         trialId: obj.trialId,
 | |
|         visitTaskId: obj.visitTaskId
 | |
|       }
 | |
|       getReadingQuestionAndAnswer(params).then(res => {
 | |
|         var list = getQuestions(res.Result.SinglePage)
 | |
|         state.visitTaskList[index].ReadingQuestions = list
 | |
|         resolve()
 | |
|       }).catch(() => { resolve() })
 | |
|     })
 | |
|   },
 | |
|   setReadingQuestionAndAnswer({ state }, obj) {
 | |
|     return new Promise(resolve => {
 | |
|       var index = state.visitTaskList.findIndex(i => i.VisitTaskId === obj.visitTaskId)
 | |
|       if (index > -1) {
 | |
|         state.visitTaskList[index].ReadingQuestions = obj.questions
 | |
|       }
 | |
|       console.log(state.visitTaskList[index].ReadingQuestions)
 | |
|       resolve()
 | |
|     })
 | |
|   },
 | |
|   addReadingQuestionAndAnswer({ state }, obj) {
 | |
|     return new Promise(resolve => {
 | |
|       var index = state.visitTaskList.findIndex(i => i.VisitTaskId === obj.visitTaskId)
 | |
|       if (index > -1) {
 | |
|         var questions = state.visitTaskList[index].ReadingQuestions
 | |
|         questions = findQuestionAndAddLesion(questions, obj)
 | |
|         state.visitTaskList[index].ReadingQuestions = questions
 | |
|       }
 | |
|       resolve()
 | |
|     })
 | |
|   },
 | |
|   updateReadingQuesstionAndAnswer({ state }, obj) {
 | |
|     return new Promise(resolve => {
 | |
|       var index = state.visitTaskList.findIndex(i => i.VisitTaskId === obj.visitTaskId)
 | |
|       if (index > -1) {
 | |
|         var questions = state.visitTaskList[index].ReadingQuestions
 | |
|         questions = findQuestionAndUpdateLesion(questions, obj)
 | |
|         state.visitTaskList[index].ReadingQuestions = questions
 | |
|       }
 | |
|       resolve()
 | |
|     })
 | |
|   },
 | |
|   removeReadingQuestionAndAnswer({ state }, obj) {
 | |
|     return new Promise(resolve => {
 | |
|       var index = state.visitTaskList.findIndex(i => i.VisitTaskId === obj.visitTaskId)
 | |
|       if (index > -1) {
 | |
|         var questions = state.visitTaskList[index].ReadingQuestions
 | |
|         questions = findQuestionAndRemoveLesion(questions, obj)
 | |
|         state.visitTaskList[index].ReadingQuestions = questions
 | |
|       }
 | |
|       console.log(state.visitTaskList[index].ReadingQuestions)
 | |
|       resolve()
 | |
|     })
 | |
|   },
 | |
| 
 | |
|   getMeasuredData({ state }, visitTaskId) {
 | |
|     return new Promise(resolve => {
 | |
|       var index = state.visitTaskList.findIndex(i => i.VisitTaskId === visitTaskId)
 | |
|       getTableAnswerRowInfoList(visitTaskId).then(res => {
 | |
|         var arr = []
 | |
|         res.Result.forEach(el => {
 | |
|           if (el.MeasureData) {
 | |
|             el.MeasureData = JSON.parse(el.MeasureData)
 | |
|             arr.push(el)
 | |
|           }
 | |
|         })
 | |
|         state.visitTaskList[index].MeasureData = arr
 | |
|         resolve()
 | |
|       }).catch(() => { resolve() })
 | |
|     })
 | |
|   },
 | |
|   addMeasuredData({ state }, obj) {
 | |
|     return new Promise(resolve => {
 | |
|       var index = state.visitTaskList.findIndex(i => i.VisitTaskId === obj.visitTaskId)
 | |
|       var measureData = state.visitTaskList[index].MeasureData
 | |
|       var idx = measureData.findIndex(item => item.MeasureData.uuid === obj.data.MeasureData.data.uuid)
 | |
|       if (idx > -1) {
 | |
|         state.visitTaskList[index].MeasureData[idx].MeasureData = obj.data.MeasureData
 | |
|       } else {
 | |
|         state.visitTaskList[index].MeasureData.push(obj.data)
 | |
|       }
 | |
| 
 | |
|       resolve()
 | |
|     })
 | |
|   },
 | |
|   removeMeasuredData({ state }, obj) {
 | |
|     return new Promise(resolve => {
 | |
|       var index = state.visitTaskList.findIndex(i => i.VisitTaskId === obj.visitTaskId)
 | |
|       var measureData = state.visitTaskList[index].MeasureData
 | |
| 
 | |
|       var uuid = obj.measureData.data.uuid
 | |
|       var idx = measureData.findIndex(item => item.MeasureData && item.MeasureData.data && item.MeasureData.data.uuid === uuid)
 | |
|       if (idx > -1) {
 | |
|         measureData.splice(idx, 1)
 | |
| 
 | |
|         state.visitTaskList[index].MeasureData = measureData
 | |
|       }
 | |
|       resolve()
 | |
|     })
 | |
|   },
 | |
|   getStudyInfo({ state }, obj) {
 | |
|     return new Promise(resolve => {
 | |
|       var index = state.visitTaskList.findIndex(i => i.VisitTaskId === obj.visitTaskId)
 | |
|       var studyList = []
 | |
|       getVisitStudyList(obj.trialId, obj.subjectVisitId, 0).then(res => {
 | |
|         res.Result.forEach((study) => {
 | |
|           const data = {}
 | |
|           data.StudyId = study.StudyId
 | |
|           data.StudyCode = study.StudyCode
 | |
|           data.Modalities = study.Modalities
 | |
|           data.SeriesCount = study.SeriesCount
 | |
|           data.InstanceCount = study.InstanceCount
 | |
|           data.InstanceCount = study.InstanceCount
 | |
|           data.PreviewImageCount = 0
 | |
|           var seriesList = []
 | |
|           study.SeriesList.forEach((series) => {
 | |
|             const imageIds = []
 | |
| 
 | |
|             series.InstanceList.forEach((id) => {
 | |
|               imageIds.push(`wadouri:/api/instance/content/${id}`)
 | |
|             })
 | |
|             seriesList.push({
 | |
|               imageIds: imageIds,
 | |
|               seriesId: series.Id,
 | |
|               imageIdIndex: 0,
 | |
|               seriesUid: series.SeriesInstanceUid,
 | |
|               seriesNumber: series.SeriesNumber,
 | |
|               sliceThickness: series.SliceThickness,
 | |
|               modality: series.Modality,
 | |
|               description: series.Description,
 | |
|               previewImageUrl: `/api/series/preview/${series.Id}`,
 | |
|               instanceCount: series.InstanceCount,
 | |
|               prefetchInstanceCount: 0,
 | |
|               loadStatus: false,
 | |
|               imageloadedArr: [],
 | |
|               studyId: study.StudyId,
 | |
|               taskBlindName: obj.taskBlindName,
 | |
|               visitTaskId: obj.visitTaskId,
 | |
|               readingTaskState: state.visitTaskList[index].ReadingTaskState,
 | |
|               isBaseLineTask: state.visitTaskList[index].IsBaseLineTask,
 | |
|               isCurrentTask: state.visitTaskList[index].IsCurrentTask
 | |
|             })
 | |
|           })
 | |
|           data.SeriesList = seriesList
 | |
|           studyList.push(data)
 | |
|         })
 | |
|         state.visitTaskList[index].StudyList = studyList
 | |
|         resolve()
 | |
|       }).catch(() => { resolve() })
 | |
|     })
 | |
|   },
 | |
|   setStatus({ state }, obj) {
 | |
|     var index = state.visitTaskList.findIndex(i => i.VisitTaskId === obj.visitTaskId)
 | |
|     state.visitTaskList[index].IsInit = true
 | |
|   }
 | |
| }
 | |
| 
 | |
| export default {
 | |
|   namespaced: true,
 | |
|   state,
 | |
|   mutations,
 | |
|   actions
 | |
| }
 | |
| 
 |