2baf29b3ae
Deliver encrypted health zone, observation API, baseline maturity pipeline, page-data bindings, and H5/WeChat channel integration for health P0. Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
1.9 KiB
JavaScript
55 lines
1.9 KiB
JavaScript
export function mapPgObservationRow(row, userId) {
|
|
return {
|
|
id: Number(row.id),
|
|
userId: String(userId),
|
|
observedAt: row.observed_at ? new Date(row.observed_at).getTime() : Date.now(),
|
|
metricType: row.metric_type,
|
|
valueNum: row.value_num != null ? Number(row.value_num) : null,
|
|
valueText: row.value_text ?? null,
|
|
unit: row.unit ?? null,
|
|
context: row.context ?? null,
|
|
source: row.source ?? 'manual',
|
|
sourceRef: row.source_ref ?? null,
|
|
qualityFlag: row.quality_flag ?? 'ok',
|
|
deletedAt: row.deleted_at ? new Date(row.deleted_at).getTime() : null,
|
|
createdAt: row.created_at ? new Date(row.created_at).getTime() : Date.now(),
|
|
};
|
|
}
|
|
|
|
export function mapObservationToPgPayload(observation) {
|
|
const payload = {
|
|
observed_at: new Date(observation.observedAt ?? Date.now()).toISOString(),
|
|
metric_type: observation.metricType,
|
|
value_num: observation.valueNum ?? null,
|
|
value_text: observation.valueText ?? null,
|
|
unit: observation.unit ?? null,
|
|
context: observation.context ?? null,
|
|
source: observation.source ?? 'manual',
|
|
source_ref: observation.sourceRef ?? null,
|
|
time_source: observation.timeSource ?? 'user_specified',
|
|
confidence: observation.confidence ?? null,
|
|
quality_flag: observation.qualityFlag ?? 'ok',
|
|
};
|
|
if (observation.rawPayload != null) {
|
|
payload.raw_payload =
|
|
typeof observation.rawPayload === 'string'
|
|
? observation.rawPayload
|
|
: JSON.stringify(observation.rawPayload);
|
|
}
|
|
return payload;
|
|
}
|
|
|
|
export function mapPgDocumentRow(row, userId) {
|
|
return {
|
|
id: Number(row.id),
|
|
userId: String(userId),
|
|
assetId: row.asset_id ?? null,
|
|
imageUrl: row.asset_id ? null : null,
|
|
source: 'manual',
|
|
notes: row.title ?? null,
|
|
docType: row.doc_type ?? 'other',
|
|
extractionStatus: row.extraction_status ?? 'pending',
|
|
createdAt: row.created_at ? new Date(row.created_at).getTime() : Date.now(),
|
|
};
|
|
}
|