feat(iace): Sprint 4B — ISO 12100 Hazard/Situation/Harm Trennung

ISO 12100 trennt: Hazard (Quelle) → Hazardous Situation (Person exponiert) → Harm (Verletzung).
Bisher war alles in einem Hazard-Record vermischt.

Implementierung als abgeleitetes Feld (keine DB-Migration noetig):
- HazardType Feld auf Hazard Entity ("hazard"|"hazardous_situation"|"harm")
- DeriveHazardType() berechnet Typ aus Scenario/PossibleHarm/Category
- Explizites Override moeglich (HazardType direkt setzen)
- GeneratedHazardType auf HazardPattern fuer Pattern-gesteuerte Zuweisung
- Store: GetHazard/ListHazards setzen HazardType automatisch
- Init-Handler: Fuellt jetzt TriggerEvent, PossibleHarm, AffectedPerson, HazardousZone
  aus Pattern-Match-Daten (vorher leer gelassen)

6 neue Tests: ScenarioAndHarm, HarmOnly, CategoryOnly, ExplicitOverride,
EmptyFallback, PatternMatchField

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-05-10 20:55:26 +02:00
parent 6e995b52d1
commit d339d1edc7
7 changed files with 119 additions and 10 deletions
+31
View File
@@ -57,6 +57,37 @@ const (
HazardStatusClosed HazardStatus = "closed"
)
// HazardType distinguishes ISO 12100 concepts in the hazard chain:
// Hazard → Hazardous Situation → Harm
const (
HazardTypeHazard = "hazard" // Source of potential harm (e.g. rotating shaft)
HazardTypeHazardousSituation = "hazardous_situation" // Person exposed to hazard (e.g. operator near shaft)
HazardTypeHarm = "harm" // Injury outcome (e.g. entanglement)
DefaultHazardType = HazardTypeHazardousSituation
)
// DeriveHazardType determines the ISO 12100 hazard type from the hazard's fields.
// If an explicit type is set, it is returned as-is. Otherwise:
// - PossibleHarm filled + Scenario filled → "hazardous_situation" (most specific)
// - Only PossibleHarm filled → "harm"
// - Only TriggerEvent/Category → "hazard" (source only)
// - Default fallback → "hazardous_situation"
func DeriveHazardType(h *Hazard) string {
if h.HazardType != "" {
return h.HazardType
}
if h.Scenario != "" && h.PossibleHarm != "" {
return HazardTypeHazardousSituation
}
if h.PossibleHarm != "" && h.Scenario == "" {
return HazardTypeHarm
}
if h.Scenario == "" && h.PossibleHarm == "" && h.Category != "" {
return HazardTypeHazard
}
return DefaultHazardType
}
// AssessmentType represents the type of risk assessment
type AssessmentType string