|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Manager;
|
|
|
|
|
|
|
|
|
|
use App\Models\Area;
|
|
|
|
|
use App\Models\Bed;
|
|
|
|
|
use App\Models\OrderItems;
|
|
|
|
|
use App\Models\Orders;
|
|
|
|
|
use App\Models\Paramedic;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
class StatisticsController extends CommonController
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
* path="/manager/statistics/overview",
|
|
|
|
|
* summary="V2-获取项目首页总览数据统计",
|
|
|
|
|
* description="获取项目首页总览数据统计",
|
|
|
|
|
* @OA\Parameter(name="project_id", in="query", @OA\Schema(type="integer"), required=true, description="医院ID"),
|
|
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="200",
|
|
|
|
|
* description="获取项目首页总览数据统计"
|
|
|
|
|
* content={
|
|
|
|
|
* @OA\MediaType(
|
|
|
|
|
* mediaType="application/json",
|
|
|
|
|
* @OA\Schema(
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="orders_all",
|
|
|
|
|
* type="integer",
|
|
|
|
|
* description="全部订单数"
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="orders_pending",
|
|
|
|
|
* type="integer",
|
|
|
|
|
* description="待处理订单数"
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="orders_ongoing",
|
|
|
|
|
* type="integer",
|
|
|
|
|
* description="进行中订单数"
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="orders_finished",
|
|
|
|
|
* type="integer",
|
|
|
|
|
* description="已完成订单数"
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="orders_finished_today",
|
|
|
|
|
* type="integer",
|
|
|
|
|
* description="今日出院人数"
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="paramedics",
|
|
|
|
|
* type="integer",
|
|
|
|
|
* description="医院护工总数"
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="bill_today",
|
|
|
|
|
* type="decimal",
|
|
|
|
|
* description="今日应扣款"
|
|
|
|
|
* ),
|
|
|
|
|
* example={
|
|
|
|
|
* "orders_all": "999",
|
|
|
|
|
* "orders_pending": "60",
|
|
|
|
|
* "orders_ongoing": "50",
|
|
|
|
|
* "orders_finished": "889"
|
|
|
|
|
* "orders_finished_today": "12"
|
|
|
|
|
* "paramedics": "126"
|
|
|
|
|
* "bill_today": "9980.00"
|
|
|
|
|
* }
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
* }
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
*/
|
|
|
|
|
public function overview()
|
|
|
|
|
{
|
|
|
|
|
$project_id = request()->project_id;
|
|
|
|
|
$counts = [];
|
|
|
|
|
$counts["orders_all"] = (new Orders())->ofProject($project_id)->count();
|
|
|
|
|
$counts["orders_pending"] = (new Orders())->ofProject($project_id)->whereIn("status", [Orders::STATUS_UNCONFIRMED, Orders::STATUS_UNASSIGNED])->count();
|
|
|
|
|
$counts["orders_ongoing"] = (new Orders())->ofProject($project_id)->where("status", Orders::STATUS_ONGOING)->count();
|
|
|
|
|
$counts["orders_finished"] = (new Orders())->ofProject($project_id)->where("status", Orders::STATUS_ONGOING)->count();
|
|
|
|
|
$counts["orders_finished_today"] = (new Orders())->ofProject($project_id)->where("to_date", date("Y-m-d"))->where("status", Orders::STATUS_ONGOING)->count();
|
|
|
|
|
$counts["paramedics"] = (new Paramedic())->ofProject($project_id)->count();
|
|
|
|
|
$counts["bill_today"] = (new OrderItems())->where("service_date", date("Y-m-d"))->whereHas("order", function ($query) use ($project_id) {
|
|
|
|
|
$query->ofProject($project_id);
|
|
|
|
|
})->sum("total");
|
|
|
|
|
|
|
|
|
|
return response()->json(compact("counts"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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());
|
|
|
|
|
}
|
|
|
|
|
}
|