surat/frontend/modules/hospital/controllers/ReportController.php

142 lines
4.3 KiB
PHP
Raw Normal View History

2024-12-25 03:04:59 +00:00
<?php
2025-03-27 06:14:00 +00:00
namespace frontend\modules\hospital\controllers;
2024-12-25 03:04:59 +00:00
use common\models\CaseDish;
use common\models\CaseNonGyn;
use common\models\CasePap;
2025-03-26 13:08:00 +00:00
use common\models\CaseSurgical;
use common\models\ConstServiceCharge;
2024-12-25 03:04:59 +00:00
use common\models\FinanceServiceCharge;
2025-03-26 13:08:00 +00:00
use common\models\HospitalCaseOpen;
use common\models\HospitalImport;
2024-12-25 03:04:59 +00:00
use Yii;
2025-03-26 13:08:00 +00:00
use yii\rest\Controller;
use common\models\HospitalImportServiceCharge;
use common\models\HospitalImportServiceChargeMapping;
use common\models\PatientCase;
use yii\db\Expression;
use yii\helpers\Json;
use common\models\User;
use common\models\CaseAutopsy;
use common\models\CaseFrozen;
use common\models\CaseHpv;
use Exception;
2024-12-25 03:04:59 +00:00
use yii\data\ActiveDataProvider;
2025-03-26 13:08:00 +00:00
use yii\web\NotFoundHttpException;
2024-12-25 03:04:59 +00:00
class ReportController extends Controller
{
2025-03-27 06:14:00 +00:00
2024-12-25 03:04:59 +00:00
/**
2025-03-26 13:08:00 +00:00
* View Report
*
* @param [type] $report_key
* @param [type] $hn
* @return void
2024-12-25 03:04:59 +00:00
*/
2025-04-25 01:37:24 +00:00
public function actionViewOld250425(/*$report_key, */$hn)
2024-12-25 03:04:59 +00:00
{
2025-04-09 07:10:25 +00:00
Yii::$app->response->format = \yii\web\Response::FORMAT_HTML;
2025-03-26 13:08:00 +00:00
$this->layout = 'hospital';
2025-04-04 06:33:00 +00:00
//$this->layout = false; // ปิด layout
2025-04-04 09:54:12 +00:00
/*
2025-04-04 06:33:00 +00:00
if (Yii::$app->user->isGuest) {
return $this->redirect(['/site/login']); // ถ้ายังไม่ล็อกอิน ให้กลับไปหน้า login
2025-04-04 09:54:12 +00:00
}*/
2024-12-25 03:04:59 +00:00
2025-04-03 10:12:43 +00:00
if (empty($hn) /*|| empty($report_key)*/) {
2025-03-26 13:08:00 +00:00
throw new NotFoundHttpException('Invalid request');
2024-12-25 03:04:59 +00:00
}
2025-04-03 10:12:43 +00:00
/*
2025-03-26 13:08:00 +00:00
if ($report_key != Yii::$app->params['report_key']) {
throw new NotFoundHttpException('Wrong report key');
2025-04-03 10:12:43 +00:00
}*/
2024-12-25 03:04:59 +00:00
2025-03-27 06:14:00 +00:00
$user = User::findIdentityByAccessToken('qSQNw67zUp0R0zZfluRzXXnGX9J9LQMv');
2025-04-09 07:10:25 +00:00
if ($user) {
Yii::$app->user->login($user, 3600);
2025-04-11 08:13:59 +00:00
} else {
throw new NotFoundHttpException('User not found');
2025-04-09 07:10:25 +00:00
}
2025-04-24 07:12:53 +00:00
//$case = PatientCase::find()->where(['like', 'h_n', $hn])->one();
$case = PatientCase::find()->where(['h_n' => $hn])->one();
2025-04-08 06:52:01 +00:00
if (!$case || empty($case->id_case)) {
2025-04-09 07:10:25 +00:00
2025-04-24 08:53:32 +00:00
return $this->render('../../../report/views/case/history_his', ['hn' => $hn]); //$this->redirect(['his','hn' => $hn]); // ถ้ายังไม่ล็อกอิน ให้กลับไปหน้า login
2025-04-11 08:13:59 +00:00
//throw new NotFoundHttpException('Patient not found');
2025-04-08 06:52:01 +00:00
}
2025-03-27 06:14:00 +00:00
2025-04-24 08:53:32 +00:00
2025-04-08 06:52:01 +00:00
//var_dump($case);
2024-12-25 03:04:59 +00:00
2025-03-26 13:08:00 +00:00
$dataProvider = new ActiveDataProvider([
2025-03-27 06:14:00 +00:00
//'query' => PatientCase::find()->where(['h_n' => $hn]),
2025-04-24 07:12:53 +00:00
//'query' => PatientCase::find()->where(['like', 'h_n', $hn]),
'query' => PatientCase::find()->where(['h_n' => $hn]),
2024-12-25 03:04:59 +00:00
]);
2025-04-24 08:53:32 +00:00
2025-03-27 06:14:00 +00:00
2025-04-25 01:37:24 +00:00
return $this->render('view-250425', [
2025-03-26 13:08:00 +00:00
'case' => $case,
'dataProvider' => $dataProvider,
2024-12-25 03:04:59 +00:00
]);
}
2025-04-09 07:10:25 +00:00
public function actionHis($hn)
{
$this->layout = 'hospital';
//$this->layout = false; // ปิด layout
if (Yii::$app->user->isGuest) {
return $this->redirect(['/site/login']); // ถ้ายังไม่ล็อกอิน ให้กลับไปหน้า login
}
return $this->render('his', [
'hn' => $hn,
]);
}
2025-04-24 08:53:32 +00:00
2025-04-25 01:37:24 +00:00
public function actionView($hn)
2025-04-24 08:53:32 +00:00
{
Yii::$app->response->format = \yii\web\Response::FORMAT_HTML;
$this->layout = 'hospital';
if (empty($hn)) {
throw new NotFoundHttpException('Invalid request');
}
$user = User::findIdentityByAccessToken('qSQNw67zUp0R0zZfluRzXXnGX9J9LQMv');
if ($user) {
Yii::$app->user->login($user, 3600);
} else {
throw new NotFoundHttpException('User not found');
}
$case = PatientCase::find()->where(['h_n' => $hn])->one();
if (!$case || empty($case->id_case)) {
return $this->render('../../../report/views/case/history_his', ['hn' => $hn]); // ถ้ายังไม่ล็อกอิน ให้กลับไปหน้า login
}
$model = Yii::$app->pathology->getCase($case->id_case);
//var_dump($model->h_n);
//die();
$dataProvider = new ActiveDataProvider([
'query' => PatientCase::find()->where(['h_n' => $hn]),
]);
2025-04-25 01:37:24 +00:00
return $this->render('view', [
2025-04-24 08:53:32 +00:00
'case' => $case,
'dataProvider' => $dataProvider,
'model' => $model,
]);
}
2025-03-26 13:08:00 +00:00
}