| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781 |
- import type { AuditRecordVO } from '#/request/schema/audit-record';
- import { isDayjs } from 'dayjs';
- import { decodeAuditRecord } from '#/request/schema/audit-record';
- // ===========================================================================
- // DTO — 嵌套
- // ===========================================================================
- /** 检查检验项目和结果 DTO,对应 OpenAPI `MrCheckInspectionResult` */
- interface CaseCheckInspectionResultDTO {
- /** 项目名称 */
- itemName?: string;
- /** 结果 */
- result?: string;
- /** 类型 1检查 2检验 */
- itemType?: number;
- }
- /** 西药/中成药处方 DTO,对应 OpenAPI `MrWmPrescription` */
- interface CaseWmPrescriptionDTO {
- /** 药品名称 */
- drugName?: string;
- /** 数量 */
- quantity?: number;
- /** 数量单位 */
- unit?: string;
- /** 规格 */
- specifications?: string;
- /** 单次用量 */
- dosage?: string;
- /** 使用频率 */
- frequency?: string;
- /** 使用天数 */
- useDays?: number;
- }
- /** 中药处方 DTO,对应 OpenAPI `MrTcmPrescription` */
- interface CaseTcmPrescriptionDTO {
- /** 剂数 */
- dosage?: string;
- /** 剂型 */
- dosageForm?: string;
- /** 处方用法 */
- prescriptionUsage?: string;
- /** 浓煎每次量 */
- thickFriedTime?: string;
- /** 频次 */
- frequency?: string;
- /** 服药时间 */
- medicationTime?: string;
- /** 嘱托 */
- entrust?: string;
- }
- /** 中药处方药品明细 DTO,对应 OpenAPI `MrTcmPrescriptionDetail` */
- interface CaseTcmPrescriptionDetailDTO {
- /** 药品名称 */
- drugName?: string;
- /** 剂量g */
- dose?: number;
- /** 用法 */
- drugUsage?: string;
- }
- /** 中/西医非药物治疗 DTO,对应 OpenAPI `MrNondrugTreatment` */
- interface CaseNondrugTreatmentDTO {
- /** 名称 */
- itemName?: string;
- /** 数量 */
- quantity?: string;
- /** 类型 1-西医 2-中医 */
- itemType?: number;
- }
- // ===========================================================================
- // DTO — 主类型
- // ===========================================================================
- /**
- * 医案病历 DTO
- * @remarks 对应 OpenAPI `MedicalRecordGrowDetail`
- */
- export interface SpecialDiseaseCaseDTO {
- /** 主键 ID */
- pid?: number | string;
- /** 专病 ID */
- specificId: number | string;
- /** 病历编号 */
- caseCode?: string;
- /** 来源病历编号 */
- sourceCode?: string;
- /** 就诊日期 */
- visitTime?: string;
- /** 性别 1-男 2-女 */
- gender?: string;
- /** 年龄 */
- age?: string;
- /** 年龄月 */
- ageMonth?: string;
- /** 年龄天 */
- ageDay?: string;
- /** 诊次 */
- diagnosisTimes?: string;
- /** 主诉 */
- chiefComplaint?: string;
- /** 现病史 */
- presentIllness?: string;
- /** 既往史 */
- historyIllness?: string;
- /** 家族史 */
- familyHistory?: string;
- /** 过敏史 */
- allergyHistory?: string;
- /** 检查检验结果补充 */
- checkInspectionComplement?: string;
- /** 西医诊断名称 */
- westernMedicine?: string;
- /** 西医诊断编码 */
- westernMedicineCode?: string;
- /** 西医其他诊断名称 */
- westernOtherMedicine?: string[];
- /** 西医其他诊断编码 */
- westernOtherMedicineCode?: string[];
- /** 中医诊断名称 */
- tcmDiagnosis?: string[];
- /** 中医诊断编码 */
- tcmDiagnosisCode?: string[];
- /** 中医诊断编码 */
- chineseMedicineCode?: string;
- /** 中医诊断名称 */
- chineseMedicineName?: string;
- /** 中医证型名称 */
- tcmPattern?: string[];
- /** 中医证型编码 */
- tcmPatternCode?: string[];
- /** 健康教育 */
- healthEducation?: string;
- /** 检查检验项目和结果 */
- checkInspectionResultList?: CaseCheckInspectionResultDTO[];
- /** 西药/中成药处方 */
- wmPrescriptions?: CaseWmPrescriptionDTO[];
- /** 中药处方 */
- tcmPrescription?: CaseTcmPrescriptionDTO;
- /** 中药处方药品明细 */
- tcmPrescriptionDetails?: CaseTcmPrescriptionDetailDTO[];
- /** 中/西医非药物治疗 */
- nondrugTreatments?: CaseNondrugTreatmentDTO[];
- /** 病历来源 1-新增 2-导入 3-接口 */
- resource?: string;
- /** 标定状态 1-待标定 2-暂存 3-标定完成 */
- calibrateStatus?: string;
- /** 标定编号 */
- calibrateCode?: string;
- /** 标定者 */
- calibrateName?: string;
- /** 标定时间 */
- calibrateTime?: string;
- /** 创建者 */
- createUser?: string;
- /** 来源创建者 */
- sourceCreateUser?: string;
- /** 创建时间 */
- createTime?: string;
- /** 来源创建时间 */
- sourceCreateTime?: string;
- /** 更新者 */
- updateUser?: string;
- /** 更新时间 */
- updateTime?: string;
- }
- // ===========================================================================
- // VO — 公共
- // ===========================================================================
- /** 编码名称对 */
- export interface CaseCodeNameVO {
- /** 编码 */
- id?: string;
- /** 名称 */
- name?: string;
- }
- /** 患者年龄 */
- interface CaseAgesVO {
- /** 岁,-> `age` */
- year: number;
- /** 月,-> `ageMonth` */
- month: number;
- /** 天,-> `ageDay` */
- day: number;
- }
- // ===========================================================================
- // VO — 嵌套(叶子)
- // ===========================================================================
- /** 检查检验项目和结果 VO */
- export interface CaseCheckInspectionResultVO {
- id?: string;
- /** 项目名称,-> `itemName` */
- name?: string;
- /** 结果,-> `result` */
- value?: string;
- /** 类型 1检查 2检验,-> `itemType` */
- type?: '1' | '2';
- }
- /** 西药/中成药处方 VO */
- export interface CaseWesternMedicineVO {
- id?: string;
- /** 药品名称,-> `drugName` */
- name?: string;
- /** 数量,-> `quantity` */
- dosage?: number;
- /** 数量单位,-> `unit` */
- unit?: string;
- /** 规格,-> `specifications` */
- size?: string;
- /** 单次用量,-> `dosage` */
- singleDose?: number;
- /** 单次用量单位 */
- singleUnit?: string;
- /** 使用频率,-> `frequency` */
- frequency?: string;
- /** 使用天数,-> `useDays` */
- usageDays?: number;
- }
- /** 中药处方 VO */
- interface CaseTraditionalRecipeVO {
- /** 剂数,-> `dosage` */
- count?: string;
- /** 剂型,-> `dosageForm` */
- type?: string;
- /** 处方用法,-> `prescriptionUsage` */
- usage?: string;
- /** 浓煎每次量,-> `thickFriedTime` */
- volume?: string;
- /** 频次,-> `frequency` */
- frequency?: string;
- /** 服药时间,-> `medicationTime` */
- frequencyTime?: string;
- /** 嘱托,-> `entrust` */
- advice?: string;
- }
- /** 中药处方药品明细 VO */
- export interface CaseTraditionalMedicineVO {
- id?: string;
- /** 药品名称,-> `drugName` */
- name?: string;
- /** 剂量,-> `dose` */
- dosage?: number;
- /** 单位,默认 g */
- unit?: string;
- /** 用法,-> `drugUsage` */
- usage?: string;
- }
- /** 中/西医非药物治疗 VO */
- export interface CaseNondrugTreatmentVO {
- id?: string;
- /** 名称,-> `itemName` */
- name?: string;
- /** 数量,-> `quantity` (quantity + unit) */
- value?: string;
- /** 数量,-> `quantity` */
- quantity?: number;
- /** 单位 */
- unit?: string;
- /** 类型 1-西医 2-中医,-> `itemType` */
- type?: '1' | '2';
- }
- // ===========================================================================
- // VO — 嵌套(业务大类)
- // ===========================================================================
- /** 患者信息 */
- interface CasePatientVO {
- /** 性别 1-男 2-女,-> `gender` */
- gender?: '1' | '2';
- /** 年龄,-> `age` / `ageMonth` / `ageDay` */
- ages: CaseAgesVO;
- }
- /** 病史 / 主诉 */
- interface CaseDiagnoseVO {
- /** 诊次,-> `diagnosisTimes` */
- order?: string;
- /** 就诊日期,-> `visitTime` YYYY-MM-DD */
- date?: string;
- /** 就诊日期,-> `visitTime` YYYY-MM-DD HH:mm:ss */
- datetime?: string;
- /** 主诉,-> `chiefComplaint` */
- zs?: string;
- /** 现病史,-> `presentIllness` */
- xb?: string;
- /** 既往史,-> `historyIllness` */
- jw?: string;
- /** 家族史,-> `familyHistory` */
- jz?: string;
- /** 过敏史,-> `allergyHistory` */
- gw?: string;
- }
- /** 检验检查 */
- interface CaseExaminationVO {
- /** 检查检验结果补充,-> `checkInspectionComplement` */
- description?: string;
- /** 检查,-> `checkInspectionResultList`(itemType=1) */
- inspection?: CaseCheckInspectionResultVO[];
- /** 检验,-> `checkInspectionResultList`(itemType=2) */
- checkout?: CaseCheckInspectionResultVO[];
- }
- /** 疾病诊断 */
- interface CaseIllnessVO {
- /** 西医诊断,-> `westernMedicine` / `westernOtherMedicine` */
- icd_10?: CaseCodeNameVO[];
- /** 中医诊断,-> `tcmDiagnosis` / `chineseMedicineName` */
- disease?: CaseCodeNameVO[];
- /** 中医证型,-> `tcmPattern` */
- symptom?: CaseCodeNameVO[];
- }
- /** 处置 */
- interface CaseTreatmentVO {
- /** 健康教育,-> `healthEducation` */
- healthEducation?: string;
- /** 西医处置,-> `wmPrescriptions` / `nondrugTreatments`(itemType=1) */
- westernRecipe?: {
- cure: CaseNondrugTreatmentVO[];
- medicines: CaseWesternMedicineVO[];
- };
- /** 中医处置,-> `tcmPrescription` / `tcmPrescriptionDetails` / `nondrugTreatments`(itemType=2) */
- traditionalRecipe?: CaseTraditionalRecipeVO & {
- cure: CaseNondrugTreatmentVO[];
- medicines: CaseTraditionalMedicineVO[];
- };
- }
- /** 来源信息 */
- interface CaseMetaSourceVO {
- /** 来源病历编号,-> `sourceCode` */
- code?: string;
- /** 病历来源 1-新增 2-导入 3-接口,-> `resource` */
- type?: string;
- /** 操作人,-> `sourceCreateUser` */
- operatedBy?: string;
- /** 操作时间,-> `sourceCreateTime` */
- operatedAt?: string;
- }
- /** 标定信息 */
- interface CaseMetaMarkVO {
- /** 标定状态 1-待标定 2-暂存 3-标定完成,-> `calibrateStatus` */
- status?: string;
- /** 标定编号,-> `calibrateCode` */
- code?: string;
- /** 操作人,-> `calibrateName` */
- operatedBy?: string;
- /** 操作时间,-> `calibrateTime` */
- operatedAt?: string;
- }
- /** 数据集信息(预留) */
- interface CaseMetaDatasetVO {
- /** 所属数据集 ID(预留) */
- id?: string;
- /** 操作人(预留) */
- operatedBy?: string;
- /** 操作时间(预留) */
- operatedAt?: string;
- }
- /** 典型病历信息(预留) */
- interface CaseMetaTypicalVO {
- /** 所属典型病历 ID(预留) */
- id?: string;
- /** 操作人(预留) */
- operatedBy?: string;
- /** 操作时间(预留) */
- operatedAt?: string;
- }
- /** 病历元信息 */
- interface CaseMetaVO {
- source: CaseMetaSourceVO;
- mark: CaseMetaMarkVO;
- dataset: CaseMetaDatasetVO;
- typical: CaseMetaTypicalVO;
- }
- // ===========================================================================
- // VO — 主类型
- // ===========================================================================
- /**
- * 医案病历 VO
- * @remarks 对应 OpenAPI `MedicalRecordGrowDetail`
- */
- export interface MedicalCaseVO extends AuditRecordVO {
- /** 主键 ID,-> `pid` */
- id?: string;
- /** 专病 ID,-> `specificId` */
- specialDiseaseId: string;
- /** 病历编号,-> `caseCode` */
- code?: string;
- patient: CasePatientVO;
- diagnose: CaseDiagnoseVO;
- examination: CaseExaminationVO;
- illness: CaseIllnessVO;
- treatment: CaseTreatmentVO;
- meta: CaseMetaVO;
- }
- export interface MedicalCaseModel extends Pick<
- MedicalCaseVO,
- 'code' | 'id' | 'specialDiseaseId'
- > {
- patient: Omit<CasePatientVO, 'ages'> & { ages: Partial<CaseAgesVO> };
- diagnose: Partial<CaseDiagnoseVO>;
- examination: Partial<CaseExaminationVO> & {
- items: CaseCheckInspectionResultVO[];
- };
- illness: Partial<CaseIllnessVO> & {
- items: (CaseCodeNameVO & { type?: keyof CaseIllnessVO })[];
- };
- treatment: Partial<CaseTreatmentVO> & {
- cure: CaseNondrugTreatmentVO[];
- traditionalRecipe: Partial<CaseTraditionalRecipeVO> & {
- cure: CaseNondrugTreatmentVO[];
- medicines: CaseTraditionalMedicineVO[];
- };
- westernRecipe: {
- cure: CaseNondrugTreatmentVO[];
- medicines: CaseWesternMedicineVO[];
- };
- };
- }
- // ===========================================================================
- // 编解码
- // ===========================================================================
- const zipCodeName = (codes?: string[], names?: string[]): CaseCodeNameVO[] => {
- const codeList = codes ?? [];
- const nameList = names ?? [];
- const length = Math.max(codeList.length, nameList.length);
- if (!length) return [];
- return Array.from({ length }, (_, index) => ({
- id: codeList[index],
- name: nameList[index],
- }));
- };
- const unzipCodeName = (items?: CaseCodeNameVO[]) => {
- const list = items ?? [];
- return {
- codes: list.map((item) => item.id).filter(Boolean) as string[],
- names: list.map((item) => item.name).filter(Boolean) as string[],
- };
- };
- export const decodeSpecialDiseaseCase = (
- dto: SpecialDiseaseCaseDTO,
- ): MedicalCaseVO => {
- const toNumber = (value?: number | string) => {
- if (value === undefined || value === null || value === '') return void 0;
- const parsed = Number(value);
- return Number.isFinite(parsed) ? parsed : void 0;
- };
- const toAgePart = (value?: string) => toNumber(value) ?? 0;
- const westernPrimary: CaseCodeNameVO[] =
- dto.westernMedicine || dto.westernMedicineCode
- ? [{ id: dto.westernMedicineCode, name: dto.westernMedicine }]
- : [];
- const tcmFromArrays = zipCodeName(dto.tcmDiagnosisCode, dto.tcmDiagnosis);
- const tcmIllness =
- tcmFromArrays.length > 0
- ? tcmFromArrays
- : (() =>
- dto.chineseMedicineName || dto.chineseMedicineCode
- ? [
- {
- id: dto.chineseMedicineCode,
- name: dto.chineseMedicineName,
- },
- ]
- : [])();
- const checkResults =
- dto.checkInspectionResultList?.map((item) => ({
- name: item.itemName,
- value: item.result,
- type: item.itemType === 1 ? '1' : '2',
- })) ?? [];
- const nondrug =
- dto.nondrugTreatments?.map((item) => ({
- name: item.itemName,
- quantity: toNumber(item.quantity),
- type: item.itemType?.toString(),
- })) ?? [];
- const traditionalMedicines =
- dto.tcmPrescriptionDetails?.map((item) => ({
- name: item.drugName,
- dosage: item.dose,
- unit: 'g',
- usage: item.drugUsage,
- })) ?? [];
- const traditionalCure = nondrug.filter(
- (item) => item.type?.toString() === '2',
- );
- const hasTraditional =
- dto.tcmPrescription ||
- traditionalMedicines.length > 0 ||
- traditionalCure.length > 0;
- return {
- ...decodeAuditRecord({
- createBy: dto.createUser,
- createTime: dto.createTime,
- updateBy: dto.updateUser,
- updateTime: dto.updateTime,
- }),
- id: dto.pid?.toString(),
- specialDiseaseId: dto.specificId?.toString() ?? '',
- code: dto.caseCode,
- patient: {
- gender: dto.gender === '1' || dto.gender === '2' ? dto.gender : void 0,
- ages: {
- year: toAgePart(dto.age),
- month: toAgePart(dto.ageMonth),
- day: toAgePart(dto.ageDay),
- },
- },
- diagnose: {
- order: dto.diagnosisTimes,
- date: dto.visitTime?.slice(0, 10),
- datetime: dto.visitTime,
- zs: dto.chiefComplaint,
- xb: dto.presentIllness,
- jw: dto.historyIllness,
- jz: dto.familyHistory,
- gw: dto.allergyHistory,
- },
- examination: {
- description: dto.checkInspectionComplement,
- inspection: checkResults.filter(
- (item) => item.type?.toString() === '1',
- ) as any,
- checkout: checkResults.filter(
- (item) => item.type?.toString() === '2',
- ) as any,
- },
- illness: {
- icd_10: [
- ...westernPrimary,
- ...zipCodeName(dto.westernOtherMedicineCode, dto.westernOtherMedicine),
- ],
- disease: tcmIllness,
- symptom: zipCodeName(dto.tcmPatternCode, dto.tcmPattern),
- },
- treatment: {
- healthEducation: dto.healthEducation,
- westernRecipe: {
- cure: nondrug.filter((item) => item.type?.toString() === '1') as any,
- medicines:
- dto.wmPrescriptions?.map((item) => {
- const dosage = item.dosage;
- const parsed = dosage ? Number(dosage) : void 0;
- const matched = dosage?.match(/^([\d.]+)(.*)$/);
- return {
- name: item.drugName,
- dosage: item.quantity,
- unit: item.unit,
- size: item.specifications,
- singleDose: Number.isFinite(parsed)
- ? parsed
- : // eslint-disable-next-line unicorn/no-unreadable-iife
- (() => (matched ? Number(matched[1]) : void 0))(),
- singleUnit: Number.isFinite(parsed)
- ? void 0
- : // eslint-disable-next-line unicorn/no-unreadable-iife
- (() => (matched ? matched[2] || void 0 : dosage))(),
- frequency: item.frequency,
- usageDays: item.useDays,
- };
- }) ?? [],
- },
- traditionalRecipe: hasTraditional
- ? ({
- count: dto.tcmPrescription?.dosage,
- type: dto.tcmPrescription?.dosageForm,
- usage: dto.tcmPrescription?.prescriptionUsage,
- volume: dto.tcmPrescription?.thickFriedTime,
- frequency: dto.tcmPrescription?.frequency,
- frequencyTime: dto.tcmPrescription?.medicationTime,
- advice: dto.tcmPrescription?.entrust,
- cure: traditionalCure,
- medicines: traditionalMedicines,
- } as any)
- : void 0,
- },
- meta: {
- source: {
- code: dto.sourceCode,
- type: dto.resource,
- operatedBy: dto.sourceCreateUser,
- operatedAt: dto.sourceCreateTime,
- },
- mark: {
- status: dto.calibrateStatus,
- code: dto.calibrateCode,
- operatedBy: dto.calibrateName,
- operatedAt: dto.calibrateTime,
- },
- dataset: {},
- typical: {},
- },
- };
- };
- export const encodeSpecialDiseaseCase = (
- vo: MedicalCaseVO,
- ): SpecialDiseaseCaseDTO => {
- const [westernPrimary, ...westernOthers] = vo.illness.icd_10 ?? [];
- const westernOther = unzipCodeName(westernOthers);
- const tcmItems = vo.illness.disease ?? [];
- const tcmUnzipped = unzipCodeName(tcmItems);
- const symptom = unzipCodeName(vo.illness.symptom);
- const checkResults = [
- ...(vo.examination.inspection ?? []),
- ...(vo.examination.checkout ?? []),
- ].map((item) => ({
- itemName: item.name,
- result: item.value,
- itemType: item.type === '1' ? 1 : 2,
- }));
- const westernCure = vo.treatment.westernRecipe?.cure ?? [];
- const traditionalCure = vo.treatment.traditionalRecipe?.cure ?? [];
- const recipe = vo.treatment.traditionalRecipe;
- const nondrugTreatments = [...westernCure, ...traditionalCure].map(
- (item) => ({
- itemName: item.name,
- quantity: item.value,
- itemType: item.type,
- }),
- );
- return {
- pid: vo.id,
- specificId: vo.specialDiseaseId,
- caseCode: vo.code,
- createUser: vo.createdBy,
- createTime: vo.createdAt,
- updateUser: vo.updatedBy,
- updateTime: vo.updatedAt,
- gender: vo.patient.gender,
- age: String(vo.patient.ages.year ?? 0),
- ageMonth: String(vo.patient.ages.month ?? 0),
- ageDay: String(vo.patient.ages.day ?? 0),
- diagnosisTimes: vo.diagnose.order,
- visitTime: vo.diagnose.datetime || vo.diagnose.date,
- chiefComplaint: vo.diagnose.zs,
- presentIllness: vo.diagnose.xb,
- historyIllness: vo.diagnose.jw,
- familyHistory: vo.diagnose.jz,
- allergyHistory: vo.diagnose.gw,
- checkInspectionComplement: vo.examination.description,
- checkInspectionResultList: checkResults.length > 0 ? checkResults : void 0,
- westernMedicine: westernPrimary?.name,
- westernMedicineCode: westernPrimary?.id,
- westernOtherMedicine:
- westernOther.names.length > 0 ? westernOther.names : void 0,
- westernOtherMedicineCode:
- westernOther.codes.length > 0 ? westernOther.codes : void 0,
- ...(tcmItems.length === 1
- ? {
- chineseMedicineName: tcmUnzipped.names[0],
- chineseMedicineCode: tcmUnzipped.codes[0],
- }
- : {
- tcmDiagnosis: tcmUnzipped.names,
- tcmDiagnosisCode: tcmUnzipped.codes,
- }),
- tcmPattern: symptom.names.length > 0 ? symptom.names : void 0,
- tcmPatternCode: symptom.codes.length > 0 ? symptom.codes : void 0,
- healthEducation: vo.treatment.healthEducation,
- wmPrescriptions: vo.treatment.westernRecipe?.medicines?.map((item) => ({
- drugName: item.name,
- quantity: item.dosage,
- unit: item.unit,
- specifications: item.size,
- dosage:
- item.singleDose === undefined && !item.singleUnit
- ? void 0
- : (() =>
- item.singleDose === undefined
- ? item.singleUnit
- : `${item.singleDose}${item.singleUnit ?? ''}`)(),
- frequency: item.frequency,
- useDays: item.usageDays,
- })),
- tcmPrescription: recipe
- ? {
- dosage: recipe.count,
- dosageForm: recipe.type,
- prescriptionUsage: recipe.usage,
- thickFriedTime: recipe.volume,
- frequency: recipe.frequency,
- medicationTime: recipe.frequencyTime,
- entrust: recipe.advice,
- }
- : void 0,
- tcmPrescriptionDetails: recipe?.medicines?.map((item) => ({
- drugName: item.name,
- dose: item.dosage,
- drugUsage: item.usage,
- })),
- ...(nondrugTreatments.length > 0 ? { nondrugTreatments } : {}),
- sourceCode: vo.meta?.source?.code,
- resource: vo.meta?.source?.type,
- calibrateStatus: vo.meta?.mark?.status,
- calibrateCode: vo.meta?.mark?.code,
- } as any;
- };
- export const encodeMedicalCaseQuery = (query: Record<string, any>): any => {
- const values = {} as any;
- if (query.operatedBy?.type === '1')
- values.createUser = query.operatedBy.value;
- if (query.operatedBy?.type === '2')
- values.calibrateName = query.operatedBy.value;
- if (
- query.operatedAt?.type === '1' &&
- Array.isArray(query.operatedAt?.value)
- ) {
- values.createBeginTime = isDayjs(query.operatedAt.value[0])
- ? query.operatedAt.value[0].startOf('day').format('YYYY-MM-DD HH:mm:ss')
- : query.operatedAt?.value[0];
- values.createEndTime = isDayjs(query.operatedAt.value[1])
- ? query.operatedAt.value[1].endOf('day').format('YYYY-MM-DD HH:mm:ss')
- : query.operatedAt?.value[1];
- }
- if (
- query.operatedAt?.type === '2' &&
- Array.isArray(query.operatedAt?.value)
- ) {
- values.calibrateBeginTime = isDayjs(query.operatedAt.value[0])
- ? query.operatedAt.value[0].startOf('day').format('YYYY-MM-DD HH:mm:ss')
- : query.operatedAt?.value[0];
- values.calibrateEndTime = isDayjs(query.operatedAt.value[1])
- ? query.operatedAt.value[1].endOf('day').format('YYYY-MM-DD HH:mm:ss')
- : query.operatedAt?.value[1];
- }
- if (Array.isArray(query.visitTime)) {
- values.visitBeginTime = isDayjs(query.visitTime[0])
- ? query.visitTime[0].startOf('day').format('YYYY-MM-DD HH:mm:ss')
- : query.visitTime[0];
- values.visitEndTime = isDayjs(query.visitTime[1])
- ? query.visitTime[1].endOf('day').format('YYYY-MM-DD HH:mm:ss')
- : query.visitTime[1];
- }
- return {
- ...values,
- specificId: query.specialDiseaseId,
- westernMedicineCodeList: query.icd_10,
- chineseMedicineCodeList: query.disease,
- calibrateStatus: query.markStatus ?? query.meta?.mark?.status,
- caseCode: query.caseCode,
- };
- };
|