diff --git a/app/Http/Controllers/Hospital/IntroduceController.php b/app/Http/Controllers/Hospital/IntroduceController.php new file mode 100644 index 0000000..3ded115 --- /dev/null +++ b/app/Http/Controllers/Hospital/IntroduceController.php @@ -0,0 +1,163 @@ +orderBy('sort', 'DESC') + ->orderBy('id', 'ASC') + ->get(); + $category_lists = $category_lists->keyBy('category_id')->map(function ($value) { return (array)$value; })->toArray(); + + $department_lists = Department::select('dept_id', 'dept_name', 'category_id') + ->where('is_enable', 1) + ->orderBy('sort', 'DESC') + ->orderBy('id', 'ASC') + ->get(); + + foreach ($department_lists as $v) { + $category_lists[$v->category_id]['item_lists'][] = [ + 'dept_id' => $v->dept_id, + 'dept_name' => $v->dept_name, + 'introduction' => $v->introduction ?: '' + ]; + } + + return jsonResponse(Response::HTTP_OK, 'success.', array_values($category_lists)); + } + + /** + * 科室详情 + * @param Request $request + * @param string $dept_id + * @return JsonResponse + * @throws GeneralException + */ + public function deptDetails(Request $request, string $dept_id): JsonResponse + { + $department_details = Department::where('dept_id', $dept_id) + ->where('is_enable', 1) + ->first(); + + if (empty($department_details)) { + throw new GeneralException('找不到该科室信息'); + } + + $details = [ + 'dept_id' => $department_details->dept_id, + 'dept_name' => $department_details->dept_name, + 'category_id' => $department_details->category_id, + 'category_name' => $department_details->departmentCategory->name, + 'introduction' => $department_details->introduction ?: '', + ]; + + return jsonResponse(Response::HTTP_OK, 'success.', $details); + } + + /** + * 获取医生列表 + * @return JsonResponse + */ + public function doctorLists(): JsonResponse + { + $doctor_lists = Doctor::select( + 'doctors.dept_id', + 'departments.dept_name', + 'doctors.doctor_id', + 'doctors.doctor_name', + 'doctors.doctor_title', + 'doctors.doctor_specialty', + 'doctors.avatar as doctor_avatar', + 'doctors.is_expert', + 'doctors.sort', + ) + ->join('departments', 'doctors.dept_id', '=', 'departments.dept_id') + ->where('doctors.is_enable', 1) + ->orderBy('doctors.sort', 'DESC') + ->orderBy('doctors.is_expert', 'DESC') + ->orderBy('doctors.id', 'ASC') + ->get() + ->toArray(); + + foreach ($doctor_lists as $k => $v) { + $doctor_lists[$k]['doctor_avatar'] = $v['doctor_avatar'] ?: ''; + } + + return jsonResponse(Response::HTTP_OK, 'success.', $doctor_lists); + } + + /** + * 获取医生详情 + * @param Request $request + * @param string $doctor_id + * @return JsonResponse + * @throws GeneralException + */ + public function doctorDetails(Request $request, string $doctor_id): JsonResponse + { + $doctor_details = Doctor::where('doctor_id', $doctor_id) + ->where('is_enable', 1) + ->first(); + + if (empty($doctor_details)) { + throw new GeneralException('找不到该科室信息'); + } + + $details = [ + 'dept_id' => $doctor_details->dept_id, + 'dept_name' => $doctor_details->department->dept_name, + 'doctor_id' => $doctor_details->doctor_id, + 'doctor_name' => $doctor_details->doctor_name, + 'doctor_title' => $doctor_details->doctor_title, + 'doctor_specialty' => $doctor_details->doctor_specialty, + 'avatar' => $doctor_details->avatar ?: '', + 'introduction' => $doctor_details->introduction ?: '', + 'is_expert' => $doctor_details->is_expert, + ]; + + return jsonResponse(Response::HTTP_OK, 'success.', $details); + } + + /** + * 获取医院导航信息 + * @throws GeneralException + */ + public function navigationDetails(Request $request): JsonResponse + { + $navigation_details = Navigation::select('area_id', 'area_name', 'longitude', 'latitude', 'address', 'telephone', 'traffic', 'guide') + ->where('area_id', 1) + ->where('is_enable', 1) + ->first(); + + if (empty($navigation_details)) { + throw new GeneralException('找不到导航信息'); + } + + $details = $navigation_details->toArray(); + $details['traffic'] = !empty($details['traffic']) ? html_entity_decode($details['traffic']) : ''; + $details['guide'] = !empty($details['guide']) ? html_entity_decode($details['guide']) : ''; + + + return jsonResponse(Response::HTTP_OK, 'success.', $details); + } +} diff --git a/app/Http/Controllers/Registration/ScheduleController.php b/app/Http/Controllers/Registration/ScheduleController.php index 2453a0d..1218cba 100644 --- a/app/Http/Controllers/Registration/ScheduleController.php +++ b/app/Http/Controllers/Registration/ScheduleController.php @@ -9,6 +9,8 @@ use App\Http\Resources\Registration\Schedule\DeptListsResource; use App\Http\Resources\Registration\Schedule\DoctorListsResource; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Redis; use Symfony\Component\HttpFoundation\Response; class ScheduleController @@ -44,6 +46,28 @@ class ScheduleController return jsonResponse(Response::HTTP_OK, 'success', DeptListsResource::make($response)->toArray()); } + /** + * 获取科室提示 + * @return JsonResponse + */ + public function deptTips(): JsonResponse + { + if (Redis::exists('department.tips')) { + $tips_lists = Redis::get('department.tips'); + $tips_lists = json_decode($tips_lists, true); + } else { + $tips_lists = DB::connection('mysql_admin')->table('department_tips') + ->select('dept_id', 'title', 'message') + ->where('is_enable', 1) + ->get() + ->toArray(); + + Redis::setex('department.tips', 4 * 3600, json_encode($tips_lists, JSON_UNESCAPED_UNICODE)); + } + + return jsonResponse(Response::HTTP_OK, 'success', $tips_lists); + } + /** * 获取医生排班列表 * @param Request $request diff --git a/app/Http/Logics/Notify/NotifyLogic.php b/app/Http/Logics/Notify/NotifyLogic.php index bfc3242..2322350 100644 --- a/app/Http/Logics/Notify/NotifyLogic.php +++ b/app/Http/Logics/Notify/NotifyLogic.php @@ -139,7 +139,7 @@ class NotifyLogic $record->dept_id, $record->docttor_id, $record->reg_id, - $extra['SHIFT']['RANKID'], + $extra['scheduleInfo']['rankId'], $record->visit_date, PayType::WECHAT_PAY->hisCode(), $order_info->order_id, @@ -158,11 +158,11 @@ class NotifyLogic $order_info->orderConfirm($order_info->order_id, $response['visitNo'], $response); // 支付平台业务确认 - $this->unifyConfirm($notify['out_trade_no'], $response['VISITNO'], $notify['openid'], $notify['transaction_id']); + $this->unifyConfirm($notify['out_trade_no'], $response['visitNo'], $notify['openid'], $notify['transaction_id']); // 推送成功 $this->sendRegistrationSuccessMessage($order_info); - } else if (isset($response['success'])) { + } else if (isset($response['success']) && $response['success'] === false) { // 失败流程 $this->handleOrderReverse($order_info, $response['msg'] ?? ''); @@ -188,15 +188,21 @@ class NotifyLogic // 挂号确认 $patient = $order_info->patient; $record = $order_info->outpatientPaymentRecord; - $extra = json_decode($record->extra_info, true); + $extra = json_decode(reset($order_info->outpatientPaymentRecord), true); $pay_time = strtotime($notify->time_end); + + foreach ($record as $v) { + $extra_info = json_decode($v->extra_info, true); + $prescription_ids[] = $extra_info['prescriptionId']; + } + $data = [ $order_info->patient_id, '0', - date('Y-m-d', $extra['JSRQ']), - $extra['prescription_ids'], - $extra['TREAID'], + date('Y-m-d', $extra['visitDate']), + implode(',', $prescription_ids), + $extra['visitNumber'], '', $order_info->order_id, PayType::WECHAT_PAY->hisCode(), @@ -207,18 +213,18 @@ class NotifyLogic $this->info('缴费订单出入参:'.$order_info->order_id, [$data, $response]); // 保存返回信息 - if (isset($response['ResultCode']) && $response['ResultCode'] === '0') { + if (isset($response['success']) && $response['success'] === true) { // 成功流程 - $order_info->orderConfirm($order_info->order_id, $response['HOSTRANNO'], $response); + $order_info->orderConfirm($order_info->order_id, $response['hosTranNo'], $response); // 支付平台业务确认 - $this->unifyConfirm($notify['out_trade_no'], $response['HOSTRANNO'], $notify['openid'], $notify['transaction_id']); + $this->unifyConfirm($notify['out_trade_no'], $response['hosTranNo'], $notify['openid'], $notify['transaction_id']); // 推送成功 $this->sendOutpatientPaymentSuccessMessage($order_info); - } else if (isset($response['ResultCode'])) { + } else if (isset($response['success']) && $response['success'] === false) { // 失败流程 - $this->handleOrderReverse($order_info, $response['ERRORMSG']); + $this->handleOrderReverse($order_info, $response['msg']); // 推送失败 $this->sendOutpatientPaymentFailureMessage($order_info); @@ -298,7 +304,6 @@ class NotifyLogic * 订单加锁 * @param string $order_id * @return false|string - * @throws RedisException */ protected function addLockOrder(string $order_id): false|string { @@ -313,7 +318,6 @@ class NotifyLogic * @param string $order_id * @param string $lock_id * @return bool - * @throws RedisException */ protected function unlockOrder(string $order_id, string $lock_id): bool { diff --git a/app/Http/Logics/Outpatient/PaymentLogic.php b/app/Http/Logics/Outpatient/PaymentLogic.php index 6fb19a5..8faa441 100644 --- a/app/Http/Logics/Outpatient/PaymentLogic.php +++ b/app/Http/Logics/Outpatient/PaymentLogic.php @@ -48,22 +48,22 @@ class PaymentLogic /** * 支付 - * @param string $patient_id + * @param string $patient_number * @param string $prescription_ids * @return array * @throws GeneralException */ - public function payment(string $patient_id, string $prescription_ids): array + public function payment(string $patient_number, string $prescription_ids): array { // 基础信息 - $patient_info = $this->getPatientInfo($patient_id, $this->open_id); - $pending_info = $this->getPendingPrescriptionDetails($patient_id, $prescription_ids); + $patient_info = $this->getPatientInfo($this->open_id, $patient_number); + $pending_info = $this->getPendingPrescriptionDetails($patient_info['patientId'], $prescription_ids); // 创建订单 $order_type = Type::OUTPATIENT_PAYMENT; $pay_type = PayType::WECHAT_PAY; $order_id = $this->order_model->getOrderId($pay_type, 'M'); - $total_fee = (float)(string) array_sum(array_column($pending_info, 'CFFYJE')); + $total_fee = (float)(string) array_sum(array_column($pending_info, 'prescriptionAmount')); $order = $this->createOrder($order_id, $pay_type, $total_fee, $order_type, $patient_info, $pending_info); @@ -78,21 +78,21 @@ class PaymentLogic /** * 获取患者信息 - * @param string $patient_id * @param string $open_id + * @param string $patient_number * @return mixed * @throws GeneralException */ - protected function getPatientInfo(string $patient_id, string $open_id): mixed + protected function getPatientInfo(string $open_id, string $patient_number): mixed { - $info = $this->patient_model->getBindPatientInfo($open_id, $patient_id); + $info = $this->patient_model->getBindPatientInfoByPatientNumber($open_id, $patient_number); if (empty($info)) { throw new GeneralException('找不到患者信息,请重新再试!', Response::HTTP_BAD_REQUEST); } - $patient_info = $this->his_client->getPatientInfo($info['patient_id'], CardType::OUTPATIENT_NO, $info['name']); - if (!isset($patient_info['success']) || !$patient_info['success']) { - throw new GeneralException($patient_info['msg'] ?? '找不到患者信息,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); + $response = $this->his_client->getPatientInfo($info['patient_id'], CardType::OUTPATIENT_NO, $info['name']); + if (!isset($response['success']) || !$response['success']) { + throw new GeneralException($response['msg'] ?? '找不到患者信息,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); } // 添加Patient 表ID @@ -115,14 +115,13 @@ class PaymentLogic { $response = $this->his_client->getPendingLists($patient_id); - if (!isset($response['RESULTCODE']) || $response['RESULTCODE'] !== '0') { - throw new GeneralException($response['ERRORMSG'] ?? '暂无相关缴费记录!', Response::HTTP_SERVICE_UNAVAILABLE); + if (!isset($response['success']) || !$response['success']) { + throw new GeneralException($response['msg'] ?? '暂无相关缴费记录!', Response::HTTP_SERVICE_UNAVAILABLE); } // 获取具体的缴费详情 - $response = xmlArrayToListByKey($response, 'ITEM'); - foreach ($response['ITEM'] as $v) { - if (str_contains($prescription_ids, $v['CFID'])) { + foreach ($response['response'] as $v) { + if (str_contains($prescription_ids, $v['prescriptionId'])) { $lists[] = $v; } } @@ -131,16 +130,17 @@ class PaymentLogic throw new GeneralException('查询不到待缴费处方,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); } + foreach ($lists as $k => $v) { - $response = $this->his_client->getPendingDetails($v['CFID'], $v['JZXH'], $v['REGID'] ?: ''); - if (!isset($response['RESULTCODE']) || $response['RESULTCODE'] !== '0') { - throw new GeneralException($response['ERRORMSG'] ?? '暂无相关缴费记录!', Response::HTTP_SERVICE_UNAVAILABLE); + $response = $this->his_client->getPendingDetails($v['prescriptionId'], $v['visitNumber'], $v['regId'] ?: ''); + if (!isset($response['success']) || !$response['success']) { + throw new GeneralException($response['msg'] ?? '暂无相关缴费记录!', Response::HTTP_SERVICE_UNAVAILABLE); } - $response = xmlArrayToListByKey($response, 'ITEM'); - $lists[$k]['prescription_lists'] = $response['ITEM']; + $lists[$k]['prescription_lists'] = $response['response']; } + $this->info('缴费处方信息', $lists); return $lists; } @@ -163,12 +163,12 @@ class PaymentLogic foreach ($pending_info as $v) { $pay_record_data[] = [ 'relate_patient_id' => $patient_info['id'], - 'dept_id' => $v['BQDM'], - 'dept_name' => $v['BQMC'], - 'doctor_id' => $v['YSGH'], - 'doctor_name' => $v['YSMC'], - 'visit_date' => date('Y-m-d', strtotime($v['JZRQ'])), - 'total_amount' => $total_fee, + 'dept_id' => $v['treatmentDepartment'], + 'dept_name' => $v['departmentName'], + 'doctor_id' => reset($v['prescription_lists'])['doctorNumber'] ?? '', + 'doctor_name' => $v['doctorName'], + 'visit_date' => date('Y-m-d', strtotime($v['visitDate'])), + 'total_amount' => $v['prescriptionAmount'] * 100, 'pre_settle_status' => 0, 'extra_info' => json_encode($v, JSON_UNESCAPED_UNICODE), ]; @@ -181,7 +181,7 @@ class PaymentLogic $total_fee * 100, 0, $this->open_id, - $patient_info['patientNumber'], + $patient_info['patientId'], $patient_info['name'], $order_type, SourceId::MINI_PROGRAM, diff --git a/app/Http/Logics/Outpatient/PendingLogic.php b/app/Http/Logics/Outpatient/PendingLogic.php index c4e4d7e..1850849 100644 --- a/app/Http/Logics/Outpatient/PendingLogic.php +++ b/app/Http/Logics/Outpatient/PendingLogic.php @@ -38,12 +38,12 @@ class PendingLogic { $response = $this->his_client->getPendingLists($patient_id); - if (!isset($response['RESULTCODE']) || $response['RESULTCODE'] !== '0') { - throw new GeneralException($response['ERRORMSG'] ?? '暂无相关缴费记录!', Response::HTTP_SERVICE_UNAVAILABLE); + if (!isset($response['success']) || !$response['success']) { + throw new GeneralException($response['msg'] ?? '暂无相关缴费记录!', Response::HTTP_SERVICE_UNAVAILABLE); } // 缓存2小时 - Cache::set('Outpatient.Pending.'. $this->open_id.'.'. $patient_id, json_encode($response, JSON_UNESCAPED_UNICODE), 2 * 60 * 60); + Cache::set('outpatient.pending.'. $this->open_id.'.'. $patient_id, json_encode($response, JSON_UNESCAPED_UNICODE), 2 * 60 * 60); return $response; } @@ -62,8 +62,8 @@ class PendingLogic $response = $this->his_client->getPendingDetails($prescription_ids, $serial_no, $reg_id); - if (!isset($response['RESULTCODE']) || $response['RESULTCODE'] !== '0') { - throw new GeneralException($response['ERRORMSG'] ?? '暂无相关缴费详情!', Response::HTTP_SERVICE_UNAVAILABLE); + if (!isset($response['success']) || !$response['success']) { + throw new GeneralException($response['msg'] ?? '暂无相关缴费详情!', Response::HTTP_SERVICE_UNAVAILABLE); } return $response; @@ -78,18 +78,17 @@ class PendingLogic */ protected function getCachePendingLists(string $patient_id, string $serial_no): mixed { - $cache_key = 'Outpatient.Pending.'. $this->open_id.'.'. $patient_id; + $cache_key = 'outpatient.pending.'. $this->open_id.'.'. $patient_id; $pending_lists = Cache::get($cache_key); if (empty($pending_lists)) { - throw new GeneralException($response['ERRORMSG'] ?? '查询不到缴费记录,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); + throw new GeneralException('查询不到缴费记录,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); } $pending_lists = json_decode($pending_lists, true); // 获取具体的缴费详情 - $pending_lists = xmlArrayToListByKey($pending_lists, 'ITEM'); - foreach ($pending_lists['ITEM'] as $v) { - if ($v['JZXH'] === $serial_no) { + foreach ($pending_lists['response'] as $v) { + if ($v['visitNumber'] === $serial_no) { $info = $v; break; } diff --git a/app/Http/Resources/Outpatient/Pending/PendingDetailsResource.php b/app/Http/Resources/Outpatient/Pending/PendingDetailsResource.php index 1246701..41caf49 100644 --- a/app/Http/Resources/Outpatient/Pending/PendingDetailsResource.php +++ b/app/Http/Resources/Outpatient/Pending/PendingDetailsResource.php @@ -16,40 +16,24 @@ class PendingDetailsResource extends JsonResource public function toArray(Request $request = null): array { $lists = []; - $this->resource = xmlArrayToListByKey($this->resource, 'ITEM'); - foreach ($this->resource['ITEM'] as $v) { + foreach ($this->resource['response'] as $v) { $lists[] = [ - 'fee_date' => $v['FYRQ'], - 'item_id' => $v['XMXH'], - 'item_code' => $v['XMBH'], - 'item_name' => $v['XMMC'], - 'price' => (float) $v['JG'], - 'quantity' => $v['MCYL'], - 'total_price' => $v['JE'], - 'package_name' => $v['ZTMC'], - 'self_pay_ratio' => $v['ZFBL'], - 'self_pay_fee' => (float) $v['ZFJE'], - 'prescription_id' => $v['CFID'], - 'unit' => $v['UNIT'], - 'prescription_type' => $v['CFTYPE'], - 'dept_id' => $v['BQDM'], - 'dept_name' => $v['BQMC'], - 'doctor_id' => $v['YSGH'], - 'doctor_name' => $v['YSMC'], - // 冗余字段 - 'national_catalog_code' => $v['GJMLBM'] ?: '', - 'single_dose' => $v['YCJL'] ?: '', - 'frequency' => $v['YPYF'] ?: '', - 'medication_days' => $v['YYTS'] ?: '', - 'administration_route' => $v['GYTJ'] ?: '', - 'hospital_approval_flag' => $v['HOSP_APPR_FLAG'] ?: '', - 'chinese_medicine_usage' => $v['TCMDRUG_USED_WAY'] ?: '', - 'external_inspection_flag' => $v['ETIP_FLAG'] ?: '', - 'external_inspection_hospital_code' => $v['ETIP_HOSP_CODE'] ?: '', - 'discharge_medication_flag' => $v['DSCG_TKDRUG_FLAG'] ?: '', - 'maternity_fee_flag' => $v['MATN_FEE_FLAG'] ?: '', - 'external_purchase_prescription_flag' => $v['RX_CIRC_FLAG'] ?: '', + 'fee_date' => $v['feeDate'], + 'item_id' => $v['itemNo'], + 'item_code' => $v['projectNumber'], + 'item_name' => $v['entryName'], + 'price' => (float) $v['unitPrice'], + 'quantity' => $v['quantity'], + 'unit' => $v['company'], + 'spec' => $v['projectSpecifications'], + 'total_price' => $v['money'], + 'prescription_id' => $v['prescriptionNumber'], + 'prescription_type' => $v['prescriptionType'], + 'dept_id' => $v['treatmentDepartment'], + 'dept_name' => $v['departmentName'], + 'doctor_id' => $v['doctorNumber'], + 'doctor_name' => $v['doctorName'], ]; } diff --git a/app/Http/Resources/Outpatient/Pending/PendingListsResource.php b/app/Http/Resources/Outpatient/Pending/PendingListsResource.php index d43c772..f25ac35 100644 --- a/app/Http/Resources/Outpatient/Pending/PendingListsResource.php +++ b/app/Http/Resources/Outpatient/Pending/PendingListsResource.php @@ -15,33 +15,24 @@ class PendingListsResource extends JsonResource */ public function toArray(Request $request = null): array { - $this->resource = xmlArrayToListByKey($this->resource, 'ITEM'); - $lists = []; - foreach ($this->resource['ITEM'] as $v) { + foreach ($this->resource['response'] as $v) { $lists[] = [ - 'category' => $v['JZLB'], - 'visit_date' => $v['JZRQ'], - 'diagnosis' => $v['CYZD'], - 'dept_id' => $v['BQDM'], - 'dept_name' => $v['BQMC'], - 'reg_id' => $v['REGID'], - 'prescription_id' => $v['CFID'], - 'total_prescription_amount' => (float) $v['YLFYZE'], - 'single_prescription_amount' => (float) $v['CFFYJE'] ?? 0, - 'doctor_id' => $v['YSGH'], - 'doctor_name' => $v['YSMC'], - 'remark' => $v['BZ'], - 'is_self_pay' => $v['ZFCF'], - 'visit_no' => $v['JZXH'], - 'prescription_number' => $v['CHHM'] ?: '', - 'prescription_type' => $v['CFTYPE'] ?: '', - 'exec_address' => $v['YFMC'] ?: '', - 'medical_type' => $v['MED_TYPE'] ?: '', - 'disease_code' => $v['DISE_CODG'] ?: '', - 'disease_name' => $v['DISE_NAME'] ?: '', - 'settlement_method' => $v['PSN_SETLWAY'] ?: '', - 'out_of_area_flag' => $v['OUT_FLAG'] ?: '' + 'category' => $v['visitType'], + 'visit_date' => date('Y-m-d', strtotime($v['visitDate'])), + 'diagnosis' => $v['outpatientDiagnosis'], + 'dept_id' => $v['treatmentDepartment'], + 'dept_name' => $v['departmentName'], + 'reg_id' => $v['regId'], + 'prescription_id' => $v['prescriptionId'], + 'total_prescription_amount' => (float) $v['prescriptionAmount'], + 'single_prescription_amount' => (float) $v['singleAmount'], + 'doctor_name' => $v['doctorName'], + 'remark' => $v['remarks'], + 'is_self_pay' => $v['isexpense'], + 'prescription_number' => $v['nrescriptionNumber'], + 'exec_address' => $v['takeMedicine'], + 'visit_no' => $v['visitNumber'], ]; } diff --git a/app/Http/Resources/Registration/Schedule/DeptListsResource.php b/app/Http/Resources/Registration/Schedule/DeptListsResource.php index 23c5280..203e4d4 100644 --- a/app/Http/Resources/Registration/Schedule/DeptListsResource.php +++ b/app/Http/Resources/Registration/Schedule/DeptListsResource.php @@ -2,10 +2,13 @@ namespace App\Http\Resources\Registration\Schedule; +use App\Models\Department; +use App\Models\DepartmentCategory; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Redis; +use mysql_xdevapi\Collection; class DeptListsResource extends JsonResource { @@ -16,27 +19,54 @@ class DeptListsResource extends JsonResource */ public function toArray(Request $request = null): array { - $department_lists = $this->getDepartmentLists(); - $sort = collect($department_lists)->pluck('sort', 'dept_id'); + // 科室分类 + $categories = $this->getDepartmentCategoryLists(); + // 科室及排序 + $departments = $this->getDepartmentLists(); + $sorts = collect($departments)->pluck('sort', 'dept_id')->toArray(); + // 根据科室的 sort 字段对 科室列表 进行排序 + usort($this->resource['response'], function ($a, $b) use ($sorts) { + $sort_a = $sorts[$a['typeId']] ?? 0; + $sort_b = $sorts[$b['typeId']] ?? 0; + return $sort_b <=> $sort_a; // 倒序排序 + }); - $lists = []; foreach ($this->resource['response'] as $v) { - $lists[] = [ + if (!isset($categories[$departments[$v['typeId']]['category_id']])) { + continue; + } + + $categories[$departments[$v['typeId']]['category_id']]['item_lists'][] = [ 'dept_id' => $v['typeId'], 'dept_name' => $v['typeName'], - // 'dept_intro' => $v['INTRODUCE'] + // 'dept_intro' => $v['introduce'] ?? '' ]; } - // 根据科室的 sort 字段对 $lists 进行排序 - usort($lists, function ($a, $b) use ($sort) { - $sort_a = $sort[$a['dept_id']] ?? 0; - $sort_b = $sort[$b['dept_id']] ?? 0; - return $sort_b <=> $sort_a; // 倒序排序 - }); + return array_values($categories); + } + + /** + * 获取科室分类 + * @return array + */ + public function getDepartmentCategoryLists(): array + { + if (Redis::exists('department.category')) { + $category_lists = Redis::get('department.category'); + $category_lists = json_decode($category_lists, true); + } else { + $category_lists = DepartmentCategory::select('id as category_id', 'name as category_name') + ->orderBy('sort', 'DESC') + ->orderBy('id', 'ASC') + ->get(); + + $category_lists = $category_lists->keyBy('category_id')->map(function ($value) { return (array)$value; })->toArray(); + Redis::setex('department.category', 4 * 3600, json_encode($category_lists, JSON_UNESCAPED_UNICODE)); + } - return $lists; + return $category_lists; } /** @@ -46,16 +76,15 @@ class DeptListsResource extends JsonResource public function getDepartmentLists(): array { if (Redis::exists('department.lists')) { - $department_lists = Redis::get('doctor.lists'); + $department_lists = Redis::get('department.lists'); $department_lists = json_decode($department_lists, true); } else { - $db = DB::connection('mysql_admin')->table('departments'); - $department_lists = $db - ->where('is_enable', 1) + $department_lists = Department::where('is_enable', 1) ->orderBy('sort', 'DESC') ->orderBy('id', 'ASC') ->get(); + $department_lists = $department_lists->keyBy('dept_id')->map(function ($value) { return (array)$value; })->toArray(); Redis::setex('department.lists', 4 * 3600, json_encode($department_lists, JSON_UNESCAPED_UNICODE)); } diff --git a/app/Http/Resources/Registration/Schedule/DoctorListsResource.php b/app/Http/Resources/Registration/Schedule/DoctorListsResource.php index 3796a09..369ca37 100644 --- a/app/Http/Resources/Registration/Schedule/DoctorListsResource.php +++ b/app/Http/Resources/Registration/Schedule/DoctorListsResource.php @@ -2,6 +2,7 @@ namespace App\Http\Resources\Registration\Schedule; +use App\Models\Doctor; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Facades\DB; @@ -16,9 +17,8 @@ class DoctorListsResource extends JsonResource */ public function toArray(Request $request = null): array { - $doctor_lists = $this->getDoctorLists(); - $specialty = collect($doctor_lists)->pluck('specialty', 'doctor_id'); - $sort = collect($doctor_lists)->pluck('sort', 'doctor_id'); + $doctors = $this->getDoctorLists(); + $sort = collect($doctors)->pluck('sort', 'doctor_id'); $lists = []; foreach ($this->resource['response'] as $k=>$v) { @@ -26,7 +26,8 @@ class DoctorListsResource extends JsonResource 'doctor_id' => $v['doctId'], 'doctor_name' => $v['doctName'], 'doctor_title' => $v['docTitle'], - 'doctor_intro' => $specialty[$v['doctId']] ?? ($v['depLocation'] ?: '暂无介绍'), + 'doctor_intro' => $doctors[$v['doctId']]['doctor_specialty'] ?? ($v['depLocation'] ?: '暂无介绍'), + 'doctor_avatar' => $doctors[$v['doctId']]['avatar'] ?: '', 'is_doctor' => (int) $v['isksDoc'], ]; @@ -66,13 +67,12 @@ class DoctorListsResource extends JsonResource $doctor_lists = Redis::get('doctor.lists'); $doctor_lists = json_decode($doctor_lists, true); } else { - $db = DB::connection('mysql_admin')->table('doctors'); - $doctor_lists = $db - ->where('is_enable', 1) + $doctor_lists = Doctor::where('is_enable', 1) ->orderBy('sort', 'DESC') ->orderBy('id', 'ASC') ->get(); + $doctor_lists = $doctor_lists->keyBy('doctor_id')->map(function ($value) { return (array)$value; })->toArray(); Redis::setex('doctor.lists', 4 * 3600, json_encode($doctor_lists, JSON_UNESCAPED_UNICODE)); } diff --git a/app/Models/Department.php b/app/Models/Department.php index ffe2733..77cd355 100644 --- a/app/Models/Department.php +++ b/app/Models/Department.php @@ -6,11 +6,23 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; class Department extends Model { use HasFactory; + /** + * @var string + */ + protected $connection = 'mysql_admin'; + + /** + * @var string + */ + protected $table = 'departments'; + /** * The attributes that are mass assignable. * @@ -18,14 +30,12 @@ class Department extends Model */ protected $fillable = [ 'dept_id', - 'type_id', 'dept_name', - 'leader_name', - 'image', - 'location', - 'telephone', + 'category_id', + 'icon', + 'introduction', 'sort', - 'intro', + 'is_enable' ]; /** @@ -35,7 +45,26 @@ class Department extends Model */ protected $casts = [ 'id' => 'integer', - 'type_id' => 'integer', + 'category_id' => 'integer', 'sort' => 'integer', + 'is_enable' => 'integer', ]; + + /** + * 科室分类 + * @return BelongsTo + */ + public function departmentCategory(): BelongsTo + { + return $this->belongsTo(DepartmentCategory::class, 'category_id'); + } + + /** + * 获取科室医生 + * @return HasMany + */ + public function doctor(): HasMany + { + return $this->hasMany(Doctor::class, 'dept_id', 'dept_id'); + } } diff --git a/app/Models/DepartmentType.php b/app/Models/DepartmentCategory.php similarity index 51% rename from app/Models/DepartmentType.php rename to app/Models/DepartmentCategory.php index 29ae9a1..9fdc168 100644 --- a/app/Models/DepartmentType.php +++ b/app/Models/DepartmentCategory.php @@ -6,21 +6,32 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; -class DepartmentType extends Model +class DepartmentCategory extends Model { use HasFactory; + /** + * @var string + */ + protected $connection = 'mysql_admin'; + + /** + * @var string + */ + protected $table = 'department_categories'; + /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ - 'type_id', - 'type_name', + 'id', + 'name', + 'description', 'sort', - 'icon', ]; /** @@ -30,7 +41,15 @@ class DepartmentType extends Model */ protected $casts = [ 'id' => 'integer', - 'type_id' => 'integer', 'sort' => 'integer', ]; + + /** + * 分类 + * @return HasMany + */ + public function department(): HasMany + { + return $this->hasMany(Department::class, 'category_id'); + } } diff --git a/app/Models/DepartmentTip.php b/app/Models/DepartmentTip.php new file mode 100644 index 0000000..65b90c2 --- /dev/null +++ b/app/Models/DepartmentTip.php @@ -0,0 +1,55 @@ + + */ + protected $fillable = [ + 'dept_id', + 'title', + 'message', + 'is_enable' + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'id' => 'integer', + 'is_enable' => 'integer', + ]; + + /** + * 科室分类 + * @return BelongsTo + */ + public function department(): BelongsTo + { + return $this->belongsTo(Department::class, 'dept_id', 'dept_id'); + } +} diff --git a/app/Models/Doctor.php b/app/Models/Doctor.php index c07c48d..e0214db 100644 --- a/app/Models/Doctor.php +++ b/app/Models/Doctor.php @@ -6,11 +6,22 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Doctor extends Model { use HasFactory; + /** + * @var string + */ + protected $connection = 'mysql_admin'; + + /** + * @var string + */ + protected $table = 'doctors'; + /** * The attributes that are mass assignable. * @@ -19,13 +30,14 @@ class Doctor extends Model protected $fillable = [ 'doctor_id', 'doctor_name', + 'doctor_title', + 'doctor_specialty', 'dept_id', - 'dept_name', - 'title', - 'image', + 'avatar', + 'introduction', 'sort', - 'adept', - 'intro', + 'is_expert', + 'is_enable', ]; /** @@ -36,5 +48,16 @@ class Doctor extends Model protected $casts = [ 'id' => 'integer', 'sort' => 'integer', + 'is_expert' => 'integer', + 'is_enable' => 'integer', ]; + + /** + * 科室 + * @return BelongsTo + */ + public function department(): BelongsTo + { + return $this->belongsTo(Department::class, 'dept_id', 'dept_id'); + } } diff --git a/app/Models/Navigation.php b/app/Models/Navigation.php new file mode 100644 index 0000000..3f090fd --- /dev/null +++ b/app/Models/Navigation.php @@ -0,0 +1,55 @@ + + */ + protected $fillable = [ + 'area_id', + 'area_name', + 'longitude', + 'latitude', + 'address', + 'telephone', + 'traffic', + 'guide', + 'sort', + 'is_enable', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'id' => 'integer', + 'area_id' => 'integer', + 'sort' => 'integer', + 'is_enable' => 'integer', + ]; + +} diff --git a/app/Services/HisHttp/Client.php b/app/Services/HisHttp/Client.php index 9347ff2..37a3968 100644 --- a/app/Services/HisHttp/Client.php +++ b/app/Services/HisHttp/Client.php @@ -59,7 +59,7 @@ class Client protected function requestHandle(string $method_name, string $request_name, array $params): mixed { //if ($request_name === 'PayRegTrade') { - dd(json_encode($params['json'], JSON_UNESCAPED_UNICODE)); + //dd(json_encode($params['json'], JSON_UNESCAPED_UNICODE)); //} try { diff --git a/app/Utils/Transfer/HisHttpClient/ClientMockHttpTransfer.php b/app/Utils/Transfer/HisHttpClient/ClientMockHttpTransfer.php index 640cd8b..ee57f62 100644 --- a/app/Utils/Transfer/HisHttpClient/ClientMockHttpTransfer.php +++ b/app/Utils/Transfer/HisHttpClient/ClientMockHttpTransfer.php @@ -186,14 +186,17 @@ class ClientMockHttpTransfer extends HttpTransferAbstract private function mockGetPendingLists(array $params) { - $this->transfer_response = '00441827197303226022门诊202107171.急性胃肠炎2.湿热证226发热门诊04-555585781.5316.210395麦明杰无特殊备注126719474-55558572普通医疗K52.9急性胃肠炎自费01441827199405226019住院202312151.高血压2.冠心病112心内科13-45678901050.75450.520876李海涛长期病管理037582913-45678901住院医疗I10高血压自费1'; + $date_1 = date('Ymd'); + $date_2 = date('Y-m-d'); + $this->transfer_response = '{"status":200,"success":true,"msg":"成功","msgDev":null,"response":[{"idCardNo":"230403199903245493","visitType":"门诊","visitDate":"'.$date_1.'","strVisitDate":"'.$date_2.'","outpatientDiagnosis":"健康查体,健康查体,健康查体,健康查体,健康查体,健康查体,健康查体","treatmentDepartment":"132","departmentName":"急诊内科","regId":"0","prescriptionId":"1-17452209","prescriptionAmount":"1.05","singleAmount":"1.05","doctorName":"管理员","remarks":"","isexpense":"1","strExpense":"自费","nrescriptionNumber":"1-17452209","takeMedicine":"","visitNumber":"3886415"}]}'; return $this; } private function mockGetPendingDetails(array $params) { - $this->transfer_response = '02021-07-14130727842220尿妊娠试验(金标法)5.6715.6715.674-5549038妊娠检查检验单8妇科门诊10537邝国超123451次口服1天口服给药000002021-07-14130727852231血常规检查12.34112.340.22.474-5549040常规检查检验单8妇科门诊10538张伟678901次静脉注射1天静脉注射000002021-07-15130727863001超声波检查80.00180.000.540.004-5549041影像检查影像单6放射科10539李明78901一次其他1天100002021-07-16130727874002CT检查300.001300.000.390.004-5549042影像检查影像单7影像科10540王磊345671次其他1天100002021-07-17130727885003心电图检查25.00125.000.12.504-5549043心电检查检查单9心内科10541赵云456781次其他1天10000'; + $date = date('Y-m-d'); + $this->transfer_response = '{"status":200,"success":true,"msg":"成功","msgDev":null,"response":[{"feeDate":"'.$date.'","itemNo":"11255860","projectNumber":"1550","entryName":"0.9%氯化钠注射液G","unitPrice":"1.05","quantity":"1","money":"1.05","remarks":"","projectSpecifications":"250ML:2.25G/瓶","prescriptionNumber":"1-17452209","company":"瓶","prescriptionType":"西药","treatmentDepartment":"132","departmentName":"急诊内科","doctorNumber":"10365","doctorName":"管理员"}]}'; return $this; } diff --git a/routes/api.php b/routes/api.php index dab56f4..cfb4c5e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,7 @@ group(function() { // 挂号模块 Route::prefix('Registration')->group(function () { Route::get('/dept', [ScheduleController::class, 'dept']); + Route::get('/dept/tips', [ScheduleController::class, 'deptTips']); Route::get('/doctor', [ScheduleController::class, 'doctor']); Route::post('/{patient_id}/register', [RegisterController::class, 'register']); @@ -54,7 +56,21 @@ Route::middleware(['apiLog'])->group(function() { // 缴费详情项目 Route::prefix('Dictionary')->group(function () { Route::get('/', [ItemController::class, 'lists']); - Route::get('/{type_id}', [ItemController::class, 'details'])->where('type_id', '[0-9]+');; + Route::get('/{type_id}', [ItemController::class, 'details'])->where('type_id', '[0-9]+'); + }); + + // 医院详情相关项目 + Route::prefix('Hospital')->group(function () { + // 科室介绍 + Route::get('/dept', [IntroduceController::class, 'deptLists']); + Route::get('/dept/{dept_id}', [IntroduceController::class, 'deptDetails'])->where('dept_id', '[0-9]+'); + + // 医生介绍 + Route::get('/doctor', [IntroduceController::class, 'doctorLists']); + Route::get('/doctor/{doctor_id}', [IntroduceController::class, 'doctorDetails'])->where('doctor_id', '[0-9]+'); + + // 医院导航 + Route::get('/navigation', [IntroduceController::class, 'navigationDetails']); }); }); });