import { Injectable } from '@nestjs/common'; import { PregnancyCase } from './case.types'; import { CarePlan } from './care-plan.types'; /** 个案与照护计划仓储抽象(内存实现,后续接入 DB)。 */ export abstract class CaseflowRepository { abstract saveCase(c: PregnancyCase): Promise; abstract findCaseById(id: string): Promise; abstract findCaseByPatient(patientId: string): Promise; abstract savePlan(p: CarePlan): Promise; abstract findPlansByCase(caseId: string): Promise; } @Injectable() export class InMemoryCaseflowRepository extends CaseflowRepository { private readonly cases = new Map(); private readonly plans: CarePlan[] = []; async saveCase(c: PregnancyCase): Promise { this.cases.set(c.id, c); return c; } async findCaseById(id: string): Promise { return this.cases.get(id) ?? null; } async findCaseByPatient(patientId: string): Promise { for (const c of this.cases.values()) { if (c.patientId === patientId) return c; } return null; } async savePlan(p: CarePlan): Promise { const idx = this.plans.findIndex((x) => x.id === p.id); if (idx >= 0) this.plans[idx] = p; else this.plans.push(p); return p; } async findPlansByCase(caseId: string): Promise { return this.plans.filter((p) => p.caseId === caseId); } }