medical-case.schema.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. import type { AuditRecordVO } from '#/request/schema/audit-record';
  2. import { isDayjs } from 'dayjs';
  3. import { decodeAuditRecord } from '#/request/schema/audit-record';
  4. // ===========================================================================
  5. // DTO — 嵌套
  6. // ===========================================================================
  7. /** 检查检验项目和结果 DTO,对应 OpenAPI `MrCheckInspectionResult` */
  8. interface CaseCheckInspectionResultDTO {
  9. /** 项目名称 */
  10. itemName?: string;
  11. /** 结果 */
  12. result?: string;
  13. /** 类型 1检查 2检验 */
  14. itemType?: number;
  15. }
  16. /** 西药/中成药处方 DTO,对应 OpenAPI `MrWmPrescription` */
  17. interface CaseWmPrescriptionDTO {
  18. /** 药品名称 */
  19. drugName?: string;
  20. /** 数量 */
  21. quantity?: number;
  22. /** 数量单位 */
  23. unit?: string;
  24. /** 规格 */
  25. specifications?: string;
  26. /** 单次用量 */
  27. dosage?: string;
  28. /** 使用频率 */
  29. frequency?: string;
  30. /** 使用天数 */
  31. useDays?: number;
  32. }
  33. /** 中药处方 DTO,对应 OpenAPI `MrTcmPrescription` */
  34. interface CaseTcmPrescriptionDTO {
  35. /** 剂数 */
  36. dosage?: string;
  37. /** 剂型 */
  38. dosageForm?: string;
  39. /** 处方用法 */
  40. prescriptionUsage?: string;
  41. /** 浓煎每次量 */
  42. thickFriedTime?: string;
  43. /** 频次 */
  44. frequency?: string;
  45. /** 服药时间 */
  46. medicationTime?: string;
  47. /** 嘱托 */
  48. entrust?: string;
  49. }
  50. /** 中药处方药品明细 DTO,对应 OpenAPI `MrTcmPrescriptionDetail` */
  51. interface CaseTcmPrescriptionDetailDTO {
  52. /** 药品名称 */
  53. drugName?: string;
  54. /** 剂量g */
  55. dose?: number;
  56. /** 用法 */
  57. drugUsage?: string;
  58. }
  59. /** 中/西医非药物治疗 DTO,对应 OpenAPI `MrNondrugTreatment` */
  60. interface CaseNondrugTreatmentDTO {
  61. /** 名称 */
  62. itemName?: string;
  63. /** 数量 */
  64. quantity?: string;
  65. /** 类型 1-西医 2-中医 */
  66. itemType?: number;
  67. }
  68. // ===========================================================================
  69. // DTO — 主类型
  70. // ===========================================================================
  71. /**
  72. * 医案病历 DTO
  73. * @remarks 对应 OpenAPI `MedicalRecordGrowDetail`
  74. */
  75. export interface SpecialDiseaseCaseDTO {
  76. /** 主键 ID */
  77. pid?: number | string;
  78. /** 专病 ID */
  79. specificId: number | string;
  80. /** 病历编号 */
  81. caseCode?: string;
  82. /** 来源病历编号 */
  83. sourceCode?: string;
  84. /** 就诊日期 */
  85. visitTime?: string;
  86. /** 性别 1-男 2-女 */
  87. gender?: string;
  88. /** 年龄 */
  89. age?: string;
  90. /** 年龄月 */
  91. ageMonth?: string;
  92. /** 年龄天 */
  93. ageDay?: string;
  94. /** 诊次 */
  95. diagnosisTimes?: string;
  96. /** 主诉 */
  97. chiefComplaint?: string;
  98. /** 现病史 */
  99. presentIllness?: string;
  100. /** 既往史 */
  101. historyIllness?: string;
  102. /** 家族史 */
  103. familyHistory?: string;
  104. /** 过敏史 */
  105. allergyHistory?: string;
  106. /** 检查检验结果补充 */
  107. checkInspectionComplement?: string;
  108. /** 西医诊断名称 */
  109. westernMedicine?: string;
  110. /** 西医诊断编码 */
  111. westernMedicineCode?: string;
  112. /** 西医其他诊断名称 */
  113. westernOtherMedicine?: string[];
  114. /** 西医其他诊断编码 */
  115. westernOtherMedicineCode?: string[];
  116. /** 中医诊断名称 */
  117. tcmDiagnosis?: string[];
  118. /** 中医诊断编码 */
  119. tcmDiagnosisCode?: string[];
  120. /** 中医诊断编码 */
  121. chineseMedicineCode?: string;
  122. /** 中医诊断名称 */
  123. chineseMedicineName?: string;
  124. /** 中医证型名称 */
  125. tcmPattern?: string[];
  126. /** 中医证型编码 */
  127. tcmPatternCode?: string[];
  128. /** 健康教育 */
  129. healthEducation?: string;
  130. /** 检查检验项目和结果 */
  131. checkInspectionResultList?: CaseCheckInspectionResultDTO[];
  132. /** 西药/中成药处方 */
  133. wmPrescriptions?: CaseWmPrescriptionDTO[];
  134. /** 中药处方 */
  135. tcmPrescription?: CaseTcmPrescriptionDTO;
  136. /** 中药处方药品明细 */
  137. tcmPrescriptionDetails?: CaseTcmPrescriptionDetailDTO[];
  138. /** 中/西医非药物治疗 */
  139. nondrugTreatments?: CaseNondrugTreatmentDTO[];
  140. /** 病历来源 1-新增 2-导入 3-接口 */
  141. resource?: string;
  142. /** 标定状态 1-待标定 2-暂存 3-标定完成 */
  143. calibrateStatus?: string;
  144. /** 标定编号 */
  145. calibrateCode?: string;
  146. /** 标定者 */
  147. calibrateName?: string;
  148. /** 标定时间 */
  149. calibrateTime?: string;
  150. /** 创建者 */
  151. createUser?: string;
  152. /** 来源创建者 */
  153. sourceCreateUser?: string;
  154. /** 创建时间 */
  155. createTime?: string;
  156. /** 来源创建时间 */
  157. sourceCreateTime?: string;
  158. /** 更新者 */
  159. updateUser?: string;
  160. /** 更新时间 */
  161. updateTime?: string;
  162. }
  163. // ===========================================================================
  164. // VO — 公共
  165. // ===========================================================================
  166. /** 编码名称对 */
  167. export interface CaseCodeNameVO {
  168. /** 编码 */
  169. id?: string;
  170. /** 名称 */
  171. name?: string;
  172. }
  173. /** 患者年龄 */
  174. interface CaseAgesVO {
  175. /** 岁,-> `age` */
  176. year: number;
  177. /** 月,-> `ageMonth` */
  178. month: number;
  179. /** 天,-> `ageDay` */
  180. day: number;
  181. }
  182. // ===========================================================================
  183. // VO — 嵌套(叶子)
  184. // ===========================================================================
  185. /** 检查检验项目和结果 VO */
  186. export interface CaseCheckInspectionResultVO {
  187. id?: string;
  188. /** 项目名称,-> `itemName` */
  189. name?: string;
  190. /** 结果,-> `result` */
  191. value?: string;
  192. /** 类型 1检查 2检验,-> `itemType` */
  193. type?: '1' | '2';
  194. }
  195. /** 西药/中成药处方 VO */
  196. export interface CaseWesternMedicineVO {
  197. id?: string;
  198. /** 药品名称,-> `drugName` */
  199. name?: string;
  200. /** 数量,-> `quantity` */
  201. dosage?: number;
  202. /** 数量单位,-> `unit` */
  203. unit?: string;
  204. /** 规格,-> `specifications` */
  205. size?: string;
  206. /** 单次用量,-> `dosage` */
  207. singleDose?: number;
  208. /** 单次用量单位 */
  209. singleUnit?: string;
  210. /** 使用频率,-> `frequency` */
  211. frequency?: string;
  212. /** 使用天数,-> `useDays` */
  213. usageDays?: number;
  214. }
  215. /** 中药处方 VO */
  216. interface CaseTraditionalRecipeVO {
  217. /** 剂数,-> `dosage` */
  218. count?: string;
  219. /** 剂型,-> `dosageForm` */
  220. type?: string;
  221. /** 处方用法,-> `prescriptionUsage` */
  222. usage?: string;
  223. /** 浓煎每次量,-> `thickFriedTime` */
  224. volume?: string;
  225. /** 频次,-> `frequency` */
  226. frequency?: string;
  227. /** 服药时间,-> `medicationTime` */
  228. frequencyTime?: string;
  229. /** 嘱托,-> `entrust` */
  230. advice?: string;
  231. }
  232. /** 中药处方药品明细 VO */
  233. export interface CaseTraditionalMedicineVO {
  234. id?: string;
  235. /** 药品名称,-> `drugName` */
  236. name?: string;
  237. /** 剂量,-> `dose` */
  238. dosage?: number;
  239. /** 单位,默认 g */
  240. unit?: string;
  241. /** 用法,-> `drugUsage` */
  242. usage?: string;
  243. }
  244. /** 中/西医非药物治疗 VO */
  245. export interface CaseNondrugTreatmentVO {
  246. id?: string;
  247. /** 名称,-> `itemName` */
  248. name?: string;
  249. /** 数量,-> `quantity` (quantity + unit) */
  250. value?: string;
  251. /** 数量,-> `quantity` */
  252. quantity?: number;
  253. /** 单位 */
  254. unit?: string;
  255. /** 类型 1-西医 2-中医,-> `itemType` */
  256. type?: '1' | '2';
  257. }
  258. // ===========================================================================
  259. // VO — 嵌套(业务大类)
  260. // ===========================================================================
  261. /** 患者信息 */
  262. interface CasePatientVO {
  263. /** 性别 1-男 2-女,-> `gender` */
  264. gender?: '1' | '2';
  265. /** 年龄,-> `age` / `ageMonth` / `ageDay` */
  266. ages: CaseAgesVO;
  267. }
  268. /** 病史 / 主诉 */
  269. interface CaseDiagnoseVO {
  270. /** 诊次,-> `diagnosisTimes` */
  271. order?: string;
  272. /** 就诊日期,-> `visitTime` YYYY-MM-DD */
  273. date?: string;
  274. /** 就诊日期,-> `visitTime` YYYY-MM-DD HH:mm:ss */
  275. datetime?: string;
  276. /** 主诉,-> `chiefComplaint` */
  277. zs?: string;
  278. /** 现病史,-> `presentIllness` */
  279. xb?: string;
  280. /** 既往史,-> `historyIllness` */
  281. jw?: string;
  282. /** 家族史,-> `familyHistory` */
  283. jz?: string;
  284. /** 过敏史,-> `allergyHistory` */
  285. gw?: string;
  286. }
  287. /** 检验检查 */
  288. interface CaseExaminationVO {
  289. /** 检查检验结果补充,-> `checkInspectionComplement` */
  290. description?: string;
  291. /** 检查,-> `checkInspectionResultList`(itemType=1) */
  292. inspection?: CaseCheckInspectionResultVO[];
  293. /** 检验,-> `checkInspectionResultList`(itemType=2) */
  294. checkout?: CaseCheckInspectionResultVO[];
  295. }
  296. /** 疾病诊断 */
  297. interface CaseIllnessVO {
  298. /** 西医诊断,-> `westernMedicine` / `westernOtherMedicine` */
  299. icd_10?: CaseCodeNameVO[];
  300. /** 中医诊断,-> `tcmDiagnosis` / `chineseMedicineName` */
  301. disease?: CaseCodeNameVO[];
  302. /** 中医证型,-> `tcmPattern` */
  303. symptom?: CaseCodeNameVO[];
  304. }
  305. /** 处置 */
  306. interface CaseTreatmentVO {
  307. /** 健康教育,-> `healthEducation` */
  308. healthEducation?: string;
  309. /** 西医处置,-> `wmPrescriptions` / `nondrugTreatments`(itemType=1) */
  310. westernRecipe?: {
  311. cure: CaseNondrugTreatmentVO[];
  312. medicines: CaseWesternMedicineVO[];
  313. };
  314. /** 中医处置,-> `tcmPrescription` / `tcmPrescriptionDetails` / `nondrugTreatments`(itemType=2) */
  315. traditionalRecipe?: CaseTraditionalRecipeVO & {
  316. cure: CaseNondrugTreatmentVO[];
  317. medicines: CaseTraditionalMedicineVO[];
  318. };
  319. }
  320. /** 来源信息 */
  321. interface CaseMetaSourceVO {
  322. /** 来源病历编号,-> `sourceCode` */
  323. code?: string;
  324. /** 病历来源 1-新增 2-导入 3-接口,-> `resource` */
  325. type?: string;
  326. /** 操作人,-> `sourceCreateUser` */
  327. operatedBy?: string;
  328. /** 操作时间,-> `sourceCreateTime` */
  329. operatedAt?: string;
  330. }
  331. /** 标定信息 */
  332. interface CaseMetaMarkVO {
  333. /** 标定状态 1-待标定 2-暂存 3-标定完成,-> `calibrateStatus` */
  334. status?: string;
  335. /** 标定编号,-> `calibrateCode` */
  336. code?: string;
  337. /** 操作人,-> `calibrateName` */
  338. operatedBy?: string;
  339. /** 操作时间,-> `calibrateTime` */
  340. operatedAt?: string;
  341. }
  342. /** 数据集信息(预留) */
  343. interface CaseMetaDatasetVO {
  344. /** 所属数据集 ID(预留) */
  345. id?: string;
  346. /** 操作人(预留) */
  347. operatedBy?: string;
  348. /** 操作时间(预留) */
  349. operatedAt?: string;
  350. }
  351. /** 典型病历信息(预留) */
  352. interface CaseMetaTypicalVO {
  353. /** 所属典型病历 ID(预留) */
  354. id?: string;
  355. /** 操作人(预留) */
  356. operatedBy?: string;
  357. /** 操作时间(预留) */
  358. operatedAt?: string;
  359. }
  360. /** 病历元信息 */
  361. interface CaseMetaVO {
  362. source: CaseMetaSourceVO;
  363. mark: CaseMetaMarkVO;
  364. dataset: CaseMetaDatasetVO;
  365. typical: CaseMetaTypicalVO;
  366. }
  367. // ===========================================================================
  368. // VO — 主类型
  369. // ===========================================================================
  370. /**
  371. * 医案病历 VO
  372. * @remarks 对应 OpenAPI `MedicalRecordGrowDetail`
  373. */
  374. export interface MedicalCaseVO extends AuditRecordVO {
  375. /** 主键 ID,-> `pid` */
  376. id?: string;
  377. /** 专病 ID,-> `specificId` */
  378. specialDiseaseId: string;
  379. /** 病历编号,-> `caseCode` */
  380. code?: string;
  381. patient: CasePatientVO;
  382. diagnose: CaseDiagnoseVO;
  383. examination: CaseExaminationVO;
  384. illness: CaseIllnessVO;
  385. treatment: CaseTreatmentVO;
  386. meta: CaseMetaVO;
  387. }
  388. export interface MedicalCaseModel extends Pick<
  389. MedicalCaseVO,
  390. 'code' | 'id' | 'specialDiseaseId'
  391. > {
  392. patient: Omit<CasePatientVO, 'ages'> & { ages: Partial<CaseAgesVO> };
  393. diagnose: Partial<CaseDiagnoseVO>;
  394. examination: Partial<CaseExaminationVO> & {
  395. items: CaseCheckInspectionResultVO[];
  396. };
  397. illness: Partial<CaseIllnessVO> & {
  398. items: (CaseCodeNameVO & { type?: keyof CaseIllnessVO })[];
  399. };
  400. treatment: Partial<CaseTreatmentVO> & {
  401. cure: CaseNondrugTreatmentVO[];
  402. traditionalRecipe: Partial<CaseTraditionalRecipeVO> & {
  403. cure: CaseNondrugTreatmentVO[];
  404. medicines: CaseTraditionalMedicineVO[];
  405. };
  406. westernRecipe: {
  407. cure: CaseNondrugTreatmentVO[];
  408. medicines: CaseWesternMedicineVO[];
  409. };
  410. };
  411. }
  412. // ===========================================================================
  413. // 编解码
  414. // ===========================================================================
  415. const zipCodeName = (codes?: string[], names?: string[]): CaseCodeNameVO[] => {
  416. const codeList = codes ?? [];
  417. const nameList = names ?? [];
  418. const length = Math.max(codeList.length, nameList.length);
  419. if (!length) return [];
  420. return Array.from({ length }, (_, index) => ({
  421. id: codeList[index],
  422. name: nameList[index],
  423. }));
  424. };
  425. const unzipCodeName = (items?: CaseCodeNameVO[]) => {
  426. const list = items ?? [];
  427. return {
  428. codes: list.map((item) => item.id).filter(Boolean) as string[],
  429. names: list.map((item) => item.name).filter(Boolean) as string[],
  430. };
  431. };
  432. export const decodeSpecialDiseaseCase = (
  433. dto: SpecialDiseaseCaseDTO,
  434. ): MedicalCaseVO => {
  435. const toNumber = (value?: number | string) => {
  436. if (value === undefined || value === null || value === '') return void 0;
  437. const parsed = Number(value);
  438. return Number.isFinite(parsed) ? parsed : void 0;
  439. };
  440. const toAgePart = (value?: string) => toNumber(value) ?? 0;
  441. const westernPrimary: CaseCodeNameVO[] =
  442. dto.westernMedicine || dto.westernMedicineCode
  443. ? [{ id: dto.westernMedicineCode, name: dto.westernMedicine }]
  444. : [];
  445. const tcmFromArrays = zipCodeName(dto.tcmDiagnosisCode, dto.tcmDiagnosis);
  446. const tcmIllness =
  447. tcmFromArrays.length > 0
  448. ? tcmFromArrays
  449. : (() =>
  450. dto.chineseMedicineName || dto.chineseMedicineCode
  451. ? [
  452. {
  453. id: dto.chineseMedicineCode,
  454. name: dto.chineseMedicineName,
  455. },
  456. ]
  457. : [])();
  458. const checkResults =
  459. dto.checkInspectionResultList?.map((item) => ({
  460. name: item.itemName,
  461. value: item.result,
  462. type: item.itemType === 1 ? '1' : '2',
  463. })) ?? [];
  464. const nondrug =
  465. dto.nondrugTreatments?.map((item) => ({
  466. name: item.itemName,
  467. quantity: toNumber(item.quantity),
  468. type: item.itemType?.toString(),
  469. })) ?? [];
  470. const traditionalMedicines =
  471. dto.tcmPrescriptionDetails?.map((item) => ({
  472. name: item.drugName,
  473. dosage: item.dose,
  474. unit: 'g',
  475. usage: item.drugUsage,
  476. })) ?? [];
  477. const traditionalCure = nondrug.filter(
  478. (item) => item.type?.toString() === '2',
  479. );
  480. const hasTraditional =
  481. dto.tcmPrescription ||
  482. traditionalMedicines.length > 0 ||
  483. traditionalCure.length > 0;
  484. return {
  485. ...decodeAuditRecord({
  486. createBy: dto.createUser,
  487. createTime: dto.createTime,
  488. updateBy: dto.updateUser,
  489. updateTime: dto.updateTime,
  490. }),
  491. id: dto.pid?.toString(),
  492. specialDiseaseId: dto.specificId?.toString() ?? '',
  493. code: dto.caseCode,
  494. patient: {
  495. gender: dto.gender === '1' || dto.gender === '2' ? dto.gender : void 0,
  496. ages: {
  497. year: toAgePart(dto.age),
  498. month: toAgePart(dto.ageMonth),
  499. day: toAgePart(dto.ageDay),
  500. },
  501. },
  502. diagnose: {
  503. order: dto.diagnosisTimes,
  504. date: dto.visitTime?.slice(0, 10),
  505. datetime: dto.visitTime,
  506. zs: dto.chiefComplaint,
  507. xb: dto.presentIllness,
  508. jw: dto.historyIllness,
  509. jz: dto.familyHistory,
  510. gw: dto.allergyHistory,
  511. },
  512. examination: {
  513. description: dto.checkInspectionComplement,
  514. inspection: checkResults.filter(
  515. (item) => item.type?.toString() === '1',
  516. ) as any,
  517. checkout: checkResults.filter(
  518. (item) => item.type?.toString() === '2',
  519. ) as any,
  520. },
  521. illness: {
  522. icd_10: [
  523. ...westernPrimary,
  524. ...zipCodeName(dto.westernOtherMedicineCode, dto.westernOtherMedicine),
  525. ],
  526. disease: tcmIllness,
  527. symptom: zipCodeName(dto.tcmPatternCode, dto.tcmPattern),
  528. },
  529. treatment: {
  530. healthEducation: dto.healthEducation,
  531. westernRecipe: {
  532. cure: nondrug.filter((item) => item.type?.toString() === '1') as any,
  533. medicines:
  534. dto.wmPrescriptions?.map((item) => {
  535. const dosage = item.dosage;
  536. const parsed = dosage ? Number(dosage) : void 0;
  537. const matched = dosage?.match(/^([\d.]+)(.*)$/);
  538. return {
  539. name: item.drugName,
  540. dosage: item.quantity,
  541. unit: item.unit,
  542. size: item.specifications,
  543. singleDose: Number.isFinite(parsed)
  544. ? parsed
  545. : // eslint-disable-next-line unicorn/no-unreadable-iife
  546. (() => (matched ? Number(matched[1]) : void 0))(),
  547. singleUnit: Number.isFinite(parsed)
  548. ? void 0
  549. : // eslint-disable-next-line unicorn/no-unreadable-iife
  550. (() => (matched ? matched[2] || void 0 : dosage))(),
  551. frequency: item.frequency,
  552. usageDays: item.useDays,
  553. };
  554. }) ?? [],
  555. },
  556. traditionalRecipe: hasTraditional
  557. ? ({
  558. count: dto.tcmPrescription?.dosage,
  559. type: dto.tcmPrescription?.dosageForm,
  560. usage: dto.tcmPrescription?.prescriptionUsage,
  561. volume: dto.tcmPrescription?.thickFriedTime,
  562. frequency: dto.tcmPrescription?.frequency,
  563. frequencyTime: dto.tcmPrescription?.medicationTime,
  564. advice: dto.tcmPrescription?.entrust,
  565. cure: traditionalCure,
  566. medicines: traditionalMedicines,
  567. } as any)
  568. : void 0,
  569. },
  570. meta: {
  571. source: {
  572. code: dto.sourceCode,
  573. type: dto.resource,
  574. operatedBy: dto.sourceCreateUser,
  575. operatedAt: dto.sourceCreateTime,
  576. },
  577. mark: {
  578. status: dto.calibrateStatus,
  579. code: dto.calibrateCode,
  580. operatedBy: dto.calibrateName,
  581. operatedAt: dto.calibrateTime,
  582. },
  583. dataset: {},
  584. typical: {},
  585. },
  586. };
  587. };
  588. export const encodeSpecialDiseaseCase = (
  589. vo: MedicalCaseVO,
  590. ): SpecialDiseaseCaseDTO => {
  591. const [westernPrimary, ...westernOthers] = vo.illness.icd_10 ?? [];
  592. const westernOther = unzipCodeName(westernOthers);
  593. const tcmItems = vo.illness.disease ?? [];
  594. const tcmUnzipped = unzipCodeName(tcmItems);
  595. const symptom = unzipCodeName(vo.illness.symptom);
  596. const checkResults = [
  597. ...(vo.examination.inspection ?? []),
  598. ...(vo.examination.checkout ?? []),
  599. ].map((item) => ({
  600. itemName: item.name,
  601. result: item.value,
  602. itemType: item.type === '1' ? 1 : 2,
  603. }));
  604. const westernCure = vo.treatment.westernRecipe?.cure ?? [];
  605. const traditionalCure = vo.treatment.traditionalRecipe?.cure ?? [];
  606. const recipe = vo.treatment.traditionalRecipe;
  607. const nondrugTreatments = [...westernCure, ...traditionalCure].map(
  608. (item) => ({
  609. itemName: item.name,
  610. quantity: item.value,
  611. itemType: item.type,
  612. }),
  613. );
  614. return {
  615. pid: vo.id,
  616. specificId: vo.specialDiseaseId,
  617. caseCode: vo.code,
  618. createUser: vo.createdBy,
  619. createTime: vo.createdAt,
  620. updateUser: vo.updatedBy,
  621. updateTime: vo.updatedAt,
  622. gender: vo.patient.gender,
  623. age: String(vo.patient.ages.year ?? 0),
  624. ageMonth: String(vo.patient.ages.month ?? 0),
  625. ageDay: String(vo.patient.ages.day ?? 0),
  626. diagnosisTimes: vo.diagnose.order,
  627. visitTime: vo.diagnose.datetime || vo.diagnose.date,
  628. chiefComplaint: vo.diagnose.zs,
  629. presentIllness: vo.diagnose.xb,
  630. historyIllness: vo.diagnose.jw,
  631. familyHistory: vo.diagnose.jz,
  632. allergyHistory: vo.diagnose.gw,
  633. checkInspectionComplement: vo.examination.description,
  634. checkInspectionResultList: checkResults.length > 0 ? checkResults : void 0,
  635. westernMedicine: westernPrimary?.name,
  636. westernMedicineCode: westernPrimary?.id,
  637. westernOtherMedicine:
  638. westernOther.names.length > 0 ? westernOther.names : void 0,
  639. westernOtherMedicineCode:
  640. westernOther.codes.length > 0 ? westernOther.codes : void 0,
  641. ...(tcmItems.length === 1
  642. ? {
  643. chineseMedicineName: tcmUnzipped.names[0],
  644. chineseMedicineCode: tcmUnzipped.codes[0],
  645. }
  646. : {
  647. tcmDiagnosis: tcmUnzipped.names,
  648. tcmDiagnosisCode: tcmUnzipped.codes,
  649. }),
  650. tcmPattern: symptom.names.length > 0 ? symptom.names : void 0,
  651. tcmPatternCode: symptom.codes.length > 0 ? symptom.codes : void 0,
  652. healthEducation: vo.treatment.healthEducation,
  653. wmPrescriptions: vo.treatment.westernRecipe?.medicines?.map((item) => ({
  654. drugName: item.name,
  655. quantity: item.dosage,
  656. unit: item.unit,
  657. specifications: item.size,
  658. dosage:
  659. item.singleDose === undefined && !item.singleUnit
  660. ? void 0
  661. : (() =>
  662. item.singleDose === undefined
  663. ? item.singleUnit
  664. : `${item.singleDose}${item.singleUnit ?? ''}`)(),
  665. frequency: item.frequency,
  666. useDays: item.usageDays,
  667. })),
  668. tcmPrescription: recipe
  669. ? {
  670. dosage: recipe.count,
  671. dosageForm: recipe.type,
  672. prescriptionUsage: recipe.usage,
  673. thickFriedTime: recipe.volume,
  674. frequency: recipe.frequency,
  675. medicationTime: recipe.frequencyTime,
  676. entrust: recipe.advice,
  677. }
  678. : void 0,
  679. tcmPrescriptionDetails: recipe?.medicines?.map((item) => ({
  680. drugName: item.name,
  681. dose: item.dosage,
  682. drugUsage: item.usage,
  683. })),
  684. ...(nondrugTreatments.length > 0 ? { nondrugTreatments } : {}),
  685. sourceCode: vo.meta?.source?.code,
  686. resource: vo.meta?.source?.type,
  687. calibrateStatus: vo.meta?.mark?.status,
  688. calibrateCode: vo.meta?.mark?.code,
  689. } as any;
  690. };
  691. export const encodeMedicalCaseQuery = (query: Record<string, any>): any => {
  692. const values = {} as any;
  693. if (query.operatedBy?.type === '1')
  694. values.createUser = query.operatedBy.value;
  695. if (query.operatedBy?.type === '2')
  696. values.calibrateName = query.operatedBy.value;
  697. if (
  698. query.operatedAt?.type === '1' &&
  699. Array.isArray(query.operatedAt?.value)
  700. ) {
  701. values.createBeginTime = isDayjs(query.operatedAt.value[0])
  702. ? query.operatedAt.value[0].startOf('day').format('YYYY-MM-DD HH:mm:ss')
  703. : query.operatedAt?.value[0];
  704. values.createEndTime = isDayjs(query.operatedAt.value[1])
  705. ? query.operatedAt.value[1].endOf('day').format('YYYY-MM-DD HH:mm:ss')
  706. : query.operatedAt?.value[1];
  707. }
  708. if (
  709. query.operatedAt?.type === '2' &&
  710. Array.isArray(query.operatedAt?.value)
  711. ) {
  712. values.calibrateBeginTime = isDayjs(query.operatedAt.value[0])
  713. ? query.operatedAt.value[0].startOf('day').format('YYYY-MM-DD HH:mm:ss')
  714. : query.operatedAt?.value[0];
  715. values.calibrateEndTime = isDayjs(query.operatedAt.value[1])
  716. ? query.operatedAt.value[1].endOf('day').format('YYYY-MM-DD HH:mm:ss')
  717. : query.operatedAt?.value[1];
  718. }
  719. if (Array.isArray(query.visitTime)) {
  720. values.visitBeginTime = isDayjs(query.visitTime[0])
  721. ? query.visitTime[0].startOf('day').format('YYYY-MM-DD HH:mm:ss')
  722. : query.visitTime[0];
  723. values.visitEndTime = isDayjs(query.visitTime[1])
  724. ? query.visitTime[1].endOf('day').format('YYYY-MM-DD HH:mm:ss')
  725. : query.visitTime[1];
  726. }
  727. return {
  728. ...values,
  729. specificId: query.specialDiseaseId,
  730. westernMedicineCodeList: query.icd_10,
  731. chineseMedicineCodeList: query.disease,
  732. calibrateStatus: query.markStatus ?? query.meta?.mark?.status,
  733. caseCode: query.caseCode,
  734. };
  735. };