treat.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. import { json } from "@utils/ajax";
  2. // import { SET_TREAT } from '@store/types/diagnosticList';
  3. import { ADD_DIAGNOSTIC, GET_DIAGNOSTIC_STR,SET_TREAT,SHOW_LOADING} from '@store/types/diagnosticList';
  4. import { SET_COMMONTREATMENT } from '@store/types/pushMessage'
  5. import { SET_DRUG_INFO, SET_TREATMENT, SET_TREAT_INFO, SET_RECOMMEND_BASIC, SET_DRUG_INFO_LIST, IS_FIRST_MAIN_DIAG, SET_ADVERSE_REACTIONS, SET_ALL_ADVERSE_REACTIONS, SET_FOLLOW_UP, DEL_FOLLOW_UP, SET_ALL_FOLLOW_UP } from '@store/types/treat';
  6. import {storageLocal,getEMRParams} from '@utils/tools';
  7. import { isAddMainSuit } from '@store/async-actions/diagnosticList';
  8. import { SAVE_FOLLOW_UP } from "@store/types/pushMessage";
  9. import {MODI_LOADING} from '@store/types/homePage.js';
  10. import { SHOW_TREAT} from '@store/types/treat.js';
  11. const api={
  12. push:'/push/pushInner',
  13. textPush:'/push/pushText'
  14. }
  15. export const addDiagnostic = (item) => {
  16. return (dispatch, getState) => {
  17. const state = getState();
  18. let url = api.push;
  19. if(+state.typeConfig.confirmType===1){
  20. url=api.textPush;
  21. }
  22. const emrData = getEMRParams();
  23. const diagnosticList = state.diagnosticList.diagnosticList;
  24. let diag = '';
  25. if(diagnosticList) {
  26. for (let i = 0; i < diagnosticList.length; i++ ) {
  27. if(i ===0 ) {
  28. diag = diag + diagnosticList[i].name;
  29. } else {
  30. diag = diag + ',' + diagnosticList[i].name;
  31. }
  32. }
  33. }
  34. if (item.type === 1) {
  35. diag = diag + ',' + item.name
  36. } else {
  37. diag = diag + ',' + item.name
  38. }
  39. const params = {
  40. "age": emrData.age,
  41. "featureType": "8",
  42. "diag": diag,
  43. "diseaseId": item.id,
  44. "lis": emrData.lis,
  45. "other": emrData.other,
  46. "pacs": emrData.pacs,
  47. "sex": emrData.sex,
  48. "symptom": emrData.current + emrData.main,
  49. "vital": emrData.vital,
  50. "patientId": emrData.patientId,
  51. };
  52. //判断是否走慢病系统
  53. const isChronic = state.diagnosticList.chronicMagItem && state.diagnosticList.chronicMagItem.name||state.mainSuit.chronicDesease && state.mainSuit.chronicDesease.name;
  54. // const isChronic = true
  55. if (isChronic) {
  56. let chronicList = JSON.parse(storageLocal.get('chronic'));
  57. if(!chronicList){
  58. getChronic().then(() =>{
  59. chronicList = JSON.parse(storageLocal.get('chronic'));
  60. for(let i=0; i<chronicList.length; i++){
  61. if(chronicList[i].id==item.id&&chronicList[i].name==item.name){ //判断某个病是否为慢病
  62. params.disType = 1
  63. }
  64. }
  65. hasTreatment(dispatch, state,item,url,params)
  66. });
  67. } else {
  68. for(let i=0; i<chronicList.length; i++){
  69. if(chronicList[i].id==item.id&&chronicList[i].name==item.name){
  70. params.disType = 1
  71. }
  72. }
  73. hasTreatment(dispatch, state, item,url,params)
  74. }
  75. } else {
  76. hasTreatment(dispatch, state, item,url,params)
  77. }
  78. }
  79. }
  80. //判断是否存在治疗方案
  81. function hasTreatment(dispatch, state,item,url, params) {
  82. json(url, params).then((data) =>{
  83. if (data.data.data) {
  84. item.treat = data.data.data.treat
  85. dispatch({
  86. type: ADD_DIAGNOSTIC,
  87. item: item
  88. })
  89. } else {
  90. item.treat = null
  91. dispatch({
  92. type: ADD_DIAGNOSTIC,
  93. item: item
  94. })
  95. }
  96. dispatch({
  97. type: GET_DIAGNOSTIC_STR
  98. });
  99. dispatch(isAddMainSuit())
  100. }).catch((e) =>{
  101. console.log(e)
  102. })
  103. }
  104. export const getTreatResult = (item) =>{
  105. return (dispatch, getState) => {
  106. dispatch({
  107. type: SET_TREAT_INFO,
  108. treatItem: item
  109. })
  110. const state = getState();
  111. let url = api.push;
  112. if(+state.typeConfig.confirmType===1){
  113. url=api.textPush;
  114. }
  115. const emrData = getEMRParams();
  116. const diagnosticList = state.diagnosticList.diagnosticList;
  117. let diag = '';
  118. if(diagnosticList) {
  119. for (let i = 0; i < diagnosticList.length; i++ ) {
  120. if(i === 0 ) {
  121. diag = diag + diagnosticList[i].name;
  122. } else {
  123. diag = diag + ',' + diagnosticList[i].name;
  124. }
  125. }
  126. }
  127. const params = {
  128. "age": emrData.age,
  129. "featureType": "8",
  130. "diag": diag,
  131. "diseaseId": item.id,
  132. "lis": emrData.lis,
  133. "other": emrData.other,
  134. "pacs": emrData.pacs,
  135. "sex": emrData.sex,
  136. "symptom": emrData.current + emrData.main,
  137. "vital": emrData.vital,
  138. "patientId": emrData.patientId,
  139. };
  140. // const params = {
  141. // "age": 20,
  142. // "diag": ",糖尿病",
  143. // "disType": 1,
  144. // "diseaseId":21773,
  145. // "featureType": "8",
  146. // "lis": [
  147. // ],
  148. // "sex": 3,
  149. // "symptom": "恶心,呕吐",
  150. // "vital": ""
  151. // }
  152. const isChronic = state.diagnosticList.chronicMagItem && state.diagnosticList.chronicMagItem.name||state.mainSuit.chronicDesease && state.mainSuit.chronicDesease.name;
  153. // const isChronic = true
  154. if (isChronic) {
  155. let chronicList = JSON.parse(storageLocal.get('chronic'));
  156. if(!chronicList){
  157. getChronic().then(() =>{
  158. chronicList = JSON.parse(storageLocal.get('chronic'));
  159. for(let i=0; i<chronicList.length; i++){
  160. if(chronicList[i].id==item.id&&chronicList[i].name==item.name){
  161. params.disType = 1
  162. }
  163. }
  164. getTreatment(item, dispatch, state, url,params, isChronic)
  165. });
  166. } else {
  167. for(let i=0; i<chronicList.length; i++){
  168. if(chronicList[i].id==item.id&&chronicList[i].name==item.name){
  169. params.disType = 1
  170. }
  171. }
  172. getTreatment(item, dispatch, state,url,params, isChronic)
  173. }
  174. } else {
  175. getTreatment(item, dispatch, state,url,params, isChronic)
  176. }
  177. }
  178. }
  179. //获取治疗方案
  180. function getTreatment(item, dispatch, state,url,params, isChronic) {
  181. json(url, params).then((data) =>{
  182. // dispatch({type:MODI_LOADING,flag:false});
  183. dispatch({type:SHOW_LOADING,flag:false});
  184. dispatch({type: SHOW_TREAT})
  185. let treat;
  186. if(data.data.data) {
  187. treat = data.data.data.treat || {}
  188. }
  189. if(treat) {
  190. let { treatment, commonTreatment, surgeryTreatment, drugHistory, adverseReactions, followUp} = treat
  191. dispatch({
  192. type: SET_TREATMENT,
  193. treatment: treatment,
  194. generalTreat: commonTreatment,
  195. surgeryTreat: surgeryTreatment,
  196. drugHistory: drugHistory,
  197. })
  198. if (adverseReactions) { //如何之前存过不良反应,则替换成之前的不良反应
  199. const allAdversReactionList = state.treat.allAdversReactionList
  200. if(allAdversReactionList) {
  201. for(let i = 0; i < allAdversReactionList.length; i++) {
  202. if(item.id == allAdversReactionList[i].id) { //判断是否存过不良反应
  203. for (let j = 0; j < adverseReactions.length; j++) { //判断不良反应是否有相同的不良反应,如果有,替换
  204. for(let z = 0; z < allAdversReactionList[i].adversReactionList.length; z++) {
  205. if(adverseReactions[j].id == allAdversReactionList[i].adversReactionList[z].id) {
  206. for(let x = 0; x < allAdversReactionList[i].adversReactionList[z].details.length; x++) {
  207. for(let y = 0; y < adverseReactions[j].details.length; y++) {//判断每一项是否选择过
  208. if(allAdversReactionList[i].adversReactionList[z].details[x].name == adverseReactions[j].details[y].name && allAdversReactionList[i].adversReactionList[z].details[x].select) {
  209. adverseReactions[j].details[y].select = allAdversReactionList[i].adversReactionList[z].details[x].select
  210. }
  211. }
  212. }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. }
  219. } else {
  220. adverseReactions = []
  221. }
  222. if(isChronic) {
  223. let chronicList = JSON.parse(storageLocal.get('chronic'));
  224. for(let i=0; i<chronicList.length; i++){
  225. if(chronicList[i].id==item.id&&chronicList[i].name==item.name){ //判断某个病是否为慢病
  226. followUp = '2周';
  227. }
  228. }
  229. }
  230. if(followUp) {
  231. const followUpList = state.treat.followUpList
  232. if(followUpList) { //判断之前有没有保存过的回访时间,如果有替换掉
  233. for(let i = 0; i < followUpList.length; i++) {
  234. if(item.id == followUpList[i].id) {
  235. followUp = followUpList[i].followUp
  236. }
  237. }
  238. }
  239. dispatch({
  240. type: SET_FOLLOW_UP,
  241. // followUp: treat.followUp,
  242. followUp: followUp,
  243. hasFollowUp: true
  244. })
  245. } else {
  246. dispatch({
  247. type: DEL_FOLLOW_UP,
  248. delItem: item,
  249. })
  250. }
  251. dispatch({
  252. type: SET_ADVERSE_REACTIONS,
  253. adversReactionList: adverseReactions
  254. })
  255. }
  256. }).catch((e) =>{
  257. console.log(e)
  258. })
  259. }
  260. //保存全部不良反应
  261. export const saveAllAdverseReactions = (item) => {
  262. return (dispatch, getState) => {
  263. const state = getState()
  264. const adversReactionList = state.treat.adversReactionList
  265. dispatch({
  266. type: SET_ALL_ADVERSE_REACTIONS,
  267. adversReactionList: {
  268. 'id': item.id,
  269. 'adversReactionList': adversReactionList
  270. }
  271. })
  272. }
  273. }
  274. //保存全部诊断的回访时间
  275. export const setAllFollowUp = (item) => {
  276. return (dispatch, getState) => {
  277. const state = getState()
  278. const followUp = state.treat.followUp
  279. dispatch({
  280. type: SET_ALL_FOLLOW_UP,
  281. followUp: {
  282. 'id': item.id,
  283. 'followUp': followUp
  284. }
  285. })
  286. }
  287. }
  288. export const getInstroduce = (item, type, position)=>{
  289. return (dispatch, getState) =>{
  290. const url = '/introduceInfo/getByQuestionId';
  291. const params = {
  292. questionId: item.id,
  293. type: type,
  294. position: position
  295. }
  296. json(url, params)
  297. .then((data)=>{
  298. if(data.data.data) {
  299. dispatch({
  300. type: SET_DRUG_INFO,
  301. instroduce: data.data.data.introduceDetailList,
  302. name: type ==8 ?item.medicitionName : type == 10 ? item.tagName : '',
  303. tagType: type
  304. })
  305. } else {
  306. dispatch({
  307. type: SET_DRUG_INFO,
  308. instroduce: [],
  309. name: type ==8 ?item.medicitionName : type == 10 ? item.tagName : '',
  310. tagType: type
  311. })
  312. }
  313. }).catch((e) => {
  314. console.log(e)
  315. })
  316. }
  317. }
  318. export const getInstroduceMore = (drugIdList) =>{
  319. return (dispatch, getState) =>{
  320. let drugInfoList = [];
  321. for (let i = 0; i < drugIdList.drugIdList.length; i++ ) {
  322. const url = '/introduceInfo/getByQuestionId';
  323. const params = {
  324. questionId: drugIdList.drugIdList[i],
  325. type: 8,
  326. position: 5
  327. }
  328. json(url, params)
  329. .then((data)=>{
  330. if(data.data.data) {
  331. drugInfoList.push(data.data.data)
  332. dispatch({
  333. type: SET_DRUG_INFO_LIST,
  334. drugInfoList: drugInfoList,
  335. })
  336. } else {
  337. drugInfoList.push([])
  338. dispatch({
  339. type: SET_DRUG_INFO_LIST,
  340. drugInfoList: drugInfoList,
  341. })
  342. }
  343. }).catch((e) => {
  344. console.log(e)
  345. })
  346. }
  347. }
  348. }
  349. //一般治疗添加到医嘱
  350. export const commonTreatAddToAdvice = () => {
  351. return (dispatch, getState) => {
  352. const state = getState();
  353. const followUp = state.treat.followUp
  354. if(state.treat.treatItem.id === state.diagnosticList.diagnosticList[0].id && state.treat.isFirstMainDiag) {
  355. dispatch({
  356. type: IS_FIRST_MAIN_DIAG
  357. })
  358. dispatch({
  359. type: SET_COMMONTREATMENT,
  360. commontreatment: state.treat.treatItem.treat.commonTreatment.text
  361. })
  362. if(followUp) {
  363. dispatch({
  364. type: SAVE_FOLLOW_UP,
  365. followUp: followUp,
  366. hasFollowUp: true
  367. })
  368. }
  369. } else {
  370. return
  371. }
  372. }
  373. }
  374. //其他推荐推荐依据不用展示
  375. // export const getRecommendBasic = (item)=>{
  376. // return (dispatch, getState) =>{
  377. // const url = '/api/icss/introduceInfo/getByQuestionId';
  378. // const params = {
  379. // questionId: item.id,
  380. // type: 9,
  381. // position: 2
  382. // }
  383. // json(url, params)
  384. // .then((data)=>{
  385. // if (data.status === 200) {
  386. // if(data.data.data) {
  387. // dispatch({
  388. // type: SET_RECOMMEND_BASIC,
  389. // recommendBasic: data.data.data.introduceDetailList,
  390. // })
  391. // } else {
  392. // dispatch({
  393. // type: SET_RECOMMEND_BASIC,
  394. // recommendBasic: [],
  395. // })
  396. // }
  397. // }
  398. // }).catch((e) => {
  399. // console.log(e)
  400. // })
  401. // }
  402. // }