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.
61 lines
2.5 KiB
61 lines
2.5 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Manager;
|
|
|
|
use App\Models\Area;
|
|
use App\Models\Bed;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class StatisticsController extends CommonController
|
|
{
|
|
/**
|
|
* @OA\Get(
|
|
* path="/manager/statistics/beds",
|
|
* summary="V2-获取项目中的床位陪护一览",
|
|
* description="获取项目中的床位陪护一览",
|
|
* @OA\Parameter(name="project_id", in="query", @OA\Schema(type="integer"), required=true, description="医院ID"),
|
|
* @OA\Parameter(name="has_ongoing_order", in="query", @OA\Schema(type="integer"), required=false, description="是否包含正在服务的订单,默认为不筛选"),
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
* @OA\Response(
|
|
* response="200",
|
|
* description="获取项目中的床位陪护一览"
|
|
* )
|
|
* )
|
|
*/
|
|
|
|
public function beds(Request $request)
|
|
{
|
|
DB::enableQueryLog();
|
|
$areas = Area::with([
|
|
"beds" => function ($query) use ($request) {
|
|
if ($request->has_ongoing_order) {
|
|
$query->has("onGoingOrder");
|
|
}
|
|
$query->with(["onGoingOrder" => function ($query) {
|
|
$query->leftJoin("paramedic", "orders.paramedic_id", "=", "paramedic.id")
|
|
->select("orders.id", "orders.bed_id", "orders.paramedic_id", "orders.status", "paramedic.name as paramedic_name");
|
|
}])->select("bed.id", "bed.name", "bed.room_id", "bed.area_id", "bed.myindex")
|
|
->leftJoin("room", "bed.room_id", "=", "room.id")
|
|
->addSelect("room.name as room_name")
|
|
->orderBy("room.name")
|
|
->orderBy("bed.name");
|
|
}])
|
|
->whereRaw("`area`.`project_id` = '{$request->project_id}'")
|
|
->orderBy("building.myindex")
|
|
->orderBy("area.myindex")
|
|
->select("area.id", "area.name", "area.building_id", "area.project_id")
|
|
->leftJoin("building", "area.building_id", "=", "building.id")
|
|
->addSelect("building.name as building_name")
|
|
->withCount("beds")
|
|
->get();
|
|
if ($request->has_ongoing_order) {
|
|
$areas = $areas->filter(function($item) {
|
|
return $item->beds->count();
|
|
});
|
|
}
|
|
|
|
return response()->json($areas->toArray());
|
|
}
|
|
}
|