香洲二院小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mini_xzey/app/Http/Controllers/Patient/PatientController.php

107 lines
2.9 KiB

<?php
declare(strict_types = 1);
namespace App\Http\Controllers\Patient;
use App\Exceptions\GeneralException;
use App\Http\Logics\Patient\PatientLogic;
use App\Http\Requests\Patient\BindPatientRequest;
use App\Http\Requests\Patient\CreatePatientRequest;
use App\Http\Resources\Patient\PatientDetailsResource;
use App\Http\Resources\Patient\PatientListsResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class PatientController
{
protected PatientLogic $patient_logic;
/**
* Patient Construct.
*/
public function __construct()
{
$this->patient_logic = new PatientLogic();
}
/**
* 获取列表
* @return JsonResponse
*/
public function lists(): JsonResponse
{
$response = $this->patient_logic->getAllPatientLists();
return jsonResponse(Response::HTTP_OK, 'success', PatientListsResource::make($response)->toArray());
}
/**
* 获取详情
* @param Request $request
* @param string $patient_id
* @return JsonResponse
* @throws GeneralException
*/
public function details(Request $request, string $patient_id): JsonResponse
{
$response = $this->patient_logic->getPatientDetails($patient_id);
return jsonResponse(Response::HTTP_OK, 'success', PatientDetailsResource::make($response)->toArray());
}
/**
* 创建档案
* @param CreatePatientRequest $request
* @return JsonResponse
* @throws GeneralException
*/
public function create(CreatePatientRequest $request): JsonResponse
{
$patient_id = $this->patient_logic->createPatient($request->safe()->all());
return jsonResponse(Response::HTTP_CREATED, 'success', ['patient_id' => $patient_id]);
}
/**
* 绑定档案
* @param BindPatientRequest $request
* @return JsonResponse
* @throws GeneralException
*/
public function bind(BindPatientRequest $request): JsonResponse
{
$patient_id = $this->patient_logic->bindPatient($request->safe()->all());
return jsonResponse(Response::HTTP_CREATED, 'success', ['patient_id' => $patient_id]);
}
/**
* 设置默认状态
* @param Request $request
* @param string $patient_id
* @return JsonResponse
* @throws GeneralException
*/
public function setDefault(Request $request, string $patient_id): JsonResponse
{
$this->patient_logic->setDefaultPatient($patient_id);
return jsonResponse(Response::HTTP_OK, 'update success.');
}
/**
* 删除
* @param Request $request
* @param string $patient_id
* @return JsonResponse
* @throws GeneralException
*/
public function delete(Request $request, string $patient_id): JsonResponse
{
$this->patient_logic->cancelBindPatient($patient_id);
return jsonResponse(Response::HTTP_OK, 'delete success.');
}
}