treat.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. import { json } from "@utils/ajax";
  2. // import { SET_TREAT } from '@store/types/diagnosticList';
  3. import { ADD_DIAGNOSTIC, GET_DIAGNOSTIC_STR,SET_TREAT} 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_TREAT})
  184. let treat;
  185. if(data.data.data) {
  186. treat = data.data.data.treat || {}
  187. }
  188. if(treat) {
  189. let { treatment, commonTreatment, surgeryTreatment, drugHistory, adverseReactions, followUp} = treat
  190. dispatch({
  191. type: SET_TREATMENT,
  192. treatment: treatment,
  193. generalTreat: commonTreatment,
  194. surgeryTreat: surgeryTreatment,
  195. drugHistory: drugHistory,
  196. })
  197. if (adverseReactions) { //如何之前存过不良反应,则替换成之前的不良反应
  198. const allAdversReactionList = state.treat.allAdversReactionList
  199. if(allAdversReactionList) {
  200. for(let i = 0; i < allAdversReactionList.length; i++) {
  201. if(item.id == allAdversReactionList[i].id) { //判断是否存过不良反应
  202. for (let j = 0; j < adverseReactions.length; j++) { //判断不良反应是否有相同的不良反应,如果有,替换
  203. for(let z = 0; z < allAdversReactionList[i].adversReactionList.length; z++) {
  204. if(adverseReactions[j].id == allAdversReactionList[i].adversReactionList[z].id) {
  205. adverseReactions[j] = allAdversReactionList[i].adversReactionList[z]
  206. }
  207. }
  208. }
  209. }
  210. }
  211. }
  212. } else {
  213. adverseReactions = []
  214. }
  215. if(isChronic) {
  216. let chronicList = JSON.parse(storageLocal.get('chronic'));
  217. for(let i=0; i<chronicList.length; i++){
  218. if(chronicList[i].id==item.id&&chronicList[i].name==item.name){ //判断某个病是否为慢病
  219. followUp = '2周';
  220. }
  221. }
  222. }
  223. if(followUp) {
  224. const followUpList = state.treat.followUpList
  225. if(followUpList) { //判断之前有没有报存过的回访时间,如果有替换掉
  226. for(let i = 0; i < followUpList.length; i++) {
  227. if(item.id == followUpList[i].id) {
  228. followUp = followUpList[i].followUp
  229. }
  230. }
  231. }
  232. dispatch({
  233. type: SET_FOLLOW_UP,
  234. // followUp: treat.followUp,
  235. followUp: followUp,
  236. hasFollowUp: true
  237. })
  238. } else {
  239. dispatch({
  240. type: DEL_FOLLOW_UP,
  241. delItem: item,
  242. })
  243. }
  244. dispatch({
  245. type: SET_ADVERSE_REACTIONS,
  246. adversReactionList: adverseReactions
  247. })
  248. }
  249. }).catch((e) =>{
  250. console.log(e)
  251. })
  252. }
  253. //保存全部不良反应
  254. export const saveAllAdverseReactions = (item) => {
  255. return (dispatch, getState) => {
  256. const state = getState()
  257. const adversReactionList = state.treat.adversReactionList
  258. dispatch({
  259. type: SET_ALL_ADVERSE_REACTIONS,
  260. adversReactionList: {
  261. 'id': item.id,
  262. 'adversReactionList': adversReactionList
  263. }
  264. })
  265. }
  266. }
  267. //保存全部诊断的回访时间
  268. export const setAllFollowUp = (item) => {
  269. return (dispatch, getState) => {
  270. const state = getState()
  271. const followUp = state.treat.followUp
  272. dispatch({
  273. type: SET_ALL_FOLLOW_UP,
  274. followUp: {
  275. 'id': item.id,
  276. 'followUp': followUp
  277. }
  278. })
  279. }
  280. }
  281. export const getInstroduce = (item, type, position)=>{
  282. return (dispatch, getState) =>{
  283. const url = '/introduceInfo/getByQuestionId';
  284. const params = {
  285. questionId: item.id,
  286. type: type,
  287. position: position
  288. }
  289. json(url, params)
  290. .then((data)=>{
  291. if(data.data.data) {
  292. dispatch({
  293. type: SET_DRUG_INFO,
  294. instroduce: data.data.data.introduceDetailList,
  295. name: type ==8 ?item.medicitionName : type == 10 ? item.tagName : '',
  296. tagType: type
  297. })
  298. } else {
  299. dispatch({
  300. type: SET_DRUG_INFO,
  301. instroduce: [],
  302. name: type ==8 ?item.medicitionName : type == 10 ? item.tagName : '',
  303. tagType: type
  304. })
  305. }
  306. }).catch((e) => {
  307. console.log(e)
  308. })
  309. }
  310. }
  311. export const getInstroduceMore = (drugIdList) =>{
  312. return (dispatch, getState) =>{
  313. let drugInfoList = [];
  314. for (let i = 0; i < drugIdList.drugIdList.length; i++ ) {
  315. const url = '/introduceInfo/getByQuestionId';
  316. const params = {
  317. questionId: drugIdList.drugIdList[i],
  318. type: 8,
  319. position: 5
  320. }
  321. json(url, params)
  322. .then((data)=>{
  323. if(data.data.data) {
  324. drugInfoList.push(data.data.data)
  325. dispatch({
  326. type: SET_DRUG_INFO_LIST,
  327. drugInfoList: drugInfoList,
  328. })
  329. } else {
  330. drugInfoList.push([])
  331. dispatch({
  332. type: SET_DRUG_INFO_LIST,
  333. drugInfoList: drugInfoList,
  334. })
  335. }
  336. }).catch((e) => {
  337. console.log(e)
  338. })
  339. }
  340. }
  341. }
  342. //一般治疗添加到医嘱
  343. export const commonTreatAddToAdvice = () => {
  344. return (dispatch, getState) => {
  345. const state = getState();
  346. const followUp = state.treat.followUp
  347. if(state.treat.treatItem.id === state.diagnosticList.diagnosticList[0].id && state.treat.isFirstMainDiag) {
  348. dispatch({
  349. type: IS_FIRST_MAIN_DIAG
  350. })
  351. dispatch({
  352. type: SET_COMMONTREATMENT,
  353. commontreatment: state.treat.treatItem.treat.commonTreatment.text
  354. })
  355. console.log('state.treat.followUp', state.treat.followUp)
  356. dispatch({
  357. type: SAVE_FOLLOW_UP,
  358. followUp: state.treat.followUp
  359. })
  360. } else {
  361. return
  362. }
  363. }
  364. }
  365. //其他推荐推荐依据不用展示
  366. // export const getRecommendBasic = (item)=>{
  367. // return (dispatch, getState) =>{
  368. // const url = '/api/icss/introduceInfo/getByQuestionId';
  369. // const params = {
  370. // questionId: item.id,
  371. // type: 9,
  372. // position: 2
  373. // }
  374. // json(url, params)
  375. // .then((data)=>{
  376. // if (data.status === 200) {
  377. // if(data.data.data) {
  378. // dispatch({
  379. // type: SET_RECOMMEND_BASIC,
  380. // recommendBasic: data.data.data.introduceDetailList,
  381. // })
  382. // } else {
  383. // dispatch({
  384. // type: SET_RECOMMEND_BASIC,
  385. // recommendBasic: [],
  386. // })
  387. // }
  388. // }
  389. // }).catch((e) => {
  390. // console.log(e)
  391. // })
  392. // }
  393. // }