Deviation Management Workflow
Deviation management tracks unplanned departures from approved procedures. Severity decides the path; history records every classification and review.
Severity
| Severity | Investigation |
|---|---|
| Critical | Full investigation and CAPA |
| Major | Investigation and risk assessment |
| Minor | Documentation and root cause |
Implementation
dart
final deviationManagement = Workflow.define<Deviation, DeviationResult>(
code: 'quality.deviation',
version: 1,
fingerprint: 'quality.deviation:v1',
input: deviationCodec,
output: deviationResultCodec,
execute: (flow, deviation) async {
final classification = await flow.userTask(
classify,
deviation,
id: 'classify',
title: 'Classify deviation',
assignment: Assignment(roleIds: ['qa_specialist']),
);
switch (classification.severity) {
case Severity.critical:
await flow.userTask(
investigate,
deviation,
id: 'critical-investigation',
title: 'Critical investigation',
assignment: Assignment(roleIds: ['qa_manager']),
);
await flow.serviceTask(createCapa, deviation, id: 'capa');
case Severity.major:
await flow.userTask(
investigate,
deviation,
id: 'major-investigation',
title: 'Major investigation',
assignment: Assignment(roleIds: ['qa_specialist']),
);
await flow.serviceTask(riskAssessment, deviation, id: 'risk');
case Severity.minor:
await flow.serviceTask(document, deviation, id: 'document');
}
final approval = await flow.userTask(
qaApproval,
deviation,
id: 'qa-approval',
title: 'QA approval',
assignment: Assignment(roleIds: ['qa_manager']),
);
return approval.approved
? DeviationResult.closed()
: DeviationResult.rejected();
},
);Dart switch over the recorded classification replaces a graph oneOf gateway. Unchosen paths are never scheduled.
Compliance
- Severity-based escalation
- Mandatory CAPA on the critical path
- QA approval before closure
- Audited cancel, retry, and redrive