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
bc527fab
authored
Nov 18, 2024
by
赵增煜
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://git.imohe.com/zhaozengyu/tzt-admin
parents
7f9439e5
1c3fa528
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
209 additions
and
154 deletions
+209
-154
app/Admin/Controllers/PrescriptionPrintController.php
+181
-154
database/migrations/2024_11_18_155308_add_prescription_pic_eseal_to_prescription_table.php
+28
-0
public/static/images/dianzizhang.png
+0
-0
No files found.
app/Admin/Controllers/PrescriptionPrintController.php
View file @
bc527fab
...
@@ -28,6 +28,7 @@ public function index(Content $content): Content
...
@@ -28,6 +28,7 @@ public function index(Content $content): Content
public
function
search
()
public
function
search
()
{
{
$prescriptionNo
=
request
(
'prescription_no'
);
$prescriptionNo
=
request
(
'prescription_no'
);
$printEseal
=
request
(
'print_eseal'
,
0
);
// 是否打印电子印章,实时生成
if
(
empty
(
$prescriptionNo
))
{
if
(
empty
(
$prescriptionNo
))
{
return
response
()
->
json
([
return
response
()
->
json
([
...
@@ -36,172 +37,198 @@ public function search()
...
@@ -36,172 +37,198 @@ 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
(
$printEseal
&&
$prescription
->
prescription_pic_eseal
)
{
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_eseal
),
],
],
]);
]);
}
}
elseif
(
$prescription
->
prescription_pic
)
{
return
response
()
->
json
([
// 创建处方图片
'status'
=>
true
,
// 处方背景图宽1653,高2339
'data'
=>
[
$img
=
Image
::
read
(
public_path
(
'static/images/chufangdan.jpg'
));
'img_url'
=>
Storage
::
url
(
$prescription
->
prescription_pic
),
],
$imageWidth
=
1653
;
]);
$centerX
=
$imageWidth
/
2
;
// 手动调整 X 坐标以居中
}
// 医院
$img
->
text
(
$prescription
->
doctor_online_hospital_name
,
$centerX
,
70
,
function
(
$font
)
{
// 创建处方图片
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
// 处方背景图宽1653,高2339
$font
->
size
(
72
);
$img
=
Image
::
read
(
public_path
(
'static/images/chufangdan.jpg'
));
$font
->
color
(
'#000000'
);
$font
->
align
(
'center'
);
// 使用 align('center') 以确保文本相对于 X 坐标居中
$imageWidth
=
1653
;
$font
->
valign
(
'top'
);
// 确保文本垂直对齐方式
$centerX
=
$imageWidth
/
2
;
// 手动调整 X 坐标以居中
});
// 医院
// 处方单编号
$img
->
text
(
$prescription
->
doctor_online_hospital_name
,
$centerX
,
70
,
function
(
$font
)
{
$img
->
text
(
"处方单编号:
{
$prescription
->
id
}
"
,
1170
,
190
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
72
);
$font
->
size
(
24
);
$font
->
color
(
'#000000'
);
$font
->
color
(
'#000000'
);
$font
->
align
(
'center'
);
// 使用 align('center') 以确保文本相对于 X 坐标居中
});
$font
->
valign
(
'top'
);
// 确保文本垂直对齐方式
// 姓名
});
$img
->
text
(
$prescription
->
patient_name
,
410
,
260
,
function
(
$font
)
{
// 处方单编号
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$img
->
text
(
"处方单编号:
{
$prescription
->
id
}
"
,
1170
,
190
,
function
(
$font
)
{
$font
->
size
(
32
);
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
color
(
'#000000'
);
$font
->
size
(
24
);
});
$font
->
color
(
'#000000'
);
// 性别
});
$gender
=
PatientModel
::
SEX_MAP
[
$prescription
->
patient_gender
];
// 姓名
$img
->
text
(
$gender
,
890
,
260
,
function
(
$font
)
{
$img
->
text
(
$prescription
->
patient_name
,
410
,
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
)
{
$gender
=
PatientModel
::
SEX_MAP
[
$prescription
->
patient_gender
];
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$img
->
text
(
$gender
,
890
,
260
,
function
(
$font
)
{
$font
->
size
(
32
);
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
color
(
'#000000'
);
$font
->
size
(
32
);
});
$font
->
color
(
'#000000'
);
// 开放日期
});
$date
=
\Carbon\Carbon
::
parse
(
$prescription
->
prescription_at
)
->
format
(
'Y-m-d'
);
// 年龄
$img
->
text
(
$date
,
1215
,
330
,
function
(
$font
)
{
$img
->
text
(
"
{
$prescription
->
patient_age
}
岁"
,
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'
);
});
});
// 诊断
// 开放日期
$img
->
text
(
$prescription
->
diagnosis_name
,
330
,
460
,
function
(
$font
)
{
$date
=
\Carbon\Carbon
::
parse
(
$prescription
->
prescription_at
)
->
format
(
'Y-m-d'
);
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$img
->
text
(
$date
,
1215
,
330
,
function
(
$font
)
{
$font
->
size
(
32
);
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
color
(
'#000000'
);
$font
->
size
(
32
);
});
$font
->
color
(
'#000000'
);
});
$drugInfo
=
$prescription
->
drug_info
;
// 每个元素包含 'pharmacy_drug', 'num'
// 诊断
$drugInfo
=
json_decode
(
$drugInfo
,
true
);
$img
->
text
(
$prescription
->
diagnosis_name
,
330
,
460
,
function
(
$font
)
{
$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'
);
});
});
// 增加 Y 坐标以打印下一行
$drugInfo
=
$prescription
->
drug_info
;
// 每个元素包含 'pharmacy_drug', 'num'
$yCoordinate
+=
40
;
// 根据字体大小调整行间距
$drugInfo
=
json_decode
(
$drugInfo
,
true
);
$medicines
=
[];
// 打印 sig 信息
foreach
(
$drugInfo
as
$v
)
{
$img
->
text
(
'Sig: '
.
$medicine
[
'sig'
],
550
,
$yCoordinate
,
function
(
$font
)
{
$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
->
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 坐标以准备打印下一个药品
// 医师签名图片
$yCoordinate
+=
60
;
// 根据字体大小调整行间距
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
);
}
// 不带印章处方图片生成
$picName
=
$prescriptionNo
.
'.jpg'
;
$tempPath
=
storage_path
(
'app/public'
)
.
$picName
;
$img
->
save
(
$tempPath
);
// 不带电子印章
// 上传到腾讯云
Storage
::
putFileAs
(
'prescriptions'
,
$tempPath
,
$picName
);
// 电子印章版处方图片生成
$eseal
=
Image
::
read
(
public_path
(
'static/images/dianzizhang.png'
));
// $eseal->rotate(90);
$eseal
->
resize
(
150
,
150
);
$img
->
place
(
$eseal
,
'bottom-right'
,
180
,
500
);
$picEsealName
=
$prescriptionNo
.
'-eseal.jpg'
;
$tempEsealPath
=
storage_path
(
'app/public'
)
.
$picEsealName
;
$img
->
save
(
$tempEsealPath
);
// 上传到腾讯云
Storage
::
putFileAs
(
'prescriptions'
,
$tempEsealPath
,
$picEsealName
);
// 删除临时文件
unlink
(
$tempPath
);
unlink
(
$tempEsealPath
);
$cosPath
=
"prescriptions/
{
$picName
}
"
;
$cosEsealPath
=
"prescriptions/
{
$picEsealName
}
"
;
// 将生成的处方图片路径存储到数据库
$prescription
->
prescription_pic
=
$cosPath
;
$prescription
->
prescription_pic_eseal
=
$cosEsealPath
;
$prescription
->
save
();
// 保存处方图片路径
if
(
$printEseal
=
true
)
{
$imgUrl
=
Storage
::
url
(
$cosEsealPath
);
}
else
{
$imgUrl
=
Storage
::
url
(
$cosPath
);
}
// 打印两行空白
return
response
()
->
json
([
$yCoordinate
+=
30
;
// 空白行间距
'status'
=>
true
,
$yCoordinate
+=
30
;
// 空白行间距
'data'
=>
[
'img_url'
=>
$imgUrl
,
// 打印“以下空白”文字
],
$img
->
text
(
'以下空白'
,
650
,
$yCoordinate
,
function
(
$font
)
{
]);
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
}
catch
(
\Exception
$e
)
{
$font
->
size
(
32
);
return
response
()
->
json
([
$font
->
color
(
'#000000'
);
'status'
=>
false
,
$font
->
align
(
'center'
);
'message'
=>
'处方生成失败:'
.
$e
->
getMessage
(),
});
]);
// 医师签名图片
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(),
// ]);
// }
}
}
}
}
database/migrations/2024_11_18_155308_add_prescription_pic_eseal_to_prescription_table.php
0 → 100644
View file @
bc527fab
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
return
new
class
extends
Migration
{
/**
* Run the migrations.
*/
public
function
up
()
:
void
{
Schema
::
table
(
'prescription'
,
function
(
Blueprint
$table
)
{
$table
->
string
(
'prescription_pic_eseal'
)
->
nullable
()
->
comment
(
'处方单带电子印章图片地址'
);
});
}
/**
* Reverse the migrations.
*/
public
function
down
()
:
void
{
Schema
::
table
(
'prescription'
,
function
(
Blueprint
$table
)
{
//
});
}
};
public/static/images/dianzizhang.png
0 → 100644
View file @
bc527fab
47.2 KB
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