Simplify lab trial dispatch and fix per-jaw pricing
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user