import {getLabelIndex,fullfillText,getIds} from '@common/js/func.js'; import config from '@config/index.js'; //插入病程变化模板 function insertPro(data,processModule){ let index; for(let i=0; i{ const res = Object.assign({},state); res.moduleData = action.data; res.processModule = action.processModule;//病程变化模板 res.processModuleName = action.processModuleName;//模板名称 res.emptyData = action.emptyData;//空模板 let data = action.data; let sliceIdx; data.map((v,i)=>{ if(v.flag && v.flag==2){ sliceIdx = i; } }) res.addModule = data.slice(0,sliceIdx+1);//截取到flag=2 有无治疗 res.update=Math.random(); return res; } //插入病程变化 export const insertProcess = (state,action)=>{ const res = Object.assign({},state); const processModule = JSON.parse(JSON.stringify(res.processModule)); let data = res.data; res.data = insertPro(data,processModule); res.saveText = fullfillText(res.data).saveText; res.update=Math.random(); return res; } function addPos(data,num){ let newData = JSON.parse(JSON.stringify(data)); newData.forEach((it,i)=>{ it.pos = num; }) return newData; } //聚焦时设置 现病史模板 export const setData = (state,action) =>{ let res = Object.assign({},state); res.editClear = false; const mainIds = action.info.mainIds; res.symptomIds = JSON.parse(JSON.stringify(mainIds)); const num = action.info.num;//点击了几次添加病情变化 const symptomFeature = action.info.symptomFeature;//分词 // const useEmpty = action.info.useEmpty; let useEmpty,mainData; // let mainData = JSON.parse(JSON.stringify(action.info.mainData));//主诉模板数据 let mainModleData = JSON.parse(JSON.stringify(action.info.mainData));//主诉模板数据 let moduleData = JSON.parse(JSON.stringify(res.moduleData));//现病史模板 let addModule = JSON.parse(JSON.stringify(res.addModule));//拷贝的模板 let current = JSON.parse(JSON.stringify(moduleData)); let newMain = []; let mainLabelModule = res.mainLabelModule;//主诉选中的症状id获取到的模板 let objToArr = []; let keyArr = Object.keys(mainLabelModule); for(let i=0; i{ return item.questionMapping.length>0; })*/ // 是否使用空模板:num=0时判断mainIds,num>=1,截取第一病程遍历是否有症状exist if(num==0){ useEmpty = mainIds.length>0 ? false:true; mainData = mainModleData; }else{ let sliceIdx; for(let j=0; j{ return item.exist; }) useEmpty = existData&&existData.length>0?false:true; } // console.log(888,useEmpty); if (useEmpty) { // res.data = res.emptyData; res.data = JSON.parse(JSON.stringify(res.emptyData)); } else { if(mainData&&mainData.length>0){//主诉使用模板 // 目前只需要将第一个主诉病程移植到现病史 let tongYong = ""; let main = [];//主症状 let withs = [];//伴随 let firstT = 0; for(let i=0; i{ if(mainCopy[k].id==v.id){ ind++; let items = v.questionMapping.filter((item)=>{ return item.symptomType==0||item.symptomType==1; }) lengArr[k] = items.length; //每一个主诉尾巴长度 if(items.length==0){//没有尾巴时给症状后加逗号(3.5) for(let j=0; j1){ insertInd += lengArr[k-1]; } newMainCopy.splice(k+insertInd+1,0,...items); } }) } // 伴随 // 去掉顿号 /* for(let b=0; b0){ for(let b=0; b{ if(withs[d].id==v.id){ withInd++; let items = v.questionMapping.filter((item)=>{ return item.symptomType==0||item.symptomType==2; }) /*if(withInd==1){ withPreLength = items.length; }else{ withInsertInd += withPreLength; }*/ withLengArr[d] = items.length; if(items.length==0){//没有尾巴时给症状后加逗号(3.5) for(let j=0; j1){ withInsertInd += withLengArr[d-1]; } newWiths.splice(d+withInsertInd+1,0,...items); } }) } } let symptomArr = newMainCopy.concat(newWiths); let newSymptomArr = JSON.parse(JSON.stringify(symptomArr)); //组装好的主症状和伴随症状插入现病史模板(flag=4前) let insertIdx = null; for(let j=0; j0){ let featureData = JSON.parse(JSON.stringify(symptomFeature)); let ind = 0; let insertInd = 0; let lengArr=[]; for(let k=0; k { if(symptomFeature[k].id==v.id){ ind++; let items = v.questionMapping.filter((item)=>{ return item.symptomType==0||item.symptomType==1; }) lengArr[k] = items.length; //每一个主诉尾巴长度 if(items.length==0){//没有尾巴时给症状后加逗号(3.5) for(let j=0; j1){ insertInd += lengArr[k-1]; } featureData.splice(k+insertInd+1,0,...items); } }) } //组装好的主症状和伴随症状插入现病史模板(flag=4前) let endFeatureData = JSON.parse(JSON.stringify(featureData)); let insertIdx = null; for(let j=0; j{ let res = Object.assign({},state); let length1 = res.data.length; let arr = JSON.parse(JSON.stringify(res.data)); const {nones,exists,withs,ikey,exclusion,excluName,ban,noneIds} = action.data; let existsId = exists && exists.length>0?getIds(exists):[]; let withsId = withs && withs.length>0?getIds(withs):[]; res.symptomIds = res.symptomIds.concat(existsId,withsId,noneIds);//搜索去重 // 伴 标签 const banText = JSON.stringify(ban)=='{}'?'':{id:ban.id,name:ban.name,value:ban.name,tagType:config.tagType}; // 处理主症状标签及尾巴展开symptomType=1 if(exists && exists.length>0){ // for(let i in exists){//ie8不支持for in循环 for(let i=0;i{return item.symptomType==0||item.symptomType==1;}))); } } let length = arr.length - length1; let withsArr = JSON.parse(JSON.stringify(arr)); // 伴 伴随症状标签及尾巴展开symptomType=2 if(withs && withs.length>0){ // for(let i in withs){ for(let i=0;i{return item.symptomType==0||item.symptomType==2;}))); /*withsArr.splice(parseInt(ikey)+length,0,getLabel(withs[i].id,withs[i].questionMapping && withs[i].questionMapping.length==0?(ban.name+withs[i].name+','):(ban.name+withs[i].name)),...(withs[i].questionMapping && withs[i].questionMapping.filter((item)=>{return item.symptomType==0||item.symptomType==2;})));*/ } } // 无 不用展开 let lengthN = withsArr.length - length1; let noneArr = JSON.parse(JSON.stringify(withsArr)); if(nones.length>1){//只点无不上去 const nonesName = nones.slice(0,nones.length-1)+','; const noneObj = Object.assign({},JSON.parse(config.textLabel),{name:nonesName,value:nonesName}); const none = nones?noneObj:''; noneArr.splice(parseInt(ikey)+lengthN,0,none); } let resData = JSON.parse(JSON.stringify(noneArr)); // res.data = resData; res.data = fullfillText(resData).newArr; res.saveText = fullfillText(resData).saveText; res.update=Math.random(); return res; }; //普通多选确定事件-主诉通用特征、初为后为等 export const setCheckBox = (state,action)=>{ const res = Object.assign({},state); const {exists,labelInx,existsName} = action.data; // 若每个选项都有符号,去掉最后一个,因与标签间的符号有冲突 let names=existsName; let pattern = new RegExp(/\,+$|\,+$|\.+$|\。+$|\、+$/);//+ 一次或多次 if(pattern.test(existsName)){ names = existsName.substr(0,existsName.length-1); } let arr = res.data; arr[labelInx].value = names; res.saveText[labelInx] = names; res.selecteds[labelInx] = action.data; res.update=Math.random(); return res; } //数字键盘选中事件 export function setNumberValue(state,action){ let res = Object.assign({},state); const param = action.params; const index = param.ikey; let labelInx = getLabelIndex(index); const subInx = index.substr(index.length-1); let item = res.data[labelInx]; // if(param.text.trim()){ if(+item.tagType===1){ item.value = param.text; res.saveText[labelInx] = param.text?item.labelPrefix+param.text+item.labelSuffix:''; }else{ item.questionMapping[subInx].value = param.text; let hasValue = false; const sub = item.questionMapping.map((it)=>{ if(it.value){ //至少有一个子值才黑显 hasValue = true; } return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||''); }); // res.saveText[labelInx] = sub.join(','); res.saveText[labelInx] = hasValue?sub.join(''):''; item.value = sub.join(''); } /*}else{//删除完标签内容则删除该标签 res.data.splice(labelInx,1); res.saveText = fullfillText(res.data).saveText; }*/ res.update = Math.random(); return res; } //单选下拉选中 export function setRadioValue(state,action){ let res = Object.assign({},state); const {ikey,id,text} = action; let labelInx = getLabelIndex(ikey); const subInx = ikey.substr(ikey.length-1); let item = res.data[labelInx]; if(typeof text != 'string'){ //需要展开项--有无治疗类型 const len = +item.copyType === 0?1:0; res.data.splice(labelInx,len,text); return res; } if(+item.tagType===1){ item.value = text; res.saveText[labelInx] = item.labelPrefix+text+item.labelSuffix; item.questionDetailList.map((its)=>{ if(its.id === id){ its.selected = true; }else{ its.selected = false; } }); }else{ item.questionMapping[subInx].value = text; /*if(item.questionMapping[subInx].controlType==1){//例如:有无治疗-未经治疗 item.value = text; }else{ item.questionMapping[subInx].value = text; }*/ let hasValue = false; const sub = item.questionMapping.map((it)=>{ //添加选中状态 it.questionDetailList.map((its)=>{ if(its.id === id){ its.selected = true; }else{ its.selected = false; } }); if(it.value){ //至少有一个子值才黑显 hasValue = true; } return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||''); }); res.saveText[labelInx] = hasValue?sub.join(''):''; } res.update = Math.random(); return res; } //双击标签输入改变值 export const changeLabelVal = (state,action)=>{ const res = Object.assign({},state); const {changeVal,totalVal,ikey,prefix,suffix} = action.data; const index = ikey; const newVal = changeVal; let labText = totalVal?totalVal:newVal; let item = res.data[index]; const next = res.data[+index+1]; const nextVal = next.value||next.name; //标签后是不是标点符号标签,是的话删除本标签时一起删除 let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg); if(labText.trim()){ if(item){ item.value = newVal; item.labelPrefix = prefix||''; item.labelSuffix = suffix||''; res.saveText[index] = labText; } }else{//删除完标签内容则删除该标签 const num = nextIsDot?2:1; res.data.splice(index,num); res.saveText = fullfillText(res.data).saveText; } res.update = Math.random(); return res; } // 数字键盘较特殊,有直接输入 export const changeNumLabelVal = (state,action)=>{ const res = Object.assign({},state); const {changeVal,totalVal,ikey,prefix,suffix} = action.data; const index = ikey; const newVal = changeVal; let item = res.data[index]; const next = res.data[+index+1]; const nextVal = next.value||next.name; //标签后是不是标点符号标签,是的话删除本标签时一起删除 let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg); let labText = totalVal?totalVal:newVal; //如单选没有前后缀 if(labText.trim()){ if(item){ item.value = newVal; item.labelPrefix = prefix||''; item.labelSuffix = suffix||''; } res.saveText[index] = labText; }else{//删除完标签内容则删除该标签 const num = nextIsDot?2:1; res.data.splice(index,num); res.saveText = fullfillText(res.data).saveText; } res.update = Math.random(); return res; } export const clearCurrentIll = (state,action)=>{ const res = Object.assign({},state); res.data = action.data; res.saveText = action.saveText; res.selecteds = action.selecteds?action.selecteds:[]; res.symptomIds = action.symptomIds; res.symptomIds = action.symptomIds; if(action.editClear){ res.editClear = action.editClear; } if(res.data.length>0){ res.editClear = false; } res.update = Math.random(); return res; } //文本模式下值保存 export const setTextModeValue = (state,action)=>{ const res = Object.assign({},state); res.saveText[0] = action.text; return res; }; //获取大数据推送症状 export const bigDataSymptom = (state,action) => { const res = Object.assign({},state); res.bigDataSymptom = action.data;//推送数据 let inlineDatas = res.data; const index = action.info.ikey; let labelInx = getLabelIndex(index); // 添加症状 暂时剔除没有id、questionMapping字段的数据 let pushDataList = action.data; /*let pushDataList = action.data.filter(function(item){ return item.id });*/ let dataList = inlineDatas[labelInx].questionMapping; for(let k=0; k{ return item.symptomType==0||item.symptomType==2; }))); res.data = fullfillText(resData).newArr; res.saveText[focusIndex] = searchData; }else{ let resData; const searchStr = res.searchStr; let innerText = span.current.innerText || span.current.innerHTML; let strIndex = innerText.indexOf(searchStr); const value = innerText.replace(searchStr,""); if(data.itemType==0){//症状 res.symptomIds.push(id); // 没有伴展开主诉symptomType=0/1的尾巴,有伴一>第一个点选上去的伴为依据,伴前展开主诉,伴后展开伴随;多余的伴以及手动输入的伴不做处理(2-25) if(banIdx==-1){ // if(strIndex <= 1){//前 if(strIndex < 1){//前 res.data.splice(focusIndex,0,text); res.saveText.splice(focusIndex,0,searchData); res.data[focusIndex+1].value = value; res.saveText[focusIndex+1] = value; resData = JSON.parse(JSON.stringify(res.data)); resData.splice(focusIndex+1,0,...(data.questionMapping.filter((item)=>{ return item.symptomType==0||item.symptomType==1; }))); }else{ res.data.splice(focusIndex+1,0,text); res.saveText.splice(focusIndex+1,0,searchData); res.data[focusIndex].value = value; res.saveText[focusIndex] = value; resData = JSON.parse(JSON.stringify(res.data)); // +2是因为插入一个文本标签 resData.splice(focusIndex+2,0,...(data.questionMapping.filter((item)=>{ return item.symptomType==0||item.symptomType==1; }))); } }else{ if(focusIndex > banIdx){//伴后 if(strIndex < 1){//前 res.data.splice(focusIndex,0,text); res.saveText.splice(focusIndex,0,searchData); res.data[focusIndex+1].value = value; res.saveText[focusIndex+1] = value; resData = JSON.parse(JSON.stringify(res.data)); resData.splice(focusIndex+1,0,...(data.questionMapping.filter((item)=>{ return item.symptomType==0||item.symptomType==2; }))); }else{ res.data.splice(focusIndex+1,0,text); res.saveText.splice(focusIndex+1,0,searchData); res.data[focusIndex].value = value; resData = JSON.parse(JSON.stringify(res.data)); // +2是因为插入一个文本标签 resData.splice(focusIndex+2,0,...(data.questionMapping.filter((item)=>{ return item.symptomType==0||item.symptomType==2; }))); } }else{//伴前 if(strIndex < 1){//前 res.data.splice(focusIndex,0,text); res.saveText.splice(focusIndex,0,searchData); res.data[focusIndex+1].value = value; res.saveText[focusIndex+1] = value; resData = JSON.parse(JSON.stringify(res.data)); resData.splice(focusIndex+1,0,...(data.questionMapping.filter((item)=>{ return item.symptomType==0||item.symptomType==1; }))); }else{ res.data.splice(focusIndex+1,0,text); res.saveText.splice(focusIndex+1,0,searchData); res.data[focusIndex].value = value; resData = JSON.parse(JSON.stringify(res.data)); // +2是因为插入一个文本标签 resData.splice(focusIndex+2,0,...(data.questionMapping.filter((item)=>{ return item.symptomType==0||item.symptomType==1; }))); } } } res.data = fullfillText(resData).newArr; res.saveText = fullfillText(resData).saveText; }else{//标签 if(strIndex < 1){//前 res.data.splice(focusIndex,0,data,textEmpty); res.saveText.splice(focusIndex,0,'',''); res.selecteds.splice(focusIndex,0,null,null); res.data[focusIndex+1].value = value; res.saveText[focusIndex+1] = value; }else{ res.data.splice(focusIndex+1,0,data,textEmpty); res.saveText.splice(focusIndex+1,0,'',''); res.selecteds.splice(focusIndex+1,0,null,null); res.data[focusIndex].value = value; res.saveText[focusIndex] = value; } } // span.current.innerText?(span.current.innerText = value):(span.current.innerHTML = value); // res.data = fullfillText(resData).newArr; // res.saveText = fullfillText(resData).saveText; } res.searchData = []; //选中清空搜索内容(即关闭搜索弹窗) res.update = Math.random(); return res; } export const clearCurrentEdit = (state,action)=>{ const res = Object.assign({},state); res.editClear = action.editClear return res; } //复制标签(如血压)事件 export function addLabelItem(state,action){ let res = Object.assign({},state); const {data,i} = action; const textLabel = JSON.parse(config.textLabel); //使用Object.assign({},data)拷贝操作时复制项和原项会同步修改 if(!data) return res; res.data.splice(i+1,0,JSON.parse(data),textLabel); res.update = Math.random(); return res; } //文本输入标签 export function setInputLabel(state,action){ let res = Object.assign({},state); const {i,text,prefix,suffix,subIndex} = action; const item = res.data[i]; if(+item.tagType===3){ //multSpred标签 item.questionMapping[subIndex].value = text; let texts = item.questionMapping.map((it)=>{ return it.value?(it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||''):''; }); res.saveText[i] = texts.join(''); res.update = Math.random(); return res; }else{ if(item){ item.value=text; } } res.saveText[i] = prefix+text+suffix; res.update = Math.random(); return res; } // backspace删除 export function backspaceText(state,action){ let res = Object.assign({},state); const {delIndex,text} = action; const data = res.data; // if(data[delIndex-1].tagType==8 ||data[delIndex-1].flag&&data[delIndex-1].flag==3){ // 前一个是文本标签或者子模板,只改变值 if(data[delIndex-1].flag&&data[delIndex-1].flag==3){//子模板不删 // data[delIndex].value = text; }else if(data[delIndex-1].tagType==8){ data.splice(delIndex,1); res.saveText.splice(delIndex,1); } else{ data.splice(delIndex-1,2); res.saveText.splice(delIndex-1,2); } // res.saveText = fullfillText(data).saveText; res.update = Math.random(); return res; } //删除后移除id export function removeId(state,action){ let res = Object.assign({},state); const {index,text} = action; const data = res.data; const id = data[index].id; let ids = res.symptomIds; if(ids.includes(id)){ ids.splice(ids.indexOf(id),1); } if(!data[index].value && data[index-1].tagType==8){ data.splice(index,1); res.saveText.splice(index,1); }else{ data[index].id = ""; data[index].name = text; data[index].value = text; } //console.log(345,action,res); res.update = Math.random(); return res; } // 单列多选 export function multipleComfirn(state,action){ let res = Object.assign({},state); const {ikey,seleData} = action.data; let data = res.data; data[ikey].value = seleData; res.saveText[ikey] = seleData; res.selecteds[ikey] = action.data; res.update = Math.random(); return res; } export function delSingleLable(state,action){ let res = Object.assign({},state); const {index} = action; let data = res.data; // 前一个不是文本标签 并且不是子模板,则删除 if(data[index-1].flag&&data[index-1].flag==3){ } else if(data[index-1].tagType != 8){ data.splice(index-1,1); res.saveText.splice(index-1,1); } res.update = Math.random(); return res; }