utils.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. import config from '@config/index.js';
  2. import {getLabelIndex,checkFullfillText,fullfillText,shiftLocalDelTag,getEMRParams,storageLocal,handleLocalDelTag} from './tools';
  3. import { json } from "./ajax";
  4. /**
  5. * 各类标签统一的处理函数
  6. *
  7. * */
  8. const api = {
  9. push:'/push/pushInner'
  10. };
  11. //数字键盘选中事件
  12. export function setNumberValue(state,action){
  13. let res = Object.assign({},state);
  14. const param = action.params;
  15. const ikey = param.ikey;
  16. let labelInx = getLabelIndex(ikey);
  17. const subInx = ikey.split("-")[2];
  18. let item = res.data[labelInx];
  19. if(+item.tagType===1){ //独立数字键盘组件
  20. item.value = param.text;
  21. res.saveText[labelInx] = param.text?item.labelPrefix+param.text+item.labelSuffix:'';
  22. }else{ //内嵌血压类型组件的数字键盘组件
  23. item.questionMapping[subInx].value = param.text;
  24. let hasValue = false;
  25. const sub = item.questionMapping.map((it)=>{
  26. if(it.value){ //至少有一个子值才黑显
  27. hasValue = true;
  28. }
  29. if(it.tagType===8){ //维护时的连接词无value
  30. return it.name;
  31. }else{
  32. //组合中未填值的子标签预览中不显示
  33. if(!it.value){
  34. return '';
  35. }
  36. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  37. }
  38. });
  39. res.saveText[labelInx] = hasValue?sub.join(''):'';
  40. }
  41. res.update = Math.random();
  42. return res;
  43. }
  44. //单选下拉选中
  45. export function setRadioValue(state,action){
  46. let res = Object.assign({},state);
  47. const {ikey,id,text} = action;
  48. let labelInx = getLabelIndex(ikey);
  49. const subInx = ikey.split("-")[2];
  50. let item = res.data[labelInx];
  51. if(+item.tagType===1){
  52. item.value = text;
  53. res.saveText[labelInx] = item.labelPrefix+text+item.labelSuffix;
  54. item.questionDetailList.map((its)=>{
  55. if(its.id === id){
  56. its.selected = true;
  57. }else{
  58. its.selected = false;
  59. }
  60. });
  61. }else{
  62. item.questionMapping[subInx].value = text;
  63. let hasValue = false;
  64. const sub = item.questionMapping.map((it)=>{
  65. //添加选中状态
  66. it.questionDetailList.map((its)=>{
  67. if(its.id === id){
  68. its.selected = true;
  69. }else{
  70. its.selected = false;
  71. }
  72. });
  73. if(it.value){ //至少有一个子值才黑显
  74. hasValue = true;
  75. }
  76. if(it.tagType===8){ //维护时的连接词无value
  77. return it.name;
  78. }else{
  79. //组合中未填值的子标签预览中不显示
  80. if(!it.value){
  81. return '';
  82. }
  83. return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
  84. }
  85. });
  86. res.saveText[labelInx] = hasValue?sub.join(''):'';
  87. item.value = sub.join('');
  88. }
  89. res.update = Math.random();
  90. return res;
  91. }
  92. //单选带输入值保存,该类型不可加入血压类型中
  93. export const setRadioInputValue = (state,action)=>{
  94. const res = Object.assign({},state);
  95. const {ikey,values,id} = action.data;
  96. let index = getLabelIndex(ikey);
  97. let item = res.data[index];
  98. let str='',temp='',obj=item.questionDetailList;
  99. if(!values){ //清空
  100. let sld=obj.find((item)=>{
  101. return item.selected==true;
  102. });
  103. sld?sld.selected=false:'';
  104. item.vals = null;
  105. item.value = '';
  106. res.saveText[index] = '';
  107. res.update = Math.random();
  108. return res;
  109. }
  110. //存值
  111. for(let i in values){
  112. temp = values[i];
  113. if(typeof temp=='object'){
  114. str+=temp.value;
  115. }else{
  116. str+=temp;
  117. }
  118. }
  119. //选中状态
  120. if(id){
  121. obj.map((its)=>{
  122. if(its.id === id){
  123. its.selected = true;
  124. }else{
  125. its.selected = false;
  126. }
  127. });
  128. }
  129. item.vals = values;
  130. item.value = str;
  131. res.saveText[index] = str;
  132. res.update = Math.random();
  133. return res;
  134. }
  135. //恢复已删除的标签
  136. export function recoveTag(state,action) {
  137. let res = Object.assign({},state);
  138. let arr = [...res.data];
  139. //arr.splice(action.index,0,action.data);
  140. const isArr= !action.data.tagType;
  141. if(!isArr){
  142. arr.splice(action.index,0,action.data);
  143. }else{
  144. //恢复连续选中删除的标签,先判断需恢复的标签中是否有子模板,有则删除数据中的子模板标签,然后恢复被删除的标签(子模板只有一个)
  145. const sonModuleInx = action.data.findIndex((it)=>it.flag=='3'); //是否有子模板
  146. if(sonModuleInx!==-1){
  147. const sonMInx = arr.findIndex((it)=>it.flag=='3');
  148. arr.splice(sonMInx,1);
  149. }
  150. const lastReTag = [...action.data].reverse()[0];
  151. if(lastReTag.tagType=='8'&&(arr[action.index]&&arr[action.index].tagType=='8')){
  152. //要恢复的标签组最后为文本标签,插入位置也为文本标签,则将2个合并为一个文本标签
  153. arr[action.index]=Object.assign(arr[action.index],lastReTag,{value:lastReTag.value+arr[action.index].value});
  154. action.data.length=action.data.length-1;
  155. }
  156. arr.splice(action.index,0,...action.data);
  157. }
  158. const dataArr = fullfillText(arr);
  159. res.data = dataArr.newArr;
  160. res.saveText = dataArr.saveText;
  161. shiftLocalDelTag();
  162. res.update = Math.random();
  163. return res;
  164. }
  165. //自由文本存值
  166. export function setCheckText(state,action) {
  167. let res = Object.assign({},state);
  168. const {i,text} = action;
  169. if(res.data[i]){
  170. res.data[i].value=text;
  171. }
  172. res.saveText[i] = text;
  173. res.update = Math.random();
  174. return res;
  175. }
  176. //复制标签(如血压)事件
  177. export function addLabelItem(state,action,boxMark){
  178. let res = Object.assign({},state);
  179. const {data,i} = action;
  180. const item = JSON.parse(data);
  181. const textL = JSON.parse(config.textLabel);
  182. //查体添加的自由文本标签需要逗号,且要设置隐藏状态
  183. const textLabel = boxMark==='4'?Object.assign({},textL,{showInCheck:item.showInCheck,name:','}):textL;
  184. //使用Object.assign({},data)拷贝操作时复制项和原项会同步修改
  185. if(!data) return res;
  186. res.data.splice(+i+2,0,item,textLabel);
  187. res.saveText.splice(+i+2,0,'','');
  188. res.update = Math.random();
  189. return res;
  190. }
  191. //文本输入标签inlineTag值保存
  192. export function setInputLabel(state,action){
  193. let res = Object.assign({}, state);
  194. const {i,text,prefix,suffix,subIndex} = action;
  195. const item = res.data[i];
  196. if(+item.tagType===3){ //multSpred标签
  197. item.questionMapping[subIndex].value = text;
  198. let texts = item.questionMapping.map((it)=>{
  199. if(it.tagType===8){
  200. return it.name;
  201. }else{
  202. return it.value?(it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||''):'';
  203. }
  204. });
  205. res.saveText[i] = texts.join('');
  206. res.update = Math.random();
  207. return res;
  208. }else{
  209. if(item){
  210. item.value=text;
  211. }
  212. }
  213. if(text){
  214. res.saveText[i] = prefix+text+suffix;
  215. }else{//删除完要清空
  216. res.saveText[i] = "";
  217. }
  218. res.update = Math.random();
  219. return res;
  220. }
  221. //获取大数据推送结果:
  222. // type需推送的类型,symData症状相关的内容(symptom入参),save参数是否要保存到本地做变化对比
  223. export async function getBigPush(type,symData,save){
  224. const emrData = getEMRParams();
  225. const params = {
  226. "ruleType":config.ruleTypeMap[type],
  227. "featureType": type, //类型1:症状,4:查体,5:检验,6:检查,7:诊断
  228. };
  229. if(save){
  230. let savePm = Object.assign({},emrData);
  231. // delete savePm.featureType;
  232. storageLocal.set('emrParam',savePm); //推送数据存储,用作推送前对比是否有变,有变才推送
  233. }
  234. return json(api.push,Object.assign({},params,emrData));
  235. }
  236. //删除选中标签
  237. export function deleteSelectedLabels(state,action){
  238. let res = Object.assign({}, state);
  239. const {start,end,boxMark} = action;
  240. let n = Math.abs(end-start)+1;
  241. const arr = res.data;
  242. const sonModuleInx = arr.findIndex((it)=>it.flag=='3');
  243. const startIsText = arr[start].tagType=='8';
  244. const endIsText = arr[end].tagType=='8';
  245. if(!startIsText&&!endIsText){
  246. n=Math.abs(end-start)+2;
  247. }
  248. if(start>end){ //从后往前选中
  249. const temp = end<sonModuleInx&&sonModuleInx<start?arr.splice(end,n,arr[sonModuleInx]):arr.splice(end,n);
  250. handleLocalDelTag(boxMark,end,temp);
  251. }else if(start===end){
  252. return res;
  253. }else{
  254. const temp = start<sonModuleInx&&sonModuleInx<end?arr.splice(start,n,arr[sonModuleInx]):arr.splice(start,n);
  255. handleLocalDelTag(boxMark,start,temp);
  256. }
  257. const newObj = boxMark=='4'?checkFullfillText(arr):fullfillText(arr);
  258. res.data = newObj.newArr;
  259. res.saveText = newObj.saveText;
  260. res.update = Math.random();
  261. //删除文字选中状态
  262. window.getSelection().empty();
  263. return res;
  264. }