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
5d74b4df
authored
Dec 04, 2024
by
lujunyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
打印
parent
c697e93b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
195 additions
and
164 deletions
+195
-164
app/Admin/Controllers/PrescriptionPrintController.php
+195
-158
resources/views/admin/prescription-print.blade.php
+0
-6
No files found.
app/Admin/Controllers/PrescriptionPrintController.php
View file @
5d74b4df
...
...
@@ -51,113 +51,114 @@ public function search()
]);
}
try
{
$pharmacy_id
=
Admin
::
user
()
->
pharmacy_id
;
// 获取处方信息
$prescription
=
PrescriptionModel
::
where
(
'id'
,
$prescriptionNo
)
->
where
(
'pharmacy_id'
,
$pharmacy_id
)
->
where
(
'status'
,
PrescriptionModel
::
PRESCRIPTION_STATUS_SUCCESS
)
->
first
();
if
(
!
$prescription
)
{
return
response
()
->
json
([
'status'
=>
false
,
'message'
=>
'未找到该处方或还未审方成功~'
]);
}
// 检查处方图片是否已经生成
// if ($isEseal && $prescription->prescription_pic_eseal) {
// return response()->json([
// 'status' => true,
// 'data' => [
// 'img_url' => $prescription->prescription_pic_eseal,
// 'drug_info' => $prescription->drug_info,
// ],
// ]);
// } elseif ($prescription->prescription_pic) {
// return response()->json([
// 'status' => true,
// 'data' => [
// 'img_url' => $prescription->prescription_pic,
// 'drug_info' => $prescription->drug_info,
// ],
// ]);
// }
//
try {
$pharmacy_id
=
Admin
::
user
()
->
pharmacy_id
;
// 获取处方信息
$prescription
=
PrescriptionModel
::
where
(
'id'
,
$prescriptionNo
)
->
where
(
'pharmacy_id'
,
$pharmacy_id
)
->
where
(
'status'
,
PrescriptionModel
::
PRESCRIPTION_STATUS_SUCCESS
)
->
first
();
if
(
!
$prescription
)
{
return
response
()
->
json
([
'status'
=>
false
,
'message'
=>
'未找到该处方或还未审方成功~'
]);
}
// 检查处方图片是否已经生成
// if ($isEseal && $prescription->prescription_pic_eseal) {
// return response()->json([
// 'status' => true,
// 'data' => [
// 'img_url' => $prescription->prescription_pic_eseal,
// 'drug_info' => $prescription->drug_info,
// ],
// ]);
// } elseif ($prescription->prescription_pic) {
// return response()->json([
// 'status' => true,
// 'data' => [
// 'img_url' => $prescription->prescription_pic,
// 'drug_info' => $prescription->drug_info,
// ],
// ]);
// }
// 创建处方图片
// 处方背景图宽1653,高2339
$backgroudImg
=
public_path
(
'static/images/xiyao.jpg'
);
if
(
$prescription
->
prescription_type
==
PrescriptionModel
::
PRESCRIPTION_TYPE_TCM
)
{
$backgroudImg
=
public_path
(
'static/images/zhongyao.jpg'
);
}
// 创建处方图片
// 处方背景图宽1653,高2339
$backgroudImg
=
public_path
(
'static/images/xiyao.jpg'
);
if
(
$prescription
->
prescription_type
==
PrescriptionModel
::
PRESCRIPTION_TYPE_TCM
)
{
$backgroudImg
=
public_path
(
'static/images/zhongyao.jpg'
);
}
$img
=
Image
::
read
(
$backgroudImg
);
$img
=
Image
::
read
(
$backgroudImg
);
$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'
));
$font
->
size
(
72
);
$font
->
color
(
'#000000'
);
$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'
));
$font
->
size
(
36
);
$font
->
color
(
'#000000'
);
});
// 姓名
$img
->
text
(
$prescription
->
patient_name
,
410
,
260
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
40
);
$font
->
color
(
'#000000'
);
});
// 性别
$gender
=
PatientModel
::
SEX_MAP
[
$prescription
->
patient_gender
];
$img
->
text
(
$gender
,
890
,
260
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
40
);
$font
->
color
(
'#000000'
);
});
// 年龄
$img
->
text
(
"
{
$prescription
->
patient_age
}
岁"
,
1270
,
260
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
40
);
$font
->
color
(
'#000000'
);
});
// 开方日期
$date
=
\Carbon\Carbon
::
parse
(
$prescription
->
prescription_at
)
->
format
(
'Y-m-d'
);
$img
->
text
(
$date
,
1215
,
330
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
40
);
$font
->
color
(
'#000000'
);
});
// 诊断
$img
->
text
(
$prescription
->
diagnosis_name
,
330
,
460
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
40
);
$font
->
color
(
'#000000'
);
});
$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'
));
$font
->
size
(
72
);
$font
->
color
(
'#000000'
);
$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'
));
$font
->
size
(
36
);
$font
->
color
(
'#000000'
);
});
// 姓名
$img
->
text
(
$prescription
->
patient_name
,
410
,
260
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
40
);
$font
->
color
(
'#000000'
);
});
// 性别
$gender
=
PatientModel
::
SEX_MAP
[
$prescription
->
patient_gender
];
$img
->
text
(
$gender
,
890
,
260
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
40
);
$font
->
color
(
'#000000'
);
});
// 年龄
$img
->
text
(
"
{
$prescription
->
patient_age
}
岁"
,
1270
,
260
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
40
);
$font
->
color
(
'#000000'
);
});
// 开方日期
$date
=
\Carbon\Carbon
::
parse
(
$prescription
->
prescription_at
)
->
format
(
'Y-m-d'
);
$img
->
text
(
$date
,
1215
,
330
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
40
);
$font
->
color
(
'#000000'
);
});
// 诊断
$img
->
text
(
$prescription
->
diagnosis_name
,
330
,
460
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
40
);
$font
->
color
(
'#000000'
);
});
$medicines
=
$prescription
->
drug_info
;
// 每个元素包含 'pharmacy_drug', 'num'
// 根据传过来的用法用量进行修改替换
if
(
$dosageData
)
{
$dosageMap
=
[];
foreach
(
$dosageData
as
$dosage
)
{
$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_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
;
}
$medicines
=
$prescription
->
drug_info
;
// 每个元素包含 'pharmacy_drug', 'num'
// 根据传过来的用法用量进行修改替换
if
(
$dosageData
)
{
$dosageMap
=
[];
foreach
(
$dosageData
as
$dosage
)
{
$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_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 坐标
// 重新保存处方信息
$prescription
->
drug_info
=
$medicines
;
// 更新药品信息
$prescription
->
save
();
// 保存更新后的处方
$prescription
->
refresh
();
// 刷新处方数据
}
// 初始 Y 坐标
$medicines
=
$prescription
->
drug_info
;
$yCoordinate
=
650
;
// 根据需要调整初始 Y 坐标
if
(
$prescription
->
prescription_type
==
PrescriptionModel
::
PRESCRIPTION_TYPE_WM
)
{
foreach
(
$medicines
as
$medicine
)
{
// 打印药品名称、规格和盒数
$medicineText
=
"
{
$medicine
[
'drug_name'
]
}
{
$medicine
[
'spec'
]
}
{
$medicine
[
'num'
]
}{
$medicine
[
'unit'
]
}
"
;
...
...
@@ -194,72 +195,108 @@ public function search()
$font
->
color
(
'#000000'
);
$font
->
align
(
'center'
);
});
}
// 医师签名图片
if
(
$prescription
->
doctor_signed_pic
)
{
$pharmacistSignPath
=
file_get_contents
(
$prescription
->
doctor_signed_pic
);
$doctorSign
=
Image
::
read
(
$pharmacistSignPath
);
$doctorSign
->
resize
(
150
,
100
);
$img
->
place
(
$doctorSign
,
'bottom-left'
,
400
,
410
);
}
// 药师签名图片
if
(
$prescription
->
pharmacist_signed_pic
)
{
$pharmacistSignPath
=
file_get_contents
(
$prescription
->
pharmacist_signed_pic
);
$pharmacistSign
=
Image
::
read
(
$pharmacistSignPath
);
$pharmacistSign
->
resize
(
150
,
100
);
$img
->
place
(
$pharmacistSign
,
'bottom-left'
,
870
,
410
);
if
(
$prescription
->
prescription_type
==
PrescriptionModel
::
PRESCRIPTION_TYPE_TCM
)
{
$lineHeight
=
100
;
// 每3条数据换行后的行间距
$horizontalSpacing
=
350
;
// 每行中的每条记录之间的水平间距
$xStart
=
400
;
// 起始x坐标值
foreach
(
$medicines
as
$k
=>
$medicine
)
{
// 每行显示3个记录,并且如果不是第一行,增加下一行的Y坐标
if
(
$k
%
3
==
0
)
{
if
(
$k
!=
0
)
{
$yCoordinate
+=
$lineHeight
;
}
}
// 计算当前记录的x坐标,每增加一个记录,x坐标就往后移动一些位置
$xCoordinate
=
$xStart
+
(
$k
%
3
)
*
$horizontalSpacing
;
// 固定药品名称12字符,数量单位12个字符,
$medicineText
=
sprintf
(
'%-12s %-12s'
,
$medicine
[
'drug_name'
],
"
{
$medicine
[
'num'
]
}{
$medicine
[
'unit'
]
}
"
);
$img
->
text
(
$medicineText
,
$xCoordinate
,
$yCoordinate
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
));
$font
->
size
(
40
);
$font
->
color
(
'#000000'
);
$font
->
align
(
'left'
);
});
}
// 不带印章处方图片生成
$picName
=
$prescriptionNo
.
'.jpg'
;
$tempPath
=
storage_path
(
'app/public'
)
.
$picName
;
$img
->
save
(
$tempPath
,
quality
:
100
);
// 不带电子印章
// 上传到腾讯云
Storage
::
putFileAs
(
'prescriptions'
,
$tempPath
,
$picName
);
// 电子印章版处方图片生成
$eseal
=
Image
::
read
(
public_path
(
'static/images/dianzizhang.png'
));
//
$eseal->rotate(90);
$
eseal
->
resize
(
420
,
420
);
$img
->
place
(
$eseal
,
'bottom-right'
,
180
,
500
);
$picEsealName
=
$prescriptionNo
.
'-eseal.jpg'
;
$tempEsealPath
=
storage_path
(
'app/public'
)
.
$picEsealName
;
$img
->
save
(
$tempEsealPath
,
quality
:
100
);
// 上传到腾讯云
Storage
::
putFileAs
(
'prescriptions'
,
$tempEsealPath
,
$picEsealName
);
$yCoordinate
+=
200
;
// 空白行间距
//
打印“以下空白”文字
$
img
->
text
(
$prescription
->
doses
.
'剂'
,
$centerX
,
$yCoordinate
,
function
(
$font
)
{
$font
->
filename
(
public_path
(
'static/fonts/SimHei.ttf'
)
);
$font
->
size
(
64
)
;
$font
->
color
(
'#000000'
)
;
$font
->
align
(
'center'
);
});
}
// 删除临时文件
unlink
(
$tempPath
);
unlink
(
$tempEsealPath
);
// 医师签名图片
if
(
$prescription
->
doctor_signed_pic
)
{
$pharmacistSignPath
=
file_get_contents
(
$prescription
->
doctor_signed_pic
);
$doctorSign
=
Image
::
read
(
$pharmacistSignPath
);
$doctorSign
->
resize
(
150
,
100
);
$img
->
place
(
$doctorSign
,
'bottom-left'
,
400
,
410
);
}
// 药师签名图片
if
(
$prescription
->
pharmacist_signed_pic
)
{
$pharmacistSignPath
=
file_get_contents
(
$prescription
->
pharmacist_signed_pic
);
$pharmacistSign
=
Image
::
read
(
$pharmacistSignPath
);
$pharmacistSign
->
resize
(
150
,
100
);
$img
->
place
(
$pharmacistSign
,
'bottom-left'
,
870
,
410
);
}
// 不带印章处方图片生成
$picName
=
$prescriptionNo
.
'.jpg'
;
$tempPath
=
storage_path
(
'app/public'
)
.
$picName
;
$img
->
save
(
$tempPath
,
quality
:
100
);
// 不带电子印章
// 上传到腾讯云
Storage
::
putFileAs
(
'prescriptions'
,
$tempPath
,
$picName
);
$cosPath
=
"prescriptions/
{
$picName
}
"
;
$cosEsealPath
=
"prescriptions/
{
$picEsealName
}
"
;
// 电子印章版处方图片生成
$eseal
=
Image
::
read
(
public_path
(
'static/images/dianzizhang.png'
));
// $eseal->rotate(90);
$eseal
->
resize
(
420
,
420
);
$img
->
place
(
$eseal
,
'bottom-right'
,
180
,
500
);
$picEsealName
=
$prescriptionNo
.
'-eseal.jpg'
;
$tempEsealPath
=
storage_path
(
'app/public'
)
.
$picEsealName
;
$img
->
save
(
$tempEsealPath
,
quality
:
100
);
// 上传到腾讯云
Storage
::
putFileAs
(
'prescriptions'
,
$tempEsealPath
,
$picEsealName
);
// 将生成的处方图片路径存储到数据库
$prescription
->
prescription_pic
=
$cosPath
;
$prescription
->
prescription_pic_eseal
=
$cosEsealPath
;
$prescription
->
save
();
// 保存处方图片路径
// 删除临时文件
unlink
(
$tempPath
);
unlink
(
$tempEsealPath
);
if
(
$isEseal
)
{
$imgUrl
=
Storage
::
url
(
$cosEsealPath
);
}
else
{
$imgUrl
=
Storage
::
url
(
$cosPath
);
}
$cosPath
=
"prescriptions/
{
$picName
}
"
;
$cosEsealPath
=
"prescriptions/
{
$picEsealName
}
"
;
$dosageList
=
DosageModel
::
where
(
'pharmacy_id'
,
$prescription
->
pharmacy_id
)
->
select
(
'id'
,
'dosage_desc'
)
->
get
()
->
toArray
();
// 将生成的处方图片路径存储到数据库
$prescription
->
prescription_pic
=
$cosPath
;
$prescription
->
prescription_pic_eseal
=
$cosEsealPath
;
$prescription
->
save
();
// 保存处方图片路径
return
response
()
->
json
([
'status'
=>
true
,
'data'
=>
[
'img_url'
=>
$imgUrl
,
'drug_info'
=>
$prescription
->
drug_info
,
'dosage_list'
=>
$dosageList
,
],
]);
}
catch
(
\Exception
$e
)
{
return
response
()
->
json
([
'status'
=>
false
,
'message'
=>
'处方生成失败:'
.
$e
->
getMessage
(),
]);
if
(
$isEseal
)
{
$imgUrl
=
Storage
::
url
(
$cosEsealPath
);
}
else
{
$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) {
// return response()->json([
// 'status' => false,
// 'message' => '处方生成失败:'.$e->getMessage(),
// ]);
// }
}
}
resources/views/admin/prescription-print.blade.php
View file @
5d74b4df
...
...
@@ -65,13 +65,7 @@
};
$
(
'#is_eseal'
).
on
(
'change'
,
()
=>
this
.
search
());
<<<<<<<
HEAD
=======
>>>>>>>
master
console
.
log
(
'事件绑定完成'
);
}
search
()
{
...
...
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