Commit 61fc9d4b by 赵增煜

导入580

parent 19cbfa7b
......@@ -8,6 +8,7 @@
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use App\Models\PharmacyModel;
use App\Models\ExternalPrescriptionModel;
use App\Admin\Extensions\ToolBar\Actions\ExternalPrescriptionImportAction;
class ExternalPrescriptionController extends AdminController
{
......@@ -29,7 +30,7 @@ protected function grid()
$grid->column('agent');
$grid->column('patient_name');
$grid->column('patient_mobile');
$grid->column('patient_gender');
$grid->column('patient_gender')->using(ExternalPrescriptionModel::SEX_MAP);
$grid->column('patient_age');
$grid->column('patient_id_card');
$grid->column('doctor_name');
......
......@@ -4,6 +4,7 @@
use App\Models\DosageModel;
use App\Models\ExternalPrescriptionModel;
use App\Models\PharmacyModel;
use Dcat\Admin\Admin;
use Dcat\Admin\Http\JsonResponse;
use Dcat\Admin\Widgets\Form;
......@@ -48,7 +49,45 @@ public function handle(array $input): JsonResponse
}
$prescriptions[$prescriptionNo]['药品明细'][] = $drug_info;
}
Log::info("prescriptions====>".json_encode($prescriptions));
// 循环插入数据
foreach($prescriptions as $prescriptionNo=>$prescription){
// 校验数据库中是否存在该数据
$externalPrescriptionModel = ExternalPrescriptionModel::where('prescription_no', $prescriptionNo)->first();
if( !$externalPrescriptionModel ){
$externalPrescriptionModel = new ExternalPrescriptionModel;
}
// 查找对应的药店ID
$pharmacy = PharmacyModel::where('name', $prescription['门店名称'])->first();
$pharmacyId = 0;
if( !$pharmacy ){
$pharmacyId = $pharmacy->id;
}
$externalPrescriptionModel->external_prescription_id = $prescriptionNo;
$externalPrescriptionModel->issue_at = $prescription['处方开具时间'];
$externalPrescriptionModel->status = $prescription['处方状态'];
$externalPrescriptionModel->company_name = $prescription['企业名称'];
$externalPrescriptionModel->pharmacy_name = $prescription['门店名称'];
$externalPrescriptionModel->pharmacy_id = $pharmacyId;
$externalPrescriptionModel->agent = $prescription['会员/代理人'];
$externalPrescriptionModel->patient_name = $prescription['就诊人姓名'];
$externalPrescriptionModel->patient_mobile = $prescription['就诊人电话'];
$externalPrescriptionModel->patient_gender = self::getGender($prescription['就诊人性别']);
$externalPrescriptionModel->patient_age = $prescription['就诊人年龄'];
$externalPrescriptionModel->patient_id_card = $prescription['就诊人身份证号'];
$externalPrescriptionModel->doctor_name = $prescription['接诊医师姓名'];
$externalPrescriptionModel->diagnosis = $prescription['诊断'];
$externalPrescriptionModel->drug_info = $prescription['药品明细'];
$externalPrescriptionModel->pharmacist_name = $prescription['审核药师'];
$externalPrescriptionModel->review_at = $prescription['药师审核时间'];
$externalPrescriptionModel->pharmacist_attr = $prescription['药师属性'];
$externalPrescriptionModel->dispatcher = $prescription['调配人'];
$externalPrescriptionModel->checker = $prescription['核对人'];
$externalPrescriptionModel->dispenser = $prescription['发药人'];
if( $externalPrescriptionModel->save() ){
$successNum++;
}
}
// Log::info("prescriptions====>".json_encode($prescriptions));
}
$return = $this->response()->success("导入成功{$successNum}条")->refresh();
......@@ -79,4 +118,18 @@ public function form()
// $downloadUrl = admin_url('dosage-template');
// $this->html("<a target='_blank' href='{$downloadUrl}'>下载用法用量导入模板</a>");
}
private static function getGender($value){
$value = trim($value);
switch ($value) {
case '男':
return 1;
case '女':
return 2;
default:
return 0;
}
}
}
\ No newline at end of file
......@@ -6,11 +6,24 @@
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
class ExternalPrescription extends Model
class ExternalPrescriptionModel extends Model
{
use HasDateTimeFormatter;
use SoftDeletes;
// 性别[0=未知,1=男,2=女]
const SEX_UNDEFINED = 0;
const SEX_MALE = 1;
const SEX_FEMALE = 2;
// 性别-文字映射
const SEX_MAP = [
self::SEX_UNDEFINED => '未知',
self::SEX_MALE => '男',
self::SEX_FEMALE => '女',
];
protected $table = 'external_prescription';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment