| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- import {
- analysisPictureStrategy,
- type HealthReportAnalysisCategory,
- HealthReportAnalysisItemConfig,
- type HealthReportAnalysisKey,
- type HealthReportAnalysisSubcategory,
- HealthReportSymptomItemConfig,
- } from '@/model/health-report-analysis.config';
- export interface HealthReportAnalysisItemDTO {
- standardValue: string;
- actualList: {
- splitImage: string;
- actualValue: string;
- contrast: string;
- attrs: string[];
- features: string;
- clinicalSignificance?: string;
- mechanismAnalyze?: string;
- }[];
- }
- export interface HealthReportDTO extends Record<HealthReportAnalysisKey, HealthReportAnalysisItemDTO>, Record<`${HealthReportAnalysisCategory}AnalysisResult`, string> {
- tonguefaceAnalysisReportId: string;
- healthAnalysisReportId: string;
- reportTime: string;
- time4: 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 interface HealthReportAnalysisItemVO {
- category: HealthReportAnalysisCategory;
- subcategory: HealthReportAnalysisSubcategory;
- standardValue: string;
- resultValue: string;
- values: {
- cover?: string;
- contrast: string;
- actualValue: string;
- resultValue: string;
- tags: string[];
- /**
- * 特征
- */
- feature: string;
- /**
- * 意义
- * @description
- * - tongue 临床意义
- * - face 病理意义
- */
- significance: string;
- /**
- * 机理分析
- */
- analysis?: string;
- }[];
- }
- export interface HealthReportAnalysisVO
- extends Record<
- HealthReportAnalysisCategory,
- {
- result: string;
- analysis: HealthReportAnalysisItemVO[];
- pictures: string[];
- }
- > {
- id?: string;
- }
- 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 HealthReportVO {
- id: string;
- date: string;
- analysis: HealthReportAnalysisVO;
- symptom: HealthReportSymptomVo;
- result: {
- status?: string;
- level?: string;
- description?: string;
- category: string;
- };
- physique: {
- label: string;
- description: string;
- };
- syndrome: {
- label: string;
- };
- syndromeElement: {
- label: string;
- };
- }
- export function fromHealthReport(data: HealthReportDTO): HealthReportVO {
- return {
- id: data.healthAnalysisReportId,
- date: data.reportTime ?? data.time4,
- analysis: fromHealthReportAnalysis(data),
- symptom: fromHealthReportSymptom(data),
- result: {
- status: data.willillStateName,
- level: data.willillDegreeName,
- description: data.willillFunctionName,
- category: data.willillSocialName,
- },
- physique: {
- label: data.constitutionGroupName,
- description: data.constitutionGroupDefinition,
- },
- syndromeElement: {
- label: data.factorItemSummary,
- },
- syndrome: {
- label: data.diagnoseSyndromeSummary,
- },
- };
- }
- export function fromHealthReportAnalysis(data: Partial<HealthReportDTO>, config = HealthReportAnalysisItemConfig): HealthReportAnalysisVO {
- const result = { id: data.tonguefaceAnalysisReportId } as HealthReportAnalysisVO;
- for (const { key, category, subcategory } of config) {
- const { analysis } =
- result[category] ??
- (result[category] = {
- analysis: [],
- result: data[`${category}AnalysisResult`] ?? '',
- pictures: analysisPictureStrategy[category]?.(data) ?? [],
- });
- if (!data[key]) continue;
- const { standardValue, actualList } = data[key]!;
- const values: HealthReportAnalysisItemVO['values'] = [];
- for (const { actualValue, splitImage: cover, ...item } of actualList) {
- const contrast = item.contrast === 's' ? '' : (item.contrast ?? '');
- const [_, features = _, significance = item.clinicalSignificance] = item.features?.match?.(
- new RegExp(`【(?:${actualValue}|正常${subcategory}|正常面色)】([^<]*)<?[\\s\\S]*?【病理意义】([^<]*)`)
- ) ?? item.features?.match?.(
- new RegExp(`([^<]*)<?[\\s\\S]*?【病理意义】([^<]*)`)
- ) ?? [item.features];
- values.push({
- cover: contrast ? cover : void 0,
- actualValue,
- // resultValue: contrast && contrast !=='r' ? `${actualValue} (${contrast})` : actualValue,
- resultValue: contrast ? `${actualValue} (${contrast})` : actualValue,
- contrast,
- feature: features ?? '',
- significance: significance ?? '',
- tags: item.attrs ?? [],
- analysis: item.mechanismAnalyze ?? '',
- });
- }
- analysis.push({
- category,
- subcategory,
- standardValue,
- resultValue: values.map((item) => item.resultValue).join('、'),
- values,
- });
- }
- return result;
- }
- export function fromHealthReportSymptom(data: Partial<HealthReportDTO>, 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;
- }
- export interface HealthIndicatorVO {
- items: HealthIndicatorItemVO[];
- id: string;
- name: string;
- }
- export interface HealthIndicatorItemVO {
- id: string;
- name: string;
- value: number;
- unit: string;
- trend: 0 | -1 | 1;
- date: string;
- }
- export function fromHealthIndicator(data: Record<string, any>): HealthIndicatorVO {
- return {
- id: data.quotaId,
- name: data.name,
- items: data.patientQuotaRecordDTOS?.map?.((item: any) => fromHealthIndicatorItem(Object.assign(item, data))) ?? [],
- };
- }
- export function fromHealthIndicatorItem(data: Record<string, any>): HealthIndicatorItemVO {
- const getTrend = (value: string) => {
- if (value?.includes('高')) return 1 as const;
- if (value?.includes('低')) return -1 as const;
- return 0 as const;
- };
- return {
- id: data.quotaId,
- name: data.name,
- unit: data.unit,
- value: data.quotaVal,
- trend: data.abnormal ? getTrend(data.abnormalDesc) : 0,
- date: data.time4 || data.time2,
- };
- }
|