Simplify lab trial dispatch and fix per-jaw pricing

This commit is contained in:
egecankomur
2026-10-10 14:52:05 +03:00
parent f44e07f378
commit d20d44a1f3
6 changed files with 204 additions and 74 deletions
+21 -27
View File
@@ -83,40 +83,34 @@ class LabJobsRepository {
return job;
}
Future<Job> handToClinic(String jobId, Job job, {String? note}) async {
final currentStep = job.currentStep;
if (currentStep == null) {
throw Exception('Geçerli bir iş adımı bulunamadı.');
Future<Job> handToClinic(String jobId, Job job,
{required bool finish, required String note}) async {
if (note.trim().isEmpty) {
throw ArgumentError('Aşama açıklaması gereklidir.');
}
final isFinal = currentStep == JobStep.cilaBitim;
final nextStep = job.nextStep;
final shouldStayAtLabAfterMeasure = !job.provaRequired &&
currentStep == JobStep.olcuKontrol &&
nextStep == JobStep.cilaBitim;
final patch = isFinal
? {'status': 'sent', 'location': 'at_clinic'}
: currentStep.requiresClinicApproval && !shouldStayAtLabAfterMeasure
? {'location': 'at_clinic'}
: {
'current_step': nextStep?.value,
'location': 'at_lab',
};
final dispatchStep = job.labDispatchStep(finish: finish);
final steps = [...job.stepTemplate];
if (!steps.contains(dispatchStep)) {
steps.insert(0, dispatchStep);
}
final patch = {
'status': finish ? 'sent' : 'in_progress',
'location': 'at_clinic',
'current_step': dispatchStep.value,
'workflow_steps': steps.map((step) => step.value).toList(),
};
final record = await _pb.collection('jobs').update(jobId, body: patch);
final updated = Job.fromJson(record.toJson());
unawaited(JobHistoryService.instance.append(
await JobHistoryService.instance.append(
jobId: jobId,
clinicTenantId: job.clinicTenantId,
labTenantId: job.labTenantId,
action: (currentStep.requiresClinicApproval &&
!shouldStayAtLabAfterMeasure) ||
isFinal
? JobHistoryAction.handedToClinic
: JobHistoryAction.stepCompleted,
step: currentStep,
note: note,
));
action: JobHistoryAction.handedToClinic,
step: dispatchStep,
note:
'${finish ? "Bitime gönderildi" : "Provaya gönderildi"}: ${note.trim()}',
);
return updated;
}