illness.schema.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. import { decodeList } from '#/request/schema';
  2. // ---------------------------------------------------------------------------
  3. // 疾病类型 — DTO
  4. // ---------------------------------------------------------------------------
  5. export interface ICD10DTO {
  6. /** 主键 */
  7. id: string;
  8. /** 西医疾病名称 */
  9. name: string;
  10. /** 西医疾病编码 */
  11. code: string;
  12. /** 西医疾病副编码 */
  13. extCode: string;
  14. /** 版本 1:ICD10 2:临床版2.0 */
  15. vision: '1' | '2';
  16. /** 类型 1:标准 2:附加 */
  17. classify: '1' | '2';
  18. /** 备注 */
  19. remarks: string;
  20. }
  21. export interface DiseaseDTO {
  22. /** 主键 */
  23. id: string;
  24. /** 中医疾病名称 */
  25. name: string;
  26. /** 中医疾病编码 */
  27. code: string;
  28. /** 子疾病 */
  29. children?: DiseaseDTO[];
  30. /** 可选用词 */
  31. optionalWords?: string;
  32. /** 属性说明 */
  33. attributes?: { content: any; field: string; title: string }[];
  34. }
  35. export interface SymptomDTO {
  36. /** 主键 */
  37. id: string;
  38. /** 中医证型名称 */
  39. name: string;
  40. /** 中医证型编码 */
  41. code: string;
  42. /** 证候分析 */
  43. analysis: string;
  44. /** 备注 */
  45. remarks: string;
  46. }
  47. /** 推荐证型 / 治法 DTO,对应 `TreatmentDiagnoseVo` */
  48. export interface TreatmentDiagnoseDTO {
  49. disId?: string;
  50. disCode?: string;
  51. disName?: string;
  52. synId?: string;
  53. synCode?: string;
  54. synName?: string;
  55. therapyId?: string;
  56. therapyCode?: string;
  57. therapyName?: string;
  58. therapy?: string;
  59. classify?: string;
  60. preType?: string;
  61. }
  62. // ---------------------------------------------------------------------------
  63. // 疾病类型 — VO
  64. // ---------------------------------------------------------------------------
  65. export interface IllnessVO {
  66. /** 主键,-> `id` */
  67. id: string;
  68. /** 名称,-> `name` */
  69. name: string;
  70. /** 编码,-> `code` */
  71. code: string;
  72. }
  73. export interface ICD10VO extends IllnessVO {
  74. /** 类型,-> `classify` */
  75. type: '1' | '2';
  76. meta: {
  77. [K: string]: any;
  78. /** 副编码,-> `extCode` */
  79. extCode: string;
  80. /** 备注,-> `remarks` */
  81. remark: string;
  82. /** 版本,-> `vision` */
  83. versions: '1' | '2';
  84. };
  85. }
  86. export interface DiseaseVO extends IllnessVO {
  87. /** 子节点,-> `children` */
  88. children: DiseaseVO[];
  89. meta: {
  90. [K: string]: any;
  91. /** 属性说明,-> `attributes` */
  92. attributes?: { content: any; field: string; title: string }[];
  93. /** 可选用词,-> `optionalWords` */
  94. keywords: string[];
  95. };
  96. }
  97. export interface SymptomVO extends IllnessVO {
  98. meta: {
  99. [K: string]: any;
  100. /** 证候分析,-> `analysis` */
  101. analysis: string;
  102. /** 备注,-> `remarks` */
  103. remark: string;
  104. };
  105. }
  106. interface IllnessQueryVO {
  107. /** 搜索关键字,-> `keyWord` */
  108. keyword?: string;
  109. /** 关键字类型,-> `searchType` 1:拼音,2:五笔,3:中文 */
  110. keywordType?: string;
  111. /** 编码,-> `keyword` */
  112. name?: string;
  113. /** 编码,-> `code` */
  114. code?: string;
  115. /** 类型,-> `classify` 0:标准,1:扩充 */
  116. type?: '0' | '1';
  117. }
  118. export interface TreatDiagnoseQueryVO {
  119. keyword?: string;
  120. disId?: string;
  121. disCode?: string;
  122. disName?: string;
  123. synId?: string;
  124. synCode?: string;
  125. synName?: string;
  126. therapyId?: string;
  127. therapyCode?: string;
  128. therapyName?: string;
  129. therapy?: string;
  130. classify?: string;
  131. preType?: string;
  132. }
  133. // ---------------------------------------------------------------------------
  134. // 编解码
  135. // ---------------------------------------------------------------------------
  136. export const decodeICD10 = (dto: ICD10DTO): ICD10VO => ({
  137. id: dto.id,
  138. name: dto.name,
  139. code: dto.code,
  140. type: dto.classify,
  141. meta: {
  142. extCode: dto.extCode,
  143. remark: dto.remarks,
  144. versions: dto.vision,
  145. },
  146. });
  147. export const decodeDisease = (dto: DiseaseDTO): DiseaseVO => ({
  148. id: dto.id,
  149. name: dto.name,
  150. code: dto.code,
  151. children: decodeList(dto.children ?? [], decodeDisease),
  152. meta: {
  153. attributes: Array.isArray(dto.attributes) ? dto.attributes : [],
  154. keywords: Array.isArray(dto.optionalWords) ? dto.optionalWords : [],
  155. },
  156. });
  157. export const decodeSymptom = (dto: SymptomDTO): SymptomVO => ({
  158. id: dto.id,
  159. name: dto.name,
  160. code: dto.code,
  161. meta: {
  162. analysis: dto.analysis,
  163. remark: dto.remarks,
  164. },
  165. });
  166. export const decodeTreatSyn = (dto: TreatmentDiagnoseDTO): IllnessVO => ({
  167. id: dto.synId ?? '',
  168. name: dto.synName ?? '',
  169. code: dto.synCode ?? '',
  170. });
  171. export const decodeTreatTherapy = (dto: TreatmentDiagnoseDTO): IllnessVO => ({
  172. id: dto.therapyId ?? '',
  173. name: dto.therapy ?? dto.therapyName ?? '',
  174. code: dto.therapyCode ?? '',
  175. });
  176. export const encodeTreatSynQuery = (
  177. query: Partial<TreatDiagnoseQueryVO>,
  178. ): Partial<TreatmentDiagnoseDTO> => {
  179. const keyword = query.keyword?.trim();
  180. return {
  181. disId: query.disId,
  182. disCode: query.disCode,
  183. disName: query.disName,
  184. synId: query.synId,
  185. synCode: query.synCode,
  186. synName: keyword || query.synName,
  187. classify: query.classify,
  188. preType: query.preType,
  189. };
  190. };
  191. export const encodeTreatTherapyQuery = (
  192. query: Partial<TreatDiagnoseQueryVO>,
  193. ): Partial<TreatmentDiagnoseDTO> => {
  194. const keyword = query.keyword?.trim();
  195. return {
  196. disId: query.disId,
  197. disCode: query.disCode,
  198. disName: query.disName,
  199. synId: query.synId,
  200. synCode: query.synCode,
  201. synName: query.synName,
  202. therapyId: query.therapyId,
  203. therapyCode: query.therapyCode,
  204. therapy: keyword || query.therapy,
  205. therapyName: keyword || query.therapyName,
  206. classify: query.classify,
  207. preType: query.preType,
  208. };
  209. };
  210. export const encodeIllnessQuery = (
  211. query: Partial<IllnessQueryVO>,
  212. ): Record<string, any> => {
  213. const keyword = query.name || query.keyword;
  214. const keywordType =
  215. query.keywordType ??
  216. ((value: string) => {
  217. if (!value) return void 0;
  218. if (/[\u4E00-\u9FFF]/.test(value)) return '3';
  219. return '1';
  220. })(keyword ?? '');
  221. return {
  222. keyWord: query.keyword,
  223. keyword: query.name,
  224. searchType: keywordType,
  225. code: query.code,
  226. classify: query.type,
  227. };
  228. };