api.illness.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import http from './http';
  2. import {getArray, randomUUID} from '@/tool';
  3. export function getDiseaseListMethod(page = 1, size = 10, query = {}) {
  4. const keyword = query.keyword;
  5. return http.post(`/basis/knowlib/diseaseQuery`, {
  6. serchtype: /* 1: 拼音码 2: 五笔码;搜索中文时可传空*/ /\w+/.test(keyword) ? '1' : '',
  7. pageid: page,
  8. pagesize: size,
  9. ...query, keyword,
  10. }, {meta: {share: true}}).then(res => {
  11. const data = res.data || {};
  12. return {
  13. total: data.disnum || 0,
  14. list: getArray(data.diseases, item => Object.assign(item, {
  15. $uid: randomUUID(),
  16. $code: item.disCode,
  17. $name: item.disname,
  18. })),
  19. };
  20. });
  21. }
  22. export function getSymptomListMethod(page = 1, size = 10, query = {}) {
  23. const keyword = query.keyword;
  24. return http.post(`/basis/knowlib/symptomQuery`, {
  25. serchtype: /* 1: 拼音码 2: 五笔码;搜索中文时可传空*/ /\w+/.test(keyword) ? '1' : '',
  26. pageid: page,
  27. pagesize: size,
  28. ...query, keyword,
  29. }, {meta: {share: true}}).then(res => {
  30. const data = res.data || {};
  31. return {
  32. total: data.sysnum || 0,
  33. list: getArray(data.sysptoms, item => Object.assign(item, {
  34. $uid: randomUUID(),
  35. $code: item.symid,
  36. $name: item.symname,
  37. therapies: getArray(item.therapys, item => Object.assign(item, {
  38. $uid: randomUUID(),
  39. $code: item.therapyCode,
  40. $name: item.therapyName,
  41. })),
  42. })),
  43. };
  44. });
  45. }
  46. export function getTherapyListMethod(page = 1, size = 10, query = {}) {
  47. const keyword = query.keyword;
  48. return http.post(`/basis/knowlib/getTherapyAll`, {
  49. serchtype: /* 1: 拼音码 2: 五笔码;搜索中文时可传空*/ /\w+/.test(keyword) ? '1' : '',
  50. pageid: page,
  51. pagesize: size,
  52. ...query, name: keyword,
  53. }, {meta: {share: true, ignoreError: true}}).then(res => {
  54. const list = getArray(res.data, item => Object.assign(item, {
  55. $uid: randomUUID(),
  56. $code: item.therapyCode,
  57. $name: item.therapy,
  58. }));
  59. return {total: list.length, list};
  60. });
  61. }
  62. /**
  63. *
  64. * 根据疾病信息推导业务处方
  65. * @param {string} business 业务类型,多个用逗号分隔
  66. * - '1' 中药处方
  67. * - '2' 中药制剂
  68. * - '3' 适宜技术
  69. * @param {object} illness 疾病信息对象
  70. * @param {string} illness.disease.id 疾病ID
  71. * @param {string} illness.disease.code 疾病代码
  72. * @param {string} illness.disease.name 疾病名称
  73. * @param {string} illness.symptom.code 证型代码
  74. * @param {string} illness.symptom.name 证型名称
  75. * @param {string} illness.therapy.code 治法代码
  76. * @param {string} illness.therapy.name 治法名称
  77. * @return {Promise<*>}
  78. */
  79. export function deduceIllnessPrescriptionMethod(business = '1,2,3', illness) {
  80. const [_, prefix = '', special, suffix = ''] = business.match(/^([^1]+)?(?:(1)(?:,|$))?([^1]*)?$/) || ['', business];
  81. const request = (business) => {
  82. if (!business) return {expList: [], schemes: []};
  83. return http.post(`/basis/knowlib/treatmentScheme`, {
  84. businesstype: business.endsWith(',') ? business.slice(0, -1) : business,
  85. disid: illness.disease.id,
  86. symid: illness.symptom.code,
  87. therapy: illness.therapy.name,
  88. therapyCode: illness.therapy.code,
  89. disCode: illness.disease.code,
  90. }).then(res => {
  91. const {expList, schemes} = res.data;
  92. return {schemes, expList: business === '1' ? {pres: expList, businesstype: business} : []};
  93. });
  94. };
  95. return Promise.all([
  96. request(special),
  97. request(`${prefix}${suffix}`),
  98. ]).then(([s, b]) => {
  99. return {
  100. expList: [s.expList, b.expList].flat(),
  101. schemes: [s.schemes, b.schemes].flat(),
  102. };
  103. }).then(({schemes, expList}) => {
  104. const categories = business.split(',');
  105. const results = {
  106. * [Symbol.iterator]() { for (const type of categories) yield this[type]; },
  107. };
  108. for (const category of categories) {
  109. const e = expList.find(item => item.businesstype === category) || {pres: []};
  110. const s = schemes.find(item => item.businesstype === category) || {pres: []};
  111. results[category] = [
  112. e.pres.map(item => Object.assign(item, {$category: category, $type: '3'})),
  113. s.pres.map(item => Object.assign(item, {$category: category, $type: '1'})),
  114. ].flat(1);
  115. if (results.index == null && results[category].length) results.index = categories.findIndex(t => t === category);
  116. }
  117. return results;
  118. });
  119. }
  120. /**
  121. * [legacy] 推导处方
  122. * {@link deduceIllnessPrescriptionMethod}
  123. */
  124. export function legacyDeduceIllnessPrescriptionMethod(business, params = {}) {
  125. return deduceIllnessPrescriptionMethod(business, {
  126. disease: {code: params.disCode, id: params.disid},
  127. symptom: {code: params.symptomCode},
  128. therapy: {code: params.therapyCode, name: params.treatment},
  129. }).then(data => {
  130. const categories = business.split(',');
  131. for (const category of categories) {
  132. const expList = [], schemes = [];
  133. for (const prescription of data[category]) {
  134. if (prescription.$type === '3') expList.push(prescription);
  135. else if (prescription.$type === '1') schemes.push(prescription);
  136. }
  137. data[category] = {code: 0, data: {expList, schemes: [{businesstype: category, presnum: schemes.length, pres: schemes}]}};
  138. }
  139. return data;
  140. });
  141. }