feat: improve patient flow and pricing workflow
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import 'dart:async';
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
import '../../../core/api/pocketbase_client.dart';
|
||||
import '../../../core/services/finance_service.dart';
|
||||
import '../../../core/services/job_history_service.dart';
|
||||
import '../../../models/job.dart';
|
||||
|
||||
const _listExpand = 'clinic_tenant_id,lab_tenant_id';
|
||||
const _listExpand = 'clinic_tenant_id,lab_tenant_id,patient_id';
|
||||
const _detailExpand = 'clinic_tenant_id,lab_tenant_id,patient_id,prosthetic_id';
|
||||
|
||||
class ClinicJobsRepository {
|
||||
@@ -51,14 +52,19 @@ class ClinicJobsRepository {
|
||||
Future<Job> createJob({
|
||||
required String clinicTenantId,
|
||||
required String labTenantId,
|
||||
required String clinicName,
|
||||
required String labName,
|
||||
required String patientCode,
|
||||
required String prostheticId,
|
||||
String? prostheticId,
|
||||
required ProstheticType prostheticType,
|
||||
required List<String> teeth,
|
||||
String? patientId,
|
||||
String? color,
|
||||
String? description,
|
||||
String? dueDate,
|
||||
double? price,
|
||||
String? currency,
|
||||
JobWorkflowType? workflowType,
|
||||
bool provaRequired = true,
|
||||
}) async {
|
||||
final record = await _pb.collection('jobs').create(body: {
|
||||
@@ -66,18 +72,38 @@ class ClinicJobsRepository {
|
||||
'lab_tenant_id': labTenantId,
|
||||
'patient_code': patientCode,
|
||||
if (patientId != null) 'patient_id': patientId,
|
||||
'prosthetic_id': prostheticId,
|
||||
if (prostheticId != null && prostheticId.isNotEmpty) 'prosthetic_id': prostheticId,
|
||||
'prosthetic_type': prostheticType.value,
|
||||
'member_count': teeth.length,
|
||||
'teeth': teeth,
|
||||
if (color != null) 'color': color,
|
||||
if (description != null) 'description': description,
|
||||
if (dueDate != null) 'due_date': dueDate,
|
||||
if (price != null) 'price': price,
|
||||
if (currency != null && currency.isNotEmpty) 'currency': currency,
|
||||
if (workflowType != null) 'workflow_type': workflowType.value,
|
||||
'status': 'pending',
|
||||
'location': 'at_clinic',
|
||||
'prova_required': provaRequired,
|
||||
});
|
||||
return Job.fromJson(record.toJson());
|
||||
final job = Job.fromJson(record.toJson());
|
||||
if (price != null && price > 0) {
|
||||
try {
|
||||
await FinanceService.instance.ensureEntriesForJob(
|
||||
jobId: job.id,
|
||||
clinicTenantId: clinicTenantId,
|
||||
labTenantId: labTenantId,
|
||||
clinicName: clinicName,
|
||||
labName: labName,
|
||||
amount: price,
|
||||
currency: currency ?? 'TRY',
|
||||
);
|
||||
} catch (_) {
|
||||
await _pb.collection('jobs').delete(job.id);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
return job;
|
||||
}
|
||||
|
||||
Future<Job> approveAtClinic(String jobId, Job job, {String? note}) async {
|
||||
@@ -134,6 +160,7 @@ class ClinicJobsRepository {
|
||||
final record = await _pb.collection('jobs').update(jobId, body: {
|
||||
'status': 'cancelled',
|
||||
});
|
||||
await FinanceService.instance.deletePendingEntriesForJob(jobId);
|
||||
unawaited(JobHistoryService.instance.append(
|
||||
jobId: jobId,
|
||||
clinicTenantId: job.clinicTenantId,
|
||||
|
||||
Reference in New Issue
Block a user