prescription.tool.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import {checkReasonableSafeMedicinesMethod} from '@/api/prescription';
  2. const reasonableSafeMap = [{
  3. type: '2', label: `慎忌禁用药`, key: 'matsjj', handle(medicine, value) {
  4. return {
  5. name: medicine['matname'] || medicine.$name,
  6. description: `(${{1: '慎用', 2: '忌用', 3: '禁用'}[value] || '---'})`,
  7. };
  8. },
  9. }, {
  10. type: '3', label: `孕妇慎忌禁`, key: 'matyfsjj', handle(medicine, value) {
  11. return {
  12. name: medicine['matname'] || medicine.$name,
  13. description: `(${{1: '孕妇慎用', 2: '孕妇忌用', 3: '孕妇禁用'}[value] || '---'})`,
  14. signName: +value === 3,
  15. };
  16. },
  17. }, {
  18. type: '4', label: `服药饮食禁忌`, key: 'matysjj', handle(medicine, value) {
  19. return {
  20. name: medicine['matname'] || medicine.$name,
  21. description: `(${value || '无'})`,
  22. };
  23. },
  24. }, {
  25. type: '5', label: `药物毒性说明`, key: 'matdxsm', handle(medicine, value) {
  26. return {
  27. name: medicine['matname'] || medicine.$name,
  28. description: `(${value || '无'})`,
  29. signName: true,
  30. };
  31. },
  32. }, {
  33. type: '6', label: `病证用药禁忌`, key: 'matbzjj', handle(medicine, value) {
  34. return {
  35. name: medicine['matname'] || medicine.$name,
  36. description: `(${value || '无'})`,
  37. };
  38. },
  39. }, {
  40. type: '7', label: `十八反`, key: 'matsbf', handle(medicine, value) {
  41. return {
  42. name: medicine['matname'] || medicine.$name,
  43. description: `反 ${value}`, signName: true,
  44. };
  45. },
  46. }, {
  47. type: '8', label: `十九畏`, key: 'matsjw', handle(medicine, value) {
  48. return {
  49. name: medicine['matname'] || medicine.$name,
  50. description: `畏 ${value}`, signName: true,
  51. };
  52. },
  53. }, {
  54. type: '9', label: `用药不宜`, key: 'matby', handle(medicine, value) {
  55. return {
  56. name: medicine['matname'] || medicine.$name,
  57. description: `不宜与 ${value} 同用`,
  58. };
  59. },
  60. }, {
  61. type: '10', label: `超剂量药品`, key: ['matmindosage', 'matmaxdosage', '$dosage'], handle(medicine, [min, max]) {
  62. const dosage = medicine.$baseDosage;
  63. return dosage < min || dosage > max ? {
  64. name: medicine['matname'] || medicine.$name, description: `(${min}~${max})`, signDescription: true,
  65. } : void 0;
  66. },
  67. }];
  68. /**
  69. * @description
  70. * 2:慎 忌 禁
  71. * 3:孕慎 孕忌 孕禁
  72. * 4:服药饮食禁忌
  73. * 5:药物毒性说明
  74. * 6:病证用药禁忌
  75. * 7:十八反
  76. * 8:十九畏
  77. * 9:用药不宜
  78. * 10:超剂量药品
  79. * @param medicines
  80. * @param {object} config
  81. * @param {string} [config.filter]
  82. * @param {string} [config.sort = '10,2,3,4,5,6,7,8,9']
  83. * @param {boolean} [config.force = true]
  84. * @param {object} [config.platform ]平台数据
  85. * @param {string} [config.platform.organization] 平台机构 - ID
  86. */
  87. export async function getReasonableSafeData(medicines, config = {}) {
  88. // const
  89. const filter = (config.filter || '').split(',').filter(Boolean);
  90. const sort = (config.filter || config.sort || '10,2,3,4,5,6,7,8,9').split(',').filter(Boolean);
  91. const {force = true} = config;
  92. if (force) await checkReasonableSafeMedicinesMethod(medicines, config.platform);
  93. const rs = {
  94. * [Symbol.iterator]() { for (const key of sort) if (this[key]) yield this[key]; },
  95. toString() {
  96. let html = ``;
  97. for (const {label, collection} of this) {
  98. html += `
  99. <div class="item"> \
  100. <div class="label">${label}:</div> \
  101. ${collection.map(item => `<div>
  102. <span class="name ${item.signName ? 'sign' : ''}">${item.name}</span> \
  103. <span class="description ${item.signDescription ? 'sign' : ''}">${item.description}</span> \
  104. </div>`).join('')}
  105. </div>
  106. `;
  107. }
  108. return html;
  109. },
  110. };
  111. for (const medicine of medicines) {
  112. if (medicine.editing) continue;
  113. for (const {key, type, label, handle, ...props} of reasonableSafeMap) {
  114. if (filter.length && !filter.includes(type)) continue;
  115. const keys = Array.isArray(key) ? key : [key];
  116. const values = keys.map(key => medicine[key]);
  117. if (values.some(value => !value)) continue;
  118. const data = handle(medicine, typeof key === 'string' ? values[0] : values);
  119. if (data == null) continue;
  120. const child = rs[type] || (rs[type] = {...props, type, label, collection: []});
  121. child.collection.push(data);
  122. }
  123. }
  124. return rs;
  125. }