export const formatTime = (date: Date) => { const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() return ( [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') ) } const formatNumber = (n: number) => { const s = n.toString() return s[1] ? s : '0' + s } export function groupBy(items: Iterable, callbackFn: (element: T, index: number) => any): Record { const obj = Object.create(null); let k = 0; for (const value of items) { const key = callbackFn(value, k++); if (key in obj) { obj[key].push(value); } else { obj[key] = [value]; } } return obj; } export const HealthReportSymptomItemConfig = { 有一点: 2.0, 偶尔: 2.0, 轻: 2.0, 有些: 3.0, 有时: 3.0, 中: 3.0, 相当: 4.0, 经常: 4.0, 重: 4.0, 非常: 5.0, 总是: 5.0, 非常重: 5.0, } as const; export interface HealthReportSymptomItemVo { /** * 症状ID */ id: string; /** * 症状名称 */ name: string; /** * 症状描述 */ label: string; /** * 症状得分 */ value: number; } export interface HealthReportSymptomVo { items: HealthReportSymptomItemVo[]; value?: string; duration?: string; influence?: string; } export interface HealthReportDTO { tonguefaceAnalysisReportId: string; healthAnalysisReportId: string; reportTime: string; pickedSymptomList?: { id: string; name: string; value: string; score: number }[]; pickedSymptom?: string; duration?: string; influenceDegree?: string; willillStateName: string; willillDegreeName: string; willillFunctionName: string; willillSocialName: string; constitutionGroupName: string; constitutionGroupDefinition: string; factorItemSummary: string; diagnoseSyndromeSummary: string; } export function fromHealthReportSymptom(data: Partial, config = HealthReportSymptomItemConfig): HealthReportSymptomVo { const result: HealthReportSymptomVo = { value: data.pickedSymptom, items: data.pickedSymptomList?.map(({ id, name, ...item }) => ({ id, name, label: item.value, value: +item.score, })) ?? [], duration: data.duration, influence: data.influenceDegree, }; if (!result.items?.length && result.value) { const matches = result.value?.matchAll(/([^,(]+)(([^)]+))/g) ?? []; for (const [_, name, label] of matches) { // @ts-ignore const value = config[label] ?? 0; result.items.push({ id: name, name, label, value }); } } return result; }