You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.6 KiB
PHP

<?php
namespace App\Http\Controllers\API\H5;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Lib\Rs;
use App\Services\PatientAuthService;
use Illuminate\Support\Facades\DB;
class ApplicationController extends Controller
{
private PatientAuthService $patientAuthService;
public function __construct(PatientAuthService $patientAuthService)
{
$this->patientAuthService = $patientAuthService;
}
/**
* 获取我的申请单列表
* POST /api/h5/applications
*/
public function list(Request $request)
{
$payload = $request->attributes->get('payload');
$idCardNo = $this->patientAuthService->getPatientIdCardNo($payload);
$status = $request->input('status', null);
$query = DB::table('exam_application as ea')
->leftJoin('patient_type as pt', 'ea.patient_type', '=', 'pt.mask')
->where('ea.patient_id_card_no', $idCardNo)
->whereNotNull('ea.patient_id_card_no')
->select([
'ea.id',
'ea.his_order_id',
'ea.his_request_no',
'ea.patient_type',
'ea.patient_name',
'ea.patient_gender',
'ea.patient_age',
'ea.examination_item_name',
'ea.examination_item_code',
'ea.examination_department_name',
'ea.apply_department_name',
'ea.apply_doctor_name',
'ea.apply_time',
'ea.payment_status',
'ea.clinical_diagnosis',
'ea.notes',
'ea.status',
'ea.created_at',
'pt.name as patient_type_name'
]);
if ($status !== null) {
$query->where('ea.status', $status);
}
$list = $query->orderBy('ea.apply_time', 'desc')
->orderBy('ea.id', 'desc')
->get();
// 为已预约的医嘱附加预约信息
$appointmentIds = $list->where('status', 1)->pluck('id')->toArray();
$appointments = [];
if (!empty($appointmentIds)) {
$appointments = DB::table('exam_appointment as ea')
->leftJoin('department_resource as dr', 'ea.department_resource_id', '=', 'dr.id')
->leftJoin('plan as p', 'ea.time_slot_id', '=', 'p.id')
->whereIn('ea.exam_application_id', $appointmentIds)
->where('ea.status', 1)
->select([
'ea.id',
'ea.exam_application_id',
'ea.appointment_time',
'ea.status as appointment_status',
'dr.name as resource_name',
'p.start_time as slot_start_time',
'p.end_time as slot_end_time'
])
->get()
->keyBy('exam_application_id')
->toArray();
}
foreach ($list as $item) {
if ($item->status === 1 && isset($appointments[$item->id])) {
$item->appointment_info = $appointments[$item->id];
} else {
$item->appointment_info = null;
}
}
return Rs::success(['list' => $list]);
}
/**
* 获取申请单详情(含检查项目详情)
* POST /api/h5/application/detail
*/
public function detail(Request $request)
{
$payload = $request->attributes->get('payload');
$idCardNo = $this->patientAuthService->getPatientIdCardNo($payload);
$applicationId = $request->input('application_id');
if (empty($applicationId)) {
return Rs::error('请提供申请单ID');
}
$application = DB::table('exam_application as ea')
->leftJoin('patient_type as pt', 'ea.patient_type', '=', 'pt.mask')
->where('ea.id', $applicationId)
->where('ea.patient_id_card_no', $idCardNo)
->select([
'ea.*',
'pt.name as patient_type_name'
])
->first();
if (!$application) {
return Rs::error('未找到该申请单');
}
// 查询关联的检查项目详情
$examItem = DB::table('exam_item')
->where('code', $application->examination_item_code)
->where('deleted', 0)
->select([
'id', 'code', 'name', 'desc', 'need_appointment',
'exam_part_code', 'fasting_status', 'check_tips',
'check_time', 'use_seats', 'status'
])
->first();
$application->exam_item_detail = $examItem;
// 如果已预约,附加预约详情
if ($application->status == 1) {
$appointment = DB::table('exam_appointment as ea')
->leftJoin('department_resource as dr', 'ea.department_resource_id', '=', 'dr.id')
->leftJoin('channel as c', 'ea.channel_id', '=', 'c.id')
->leftJoin('plan as p', 'ea.time_slot_id', '=', 'p.id')
->where('ea.exam_application_id', $applicationId)
->where('ea.status', 1)
->select([
'ea.id', 'ea.appointment_time', 'ea.status as appointment_status',
'ea.department_resource_id', 'dr.name as resource_name',
'c.name as channel_name',
'p.start_time as slot_start_time', 'p.end_time as slot_end_time',
'dr.cancel_reason_required'
])
->first();
$application->appointment_info = $appointment;
}
return Rs::success($application);
}
}