66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Services;
|
|
|
|
use App\ModelFilters\PatientRecordFilter;
|
|
use App\Models\PatientRecord;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Slowlyo\OwlAdmin\Admin;
|
|
|
|
class PatientRecordService extends BaseService
|
|
{
|
|
protected string $modelName = PatientRecord::class;
|
|
|
|
protected array $withRelationships = ['doctor', 'patient', 'type', 'notifyUser'];
|
|
|
|
protected string $modelFilterName = PatientRecordFilter::class;
|
|
|
|
public function listQuery()
|
|
{
|
|
$model = $this->getModel();
|
|
$filter = $this->getModelFilter();
|
|
|
|
$query = $this->query();
|
|
if ($this->withRelationships) {
|
|
$query->with($this->withRelationships);
|
|
}
|
|
|
|
if ($filter) {
|
|
$query->filter(request()->input(), $filter);
|
|
}
|
|
|
|
return $query->sort();
|
|
}
|
|
|
|
public function resloveData($data)
|
|
{
|
|
$creator_id = data_get($data, 'creator_id');
|
|
if (!$creator_id) {
|
|
$data['creator_id'] = data_get(Admin::user(), 'id');
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
public function validate($data, $id = null)
|
|
{
|
|
$createRules = [
|
|
'patient_id' => 'required',
|
|
'type_id' => 'required',
|
|
'treat_at' => 'required',
|
|
'doctor_id' => 'required',
|
|
'origin_price' => ['required', 'numeric'],
|
|
'sell_price' => ['required', 'numeric'],
|
|
'order_status' => 'required',
|
|
];
|
|
$updateRules = [
|
|
'origin_price' => 'numeric',
|
|
'sell_price' => 'numeric',
|
|
];
|
|
$validator = Validator::make($data, $id ? $updateRules : $createRules);
|
|
if ($validator->fails()) {
|
|
return $validator->errors()->first();
|
|
}
|
|
return true;
|
|
}
|
|
}
|