import { decodeList } from '#/request/schema'; // --------------------------------------------------------------------------- // 疾病类型 — DTO // --------------------------------------------------------------------------- export interface ICD10DTO { /** 主键 */ id: string; /** 西医疾病名称 */ name: string; /** 西医疾病编码 */ code: string; /** 西医疾病副编码 */ extCode: string; /** 版本 1:ICD10 2:临床版2.0 */ vision: '1' | '2'; /** 类型 1:标准 2:附加 */ classify: '1' | '2'; /** 备注 */ remarks: string; } export interface DiseaseDTO { /** 主键 */ id: string; /** 中医疾病名称 */ name: string; /** 中医疾病编码 */ code: string; /** 子疾病 */ children?: DiseaseDTO[]; /** 可选用词 */ optionalWords?: string; /** 属性说明 */ attributes?: { content: any; field: string; title: string }[]; } export interface SymptomDTO { /** 主键 */ id: string; /** 中医证型名称 */ name: string; /** 中医证型编码 */ code: string; /** 证候分析 */ analysis: string; /** 备注 */ remarks: string; } /** 推荐证型 / 治法 DTO,对应 `TreatmentDiagnoseVo` */ export interface TreatmentDiagnoseDTO { disId?: string; disCode?: string; disName?: string; synId?: string; synCode?: string; synName?: string; therapyId?: string; therapyCode?: string; therapyName?: string; therapy?: string; classify?: string; preType?: string; } // --------------------------------------------------------------------------- // 疾病类型 — VO // --------------------------------------------------------------------------- export interface IllnessVO { /** 主键,-> `id` */ id: string; /** 名称,-> `name` */ name: string; /** 编码,-> `code` */ code: string; } export interface ICD10VO extends IllnessVO { /** 类型,-> `classify` */ type: '1' | '2'; meta: { [K: string]: any; /** 副编码,-> `extCode` */ extCode: string; /** 备注,-> `remarks` */ remark: string; /** 版本,-> `vision` */ versions: '1' | '2'; }; } export interface DiseaseVO extends IllnessVO { /** 子节点,-> `children` */ children: DiseaseVO[]; meta: { [K: string]: any; /** 属性说明,-> `attributes` */ attributes?: { content: any; field: string; title: string }[]; /** 可选用词,-> `optionalWords` */ keywords: string[]; }; } export interface SymptomVO extends IllnessVO { meta: { [K: string]: any; /** 证候分析,-> `analysis` */ analysis: string; /** 备注,-> `remarks` */ remark: string; }; } interface IllnessQueryVO { /** 搜索关键字,-> `keyWord` */ keyword?: string; /** 关键字类型,-> `searchType` 1:拼音,2:五笔,3:中文 */ keywordType?: string; /** 编码,-> `keyword` */ name?: string; /** 编码,-> `code` */ code?: string; /** 类型,-> `classify` 0:标准,1:扩充 */ type?: '0' | '1'; } export interface TreatDiagnoseQueryVO { keyword?: string; disId?: string; disCode?: string; disName?: string; synId?: string; synCode?: string; synName?: string; therapyId?: string; therapyCode?: string; therapyName?: string; therapy?: string; classify?: string; preType?: string; } // --------------------------------------------------------------------------- // 编解码 // --------------------------------------------------------------------------- export const decodeICD10 = (dto: ICD10DTO): ICD10VO => ({ id: dto.id, name: dto.name, code: dto.code, type: dto.classify, meta: { extCode: dto.extCode, remark: dto.remarks, versions: dto.vision, }, }); export const decodeDisease = (dto: DiseaseDTO): DiseaseVO => ({ id: dto.id, name: dto.name, code: dto.code, children: decodeList(dto.children ?? [], decodeDisease), meta: { attributes: Array.isArray(dto.attributes) ? dto.attributes : [], keywords: Array.isArray(dto.optionalWords) ? dto.optionalWords : [], }, }); export const decodeSymptom = (dto: SymptomDTO): SymptomVO => ({ id: dto.id, name: dto.name, code: dto.code, meta: { analysis: dto.analysis, remark: dto.remarks, }, }); export const decodeTreatSyn = (dto: TreatmentDiagnoseDTO): IllnessVO => ({ id: dto.synId ?? '', name: dto.synName ?? '', code: dto.synCode ?? '', }); export const decodeTreatTherapy = (dto: TreatmentDiagnoseDTO): IllnessVO => ({ id: dto.therapyId ?? '', name: dto.therapy ?? dto.therapyName ?? '', code: dto.therapyCode ?? '', }); export const encodeTreatSynQuery = ( query: Partial, ): Partial => { const keyword = query.keyword?.trim(); return { disId: query.disId, disCode: query.disCode, disName: query.disName, synId: query.synId, synCode: query.synCode, synName: keyword || query.synName, classify: query.classify, preType: query.preType, }; }; export const encodeTreatTherapyQuery = ( query: Partial, ): Partial => { const keyword = query.keyword?.trim(); return { disId: query.disId, disCode: query.disCode, disName: query.disName, synId: query.synId, synCode: query.synCode, synName: query.synName, therapyId: query.therapyId, therapyCode: query.therapyCode, therapy: keyword || query.therapy, therapyName: keyword || query.therapyName, classify: query.classify, preType: query.preType, }; }; export const encodeIllnessQuery = ( query: Partial, ): Record => { const keyword = query.name || query.keyword; const keywordType = query.keywordType ?? ((value: string) => { if (!value) return void 0; if (/[\u4E00-\u9FFF]/.test(value)) return '3'; return '1'; })(keyword ?? ''); return { keyWord: query.keyword, keyword: query.name, searchType: keywordType, code: query.code, classify: query.type, }; };