d339d1edc7
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>
225 lines
8.7 KiB
Go
225 lines
8.7 KiB
Go
package iace
|
|
|
|
// ============================================================================
|
|
// Constants / Enums
|
|
// ============================================================================
|
|
|
|
// ProjectStatus represents the lifecycle status of an IACE project
|
|
type ProjectStatus string
|
|
|
|
const (
|
|
ProjectStatusDraft ProjectStatus = "draft"
|
|
ProjectStatusOnboarding ProjectStatus = "onboarding"
|
|
ProjectStatusClassification ProjectStatus = "classification"
|
|
ProjectStatusHazardAnalysis ProjectStatus = "hazard_analysis"
|
|
ProjectStatusMitigation ProjectStatus = "mitigation"
|
|
ProjectStatusVerification ProjectStatus = "verification"
|
|
ProjectStatusTechFile ProjectStatus = "tech_file"
|
|
ProjectStatusCompleted ProjectStatus = "completed"
|
|
ProjectStatusArchived ProjectStatus = "archived"
|
|
)
|
|
|
|
// ComponentType represents the type of a system component
|
|
type ComponentType string
|
|
|
|
const (
|
|
ComponentTypeSoftware ComponentType = "software"
|
|
ComponentTypeFirmware ComponentType = "firmware"
|
|
ComponentTypeAIModel ComponentType = "ai_model"
|
|
ComponentTypeHMI ComponentType = "hmi"
|
|
ComponentTypeSensor ComponentType = "sensor"
|
|
ComponentTypeActuator ComponentType = "actuator"
|
|
ComponentTypeController ComponentType = "controller"
|
|
ComponentTypeNetwork ComponentType = "network"
|
|
ComponentTypeMechanical ComponentType = "mechanical"
|
|
ComponentTypeElectrical ComponentType = "electrical"
|
|
ComponentTypeOther ComponentType = "other"
|
|
)
|
|
|
|
// RegulationType represents the applicable EU regulation
|
|
type RegulationType string
|
|
|
|
const (
|
|
RegulationNIS2 RegulationType = "nis2"
|
|
RegulationAIAct RegulationType = "ai_act"
|
|
RegulationCRA RegulationType = "cra"
|
|
RegulationMachineryRegulation RegulationType = "machinery_regulation"
|
|
)
|
|
|
|
// HazardStatus represents the lifecycle status of a hazard
|
|
type HazardStatus string
|
|
|
|
const (
|
|
HazardStatusIdentified HazardStatus = "identified"
|
|
HazardStatusAssessed HazardStatus = "assessed"
|
|
HazardStatusMitigated HazardStatus = "mitigated"
|
|
HazardStatusAccepted HazardStatus = "accepted"
|
|
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
|
|
|
|
const (
|
|
AssessmentTypeInitial AssessmentType = "initial"
|
|
AssessmentTypePostMitigation AssessmentType = "post_mitigation"
|
|
AssessmentTypeReassessment AssessmentType = "reassessment"
|
|
)
|
|
|
|
// RiskLevel represents the severity level of a risk
|
|
type RiskLevel string
|
|
|
|
const (
|
|
RiskLevelNotAcceptable RiskLevel = "not_acceptable" // ISO 12100 mode: > 300
|
|
RiskLevelVeryHigh RiskLevel = "very_high" // ISO 12100 mode: 151-300
|
|
RiskLevelCritical RiskLevel = "critical"
|
|
RiskLevelHigh RiskLevel = "high"
|
|
RiskLevelMedium RiskLevel = "medium"
|
|
RiskLevelLow RiskLevel = "low"
|
|
RiskLevelNegligible RiskLevel = "negligible"
|
|
)
|
|
|
|
// ReductionType represents the type of risk reduction measure
|
|
type ReductionType string
|
|
|
|
const (
|
|
ReductionTypeDesign ReductionType = "design"
|
|
ReductionTypeProtective ReductionType = "protective"
|
|
ReductionTypeInformation ReductionType = "information"
|
|
)
|
|
|
|
// MitigationStatus represents the lifecycle status of a mitigation measure
|
|
type MitigationStatus string
|
|
|
|
const (
|
|
MitigationStatusPlanned MitigationStatus = "planned"
|
|
MitigationStatusImplemented MitigationStatus = "implemented"
|
|
MitigationStatusVerified MitigationStatus = "verified"
|
|
MitigationStatusRejected MitigationStatus = "rejected"
|
|
)
|
|
|
|
// VerificationMethod represents the method used for verification
|
|
type VerificationMethod string
|
|
|
|
const (
|
|
VerificationMethodTest VerificationMethod = "test"
|
|
VerificationMethodAnalysis VerificationMethod = "analysis"
|
|
VerificationMethodInspection VerificationMethod = "inspection"
|
|
VerificationMethodReview VerificationMethod = "review"
|
|
VerificationMethodDesignReview VerificationMethod = "design_review"
|
|
VerificationMethodCalculation VerificationMethod = "calculation"
|
|
VerificationMethodTestReport VerificationMethod = "test_report"
|
|
VerificationMethodValidation VerificationMethod = "validation"
|
|
VerificationMethodElectricalTest VerificationMethod = "electrical_test"
|
|
VerificationMethodSoftwareTest VerificationMethod = "software_test"
|
|
VerificationMethodPenetrationTest VerificationMethod = "penetration_test"
|
|
VerificationMethodAcceptanceProtocol VerificationMethod = "acceptance_protocol"
|
|
VerificationMethodUserTest VerificationMethod = "user_test"
|
|
VerificationMethodDocRelease VerificationMethod = "documentation_release"
|
|
)
|
|
|
|
// TechFileSectionStatus represents the status of a technical file section
|
|
type TechFileSectionStatus string
|
|
|
|
const (
|
|
TechFileSectionStatusDraft TechFileSectionStatus = "draft"
|
|
TechFileSectionStatusGenerated TechFileSectionStatus = "generated"
|
|
TechFileSectionStatusReviewed TechFileSectionStatus = "reviewed"
|
|
TechFileSectionStatusApproved TechFileSectionStatus = "approved"
|
|
)
|
|
|
|
// MonitoringEventType represents the type of monitoring event
|
|
type MonitoringEventType string
|
|
|
|
const (
|
|
MonitoringEventTypeIncident MonitoringEventType = "incident"
|
|
MonitoringEventTypeUpdate MonitoringEventType = "update"
|
|
MonitoringEventTypeDriftAlert MonitoringEventType = "drift_alert"
|
|
MonitoringEventTypeRegulationChange MonitoringEventType = "regulation_change"
|
|
MonitoringEventTypeAudit MonitoringEventType = "audit"
|
|
)
|
|
|
|
// AuditAction represents the type of action recorded in the audit trail
|
|
type AuditAction string
|
|
|
|
const (
|
|
AuditActionCreate AuditAction = "create"
|
|
AuditActionUpdate AuditAction = "update"
|
|
AuditActionDelete AuditAction = "delete"
|
|
AuditActionApprove AuditAction = "approve"
|
|
AuditActionVerify AuditAction = "verify"
|
|
)
|
|
|
|
// LifecyclePhase represents a machine lifecycle phase per ISO 12100 methodology
|
|
type LifecyclePhase string
|
|
|
|
const (
|
|
LPTransport LifecyclePhase = "transport"
|
|
LPStorage LifecyclePhase = "storage"
|
|
LPAssembly LifecyclePhase = "assembly"
|
|
LPInstallation LifecyclePhase = "installation"
|
|
LPCommissioning LifecyclePhase = "commissioning"
|
|
LPParameterization LifecyclePhase = "parameterization"
|
|
LPSetup LifecyclePhase = "setup"
|
|
LPNormalOperation LifecyclePhase = "normal_operation"
|
|
LPAutoOperation LifecyclePhase = "automatic_operation"
|
|
LPManualOperation LifecyclePhase = "manual_operation"
|
|
LPTeachMode LifecyclePhase = "teach_mode"
|
|
LPProductionStart LifecyclePhase = "production_start"
|
|
LPProductionStop LifecyclePhase = "production_stop"
|
|
LPProcessMonitoring LifecyclePhase = "process_monitoring"
|
|
LPCleaning LifecyclePhase = "cleaning"
|
|
LPMaintenance LifecyclePhase = "maintenance"
|
|
LPInspection LifecyclePhase = "inspection"
|
|
LPCalibration LifecyclePhase = "calibration"
|
|
LPFaultClearing LifecyclePhase = "fault_clearing"
|
|
LPRepair LifecyclePhase = "repair"
|
|
LPChangeover LifecyclePhase = "changeover"
|
|
LPSoftwareUpdate LifecyclePhase = "software_update"
|
|
LPRemoteMaintenance LifecyclePhase = "remote_maintenance"
|
|
LPDecommissioning LifecyclePhase = "decommissioning"
|
|
LPDisposal LifecyclePhase = "disposal"
|
|
)
|
|
|
|
// ReviewStatus represents the review state of a hazard assessment
|
|
type ReviewStatus string
|
|
|
|
const (
|
|
ReviewStatusDraft ReviewStatus = "draft"
|
|
ReviewStatusInReview ReviewStatus = "in_review"
|
|
ReviewStatusReviewed ReviewStatus = "reviewed"
|
|
ReviewStatusApproved ReviewStatus = "approved"
|
|
ReviewStatusRejected ReviewStatus = "rejected"
|
|
)
|