|
|
@@ -1,93 +1,34 @@
|
|
|
function gather(
|
|
|
data: App.Health.Index.Data[],
|
|
|
- transform: (model: App.Health.Index.Model) => any,
|
|
|
+ transform: (model: App.Health.Index.Model, index?: number) => any,
|
|
|
skip = false,
|
|
|
- link = { 血压: [1, 2], }
|
|
|
+ // link = { 血压: ['收缩压', '舒张压'], }
|
|
|
+ link = {}
|
|
|
) {
|
|
|
const ref = ((link) => {
|
|
|
const ref: Record<string, { id: string; name: string; }> = {};
|
|
|
Object.entries(link).forEach(([name, keys]) => {
|
|
|
const _ = { id: name, name };
|
|
|
- keys.forEach(key => { ref[key] = _; })
|
|
|
+ (keys as AnyArray).forEach(key => { ref[key] = _; })
|
|
|
})
|
|
|
return ref;
|
|
|
})(link);
|
|
|
|
|
|
- const cache = new Map<{ id: string; name: string; }, App.Health.Index.Ruler[]>();
|
|
|
+ const cache = new Map<{ id: string; name: string; }, App.Health.Index.Chart[]>();
|
|
|
for (const item of data) {
|
|
|
if (skip && item.isAuto) continue;
|
|
|
const model = createHealthIndex(item);
|
|
|
- const _ = ref[model.id] ?? { id: model.id, name: model.name };
|
|
|
+ const _ = ref[model.name] ?? { id: model.id, name: model.name };
|
|
|
if (ref[model.id]) model.name = model.name.replace(_.name, '');
|
|
|
if (cache.has(_)) {
|
|
|
- cache.get(_)?.push(transform(model))
|
|
|
+ cache.get(_)?.push(transform(model, cache.get(_)?.length));
|
|
|
} else {
|
|
|
- cache.set(_, [transform(model)])
|
|
|
+ cache.set(_, [transform(model)]);
|
|
|
}
|
|
|
}
|
|
|
return [...cache].map(gather => ({ ...gather[0], options: gather[1] }))
|
|
|
}
|
|
|
|
|
|
-export function healthIndex2Ruler(model: App.Health.Index.Model): App.Health.Index.Ruler {
|
|
|
- let { scope, range, precision, values, ...ruler } = model;
|
|
|
- const min = range?.[0] ?? Math.floor(scope[0] * 0.5);
|
|
|
- const max = range?.[1] ?? Math.floor(scope[1] * 1.5);
|
|
|
- precision = ((diff) => {
|
|
|
- if (diff < 5) return 0.01;
|
|
|
- if (diff < 10) return 0.1;
|
|
|
- else return 1;
|
|
|
- })(max - min)
|
|
|
- return {
|
|
|
- ...ruler, min, max, precision,
|
|
|
- markLine: [
|
|
|
- { value: scope[0], style: {} },
|
|
|
- { value: scope[1], style: {} },
|
|
|
- ],
|
|
|
- value: values?.slice(-1)[0]?.value,
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-export function healthIndex2Progress(model: App.Health.Index.Model[]): AnyObject[] {
|
|
|
- return model.filter((item) => item.values?.length).map(item => {
|
|
|
- const { scope, range, values } = item;
|
|
|
- const { value, abnormal, description = '' } = values?.slice(-1)[0]!
|
|
|
- const length = range[1] - range[0];
|
|
|
-
|
|
|
- const scopeOffsetLeft = `${Math.floor((scope[0] - range[0]) * 100 / length)}%`;
|
|
|
- const scopeOffsetRight = `${100 - Math.floor((scope[1] - range[0]) * 100 / length)}%`;
|
|
|
-
|
|
|
- let valueOffset = Math.floor((value - range[0]) * 100 / length);
|
|
|
- let valueOffsetLeft = '0';
|
|
|
- let valueOffsetRight = '0';
|
|
|
- let valueType;
|
|
|
-
|
|
|
- if (value > scope[1]) {
|
|
|
- valueType = 'big';
|
|
|
- valueOffsetLeft = scopeOffsetLeft;
|
|
|
- valueOffsetRight = `${100 - valueOffset}%`;
|
|
|
- } else if (value < scope[0]) {
|
|
|
- valueType = 'small';
|
|
|
- valueOffsetLeft = `${valueOffset}%`;
|
|
|
- valueOffsetRight = scopeOffsetRight;
|
|
|
- } else {
|
|
|
- valueType = 'normal';
|
|
|
- valueOffsetLeft = scopeOffsetLeft;
|
|
|
- valueOffsetRight = scopeOffsetRight;
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- name: item.name, unit: item.unit,
|
|
|
- value, min: scope[0], max: scope[1],
|
|
|
- abnormal, description: description?.replace(item.name, ''),
|
|
|
- scopeOffsetLeft, scopeOffsetRight,
|
|
|
- valueType, valueOffset: `${valueOffset}%`,
|
|
|
- valueOffsetLeft, valueOffsetRight,
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
export function createHealthIndex(data: App.Health.Index.Data): App.Health.Index.Model {
|
|
|
const { quotaId: id, minVal, maxVal, inputMin, inputMax, inputPrecision, patientQuotaRecordDTOS, ...model } = data;
|
|
|
const scope = [+minVal, +maxVal] as const;
|
|
|
@@ -105,58 +46,64 @@ export function createHealthIndex(data: App.Health.Index.Data): App.Health.Index
|
|
|
} as App.Health.Index.Model
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-export function transformHealthIndex2Ruler(data: App.Health.Index.Data[]): { id: string, name: string, options: App.Health.Index.Ruler[] }[] {
|
|
|
- // const ref = ((link) => {
|
|
|
- // const ref: Record<string, { id: string; name: string; }> = {};
|
|
|
- // Object.entries(link).forEach(([name, keys]) => {
|
|
|
- // const _ = { id: name, name };
|
|
|
- // keys.forEach(key => { ref[key] = _; })
|
|
|
- // })
|
|
|
- // return ref;
|
|
|
- // })({ 血压: [1, 2], })
|
|
|
- // const cache = new Map<{ id: string; name: string; }, App.Health.Index.Ruler[]>();
|
|
|
- // for (const item of data) {
|
|
|
- // if (item.isAuto) continue;
|
|
|
- // const model = createHealthIndex(item);
|
|
|
- // const _ = ref[model.id] ?? { id: model.id, name: model.name };
|
|
|
- // if (ref[model.id]) model.name = model.name.replace(_.name, '');
|
|
|
- // if (cache.has(_)) {
|
|
|
- // cache.get(_)?.push(healthIndex2Ruler(model))
|
|
|
- // } else {
|
|
|
- // cache.set(_, [healthIndex2Ruler(model)])
|
|
|
- // }
|
|
|
- // }
|
|
|
- // return [...cache].map(gather => ({ ...gather[0], options: gather[1] }))
|
|
|
- return gather(data, healthIndex2Ruler, true);
|
|
|
-}
|
|
|
-
|
|
|
-export function healthIndex2Chart(model: App.Health.Index.Model): AnyObject {
|
|
|
- return {
|
|
|
+export function healthIndex2Chart(model: App.Health.Index.Model, index = 0): AnyObject {
|
|
|
+ const data = model.values?.map(t => [t.date, t.value]) ?? [];
|
|
|
+ const yAxis = {
|
|
|
+ name: model.unit,
|
|
|
+ nameTextStyle: { color: '#ccc' },
|
|
|
+ type: 'value', scale: true,
|
|
|
+ min: model.range[0],
|
|
|
+ max: Math.min(
|
|
|
+ model.range[1],
|
|
|
+ Math.floor(Math.max(model.scope[1], ...data.map((item: AnyArray) => item[1])) * 2)
|
|
|
+ ),
|
|
|
+ minInterval: model.precision >= 1 ? model.precision : void 0,
|
|
|
+ axisLine: { show: true }
|
|
|
+ }
|
|
|
+ const series = {
|
|
|
name: model.name,
|
|
|
+ yAxisIndex: 0,
|
|
|
type: 'line', smooth: true,
|
|
|
- data: model.values?.map(t => [t.date, t.value]),
|
|
|
+ data,
|
|
|
markLine: {
|
|
|
data: model.scope.map(value => { return { yAxis: value } })
|
|
|
}
|
|
|
}
|
|
|
+ const visualMap = {
|
|
|
+ show: false,
|
|
|
+ type: 'piecewise',
|
|
|
+ pieces: [
|
|
|
+ { gt: model.scope[1] },
|
|
|
+ { gte: model.scope[0], lte: model.scope[1] },
|
|
|
+ { lt: model.scope[0] }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ return { yAxis, series, visualMap }
|
|
|
}
|
|
|
|
|
|
export function transformHealthIndex2Chart(data: App.Health.Index.Data[]): AnyObject[] {
|
|
|
const list = gather(data, healthIndex2Chart)
|
|
|
+ console.log(list, 'transformHealthIndex2Chart-->list');
|
|
|
+
|
|
|
const charts = [];
|
|
|
for (const item of list) {
|
|
|
const xAxis = { type: 'category', axisLabel: { overflow: 'breakAll' } }
|
|
|
- const yAxis = { type: 'value', scale: true, }
|
|
|
- const series = item.options.filter((item: any) => item.data?.length)
|
|
|
+ const yAxis = [], series = [], visualMap = [];
|
|
|
+ for (const option of item.options) {
|
|
|
+ yAxis.push(option.yAxis);
|
|
|
+ visualMap.push(option.visualMap);
|
|
|
+ if (option.series.data?.length) series.push(option.series);
|
|
|
+ }
|
|
|
if (!series.length) continue;
|
|
|
charts.push({
|
|
|
id: item.id,
|
|
|
title: { text: `${item.name}` },
|
|
|
tooltip: { trigger: 'axis' },
|
|
|
legend: { show: series.length > 1 },
|
|
|
- xAxis, yAxis,
|
|
|
- series,
|
|
|
+ grid: { bottom: 25 },
|
|
|
+ xAxis, yAxis: yAxis[0],
|
|
|
+ series, visualMap,
|
|
|
})
|
|
|
}
|
|
|
return charts;
|