Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵增煜
/
tzt-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4883b7d1
authored
Nov 18, 2024
by
lujunyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
处方打印
parent
e8005877
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
165 additions
and
173 deletions
+165
-173
app/Admin/Controllers/PrescriptionController.php
+6
-8
app/Admin/Controllers/PrescriptionPrintController.php
+156
-163
app/Admin/Extensions/ToolBar/Forms/AddPharmacyDrugForm.php
+2
-1
app/Models/PharmacyDrugModel.php
+1
-1
No files found.
app/Admin/Controllers/PrescriptionController.php
View file @
4883b7d1
...
@@ -144,17 +144,15 @@ protected function form()
...
@@ -144,17 +144,15 @@ protected function form()
$form
->
hidden
(
'pharmacist_license_number'
);
$form
->
hidden
(
'pharmacist_license_number'
);
$form
->
hidden
(
'pharmacist_signed_pic'
);
$form
->
hidden
(
'pharmacist_signed_pic'
);
// $form->multipleSelect('inquiry_info')->options(InquiryModel::all()->pluck('question', 'id'))->width(4)->saving(function ($v) {
// return json_encode($v);
// });
$form
->
table
(
'inquiry_info'
,
function
(
$table
)
{
$form
->
table
(
'inquiry_info'
,
function
(
$table
)
{
$table
->
select
(
'inquiry'
,
'问题项'
)
->
options
(
InquiryModel
::
all
()
->
pluck
(
'question'
,
'id'
))
->
width
(
3
)
;
$table
->
select
(
'inquiry'
,
'问题项'
)
->
options
(
InquiryModel
::
all
()
->
pluck
(
'question'
,
'id'
));
$table
->
radio
(
'selected'
,
'选择项'
)
->
options
([
1
=>
'是'
,
0
=>
'否'
])
->
width
(
43
)
;
$table
->
radio
(
'selected'
,
'选择项'
)
->
options
([
1
=>
'是'
,
0
=>
'否'
]);
})
->
saveAsJson
();
})
->
saveAsJson
();
$form
->
multipleSelect
(
'drug_info'
)
->
options
(
PharmacyDrugModel
::
with
(
'drug'
)
->
get
()
->
pluck
(
'drug'
)
->
pluck
(
'name'
,
'id'
))
->
width
(
4
)
->
saving
(
function
(
$v
)
{
$form
->
table
(
'drug_info'
,
function
(
$table
)
{
return
json_encode
(
$v
);
$table
->
select
(
'pharmacy_drug'
,
'药品'
)
->
options
(
PharmacyDrugModel
::
with
(
'drug'
)
->
get
()
->
pluck
(
'drug.name'
,
'id'
))
->
width
(
3
);
});
$table
->
number
(
'num'
,
'数量'
)
->
min
(
1
)
->
default
(
1
)
->
width
(
4
);
})
->
saveAsJson
();
$form
->
switch
(
'is_voided'
)
->
width
(
4
);
$form
->
switch
(
'is_voided'
)
->
width
(
4
);
$form
->
display
(
'created_at'
)
->
width
(
4
);
$form
->
display
(
'created_at'
)
->
width
(
4
);
...
...
app/Admin/Controllers/PrescriptionPrintController.php
View file @
4883b7d1
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
namespace
App\Admin\Controllers
;
namespace
App\Admin\Controllers
;
use
App\Models\PatientModel
;
use
App\Models\PharmacyDrugModel
;
use
App\Models\PrescriptionModel
;
use
App\Models\PrescriptionModel
;
use
Dcat\Admin\Http\Controllers\AdminController
;
use
Dcat\Admin\Http\Controllers\AdminController
;
use
Dcat\Admin\Layout\Content
;
use
Dcat\Admin\Layout\Content
;
...
@@ -34,181 +36,172 @@ public function search()
...
@@ -34,181 +36,172 @@ public function search()
]);
]);
}
}
try
{
// try {
// 获取处方信息
// 获取处方信息
$prescription
=
PrescriptionModel
::
where
(
'id'
,
$prescriptionNo
)
->
first
();
$prescription
=
PrescriptionModel
::
where
(
'id'
,
$prescriptionNo
)
->
first
();
if
(
!
$prescription
)
{
if
(
!
$prescription
)
{
return
response
()
->
json
([
'status'
=>
false
,
'message'
=>
'未找到该处方'
]);
return
response
()
->
json
([
'status'
=>
false
,
'message'
=>
'未找到该处方'
]);
}
}
// 检查处方图片是否已经生成
// 检查处方图片是否已经生成
if
(
$prescription
->
prescription_pic
)
{
if
(
$prescription
->
prescription_pic
)
{
return
response
()
->
json
([
return
response
()
->
json
([
'status'
=>
true
,
'status'
=>
true
,
'data'
=>
[
'data'
=>
[
'img_url'
=>
Storage
::
url
(
$prescription
->
prescription_pic
),
'img_url'
=>
Storage
::
url
(
$prescription
->
prescription_pic
),
],
],
]);
]);
}
}
// 创建处方图片
// 创建处方图片
// 处方背景图宽1653,高2339
// 处方背景图宽1653,高2339
$img
=
Image
::
read
(
public_path
(
'static/images/chufangdan.jpg'
));
$img
=
Image
::
read
(
public_path
(
'static/images/chufangdan.jpg'
));
$imageWidth
=
1653
;
// 医院
$centerX
=
$imageWidth
/
2
;
// 手动调整 X 坐标以居中
$imageWidth
=
1653
;
// 医院
// 手动调整 X 坐标以居中
$img
->
text
(
$prescription
->
doctor_online_hospital_name
,
$centerX
,
70
,
function
(
$font
)
{
$centerX
=
$imageWidth
/
2
;
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$img
->
text
(
'江阴康恒诊所处方'
,
$centerX
,
70
,
function
(
$font
)
{
$font
->
size
(
72
);
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
color
(
'#000000'
);
$font
->
size
(
72
);
$font
->
align
(
'center'
);
// 使用 align('center') 以确保文本相对于 X 坐标居中
$font
->
color
(
'#000000'
);
$font
->
valign
(
'top'
);
// 确保文本垂直对齐方式
$font
->
align
(
'center'
);
// 使用 align('center') 以确保文本相对于 X 坐标居中
});
$font
->
valign
(
'top'
);
// 确保文本垂直对齐方式
// 处方单编号
});
$img
->
text
(
$prescription
->
id
,
1170
,
190
,
function
(
$font
)
{
// 处方单编号
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$img
->
text
(
'处方单编号:10000001'
,
1170
,
190
,
function
(
$font
)
{
$font
->
size
(
24
);
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
color
(
'#000000'
);
$font
->
size
(
24
);
});
$font
->
color
(
'#000000'
);
// 姓名
});
$img
->
text
(
$prescription
->
patient_name
,
410
,
260
,
function
(
$font
)
{
// 姓名
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$img
->
text
(
'周永福'
,
410
,
260
,
function
(
$font
)
{
$font
->
size
(
32
);
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
color
(
'#000000'
);
$font
->
size
(
32
);
});
$font
->
color
(
'#000000'
);
// 性别
});
$gender
=
PatientModel
::
SEX_MAP
[
$prescription
->
patient_gender
];
// 性别
$img
->
text
(
$gender
,
890
,
260
,
function
(
$font
)
{
$img
->
text
(
'男'
,
890
,
260
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
32
);
$font
->
size
(
32
);
$font
->
color
(
'#000000'
);
$font
->
color
(
'#000000'
);
});
});
// 年龄
// 年龄
$img
->
text
(
"
{
$prescription
->
patient_age
}
岁"
,
1270
,
260
,
function
(
$font
)
{
$img
->
text
(
'65岁'
,
1270
,
260
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
32
);
$font
->
size
(
32
);
$font
->
color
(
'#000000'
);
$font
->
color
(
'#000000'
);
});
});
// 日期
// 日期
$date
=
\Carbon\Carbon
::
parse
(
$prescription
->
created_at
)
->
format
(
'Y-m-d'
);
$img
->
text
(
'2024-10-23'
,
1215
,
330
,
function
(
$font
)
{
$img
->
text
(
$date
,
1215
,
330
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
32
);
$font
->
size
(
32
);
$font
->
color
(
'#000000'
);
$font
->
color
(
'#000000'
);
});
});
// 诊断
// 诊断
$img
->
text
(
'呼吸道感染'
,
330
,
460
,
function
(
$font
)
{
$img
->
text
(
$prescription
->
diagnosis_name
,
330
,
460
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
32
);
$font
->
color
(
'#000000'
);
});
$drugInfo
=
$prescription
->
drug_info
;
// 每个元素包含 'pharmacy_drug', 'num'
$drugInfo
=
json_decode
(
$drugInfo
,
true
);
$medicines
=
[];
foreach
(
$drugInfo
as
$v
)
{
$pharmacyDrug
=
PharmacyDrugModel
::
with
([
'drug'
,
'dosage'
])
->
find
(
$v
[
'pharmacy_drug'
]);
$medicines
[]
=
[
'name'
=>
$pharmacyDrug
->
drug
->
name
,
'spec'
=>
$pharmacyDrug
->
drug
->
spec
,
'num'
=>
$v
[
'num'
],
'sig'
=>
$pharmacyDrug
->
dosage
->
dosage_desc
,
];
}
// 初始 Y 坐标
$yCoordinate
=
650
;
// 根据需要调整初始 Y 坐标
foreach
(
$medicines
as
$medicine
)
{
// 打印药品名称、规格和盒数
$medicineText
=
"
{
$medicine
[
'name'
]
}
{
$medicine
[
'spec'
]
}
{
$medicine
[
'num'
]
}{
$pharmacyDrug
->
unit
}
"
;
$img
->
text
(
$medicineText
,
550
,
$yCoordinate
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
32
);
$font
->
size
(
32
);
$font
->
color
(
'#000000'
);
$font
->
color
(
'#000000'
);
$font
->
align
(
'center'
);
});
});
// 假设 $prescription->medicines 是一个包含药品信息的数组
// 增加 Y 坐标以打印下一行
// $medicines = $prescription->drug_info; // 每个元素包含 'name', 'spec', 'box', 'sig'
$yCoordinate
+=
40
;
// 根据字体大小调整行间距
$medicines
=
[
[
// 打印 sig 信息
'name'
=>
'阿莫西林胶囊'
,
$img
->
text
(
'Sig: '
.
$medicine
[
'sig'
],
550
,
$yCoordinate
,
function
(
$font
)
{
'spec'
=>
'0.5g*20粒'
,
'box'
=>
2
,
'sig'
=>
'每日三次,每次两粒,饭后服用'
,
],
[
'name'
=>
'布洛芬片'
,
'spec'
=>
'0.2g*30片'
,
'box'
=>
1
,
'sig'
=>
'每日两次,每次一片,必要时服用'
,
],
[
'name'
=>
'维生素C片'
,
'spec'
=>
'100mg*100片'
,
'box'
=>
1
,
'sig'
=>
'每日一次,每次一片,早晨服用'
,
],
];
// 初始 Y 坐标
$yCoordinate
=
650
;
// 根据需要调整初始 Y 坐标
foreach
(
$medicines
as
$medicine
)
{
// 打印药品名称、规格和盒数
$medicineText
=
"
{
$medicine
[
'name'
]
}
{
$medicine
[
'spec'
]
}
{
$medicine
[
'box'
]
}
盒"
;
$img
->
text
(
$medicineText
,
550
,
$yCoordinate
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
32
);
$font
->
color
(
'#000000'
);
$font
->
align
(
'center'
);
});
// 增加 Y 坐标以打印下一行
$yCoordinate
+=
40
;
// 根据字体大小调整行间距
// 打印 sig 信息
$img
->
text
(
'Sig: '
.
$medicine
[
'sig'
],
550
,
$yCoordinate
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
32
);
$font
->
color
(
'#000000'
);
$font
->
align
(
'center'
);
});
// 增加 Y 坐标以准备打印下一个药品
$yCoordinate
+=
60
;
// 根据字体大小调整行间距
}
// 打印两行空白
$yCoordinate
+=
30
;
// 空白行间距
$yCoordinate
+=
30
;
// 空白行间距
// 打印“以下空白”文字
$img
->
text
(
'以下空白'
,
650
,
$yCoordinate
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
32
);
$font
->
size
(
32
);
$font
->
color
(
'#000000'
);
$font
->
color
(
'#000000'
);
$font
->
align
(
'center'
);
$font
->
align
(
'center'
);
});
});
// 医师签名图片
// 增加 Y 坐标以准备打印下一个药品
if
(
$prescription
->
doctor_signed_pic
)
{
$yCoordinate
+=
60
;
// 根据字体大小调整行间距
$doctorSignData
=
base64_decode
(
$prescription
->
doctor_signed_pic
);
}
$doctorSign
=
Image
::
read
(
$doctorSignData
);
$doctorSign
->
rotate
(
90
);
$doctorSign
->
resize
(
150
,
100
);
$img
->
place
(
$doctorSign
,
'bottom-left'
,
400
,
410
);
}
// 药师签名图片
if
(
$prescription
->
pharmacist_signed_pic
)
{
$pharmacistSignData
=
base64_decode
(
$prescription
->
pharmacist_signed_pic
);
$pharmacistSign
=
Image
::
read
(
$pharmacistSignData
);
$pharmacistSign
->
rotate
(
90
);
$pharmacistSign
->
resize
(
150
,
100
);
$img
->
place
(
$pharmacistSign
,
'bottom-left'
,
870
,
410
);
}
// 将图片保存到临时文件
$tempPath
=
storage_path
(
'app/public'
)
.
$prescriptionNo
.
'.jpg'
;
$img
->
save
(
$tempPath
);
// 上传到腾讯云
Storage
::
putFileAs
(
'prescriptions'
,
$tempPath
,
$prescriptionNo
.
'.jpg'
);
// 删除临时文件
unlink
(
$tempPath
);
$cosPath
=
'prescriptions/'
.
$prescriptionNo
.
'.jpg'
;
// 将生成的图片路径存储到数据库
$prescription
->
prescription_pic
=
$cosPath
;
$prescription
->
save
();
return
response
()
->
json
([
// 打印两行空白
'status'
=>
true
,
$yCoordinate
+=
30
;
// 空白行间距
'data'
=>
[
$yCoordinate
+=
30
;
// 空白行间距
'img_url'
=>
Storage
::
url
(
$cosPath
),
],
// 打印“以下空白”文字
]);
$img
->
text
(
'以下空白'
,
650
,
$yCoordinate
,
function
(
$font
)
{
}
catch
(
\Exception
$e
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
return
response
()
->
json
([
$font
->
size
(
32
);
'status'
=>
false
,
$font
->
color
(
'#000000'
);
'message'
=>
'处方生成失败:'
.
$e
->
getMessage
(),
$font
->
align
(
'center'
);
]);
});
// 医师签名图片
if
(
$prescription
->
doctor_signed_pic
)
{
$pharmacistSignPath
=
Storage
::
url
(
$prescription
->
doctor_signed_pic
);
$doctorSign
=
Image
::
read
(
file_get_contents
(
$pharmacistSignPath
));
$doctorSign
->
rotate
(
90
);
$doctorSign
->
resize
(
150
,
100
);
$img
->
place
(
$doctorSign
,
'bottom-left'
,
400
,
410
);
}
// 药师签名图片
if
(
$prescription
->
pharmacist_signed_pic
)
{
$pharmacistSignPath
=
Storage
::
url
(
$prescription
->
pharmacist_signed_pic
);
$pharmacistSign
=
Image
::
read
(
file_get_contents
(
$pharmacistSignPath
));
$pharmacistSign
->
rotate
(
90
);
$pharmacistSign
->
resize
(
150
,
100
);
$img
->
place
(
$pharmacistSign
,
'bottom-left'
,
870
,
410
);
}
}
// 将图片保存到临时文件
$tempPath
=
storage_path
(
'app/public'
)
.
$prescriptionNo
.
'.jpg'
;
$img
->
save
(
$tempPath
);
// 上传到腾讯云
Storage
::
putFileAs
(
'prescriptions'
,
$tempPath
,
$prescriptionNo
.
'.jpg'
);
// 删除临时文件
unlink
(
$tempPath
);
$cosPath
=
'prescriptions/'
.
$prescriptionNo
.
'.jpg'
;
// 将生成的图片路径存储到数据库
$prescription
->
prescription_pic
=
$cosPath
;
$prescription
->
save
();
return
response
()
->
json
([
'status'
=>
true
,
'data'
=>
[
'img_url'
=>
Storage
::
url
(
$cosPath
),
],
]);
// } catch (\Exception $e) {
// return response()->json([
// 'status' => false,
// 'message' => '处方生成失败:'.$e->getMessage(),
// ]);
// }
}
}
}
}
app/Admin/Extensions/ToolBar/Forms/AddPharmacyDrugForm.php
View file @
4883b7d1
...
@@ -35,11 +35,12 @@ public function handle(array $input)
...
@@ -35,11 +35,12 @@ public function handle(array $input)
return
$this
->
response
()
->
error
(
'请选择药品'
)
->
refresh
();
return
$this
->
response
()
->
error
(
'请选择药品'
)
->
refresh
();
}
}
foreach
(
$ids
as
$id
)
{
foreach
(
$ids
as
$id
)
{
//
$drug = DrugModel::find($id);
$drug
=
DrugModel
::
find
(
$id
);
$where
=
[
'drug_id'
=>
$id
];
$where
=
[
'drug_id'
=>
$id
];
$data
=
[
$data
=
[
'pharmacy_id'
=>
Admin
::
user
()
->
pharmacy_id
,
'pharmacy_id'
=>
Admin
::
user
()
->
pharmacy_id
,
'drug_id'
=>
$id
,
'drug_id'
=>
$id
,
'unit'
=>
$drug
->
unit
,
];
];
PharmacyDrugModel
::
updateOrCreate
(
$where
,
$data
);
PharmacyDrugModel
::
updateOrCreate
(
$where
,
$data
);
}
}
...
...
app/Models/PharmacyDrugModel.php
View file @
4883b7d1
...
@@ -13,7 +13,7 @@ class PharmacyDrugModel extends Model
...
@@ -13,7 +13,7 @@ class PharmacyDrugModel extends Model
protected
$table
=
'pharmacy_drug'
;
protected
$table
=
'pharmacy_drug'
;
public
$fillable
=
[
'pharmacy_id'
,
'drug_id'
];
public
$fillable
=
[
'pharmacy_id'
,
'drug_id'
,
'unit'
];
// 关联药品池
// 关联药品池
public
function
drug
()
public
function
drug
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment