Treatment Plan Templates — Structured Care Plans
Audiences: doctor, clinical-buyer, developer
Doctors define structured treatment plan templates — sections, expected outputs, and locale — that the AI summarization engine uses to generate consistent, clinic-specific care plans from clinical encounter data.
Business Purpose
Without structured templates, AI-generated treatment plans are freeform and clinic-specific expectations are lost. The treatment-plan-template module lets clinic admins define a library of reusable templates: which sections a plan must contain (e.g. "Diagnosis Summary", "Medication Plan", "Follow-up Schedule"), what output format to expect (PDF, MARKDOWN, JSON), and the plan's locale. When TUCAN or the document generation engine produces a treatment plan, it resolves the appropriate template for the org/locale pair and uses it to structure the output.
The system mirrors the summarization template pattern in the doxing module — same Prisma model shape, same status lifecycle, same ensureDefault() seeding mechanism. This design lets the AI pipeline apply consistent clinical logic regardless of which org runs it.
Commercial value: standardized treatment plans improve documentation quality, satisfy health insurer requirements for structured care records, and reduce the cognitive load on doctors who currently write plans from scratch.
Audiences
- Investor: Structured treatment plans are a gateway to automated reimbursement documentation — a key unlock for GKV (statutory health insurance) billing automation. Template library differentiates Dudoxx HMS from generic AI scribing tools.
- Clinical buyer (doctor/nurse/receptionist): Doctors see the clinic's standard sections pre-filled when creating a treatment plan. Templates can be set as clinic defaults or published for specific specialties. Admins publish/archive templates without developer involvement.
- Developer/partner:
TreatmentPlanTemplateController+TreatmentPlanTemplateService— standard NestJS CRUD with lifecycle endpoints (publish,archive,ensureDefault).organizationIdis always derived from the Trusted Gateway tenant context (X-Clinic-ID→req.clinicId); never from the client payload. Write endpoints require@RequireAdminRole(). - Internal (ops/support):
ensureDefault()is an idempotent seeding endpoint — it creates a default template for an org/locale if none exists, deduplicates multiple defaults, and can be called safely during tenant provisioning. Status lifecycle:DRAFT → PUBLISHED → ARCHIVED.
Architecture
documents/treatment-plan-template/
├── treatment-plan-template.controller.ts — REST CRUD + lifecycle endpoints
├── treatment-plan-template.module.ts — Module wiring
├── services/
│ └── treatment-plan-template.service.ts — Business logic, org ID resolution, dedup
└── dto/
└── treatment-plan-template.dto.ts — CreateDto, UpdateDto, ResponseDto,
ExpectedSectionDto, OutputFormatValue, TemplateStatusValue
Prisma model: DocumentTreatmentPlanTemplate in prisma-main (ddx_api_main). Key fields:
| Field | Type | Purpose |
|---|---|---|
organizationId | String | Tenant scoping |
locale | String | "de" / "en" — resolved on template lookup |
name | String | Template display name |
description | String? | Optional admin notes |
sections | Json | Array of ExpectedSectionDto (section name + instructions) |
outputFormat | SummarizationOutputFormat | PDF, MARKDOWN, JSON |
status | SummarizationTemplateStatus | DRAFT, PUBLISHED, ARCHIVED |
isDefault | Boolean | One active default per org/locale |
isActive | Boolean | Soft-delete flag |
Status lifecycle:
DRAFT → PUBLISHED (admin publishes) → ARCHIVED
↑
ensureDefault() creates in DRAFT; caller must publish
Only PUBLISHED + isActive=true templates are selected for document generation. ARCHIVED templates are preserved for audit but not used in new plan generation.
Tech Stack & Choices
| Concern | Choice | Rationale |
|---|---|---|
| Storage | DocumentTreatmentPlanTemplate in prisma-main | Co-located with other document models; org-scoped via organizationId |
| Auth | @RequireAdminRole() on write endpoints | Only SUPER_ADMIN / CLINIC_ADMIN manage templates; doctors use them read-only |
| Org resolution | getOrganizationIdOrThrow(req) — derives from req.clinicId | Never trusts organizationId from request body; Trusted Gateway pattern |
| Default seeding | ensureDefault(orgIdOrSlug, locale) — idempotent | Called during tenant provisioning; safe to call repeatedly |
| Output formats | SummarizationOutputFormat enum (PDF, MARKDOWN, JSON) | Reuses the same enum as summarization templates for pipeline consistency |
| Sections | ExpectedSectionDto[] JSON column | Flexible section schema without schema migrations; each section has name + instructions for the AI |
| Deduplication | ensureDefault() degrades multiple defaults to one | Prevents multiple defaults from conflicting in template resolution |
Data Flow
Template resolution for AI document generation
- TUCAN document generation tool calls
TreatmentPlanTemplateService.ensureDefault(orgId, locale)→ gets or creates the default template. - If a
PUBLISHED+isDefault=truetemplate exists for{ organizationId, locale }, it is returned immediately. - AI engine reads the
sectionsJSON → uses each section'sname+instructionsas a structured prompt to the LLM. - Output is formatted per
outputFormatand returned as the generated treatment plan.
Admin creates a template
- Admin calls
POST /treatment-plan-templateswithCreateTreatmentPlanTemplateDto(name, sections, locale, outputFormat). getOrganizationIdOrThrow(req)extractsorganizationIdfromreq.clinicId(Trusted Gateway).TreatmentPlanTemplateService.create()writes row withstatus: DRAFT,isActive: true,isDefault: false.- Admin calls
PATCH /treatment-plan-templates/:id/publish→ status changes toPUBLISHED. - Admin calls
PATCH /treatment-plan-templates/:id/set-default→isDefault = true; any previous default for same{ organizationId, locale }is unset.
EnsureDefault (tenant provisioning)
- Tenant provisioner calls
POST /treatment-plan-templates/ensure-defaultwith{ locale: "de" }. TreatmentPlanTemplateService.ensureDefault(orgId, "de"):- Queries for existing
PUBLISHED + isDefault + isActivetemplates for the org/locale. - If found and count > 1: degrades extras to
isDefault = false, returns preferred. - If none found: creates a platform default template in
DRAFTstatus with Dudoxx's standard German clinical sections.
- Queries for existing
- Returns the active default template.
Implicated Code
ddx-api/src/documents/treatment-plan-template/treatment-plan-template.controller.ts:1—TreatmentPlanTemplateController;@RequireAdminRole()on write endpoints;getOrganizationIdOrThrow(req)helper at:60;@ApiTags('Treatment Plan Templates')ddx-api/src/documents/treatment-plan-template/services/treatment-plan-template.service.ts:29—TreatmentPlanTemplateService;ensureDefault()at:57— idempotent default creation with dedup logic at:76–82ddx-api/src/documents/treatment-plan-template/services/treatment-plan-template.service.ts:34—resolveOrganizationIdOrThrow()— resolves both UUID and slug to org UUID via Prisma OR queryddx-api/src/documents/treatment-plan-template/dto/treatment-plan-template.dto.ts—CreateTreatmentPlanTemplateDto,UpdateTreatmentPlanTemplateDto,ExpectedSectionDto(section name + instructions),OutputFormatValue,TemplateStatusValueddx-api/src/documents/treatment-plan-template/treatment-plan-template.module.ts—TreatmentPlanTemplateModule;TreatmentPlanTemplateServiceprovider;PrismaModuleimport
Operational Notes
- Idempotent provisioning:
POST /treatment-plan-templates/ensure-defaultcan be called multiple times during tenant setup. It only creates a template if noPUBLISHED + isDefault + isActivetemplate exists. Safe to include in the seeder pipeline. - Multiple defaults deduplication: If the database somehow accumulates multiple default templates for the same org/locale (schema migration edge case),
ensureDefault()automatically degrades extras. The most-recently-updated template wins. - Org slug resolution:
resolveOrganizationIdOrThrow()accepts both UUID and clinic slug (e.g."ddx-hamburg-clinic"). This matches the org service convention used throughout the platform. - Sections schema:
sectionsis aJsonPrisma field — theExpectedSectionDto[]shape is validated in the DTO layer but not enforced at the DB level. Future schema changes (adding arequired: booleanfield to sections) are non-breaking. - AI integration: Treatment plan template sections are consumed by TUCAN document generation tools and the
document-generationmodule. TheoutputFormatfield controls which renderer is invoked (PDF→ ddx-pdf-engine,MARKDOWN→ raw text,JSON→ structured data). - Validation commands:
pnpm tsc:check(ddx-api);pnpm prisma:generate:allifDocumentTreatmentPlanTemplatemodel changes.
Related Topics
- Document Management — uses treatment plan templates to structure AI-generated care plan documents; generated treatment plans are stored as
PatientDocumentrecords inddx_api_main - Doxing — OCR and Summarization — sibling template system (
SummarizationTemplate) follows the same pattern; sharesSummarizationOutputFormatandSummarizationTemplateStatusenums - FHIR ResourceFacade — FHIR
CarePlanresources map to treatment plan instances (not templates); templates are Prisma-only