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>
44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
export function createInMemoryHealthDocumentStore() {
|
|
const rowsByUser = new Map();
|
|
let nextId = 1;
|
|
|
|
return {
|
|
async list(userId, { limit = 50 } = {}) {
|
|
const rows = rowsByUser.get(String(userId)) ?? [];
|
|
return rows.slice(0, limit);
|
|
},
|
|
async insert(userId, document) {
|
|
if (document?.confirmed !== true) {
|
|
const error = Object.assign(new Error('报告必须确认归档后才能保存'), {
|
|
code: 'health_document_unconfirmed',
|
|
});
|
|
throw error;
|
|
}
|
|
const row = {
|
|
id: nextId++,
|
|
userId: String(userId),
|
|
assetId: document.assetId ?? null,
|
|
imageUrl: document.imageUrl ?? null,
|
|
source: document.source ?? 'manual',
|
|
notes: document.notes ?? null,
|
|
docType: document.docType ?? 'other',
|
|
reportDate: document.reportDate ?? null,
|
|
institution: document.institution ?? null,
|
|
ocrText: document.ocrText ?? null,
|
|
extractedMetrics: document.extractedMetrics ?? [],
|
|
extractionStatus: document.extractionStatus ?? 'pending',
|
|
createdAt: document.createdAt ?? Date.now(),
|
|
};
|
|
const list = rowsByUser.get(row.userId) ?? [];
|
|
list.unshift(row);
|
|
rowsByUser.set(row.userId, list);
|
|
return row;
|
|
},
|
|
};
|
|
}
|
|
|
|
export function parseHealthAssetIdFromUrl(imageUrl = '') {
|
|
const match = String(imageUrl).match(/\/mindspace\/v1\/assets\/([^/?#]+)/);
|
|
return match ? decodeURIComponent(match[1]) : null;
|
|
}
|