Commit fc67c87d by lujunyi

打印处方

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