// ============================================================================= // Obligations Document — HTML Document Builder // ============================================================================= import type { Obligation, ObligationComplianceCheckResult } from '../obligations-compliance' import type { ObligationDocumentOrgHeader, ObligationDocumentRevision } from './types-defaults' import { STATUS_LABELS_DE, STATUS_BADGE_CLASSES, PRIORITY_LABELS_DE, PRIORITY_BADGE_CLASSES, } from './types-defaults' import { escHtml, formatDateDE } from './helpers' import { getDocumentStyles } from './html-styles' import { buildSection6, buildSection7, buildSection8, buildSection9, buildSection10, buildSection11, buildFooter, } from './html-builder-sections-6-11' export function buildObligationDocumentHtml( obligations: Obligation[], orgHeader: ObligationDocumentOrgHeader, complianceResult: ObligationComplianceCheckResult | null, revisions: ObligationDocumentRevision[] ): string { const today = new Date().toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', }) const orgName = orgHeader.organizationName || 'Organisation' // Group obligations by source (regulation) const bySource = new Map() for (const o of obligations) { const src = o.source || 'Sonstig' if (!bySource.has(src)) bySource.set(src, []) bySource.get(src)!.push(o) } // Build role map const roleMap = new Map() for (const o of obligations) { const role = o.responsible || 'Nicht zugewiesen' if (!roleMap.has(role)) roleMap.set(role, []) roleMap.get(role)!.push(o) } const distinctSources = Array.from(bySource.keys()).sort() let html = getDocumentStyles(`Pflichtenregister — ${escHtml(orgName)}`) html += buildCoverPage(orgHeader, orgName, today) html += buildTOC() html += buildSection1(orgName) html += buildSection2(orgName, orgHeader, bySource, obligations, distinctSources) html += buildSection3() html += buildSection4(bySource, obligations) html += buildSection5(bySource) html += buildSection6(bySource) html += buildSection7(roleMap) html += buildSection8(obligations, today) html += buildSection9(obligations) html += buildSection10(complianceResult) html += buildSection11(revisions, orgHeader, today) html += buildFooter(orgName, today, orgHeader.documentVersion) return html } function buildCoverPage( orgHeader: ObligationDocumentOrgHeader, orgName: string, today: string ): string { return `

Pflichtenregister

Regulatorische Pflichten — DSGVO, AI Act, NIS2 und weitere
Organisation: ${escHtml(orgName)}
${orgHeader.industry ? `
Branche: ${escHtml(orgHeader.industry)}
` : ''} ${orgHeader.dpoName ? `
DSB: ${escHtml(orgHeader.dpoName)}
` : ''} ${orgHeader.dpoContact ? `
DSB-Kontakt: ${escHtml(orgHeader.dpoContact)}
` : ''} ${orgHeader.responsiblePerson ? `
Verantwortlicher: ${escHtml(orgHeader.responsiblePerson)}
` : ''} ${orgHeader.legalDepartment ? `
Rechtsabteilung: ${escHtml(orgHeader.legalDepartment)}
` : ''}
` } function buildTOC(): string { const sections = [ 'Ziel und Zweck', 'Geltungsbereich', 'Methodik', 'Regulatorische Grundlagen', 'Pflichtenuebersicht', 'Detaillierte Pflichten', 'Verantwortlichkeiten', 'Fristen und Termine', 'Nachweisverzeichnis', 'Compliance-Status', 'Aenderungshistorie', ] return `

Inhaltsverzeichnis

${sections.map((s, i) => `
${i + 1}. ${escHtml(s)}
`).join('\n ')}
` } function buildSection1(orgName: string): string { return `
1. Ziel und Zweck

Dieses Pflichtenregister dokumentiert alle regulatorischen Pflichten, denen ${escHtml(orgName)} unterliegt. Es dient der systematischen Erfassung, Ueberwachung und Nachverfolgung aller Compliance-Anforderungen aus den anwendbaren Regulierungen.

Das Register erfuellt folgende Zwecke:

  • Vollstaendige Erfassung aller anwendbaren regulatorischen Pflichten
  • Zuordnung von Verantwortlichkeiten und Fristen
  • Nachverfolgung des Umsetzungsstatus
  • Dokumentation von Nachweisen fuer Audits
  • Identifikation von Compliance-Luecken und Handlungsbedarf
RechtsrahmenRelevanz
DSGVO (EU) 2016/679Datenschutz-Grundverordnung — Kernregulierung fuer personenbezogene Daten
AI Act (EU) 2024/1689KI-Verordnung — Anforderungen an KI-Systeme nach Risikoklasse
NIS2 (EU) 2022/2555Netzwerk- und Informationssicherheit — Cybersicherheitspflichten
BDSGBundesdatenschutzgesetz — Nationale Ergaenzung zur DSGVO
` } function buildSection2( orgName: string, orgHeader: ObligationDocumentOrgHeader, bySource: Map, obligations: Obligation[], distinctSources: string[] ): string { let html = `
2. Geltungsbereich

Dieses Pflichtenregister gilt fuer alle Geschaeftsprozesse und IT-Systeme von ${escHtml(orgName)}${orgHeader.industry ? ` (Branche: ${escHtml(orgHeader.industry)})` : ''}.

Anwendbare Regulierungen:

` for (const [source, obls] of bySource.entries()) { const completed = obls.filter(o => o.status === 'completed').length const pct = obls.length > 0 ? Math.round((completed / obls.length) * 100) : 0 html += ` ` } html += `
RegulierungAnzahl PflichtenStatus
${escHtml(source)} ${obls.length} ${completed}/${obls.length} abgeschlossen (${pct}%)

Insgesamt umfasst dieses Register ${obligations.length} Pflichten aus ${distinctSources.length} Regulierungen.

` return html } function buildSection3(): string { return `
3. Methodik

Die Identifikation und Bewertung der Pflichten erfolgt in drei Schritten:

Pflicht-Identifikation: Systematische Analyse aller anwendbaren Regulierungen und Extraktion der einzelnen Pflichten mit Artikel-Referenz, Beschreibung und Zielgruppe.
Bewertung und Priorisierung: Jede Pflicht wird nach Prioritaet (kritisch, hoch, mittel, niedrig) und Dringlichkeit (Frist) bewertet. Die Bewertung basiert auf dem Risikopotenzial bei Nichterfuellung.
Ueberwachung und Nachverfolgung: Regelmaessige Pruefung des Umsetzungsstatus, Aktualisierung der Fristen und Dokumentation von Nachweisen.

Die Pflichten werden ueber einen automatisierten Compliance-Check geprueft, der 11 Kriterien umfasst (siehe Abschnitt 10: Compliance-Status).

` } function buildSection4(bySource: Map, obligations: Obligation[]): string { const totalCritical = obligations.filter(o => o.priority === 'critical').length const totalHigh = obligations.filter(o => o.priority === 'high').length const totalMedium = obligations.filter(o => o.priority === 'medium').length const totalLow = obligations.filter(o => o.priority === 'low').length const totalCompleted = obligations.filter(o => o.status === 'completed').length let html = `
4. Regulatorische Grundlagen

Die folgende Tabelle zeigt die regulatorischen Grundlagen mit Artikelzahl und Umsetzungsstatus:

` for (const [source, obls] of bySource.entries()) { const critical = obls.filter(o => o.priority === 'critical').length const high = obls.filter(o => o.priority === 'high').length const medium = obls.filter(o => o.priority === 'medium').length const low = obls.filter(o => o.priority === 'low').length const completed = obls.filter(o => o.status === 'completed').length html += ` ` } html += `
Regulierung Pflichten Kritisch Hoch Mittel Niedrig Abgeschlossen
${escHtml(source)} ${obls.length} ${critical} ${high} ${medium} ${low} ${completed}
Gesamt ${obligations.length} ${totalCritical} ${totalHigh} ${totalMedium} ${totalLow} ${totalCompleted}
` return html } function buildSection5(bySource: Map): string { let html = `
5. Pflichtenuebersicht

Uebersicht aller Pflichten nach Regulierung und Status:

` for (const [source, obls] of bySource.entries()) { const pending = obls.filter(o => o.status === 'pending').length const inProgress = obls.filter(o => o.status === 'in-progress').length const completed = obls.filter(o => o.status === 'completed').length const overdue = obls.filter(o => o.status === 'overdue').length html += ` ` } html += `
Regulierung Gesamt Ausstehend In Bearbeitung Abgeschlossen Ueberfaellig
${escHtml(source)} ${obls.length} ${pending} ${inProgress} ${completed} ${overdue > 0 ? `${overdue}` : '0'}
` return html }