|
|
<?php
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class HisDictSyncService
|
|
|
{
|
|
|
public function syncDepartment(array $params): array
|
|
|
{
|
|
|
if (empty($params['code'])) {
|
|
|
return ['success' => false, 'message' => '缺少必填字段: code'];
|
|
|
}
|
|
|
if (empty($params['name'])) {
|
|
|
return ['success' => false, 'message' => '缺少必填字段: name'];
|
|
|
}
|
|
|
|
|
|
$status = isset($params['status']) ? (int)$params['status'] : 1;
|
|
|
|
|
|
$existing = DB::table('department')
|
|
|
->where('code', $params['code'])
|
|
|
->where('deleted', 0)
|
|
|
->first();
|
|
|
|
|
|
if ($existing) {
|
|
|
DB::table('department')->where('id', $existing->id)->update([
|
|
|
'name' => $params['name'],
|
|
|
'status' => $status,
|
|
|
'updated_at' => now(),
|
|
|
]);
|
|
|
return ['success' => true, 'message' => '科室更新成功', 'data' => ['id' => $existing->id, 'code' => $params['code']]];
|
|
|
}
|
|
|
|
|
|
$id = DB::table('department')->insertGetId([
|
|
|
'code' => $params['code'],
|
|
|
'name' => $params['name'],
|
|
|
'status' => $status,
|
|
|
'deleted' => 0,
|
|
|
'created_at' => now(),
|
|
|
'updated_at' => now(),
|
|
|
]);
|
|
|
|
|
|
return ['success' => true, 'message' => '科室创建成功', 'data' => ['id' => $id, 'code' => $params['code']]];
|
|
|
}
|
|
|
|
|
|
public function syncResource(array $params): array
|
|
|
{
|
|
|
if (empty($params['code'])) {
|
|
|
return ['success' => false, 'message' => '缺少必填字段: code'];
|
|
|
}
|
|
|
if (empty($params['name'])) {
|
|
|
return ['success' => false, 'message' => '缺少必填字段: name'];
|
|
|
}
|
|
|
$departmentId = null;
|
|
|
if (!empty($params['department_code'])) {
|
|
|
$department = DB::table('department')
|
|
|
->where('code', $params['department_code'])
|
|
|
->where('deleted', 0)
|
|
|
->first();
|
|
|
if ($department) {
|
|
|
$departmentId = $department->id;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$status = isset($params['status']) ? (int)$params['status'] : 1;
|
|
|
|
|
|
$existing = DB::table('department_resource')
|
|
|
->where('code', $params['code'])
|
|
|
->where('deleted', 0)
|
|
|
->first();
|
|
|
|
|
|
if ($existing) {
|
|
|
$updateData = [
|
|
|
'name' => $params['name'],
|
|
|
'status' => $status,
|
|
|
'updated_at' => now(),
|
|
|
];
|
|
|
if ($departmentId !== null) {
|
|
|
$updateData['department_id'] = $departmentId;
|
|
|
}
|
|
|
DB::table('department_resource')->where('id', $existing->id)->update($updateData);
|
|
|
return ['success' => true, 'message' => '检查室更新成功', 'data' => ['id' => $existing->id, 'code' => $params['code']]];
|
|
|
}
|
|
|
|
|
|
$id = DB::table('department_resource')->insertGetId([
|
|
|
'department_id' => $departmentId,
|
|
|
'name' => $params['name'],
|
|
|
'code' => $params['code'],
|
|
|
'status' => $status,
|
|
|
'deleted' => 0,
|
|
|
'created_at' => now(),
|
|
|
'updated_at' => now(),
|
|
|
]);
|
|
|
|
|
|
return ['success' => true, 'message' => '检查室创建成功', 'data' => ['id' => $id, 'code' => $params['code']]];
|
|
|
}
|
|
|
|
|
|
public function syncItemClass(array $params): array
|
|
|
{
|
|
|
if (empty($params['code'])) {
|
|
|
return ['success' => false, 'message' => '缺少必填字段: code'];
|
|
|
}
|
|
|
if (empty($params['name'])) {
|
|
|
return ['success' => false, 'message' => '缺少必填字段: name'];
|
|
|
}
|
|
|
|
|
|
$pid = 0;
|
|
|
if (!empty($params['parent_code'])) {
|
|
|
$parent = DB::table('exam_item_class')
|
|
|
->where('code', $params['parent_code'])
|
|
|
->where('deleted', 0)
|
|
|
->first();
|
|
|
if ($parent) {
|
|
|
$pid = $parent->id;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$status = isset($params['status']) ? (int)$params['status'] : 1;
|
|
|
|
|
|
$existing = DB::table('exam_item_class')
|
|
|
->where('code', $params['code'])
|
|
|
->where('deleted', 0)
|
|
|
->first();
|
|
|
|
|
|
if ($existing) {
|
|
|
DB::table('exam_item_class')->where('id', $existing->id)->update([
|
|
|
'name' => $params['name'],
|
|
|
'pid' => $pid,
|
|
|
'status' => $status,
|
|
|
'updated_at' => now(),
|
|
|
]);
|
|
|
return ['success' => true, 'message' => '项目分类更新成功', 'data' => ['id' => $existing->id, 'code' => $params['code']]];
|
|
|
}
|
|
|
|
|
|
$id = DB::table('exam_item_class')->insertGetId([
|
|
|
'code' => $params['code'],
|
|
|
'name' => $params['name'],
|
|
|
'pid' => $pid,
|
|
|
'status' => $status,
|
|
|
'deleted' => 0,
|
|
|
'created_at' => now(),
|
|
|
'updated_at' => now(),
|
|
|
]);
|
|
|
|
|
|
return ['success' => true, 'message' => '项目分类创建成功', 'data' => ['id' => $id, 'code' => $params['code']]];
|
|
|
}
|
|
|
|
|
|
public function syncItem(array $params): array
|
|
|
{
|
|
|
if (empty($params['code'])) {
|
|
|
return ['success' => false, 'message' => '缺少必填字段: code'];
|
|
|
}
|
|
|
if (empty($params['name'])) {
|
|
|
return ['success' => false, 'message' => '缺少必填字段: name'];
|
|
|
}
|
|
|
|
|
|
$classId = null;
|
|
|
if (!empty($params['class_code'])) {
|
|
|
$class = DB::table('exam_item_class')
|
|
|
->where('code', $params['class_code'])
|
|
|
->where('deleted', 0)
|
|
|
->first();
|
|
|
if ($class) {
|
|
|
$classId = $class->id;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$status = isset($params['status']) ? (int)$params['status'] : 1;
|
|
|
|
|
|
$existing = DB::table('exam_item')
|
|
|
->where('code', $params['code'])
|
|
|
->where('deleted', 0)
|
|
|
->first();
|
|
|
|
|
|
if ($existing) {
|
|
|
$updateData = [
|
|
|
'name' => $params['name'],
|
|
|
'status' => $status,
|
|
|
'updated_at' => now(),
|
|
|
];
|
|
|
if ($classId !== null) {
|
|
|
$updateData['class_id'] = $classId;
|
|
|
}
|
|
|
if (isset($params['desc'])) {
|
|
|
$updateData['desc'] = $params['desc'];
|
|
|
}
|
|
|
if (isset($params['need_appointment'])) {
|
|
|
$updateData['need_appointment'] = (int)$params['need_appointment'];
|
|
|
}
|
|
|
if (isset($params['fasting_status'])) {
|
|
|
$updateData['fasting_status'] = (int)$params['fasting_status'];
|
|
|
}
|
|
|
if (isset($params['check_tips'])) {
|
|
|
$updateData['check_tips'] = $params['check_tips'];
|
|
|
}
|
|
|
if (isset($params['check_time'])) {
|
|
|
$updateData['check_time'] = (int)$params['check_time'];
|
|
|
}
|
|
|
if (isset($params['use_seats'])) {
|
|
|
$updateData['use_seats'] = (int)$params['use_seats'];
|
|
|
}
|
|
|
DB::table('exam_item')->where('id', $existing->id)->update($updateData);
|
|
|
return ['success' => true, 'message' => '检查项目更新成功', 'data' => ['id' => $existing->id, 'code' => $params['code']]];
|
|
|
}
|
|
|
|
|
|
$id = DB::table('exam_item')->insertGetId([
|
|
|
'class_id' => $classId,
|
|
|
'code' => $params['code'],
|
|
|
'name' => $params['name'],
|
|
|
'desc' => $params['desc'] ?? null,
|
|
|
'need_appointment' => isset($params['need_appointment']) ? (int)$params['need_appointment'] : 1,
|
|
|
'fasting_status' => isset($params['fasting_status']) ? (int)$params['fasting_status'] : 0,
|
|
|
'check_tips' => $params['check_tips'] ?? null,
|
|
|
'check_time' => isset($params['check_time']) ? (int)$params['check_time'] : null,
|
|
|
'use_seats' => isset($params['use_seats']) ? (int)$params['use_seats'] : 1,
|
|
|
'status' => $status,
|
|
|
'deleted' => 0,
|
|
|
'created_at' => now(),
|
|
|
'updated_at' => now(),
|
|
|
]);
|
|
|
|
|
|
return ['success' => true, 'message' => '检查项目创建成功', 'data' => ['id' => $id, 'code' => $params['code']]];
|
|
|
}
|
|
|
|
|
|
public function syncStaff(array $params): array
|
|
|
{
|
|
|
if (empty($params['his_code'])) {
|
|
|
return ['success' => false, 'message' => '缺少必填字段: his_code'];
|
|
|
}
|
|
|
if (empty($params['name'])) {
|
|
|
return ['success' => false, 'message' => '缺少必填字段: name'];
|
|
|
}
|
|
|
|
|
|
$status = isset($params['status']) ? (int)$params['status'] : 1;
|
|
|
|
|
|
$deptId = null;
|
|
|
if (!empty($params['dept_code'])) {
|
|
|
$dept = DB::table('department')
|
|
|
->where('code', $params['dept_code'])
|
|
|
->where('deleted', 0)
|
|
|
->first();
|
|
|
if ($dept) {
|
|
|
$deptId = $dept->id;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$existing = DB::table('sys_user')
|
|
|
->where('his_code', $params['his_code'])
|
|
|
->where('deleted', 0)
|
|
|
->first();
|
|
|
|
|
|
if ($existing) {
|
|
|
$updateData = [
|
|
|
'nickname' => $params['name'],
|
|
|
'status' => $status,
|
|
|
'update_time' => now(),
|
|
|
];
|
|
|
if ($deptId !== null) {
|
|
|
$updateData['dept_id'] = $deptId;
|
|
|
}
|
|
|
if (isset($params['ward_code'])) {
|
|
|
$updateData['ward_code'] = $params['ward_code'];
|
|
|
}
|
|
|
DB::table('sys_user')->where('id', $existing->id)->update($updateData);
|
|
|
return ['success' => true, 'message' => '人员信息更新成功', 'data' => ['id' => $existing->id, 'his_code' => $params['his_code']]];
|
|
|
}
|
|
|
|
|
|
$id = DB::table('sys_user')->insertGetId([
|
|
|
'username' => $params['his_code'],
|
|
|
'password' => Hash::make('111111'),
|
|
|
'nickname' => $params['name'],
|
|
|
'status' => $status,
|
|
|
'dept_id' => $deptId,
|
|
|
'his_code' => $params['his_code'],
|
|
|
'ward_code' => $params['ward_code'] ?? null,
|
|
|
'deleted' => 0,
|
|
|
'create_time' => now(),
|
|
|
'update_time' => now(),
|
|
|
]);
|
|
|
|
|
|
return ['success' => true, 'message' => '人员创建成功(默认密码111111)', 'data' => ['id' => $id, 'his_code' => $params['his_code']]];
|
|
|
}
|
|
|
}
|