Add pricing entry flow and platform admin foundations
This commit is contained in:
@@ -24,26 +24,32 @@ class LabJobsRepository {
|
||||
if (status != null) filterParts.add('status = "$status"');
|
||||
|
||||
final result = await _pb.collection('jobs').getList(
|
||||
page: page,
|
||||
perPage: limit,
|
||||
filter: filterParts.join(' && '),
|
||||
expand: _listExpand,
|
||||
);
|
||||
page: page,
|
||||
perPage: limit,
|
||||
filter: filterParts.join(' && '),
|
||||
expand: _listExpand,
|
||||
);
|
||||
return (result.items.map((r) => Job.fromJson(r.toJson())).toList()
|
||||
..sort((a, b) => b.dateCreated.compareTo(a.dateCreated)));
|
||||
}
|
||||
|
||||
Future<List<Job>> listInProgress(String labTenantId, {int limit = 50, String? location}) async {
|
||||
final filterParts = ['lab_tenant_id = "$labTenantId"', 'status = "in_progress"'];
|
||||
Future<List<Job>> listInProgress(String labTenantId,
|
||||
{int limit = 50, String? location}) async {
|
||||
final filterParts = [
|
||||
'lab_tenant_id = "$labTenantId"',
|
||||
'status = "in_progress"'
|
||||
];
|
||||
if (location != null) filterParts.add('location = "$location"');
|
||||
final result = await _pb.collection('jobs').getList(
|
||||
perPage: limit,
|
||||
filter: filterParts.join(' && '),
|
||||
expand: _listExpand,
|
||||
);
|
||||
perPage: limit,
|
||||
filter: filterParts.join(' && '),
|
||||
expand: _listExpand,
|
||||
);
|
||||
return (result.items.map((r) => Job.fromJson(r.toJson())).toList()
|
||||
..sort((a, b) {
|
||||
if (a.dueDate == null && b.dueDate == null) return b.dateCreated.compareTo(a.dateCreated);
|
||||
if (a.dueDate == null && b.dueDate == null) {
|
||||
return b.dateCreated.compareTo(a.dateCreated);
|
||||
}
|
||||
if (a.dueDate == null) return 1;
|
||||
if (b.dueDate == null) return -1;
|
||||
final cmp = a.dueDate!.compareTo(b.dueDate!);
|
||||
@@ -52,7 +58,8 @@ class LabJobsRepository {
|
||||
}
|
||||
|
||||
Future<Job> getJob(String jobId) async {
|
||||
final record = await _pb.collection('jobs').getOne(jobId, expand: _detailExpand);
|
||||
final record =
|
||||
await _pb.collection('jobs').getOne(jobId, expand: _detailExpand);
|
||||
return Job.fromJson(record.toJson());
|
||||
}
|
||||
|
||||
@@ -75,10 +82,21 @@ class LabJobsRepository {
|
||||
}
|
||||
|
||||
Future<Job> handToClinic(String jobId, Job job, {String? note}) async {
|
||||
final isFinal = job.currentStep == JobStep.cilaBitim;
|
||||
final currentStep = job.currentStep;
|
||||
if (currentStep == null) {
|
||||
throw Exception('Geçerli bir iş adımı bulunamadı.');
|
||||
}
|
||||
|
||||
final isFinal = currentStep == JobStep.cilaBitim;
|
||||
final nextStep = job.nextStep;
|
||||
final patch = isFinal
|
||||
? {'status': 'sent', 'location': 'at_clinic'}
|
||||
: {'location': 'at_clinic'};
|
||||
: currentStep.requiresClinicApproval
|
||||
? {'location': 'at_clinic'}
|
||||
: {
|
||||
'current_step': nextStep?.value,
|
||||
'location': 'at_lab',
|
||||
};
|
||||
|
||||
final record = await _pb.collection('jobs').update(jobId, body: patch);
|
||||
final updated = Job.fromJson(record.toJson());
|
||||
@@ -86,8 +104,10 @@ class LabJobsRepository {
|
||||
jobId: jobId,
|
||||
clinicTenantId: job.clinicTenantId,
|
||||
labTenantId: job.labTenantId,
|
||||
action: JobHistoryAction.handedToClinic,
|
||||
step: job.currentStep,
|
||||
action: currentStep.requiresClinicApproval || isFinal
|
||||
? JobHistoryAction.handedToClinic
|
||||
: JobHistoryAction.stepCompleted,
|
||||
step: currentStep,
|
||||
note: note,
|
||||
));
|
||||
return updated;
|
||||
@@ -109,7 +129,8 @@ class LabJobsRepository {
|
||||
}
|
||||
|
||||
Future<void> bulkAcceptPending(String labTenantId) async {
|
||||
final pending = await listInbound(labTenantId, status: 'pending', limit: 200);
|
||||
final pending =
|
||||
await listInbound(labTenantId, status: 'pending', limit: 200);
|
||||
await Future.wait(pending.map((j) => acceptJob(j)));
|
||||
}
|
||||
|
||||
@@ -121,11 +142,14 @@ class LabJobsRepository {
|
||||
return r.totalItems;
|
||||
}
|
||||
|
||||
Future<int> countDelivered(String labTenantId, {DateTime? from, DateTime? to}) async {
|
||||
Future<int> countDelivered(String labTenantId,
|
||||
{DateTime? from, DateTime? to}) async {
|
||||
final parts = ['lab_tenant_id = "$labTenantId"', 'status = "delivered"'];
|
||||
if (from != null) parts.add('updated >= "${_date(from)}"');
|
||||
if (to != null) parts.add('updated < "${_date(to)}"');
|
||||
final r = await _pb.collection('jobs').getList(perPage: 1, filter: parts.join(' && '));
|
||||
final r = await _pb
|
||||
.collection('jobs')
|
||||
.getList(perPage: 1, filter: parts.join(' && '));
|
||||
return r.totalItems;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user