Commit fc67c87d by lujunyi

打印处方

parent 08cbe583
......@@ -3,6 +3,7 @@
namespace App\Admin\Controllers;
use App\Admin\Repositories\PharmacyRepository;
use App\Models\DosageModel;
use App\Models\PharmacistModel;
use App\Models\PharmacyDrugModel;
use App\Models\PharmacyModel;
......@@ -168,11 +169,19 @@ protected function form()
$name = $form->name;
// 复制药店pharmacy_id=1的药店商品到新建药店
if ($form->isCreating()) {
$originalModels = PharmacyDrugModel::where('pharmacy_id', 1)->get();
foreach ($originalModels as $model) {
$pharmacyModel = $model->replicate();
$pharmacyModel->pharmacy_id = $pharmacyId;
$pharmacyModel->save();
// 复制药品
$originalPharmacyModels = PharmacyDrugModel::where('pharmacy_id', 1)->get();
foreach ($originalPharmacyModels as $pharmacyModel) {
$pharmacyNewModel = $pharmacyModel->replicate();
$pharmacyNewModel->pharmacy_id = $pharmacyId;
$pharmacyNewModel->save();
}
// 复制用法用量
$originalDosageModels = DosageModel::where('pharmacy_id', 1)->get();
foreach ($originalDosageModels as $dosageModel) {
$dosageNewModel = $dosageModel->replicate();
$dosageNewModel->pharmacy_id = $pharmacyId;
$dosageNewModel->save();
}
}
......
......@@ -2,6 +2,7 @@
namespace App\Admin\Controllers;
use App\Models\DosageModel;
use App\Models\PatientModel;
use App\Models\PrescriptionModel;
use Dcat\Admin\Admin;
......@@ -133,22 +134,24 @@ public function search()
if ($dosageData) {
$dosageMap = [];
foreach ($dosageData as $dosage) {
$dosageMap[$dosage['pharmacy_drug_id']] = $dosage['dosage_desc'];
$dosageMap[$dosage['pharmacy_drug_id']] = $dosage['dosage_id'];
}
// 更新 drug_info 中的 dosage_desc
foreach ($medicines as &$medicine) {
if (isset($dosageMap[$medicine['pharmacy_drug_id']])) {
$medicine['dosage_desc'] = $dosageMap[$medicine['pharmacy_drug_id']];
$medicine['dosage_id'] = $dosageMap[$medicine['pharmacy_drug_id']];
$tmpDosage = DosageModel::where('pharmacy_id', $prescription->pharmacy_id)->where('id', $dosageMap[$medicine['pharmacy_drug_id']])->first();
$medicine['dosage_desc'] = $tmpDosage->dosage_desc;
}
}
// 重新保存处方信息
$prescription->drug_info = $medicines; // 更新药品信息
$prescription->save(); // 保存更新后的处方
$prescription->refresh(); // 刷新处方数据
}
// 初始 Y 坐标
$medicines = $prescription->drug_info;
$yCoordinate = 650; // 根据需要调整初始 Y 坐标
foreach ($medicines as $medicine) {
// 打印药品名称、规格和盒数
$medicineText = "{$medicine['drug_name']} {$medicine['spec']} {$medicine['num']}{$medicine['unit']}";
......@@ -190,7 +193,6 @@ public function search()
if ($prescription->doctor_signed_pic) {
$pharmacistSignPath = file_get_contents($prescription->doctor_signed_pic);
$doctorSign = Image::read($pharmacistSignPath);
// $doctorSign->rotate(90);
$doctorSign->resize(150, 100);
$img->place($doctorSign, 'bottom-left', 400, 410);
}
......@@ -198,7 +200,6 @@ public function search()
if ($prescription->pharmacist_signed_pic) {
$pharmacistSignPath = file_get_contents($prescription->pharmacist_signed_pic);
$pharmacistSign = Image::read($pharmacistSignPath);
// $pharmacistSign->rotate(90);
$pharmacistSign->resize(150, 100);
$img->place($pharmacistSign, 'bottom-left', 870, 410);
}
......@@ -238,11 +239,14 @@ public function search()
$imgUrl = Storage::url($cosPath);
}
$dosageList = DosageModel::where('pharmacy_id', $prescription->pharmacy_id)->select('id', 'dosage_desc')->get()->toArray();
return response()->json([
'status' => true,
'data' => [
'img_url' => $imgUrl,
'drug_info' => $prescription->drug_info,
'dosage_list' => $dosageList,
],
]);
} catch (\Exception $e) {
......
......@@ -7,7 +7,7 @@
<label class="form-check-label" for="is_eseal">带电子印章</label>
</div>
<button class="btn btn-primary" type="button" id="search-btn" style="margin-left: 10px;">
<i class="fa fa-search"></i> 搜索
<i class="fa fa-search"></i> 搜索打印处方
</button>
</div>
</div>
......@@ -87,11 +87,11 @@
Dcat.loading(false);
if (response.status) {
$('#prescription-image').attr('src', response.data.img_url);
$('#prescription-image').attr('src', response.data.img_url + '?t=' + new Date().getTime());
$('#download-btn').data('url', response.data.img_url);
$('#prescription-container').show();
this.showEditableForm(response.data.drug_info);
this.showEditableForm(response.data.drug_info,response.data.dosage_list);
} else {
Dcat.error(response.message || '获取处方失败');
}
......@@ -128,7 +128,10 @@
}
// 新增:展示可编辑的药品信息表单
showEditableForm(drugs) {
showEditableForm(drugs, dosage_list) {
console.log('drugs:', drugs); // 调试信息
console.log('dosage_list:', dosage_list); // 调试信息
// 仅在 drugs 有值时生成表单
// 清空现有的药品信息表单
$('#editable-drug-list').remove();
......@@ -139,7 +142,17 @@
<div class="drug-item input-group mb-2">
<input type="hidden" name="pharmacy_drug_id[]" value="${drug.pharmacy_drug_id}">
<label class="input-group-text">${drug.drug_name} || ${drug.spec} || ${drug.num}${drug.unit}</label>
<input type="text" class="form-control" name="dosage_desc[]" value="${drug.dosage_desc}" placeholder="请输入剂量">
<select class="form-control" name="dosage_id[]">
${Array.isArray(dosage_list) && dosage_list.length > 0 ?
(() => {
let options = '';
dosage_list.forEach(dose => {
options += `<option value="${dose.id}" ${drug.dosage_id === dose.id ? 'selected' : ''}>${dose.dosage_desc}</option>`; // 判断是否选中
});
return options;
})() :
'<option value="">无可用剂量</option>'}
</select>
</div>
`;
});
......@@ -153,10 +166,10 @@
let dosageData = [];
$('#editable-drug-list .drug-item').each(function() {
let drugId = $(this).find('input[name="pharmacy_drug_id[]"]').val();
let dosageDesc = $(this).find('input[name="dosage_desc[]"]').val();
let dosageId = $(this).find('select[name="dosage_id[]"]').val();
dosageData.push({
pharmacy_drug_id: parseInt(drugId),
dosage_desc: dosageDesc
dosage_id: parseInt(dosageId)
});
});
return JSON.stringify(dosageData);
......
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