2024-12-25 03:04:59 +00:00
< ? php
namespace frontend\modules\register\controllers ;
2025-03-31 02:48:37 +00:00
use Yii ;
use yii\helpers\Html ;
use yii\web\Response ;
use yii\base\Exception ;
use common\models\CaseHpv ;
use common\models\CasePap ;
use common\models\Patient ;
2025-04-02 01:49:13 +00:00
use yii\httpclient\Client ;
2024-12-25 03:04:59 +00:00
use common\models\CaseDish ;
use common\models\CaseFish ;
use common\models\CaseFlow ;
2025-03-31 02:48:37 +00:00
use yii\widgets\ActiveForm ;
2024-12-25 03:04:59 +00:00
use common\models\CaseFrozen ;
2025-03-31 02:48:37 +00:00
use common\models\CaseNonGyn ;
use common\models\CaseAutopsy ;
use common\models\CaseExternal ;
2024-12-25 03:04:59 +00:00
use common\models\CaseNecropsy ;
use common\models\CaseSurgical ;
2025-03-31 02:48:37 +00:00
use common\models\StainingTest ;
use common\models\CaseMolecular ;
use common\models\ConstHospital ;
2024-12-25 03:04:59 +00:00
use common\models\DishDiagnosis ;
use common\models\FishDiagnosis ;
use common\models\FlowDiagnosis ;
2025-03-31 02:48:37 +00:00
use common\models\HistoStaining ;
use common\models\ImmunoStaining ;
2024-12-25 03:04:59 +00:00
use common\models\FrozenDiagnosis ;
use common\models\SurgicalOperate ;
2025-03-31 02:48:37 +00:00
use yii\web\NotFoundHttpException ;
use common\models\AutopsyDiagnosis ;
use common\models\CytoPapDiagnosis ;
use common\models\NecropsyDiagnosis ;
use common\models\SurgicalDiagnosis ;
2024-12-25 03:04:59 +00:00
use common\models\ConstServiceCharge ;
2025-03-31 02:48:37 +00:00
use common\models\CytoSideOfSpecimen ;
use common\models\MolecularDiagnosis ;
use common\models\CytoNonGynDiagnosis ;
2024-12-25 03:04:59 +00:00
use common\models\FinanceServiceCharge ;
2025-03-31 02:48:37 +00:00
use common\models\ConstLookupAddressName ;
2025-04-02 01:49:13 +00:00
use frontend\modules\register\models\CaseExternalSearch ;
2025-04-02 07:03:34 +00:00
use yii\helpers\Json ;
2024-12-25 03:04:59 +00:00
class CaseController extends \yii\web\Controller
{
/**
* @ return array | \yii\db\ActiveRecord []
*/
public function actionGetPatientList ()
{
$this -> enableCsrfValidation = false ;
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$patient = Patient :: find () -> select ([ 'id as id' , 'name as value' , 'name as label' ])
-> where ( " name != '-' " )
-> andFilterWhere ([ 'like' , 'name' , Yii :: $app -> request -> post ( 'search' )])
-> orderBy ([ 'name' => SORT_ASC ]) -> asArray () -> limit ( 50 ) -> all ();
return $patient ;
}
/**
* @ return string
*/
public function actionIndex ()
{
return $this -> render ( 'index' );
}
/**
* @ return array | string | void | Response
* @ throws Exception
*/
public function actionFlow ()
{
$model = new CaseFlow (); //['scenario' => 'register']
$model -> id_case = $this -> getIdCase ( 'F' );
//$model->no_slide = "1";
//$finance = new FinanceServiceCharge();
$patient = new Patient ();
$model -> nation = 'ไทย' ;
$model -> age_unit = 'ปี' ;
Yii :: $app -> session -> setFlash ( 'info' , 'ลงทะเบียนงาน FLOW หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
//$patient->load(Yii::$app->request->post());
//$finance->load(Yii::$app->request->post());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$result = ActiveForm :: validate ( $model /*, $finance*/ );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())
//$patient->load(Yii::$app->request->post())
//&& $finance->load(Yii::$app->request->post())
) //$operate->load(Yii::$app->request->post())) {
{
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
/* var_dump ( $model );
die (); */
$patient_old = Patient :: find ()
-> filterWhere ([ 'given_name' => $patient -> given_name ])
-> one ();
// บันทึกผู้ป่วย
if ( ! empty ( $model -> patient_id ) && $patient_old ) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient_update = Patient :: findOne ( $model -> patient_id );
$patient_update -> gender = $patient -> gender ;
$patient_update -> nation = $patient -> nation ;
$patient_update -> birthdate = $patient -> birthdate ;
$patient_update -> age = $patient -> age ;
$patient_update -> age_unit = $patient -> age_unit ;
$patient_update -> hospital_id = $patient -> hospital_id ;
$patient_update -> h_n = $patient -> h_n ;
$patient_update -> id_card = $patient -> id_card ;
$patient_update -> save ( false );
$patient = $patient_update ;
} else {
$patient -> given_name = $model -> given_name ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> surname = $model -> surname ;
$patient -> title_id = $model -> title_id ;
$patient -> gender = $model -> gender ;
$patient -> nation = $model -> nation ;
$patient -> birthdate = $model -> birthdate ;
$patient -> age = $model -> age ;
$patient -> age_unit = $model -> age_unit ;
$patient -> hospital_id = $model -> hospital_id ;
$patient -> h_n = $model -> h_n ;
$patient -> id_card = $model -> id_card ;
//$patient->name = $model->autocomplete_patient; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
//$patient->hospital_id = $model->hospital_id;
if ( $patient -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'เพิ่ม/แก้ไขข้อมูลผู้ป่วยแล้ว' );
} else {
Yii :: $app -> session -> setFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . isset ( $patient ) ? Html :: encode ( $patient -> getFullname ()) : '' );
}
}
// ได้ $patient->id ล่ะ
/*
* บันทึก FLOW
*/
$model -> patient_id = $patient -> id ;
$model -> status_id = 1 ;
$model -> pathologist_id = 1 ;
//ตรวจสอบ Side of Specimen ถ้ามีการเพิ่มใหม่ให้บันทึก Side of Specimen ใหม่
if ( ! empty ( $model -> cyto_side_of_specimen ) && empty ( $model -> side_of_specimen )) {
$specimen = new CytoSideOfSpecimen ();
$specimen -> name = $model -> cyto_side_of_specimen ;
$specimen -> save ();
$model -> side_of_specimen = $specimen -> id ;
}
############# Next IdCase Again ##############
//$model->id_case = $this->getIdCase('FN'); // ค้นหารหัสต่อไป
$model -> files = $model -> uploadFile ( $model , 'files' );
//Upload Outlab Report
if ( $model -> is_outlab ) {
$outlab_at = date ( 'Y-m-d H:i:s' );
$model -> status_id = 7 ;
$flow_diagnosis = FlowDiagnosis :: findOne ([ 'id_case' => $model -> id_case , 'report_type' => 'outlab' ]);
if ( ! $flow_diagnosis ) {
$flow_diagnosis = new FlowDiagnosis ();
$flow_diagnosis -> id_case = $model -> id_case ;
$flow_diagnosis -> report_type = 'outlab' ;
//$flow_diagnosis->status_id = 1;
//$surgical_diagnosis->pathologist_at = $outlab_at;
}
if ( $flow_diagnosis -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
var_dump ( $flow_diagnosis -> getFirstErrors ());
die ();
}
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = date ( 'Y-m-d H:i:s' );
$model -> receive_at = date ( 'Y-m-d H:i:s' );
if ( $model -> save ()) {
$hospital = ConstHospital :: findOne ( $model -> hospital_id );
/* $finance -> id_case = $model -> id_case ;
$finance -> hospital_id = $model -> hospital_id ;
$finance -> price = Yii :: $app -> pathology -> getHosPrice ( $model -> hospital_id , $finance -> charge_id );
$finance -> df = Yii :: $app -> pathology -> getHosDF ( $model -> hospital_id , $finance -> charge_id );
$finance -> occur_at = $time_now ;
$finance -> is_cash = 0 ;
$finance -> is_able = 0 ; //คิดเงิน
if ( $finance -> save ()) {
} else {
var_dump ( $finance -> getFirstErrors ());
die ();
} */
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึกข้อมูลเรียบร้อยแล้ว' );
} /* else {
var_dump ( $model -> getFirstErrors ());
die ();
} */
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลงทะเบียน Flow เรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/flow' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
throw new Exception ( $e -> getMessage ());
}
} // if post()
return $this -> render ( 'flow' , [
'model' => $model ,
//'finance' => $finance,
]);
}
/**
* @ return array | string | void | Response
* @ throws Exception
*/
2025-01-02 03:31:23 +00:00
/*
2024-12-25 03:04:59 +00:00
public function actionFrozen ()
{
//$finance = new FinanceServiceCharge();
$model = new CaseFrozen (); //['scenario' => 'register']
2024-12-27 09:24:36 +00:00
$model -> id_case = $this -> getIdCase ( 'F' );
2024-12-25 03:04:59 +00:00
//$model->no_slide = "1";
$patient = new Patient ();
$model -> nation = 'ไทย' ;
$model -> age_unit = 'ปี' ;
Yii :: $app -> session -> setFlash ( 'info' , 'ลงทะเบียนงาน FROZEN หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
//$patient->load(Yii::$app->request->post());
//$finance->load(Yii::$app->request->post());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
2025-01-02 03:31:23 +00:00
$result = ActiveForm :: validate ( $model );
2024-12-25 03:04:59 +00:00
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())
//$patient->load(Yii::$app->request->post())
//&& $finance->load(Yii::$app->request->post())
) //$operate->load(Yii::$app->request->post())) {
{
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
$patient_old = Patient :: find ()
-> filterWhere ([ 'given_name' => $patient -> given_name ])
-> one ();
// บันทึกผู้ป่วย
if ( ! empty ( $model -> patient_id ) && $patient_old ) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient_update = Patient :: findOne ( $model -> patient_id );
$patient_update -> gender = $patient -> gender ;
$patient_update -> nation = $patient -> nation ;
$patient_update -> birthdate = $patient -> birthdate ;
$patient_update -> age = $patient -> age ;
$patient_update -> age_unit = $patient -> age_unit ;
$patient_update -> hospital_id = $patient -> hospital_id ;
$patient_update -> h_n = $patient -> h_n ;
$patient_update -> id_card = $patient -> id_card ;
$patient_update -> save ( false );
$patient = $patient_update ;
} else {
$patient -> given_name = $model -> given_name ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> surname = $model -> surname ;
$patient -> title_id = $model -> title_id ;
$patient -> gender = $model -> gender ;
$patient -> nation = $model -> nation ;
$patient -> birthdate = $model -> birthdate ;
$patient -> age = $model -> age ;
$patient -> age_unit = $model -> age_unit ;
$patient -> hospital_id = $model -> hospital_id ;
$patient -> h_n = $model -> h_n ;
$patient -> id_card = $model -> id_card ;
//$patient->name = $model->autocomplete_patient; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
//$patient->hospital_id = $model->hospital_id;
if ( $patient -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'เพิ่ม/แก้ไขข้อมูลผู้ป่วยแล้ว' );
} else {
Yii :: $app -> session -> setFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . isset ( $patient ) ? Html :: encode ( $patient -> getFullname ()) : '' );
}
}
// ได้ $patient->id ล่ะ
$model -> patient_id = $patient -> id ;
$model -> status_id = 1 ;
$model -> pathologist_id = 1 ;
//ตรวจสอบ Side of Specimen ถ้ามีการเพิ่มใหม่ให้บันทึก Side of Specimen ใหม่
if ( ! empty ( $model -> cyto_side_of_specimen ) && empty ( $model -> side_of_specimen )) {
$specimen = new CytoSideOfSpecimen ();
$specimen -> name = $model -> cyto_side_of_specimen ;
$specimen -> save ();
$model -> side_of_specimen = $specimen -> id ;
}
############# Next IdCase Again ##############
//$model->id_case = $this->getIdCase('FN'); // ค้นหารหัสต่อไป
$model -> files = $model -> uploadFile ( $model , 'files' );
$model -> specimen_img = $model -> uploadGross ( $model , 'specimen_img' );
if ( ! empty ( $model -> specimen_img )) {
$model -> specimen_img_at = date ( 'Y-m-d H:i:s' );
$model -> specimen_img_update_id = Yii :: $app -> user -> getId ();
}
//Upload Outlab Report
if ( $model -> is_outlab ) {
$outlab_at = date ( 'Y-m-d H:i:s' );
$model -> status_id = 7 ;
$frozen_diagnosis = FrozenDiagnosis :: findOne ([ 'id_case' => $model -> id_case , 'report_type' => 'outlab' ]);
if ( ! $frozen_diagnosis ) {
$frozen_diagnosis = new FrozenDiagnosis ();
$frozen_diagnosis -> id_case = $model -> id_case ;
$frozen_diagnosis -> report_type = 'outlab' ;
//$frozen_diagnosis->status_id = 1;
//$surgical_diagnosis->pathologist_at = $outlab_at;
}
if ( $frozen_diagnosis -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
var_dump ( $frozen_diagnosis -> getFirstErrors ());
die ();
}
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = date ( 'Y-m-d H:i:s' );
$model -> receive_at = date ( 'Y-m-d H:i:s' );
if ( $model -> save ()) {
$hospital = ConstHospital :: findOne ( $model -> hospital_id );
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึกข้อมูลเรียบร้อยแล้ว' );
2025-01-02 03:31:23 +00:00
}
2024-12-25 03:04:59 +00:00
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลงทะเบียน Frozen เรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/frozen' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
throw new Exception ( $e -> getMessage ());
}
} // if post()
return $this -> render ( 'frozen' , [
'model' => $model ,
//'finance' => $finance,
]);
}
2025-01-02 03:31:23 +00:00
*/
/*
* ลงทะเบียน CASE Frozen
*/
public function actionFrozen ()
{
$model = new CaseFrozen ();
2025-01-21 04:32:19 +00:00
//$model = new CaseFrozen(['scenario' => 'register']);
2025-01-02 03:31:23 +00:00
$time_now = date ( 'Y-m-d H:i:s' );
2025-01-21 04:32:19 +00:00
//$model->id_case = $this->getIdCase('F'); // ค้นหารหัสต่อไป
2025-01-02 03:31:23 +00:00
$patient = new Patient ();
$model -> nation = 'ไทย' ;
$model -> age_unit = 'ปี' ;
$model -> receive_at = empty ( $model -> receive_at ) ? date ( 'd/m/Y' ) : $model -> receive_at ;
Yii :: $app -> session -> setFlash ( 'info' , 'ลงทะเบียนงานศัลยพยาธิ หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$result = ActiveForm :: validate ( $model );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
/** echo '<pre>' ;
* var_dump ( $model );
* var_dump ( $patient );
* echo '</pre>' ;
* die (); */
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
$patient_old = Patient :: find ()
-> filterWhere ([ 'given_name' => $patient -> given_name ])
-> one ();
// บันทึกผู้ป่วย
if ( ! empty ( $model -> patient_id ) && $patient_old ) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient_update = Patient :: findOne ( $model -> patient_id );
$patient_update -> gender = $patient -> gender ;
$patient_update -> nation = $patient -> nation ;
$patient_update -> birthdate = $patient -> birthdate ;
$patient_update -> age = $patient -> age ;
$patient_update -> age_unit = $patient -> age_unit ;
$patient_update -> hospital_id = $patient -> hospital_id ;
$patient_update -> h_n = $patient -> h_n ;
$patient_update -> id_card = $patient -> id_card ;
$patient_update -> save ();
$patient = $patient_update ;
} else {
$patient -> given_name = $model -> given_name ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> surname = $model -> surname ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> title_id = $model -> title_id ;
$patient -> gender = $model -> gender ;
$patient -> nation = $model -> nation ;
$patient -> birthdate = $model -> birthdate ;
$patient -> age = $model -> age ;
$patient -> age_unit = $model -> age_unit ;
$patient -> hospital_id = $model -> hospital_id ;
$patient -> h_n = $model -> h_n ;
$patient -> id_card = $model -> id_card ;
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
if ( $patient -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'เพิ่ม/แก้ไขข้อมูลผู้ป่วยแล้ว' );
} else {
Yii :: $app -> session -> setFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . $patient -> given_name );
}
}
$model -> patient_id = $patient -> id ; // นำ ID ผู้ป่วยมากำหนดใน patient_id ใหม่
$model -> status_id = 1 ;
// ตรวจสอบก่อนว่าต้องเก็บข้อมูลเก่าไว้ไหม
//$model->hospital_id = $patient->hospital_id; // กำหนดโรงพยาบาลให้ CaseSurgical ด้วย
//แก้ไขให้ hospital อยู่ใน CaseSurgical แล้ว
//อัพโหลดภาพ Specimen Container
$model -> specimen_container_img = $model -> uploadSpecimenContainer ( $model , 'specimen_container_img' );
//อัพโหลดไฟล์ Request
$model -> files = $model -> uploadFile ( $model , 'files' );
//if case reference
if ( ! empty ( $model -> case_reference )) {
$case_reference = CaseFrozen :: findOne ([ 'id_case' => $model -> case_reference ]);
if ( $case_reference ) {
$model -> gross_description = $case_reference -> gross_description ;
$model -> microscopic_description = $case_reference -> microscopic_description ;
$model -> diagnosis = $case_reference -> diagnosis ;
$model -> additional_diagnosis = $case_reference -> additional_diagnosis ;
}
}
//Upload Outlab Report
if ( $model -> is_outlab ) {
$outlab_at = date ( 'Y-m-d H:i:s' );
$model -> status_id = 15 ;
$surgical_diagnosis = FrozenDiagnosis :: findOne ([ 'id_case' => $model -> id_case , 'report_type' => 'outlab' ]);
if ( ! $surgical_diagnosis ) {
$surgical_diagnosis = new FrozenDiagnosis ();
$surgical_diagnosis -> id_case = $model -> id_case ;
$surgical_diagnosis -> report_type = 'outlab' ;
$surgical_diagnosis -> status_id = 11 ;
$surgical_diagnosis -> pathologist_at = $outlab_at ;
}
$surgical_diagnosis -> id_case = $model -> id_case ;
$surgical_diagnosis -> report_type = 'outlab' ;
$surgical_diagnosis -> status_id = 11 ;
$surgical_diagnosis -> pathologist_at = $outlab_at ;
if ( $surgical_diagnosis -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Upload' , 'อัพโหลดไฟล์ Frozen Outlab: ' . $model -> id_case , Yii :: $app -> user -> getId (), FrozenDiagnosis :: tableName ());
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
2025-03-22 10:58:33 +00:00
//var_dump($surgical_diagnosis->getFirstErrors());
//die();
2025-01-02 03:31:23 +00:00
}
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = date ( 'Y-m-d H:i:s' );
$model -> receive_at = $time_now ;
if ( $model -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Create' , 'ลงทะเบียน Case Frozen: ' . $model -> id_case , Yii :: $app -> user -> getId (), CaseFrozen :: tableName ());
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึกข้อมูลเรียบร้อยแล้ว' );
//หากไม่มี HN ให้ Request จาก HIS
if ( empty ( $model -> h_n )) {
Yii :: $app -> pathology -> requestHisHn ( $model -> id_case );
}
}
$transaction -> commit ();
// set flash and redirect
Yii :: $app -> session -> setFlash ( 'success' , 'ลงทะเบียน Frozen เรียบร้อยแล้ว' );
return $this -> redirect ([
'/register/case-update/frozen' ,
'id_case' => $model -> id_case
]);
} catch ( Exception $e ) {
var_dump ( $e -> getMessage ());
die ();
$transaction -> rollBack ();
throw new Exception ( $e -> getMessage ());
}
}
return $this -> render ( 'frozen' , [
'model' => $model ,
]);
}
2024-12-25 03:04:59 +00:00
2024-12-27 09:24:36 +00:00
public function actionGetFrozenCase ()
{
Yii :: $app -> response -> format = Response :: FORMAT_RAW ;
$this -> enableCsrfValidation = false ;
$case = Yii :: $app -> request -> post ( 'case' );
2025-04-11 04:01:19 +00:00
//$year = substr(date('Y'), 2);
$year = substr ( date ( 'Y' ) + 543 , 2 );
2024-12-27 09:24:36 +00:00
$lastRecord = CaseFrozen :: find () -> where ([ 'like' , 'id_case' , $case . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
if ( $lastRecord ) {
$digit = explode ( '-' , $lastRecord -> id_case );
$lastDigit = (( int ) $digit [ 1 ]); // change string to integer for +1
$lastDigit ++ ;
$lastDigit = str_pad ( $lastDigit , 5 , '0' , STR_PAD_LEFT );
} else {
$lastDigit = '00001' ;
}
return $case . $year . '-' . $lastDigit ;
}
2024-12-25 03:04:59 +00:00
/**
* @ return array | string | void | Response
* @ throws Exception
*/
public function actionFish ()
{
$model = new CaseFish (); //['scenario' => 'register']
$model -> id_case = $this -> getIdCase ( 'I' );
//$model->no_slide = "1";
//$finance = new FinanceServiceCharge();
$patient = new Patient ();
$model -> nation = 'ไทย' ;
$model -> age_unit = 'ปี' ;
Yii :: $app -> session -> setFlash ( 'info' , 'ลงทะเบียนงาน FISH หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
//$patient->load(Yii::$app->request->post());
//$finance->load(Yii::$app->request->post());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$result = ActiveForm :: validate ( $model /*, $finance*/ );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())
//$patient->load(Yii::$app->request->post())
//&& $finance->load(Yii::$app->request->post())
) //$operate->load(Yii::$app->request->post())) {
{
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
// บันทึกผู้ป่วยก่อน Patient
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
/* var_dump ( $model );
die (); */
$time_now = date ( 'Y-m-d H:i:s' );
$patient_old = Patient :: find ()
-> filterWhere ([ 'given_name' => $patient -> given_name ])
-> one ();
// บันทึกผู้ป่วย
if ( ! empty ( $model -> patient_id ) && $patient_old ) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient_update = Patient :: findOne ( $model -> patient_id );
$patient_update -> gender = $patient -> gender ;
$patient_update -> nation = $patient -> nation ;
$patient_update -> birthdate = $patient -> birthdate ;
$patient_update -> age = $patient -> age ;
$patient_update -> age_unit = $patient -> age_unit ;
$patient_update -> hospital_id = $patient -> hospital_id ;
$patient_update -> h_n = $patient -> h_n ;
$patient_update -> id_card = $patient -> id_card ;
$patient_update -> save ( false );
$patient = $patient_update ;
} else {
$patient -> given_name = $model -> given_name ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> surname = $model -> surname ;
$patient -> title_id = $model -> title_id ;
$patient -> gender = $model -> gender ;
$patient -> nation = $model -> nation ;
$patient -> birthdate = $model -> birthdate ;
$patient -> age = $model -> age ;
$patient -> age_unit = $model -> age_unit ;
$patient -> hospital_id = $model -> hospital_id ;
$patient -> h_n = $model -> h_n ;
$patient -> id_card = $model -> id_card ;
//$patient->name = $model->autocomplete_patient; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
//$patient->hospital_id = $model->hospital_id;
if ( $patient -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'เพิ่ม/แก้ไขข้อมูลผู้ป่วยแล้ว' );
} else {
Yii :: $app -> session -> setFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . isset ( $patient ) ? Html :: encode ( $patient -> getFullname ()) : '' );
}
}
// ได้ $patient->id ล่ะ
$model -> patient_id = $patient -> id ;
$model -> status_id = 1 ;
$model -> pathologist_id = 1 ;
//ตรวจสอบ Side of Specimen ถ้ามีการเพิ่มใหม่ให้บันทึก Side of Specimen ใหม่
if ( ! empty ( $model -> cyto_side_of_specimen ) && empty ( $model -> side_of_specimen )) {
$specimen = new CytoSideOfSpecimen ();
$specimen -> name = $model -> cyto_side_of_specimen ;
$specimen -> save ();
$model -> side_of_specimen = $specimen -> id ;
}
############# Next IdCase Again ##############
//$model->id_case = $this->getIdCase('FN'); // ค้นหารหัสต่อไป
$model -> files = $model -> uploadFile ( $model , 'files' );
//Upload Outlab Report
if ( $model -> is_outlab ) {
$outlab_at = date ( 'Y-m-d H:i:s' );
$model -> status_id = 7 ;
$fish_diagnosis = FishDiagnosis :: findOne ([ 'id_case' => $model -> id_case , 'report_type' => 'outlab' ]);
if ( ! $fish_diagnosis ) {
$fish_diagnosis = new FishDiagnosis ();
$fish_diagnosis -> id_case = $model -> id_case ;
$fish_diagnosis -> report_type = 'outlab' ;
//$fish_diagnosis->status_id = 1;
//$surgical_diagnosis->pathologist_at = $outlab_at;
}
if ( $fish_diagnosis -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
var_dump ( $fish_diagnosis -> getFirstErrors ());
die ();
}
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = date ( 'Y-m-d H:i:s' );
$model -> receive_at = date ( 'Y-m-d H:i:s' );
if ( $model -> save ()) {
$hospital = ConstHospital :: findOne ( $model -> hospital_id );
/* $finance -> id_case = $model -> id_case ;
$finance -> hospital_id = $model -> hospital_id ;
$finance -> price = Yii :: $app -> pathology -> getHosPrice ( $model -> hospital_id , $finance -> charge_id );
$finance -> df = Yii :: $app -> pathology -> getHosDF ( $model -> hospital_id , $finance -> charge_id );
$finance -> occur_at = $time_now ;
$finance -> is_cash = 0 ;
$finance -> is_able = 0 ; //คิดเงิน
if ( $finance -> save ()) {
} else {
var_dump ( $finance -> getFirstErrors ());
die ();
} */
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึกข้อมูลเรียบร้อยแล้ว' );
} else {
var_dump ( $model -> getFirstErrors ());
die ();
}
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลงทะเบียน Fish เรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/fish' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
throw new Exception ( $e -> getMessage ());
}
} // if post()
return $this -> render ( 'fish' , [
'model' => $model ,
//'finance' => $finance,
]);
}
public function actionDish ()
{
$model = new CaseDish (); //['scenario' => 'register']
$model -> id_case = $this -> getIdCase ( 'D' );
//$model->no_slide = "1";
//$finance = new FinanceServiceCharge();
$patient = new Patient ();
$model -> nation = 'ไทย' ;
$model -> age_unit = 'ปี' ;
Yii :: $app -> session -> setFlash ( 'info' , 'ลงทะเบียนงาน DISH หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
//$patient->load(Yii::$app->request->post());
//$finance->load(Yii::$app->request->post());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$result = ActiveForm :: validate ( $model /*, $finance*/ );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())
//$patient->load(Yii::$app->request->post())
//&& $finance->load(Yii::$app->request->post())
) //$operate->load(Yii::$app->request->post())) {
{
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
/* var_dump ( $model );
die (); */
$patient_old = Patient :: find ()
-> filterWhere ([ 'given_name' => $patient -> given_name ])
-> one ();
// บันทึกผู้ป่วย
if ( ! empty ( $model -> patient_id ) && $patient_old ) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient_update = Patient :: findOne ( $model -> patient_id );
$patient_update -> gender = $patient -> gender ;
$patient_update -> nation = $patient -> nation ;
$patient_update -> birthdate = $patient -> birthdate ;
$patient_update -> age = $patient -> age ;
$patient_update -> age_unit = $patient -> age_unit ;
$patient_update -> hospital_id = $patient -> hospital_id ;
$patient_update -> h_n = $patient -> h_n ;
$patient_update -> id_card = $patient -> id_card ;
$patient_update -> save ( false );
$patient = $patient_update ;
} else {
$patient -> given_name = $model -> given_name ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> surname = $model -> surname ;
$patient -> title_id = $model -> title_id ;
$patient -> gender = $model -> gender ;
$patient -> nation = $model -> nation ;
$patient -> birthdate = $model -> birthdate ;
$patient -> age = $model -> age ;
$patient -> age_unit = $model -> age_unit ;
$patient -> hospital_id = $model -> hospital_id ;
$patient -> h_n = $model -> h_n ;
$patient -> id_card = $model -> id_card ;
//$patient->name = $model->autocomplete_patient; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
//$patient->hospital_id = $model->hospital_id;
if ( $patient -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'เพิ่ม/แก้ไขข้อมูลผู้ป่วยแล้ว' );
} else {
Yii :: $app -> session -> setFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . isset ( $patient ) ? Html :: encode ( $patient -> getFullname ()) : '' );
}
}
// ได้ $patient->id ล่ะ
/*
* บันทึก FROZEN
*/
$model -> patient_id = $patient -> id ;
$model -> status_id = 1 ;
$model -> pathologist_id = 1 ;
//ตรวจสอบ Side of Specimen ถ้ามีการเพิ่มใหม่ให้บันทึก Side of Specimen ใหม่
if ( ! empty ( $model -> cyto_side_of_specimen ) && empty ( $model -> side_of_specimen )) {
$specimen = new CytoSideOfSpecimen ();
$specimen -> name = $model -> cyto_side_of_specimen ;
$specimen -> save ();
$model -> side_of_specimen = $specimen -> id ;
}
############# Next IdCase Again ##############
//$model->id_case = $this->getIdCase('FN'); // ค้นหารหัสต่อไป
$model -> files = $model -> uploadFile ( $model , 'files' );
$model -> specimen_img = $model -> uploadGross ( $model , 'specimen_img' );
if ( ! empty ( $model -> specimen_img )) {
$model -> specimen_img_at = date ( 'Y-m-d H:i:s' );
$model -> specimen_img_update_id = Yii :: $app -> user -> getId ();
}
//Upload Outlab Report
if ( $model -> is_outlab ) {
$outlab_at = date ( 'Y-m-d H:i:s' );
$model -> status_id = 7 ;
$dish_diagnosis = DishDiagnosis :: findOne ([ 'id_case' => $model -> id_case , 'report_type' => 'outlab' ]);
if ( ! $dish_diagnosis ) {
$dish_diagnosis = new DishDiagnosis ();
$dish_diagnosis -> id_case = $model -> id_case ;
$dish_diagnosis -> report_type = 'outlab' ;
$dish_diagnosis -> status_id = 1 ;
//$surgical_diagnosis->pathologist_at = $outlab_at;
}
if ( $dish_diagnosis -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
var_dump ( $dish_diagnosis -> getFirstErrors ());
die ();
}
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = date ( 'Y-m-d H:i:s' );
$model -> receive_at = date ( 'Y-m-d H:i:s' );
if ( $model -> save ()) {
$hospital = ConstHospital :: findOne ( $model -> hospital_id );
/**/
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึกข้อมูลเรียบร้อยแล้ว' );
} /* else {
var_dump ( $model -> getFirstErrors ());
die ();
} */
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลงทะเบียน Dish เรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/dish' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
throw new Exception ( $e -> getMessage ());
}
} // if post()
return $this -> render ( 'dish' , [
'model' => $model ,
//'finance' => $finance,
]);
}
/**
* ลงทะเบียน HPV
* @ param $case
* @ return string
*/
public function actionHpv ()
{
$model = new CaseHpv ();
$model -> id_case = $this -> getIdCase ( 'H' ); // ค้นหารหัสต่อไป
$patient = new Patient ();
$patient -> nation = 'ไทย' ;
$finance = new FinanceServiceCharge ();
Yii :: $app -> session -> addFlash ( 'info' , 'ลงทะเบียนงาน HPV หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
$patient -> load ( Yii :: $app -> request -> post ());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$result = ActiveForm :: validate ( $model , $patient );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ()) && $patient -> load ( Yii :: $app -> request -> post ()) && $finance -> load ( Yii :: $app -> request -> post ())) {
$time_now = date ( 'Y-m-d H:i:s' );
$transaction = Yii :: $app -> db -> beginTransaction ();
//return $_POST['CaseHpv']['autocomplete_patient'];
//return $model->autocomplete_patient;
//print_r($_POST);
//return $patient->name;
try {
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
// var_dump($patient);
// var_dump($model);
// บันทึกผู้ป่วย
if ( intval ( $model -> patient_id )) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient = Patient :: findOne ( $model -> patient_id );
} else {
$patient -> name = $_POST [ 'CaseHpv' ][ 'autocomplete_patient' ]; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
$patient -> hospital_id = $model -> hospital_id ;
if ( $patient -> save ( false )) {
Yii :: $app -> session -> addFlash ( 'success' , 'เพิ่มผู้ป่วยแล้ว' );
} else {
Yii :: $app -> session -> addFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . $patient -> name );
}
}
// บันทึก HPV
$model -> patient_id = $patient -> id ; // นำ ID ผู้ป่วยมากำหนดใน patient_id ใหม่
$model -> status_id = 1 ;
//$model->pathologist_id = 1;
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = $time_now ;
//$model->files = $model->uploadFile($model, 'files');
if ( $model -> save ( false )) {
Yii :: $app -> session -> addFlash ( 'success' , 'ลงทะเบียน HPV เรียบร้อยแล้ว' );
$charge = ConstServiceCharge :: findOne ( $finance -> charge_id );
$hospital = ConstHospital :: findOne ( $model -> hospital_id );
$finance -> id_case = $model -> id_case ;
$finance -> hospital_id = $model -> hospital_id ;
$finance -> charge_id = $charge -> id ;
$finance -> price = $hospital -> is_private == 1 ? $charge -> price_private : $charge -> price ;
$finance -> occur_at = $time_now ;
$finance -> is_cash = 0 ;
$finance -> is_able = 0 ; //คิดเงิน
$finance -> save ();
}
$transaction -> commit ();
// set flash and redirect
return $this -> redirect ([
'/register/case-update/hpv' ,
'id_case' => $model -> id_case
]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
throw new Exception ( $e -> getMessage ());
}
}
return $this -> render ( 'hpv' , [
'model' => $model ,
'patient' => $patient ,
'finance' => $finance
]);
}
/**
* Register Autopsy Case
*
* @ return void
*/
public function actionAutopsy ()
{
$model = new CaseAutopsy (); //['scenario' => 'register']
$model -> id_case = $this -> getIdCase ( 'A' );
$model -> die_agree = " 1 " ;
$patient = new Patient ();
$model -> nation = 'ไทย' ;
$model -> age_unit = 'ปี' ;
Yii :: $app -> session -> setFlash ( 'info' , 'ลงทะเบียนงาน AUTOPSY หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$result = ActiveForm :: validate ( $model /*, $finance*/ );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
/* var_dump ( $model );
die (); */
//$model->body_id = $model->id;
$patient_old = Patient :: find ()
-> filterWhere ([ 'given_name' => $patient -> given_name ])
-> one ();
// บันทึกผู้ป่วย
if ( ! empty ( $model -> patient_id ) && $patient_old ) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient_update = Patient :: findOne ( $model -> patient_id );
$patient_update -> gender = $patient -> gender ;
$patient_update -> nation = $patient -> nation ;
$patient_update -> birthdate = $patient -> birthdate ;
$patient_update -> age = $patient -> age ;
$patient_update -> age_unit = $patient -> age_unit ;
$patient_update -> hospital_id = $patient -> hospital_id ;
$patient_update -> h_n = $patient -> h_n ;
$patient_update -> id_card = $patient -> id_card ;
$patient_update -> save ( false );
$patient = $patient_update ;
} else {
$patient -> given_name = $model -> given_name ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> surname = $model -> surname ;
$patient -> title_id = $model -> title_id ;
$patient -> gender = $model -> gender ;
$patient -> nation = $model -> nation ;
$patient -> birthdate = $model -> birthdate ;
$patient -> age = $model -> age ;
$patient -> age_unit = $model -> age_unit ;
$patient -> hospital_id = $model -> hospital_id ;
$patient -> h_n = $model -> h_n ;
$patient -> id_card = $model -> id_card ;
//$patient->name = $model->autocomplete_patient; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
//$patient->hospital_id = $model->hospital_id;
if ( $patient -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'เพิ่ม/แก้ไขข้อมูลผู้ป่วยแล้ว' );
} else {
Yii :: $app -> session -> setFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . isset ( $patient ) ? Html :: encode ( $patient -> getFullname ()) : '' );
}
}
// ได้ $patient->id ล่ะ
/*
* บันทึก Autopsy
*/
$model -> patient_id = $patient -> id ;
$model -> status_id = 1 ;
$model -> pathologist_id = 1 ;
############# Next IdCase Again ##############
//$model->id_case = $this->getIdCase('FN'); // ค้นหารหัสต่อไป
//อัพโหลดไฟล์ Request
$model -> files = $model -> uploadFile ( $model , 'files' );
//อัพโหลดภาพ Specimen Container
$model -> specimen_container_img = $model -> uploadSpecimenContainer ( $model , 'specimen_container_img' );
//Upload Outlab Report
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
//Upload Outlab Report
if ( $model -> is_outlab ) {
$outlab_at = date ( 'Y-m-d H:i:s' );
$model -> status_id = 15 ;
$autopsy_diagnosis = AutopsyDiagnosis :: findOne ([ 'id_case' => $model -> id_case , 'report_type' => 'outlab' ]);
if ( ! $autopsy_diagnosis ) {
$autopsy_diagnosis = new AutopsyDiagnosis ();
$autopsy_diagnosis -> id_case = $model -> id_case ;
$autopsy_diagnosis -> report_type = 'outlab' ;
$autopsy_diagnosis -> status_id = 11 ;
$autopsy_diagnosis -> pathologist_at = $outlab_at ;
}
$autopsy_diagnosis -> id_case = $model -> id_case ;
$autopsy_diagnosis -> report_type = 'outlab' ;
$autopsy_diagnosis -> status_id = 11 ;
$autopsy_diagnosis -> pathologist_at = $outlab_at ;
if ( $autopsy_diagnosis -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Upload' , 'อัพโหลดไฟล์ Autopsy Outlab: ' . $model -> id_case , Yii :: $app -> user -> getId (), AutopsyDiagnosis :: tableName ());
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
2025-03-22 10:58:33 +00:00
//var_dump($autopsy_diagnosis->getFirstErrors());
//die();
2024-12-25 03:04:59 +00:00
}
}
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = $time_now ;
$model -> receive_at = $time_now ;
$hospital = ConstHospital :: findOne ( $model -> hospital_id );
if ( $model -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Create' , 'ลงทะเบียน Case Autopsy: ' . $model -> id_case , Yii :: $app -> user -> getId (), CaseAutopsy :: tableName ());
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึกข้อมูลเรียบร้อยแล้ว' );
} /* else {
var_dump ( $model -> getFirstErrors ());
die ();
} */
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลงทะเบียน Autopsy เรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/autopsy' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
throw new Exception ( $e -> getMessage ());
}
} // if post()
return $this -> render ( 'autopsy' , [
'model' => $model ,
]);
}
/**
* ลงทะเบียน NonGyn
* @ return \yii\web\Response | string
*/
public function actionNonGyn ()
{
$model = new CaseNonGyn (); //['scenario' => 'register']
$model -> id_case = $this -> getIdCase ( 'C' );
$model -> no_slide = " 1 " ;
$patient = new Patient ();
$model -> nation = 'ไทย' ;
$model -> age_unit = 'ปี' ;
$model -> receive_at = empty ( $model -> receive_at ) ? date ( 'd/m/Y' ) : $model -> receive_at ;
// บันทึกผู้ป่วย
Yii :: $app -> session -> setFlash ( 'info' , 'ลงทะเบียนงาน Cyto (Non-gyn) หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$result = ActiveForm :: validate ( $model );
return $result ;
}
if (
$model -> load ( Yii :: $app -> request -> post ())
) {
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
$patient_old = Patient :: find ()
-> filterWhere ([ 'given_name' => $patient -> given_name ])
-> one ();
// บันทึกผู้ป่วย
if ( ! empty ( $model -> patient_id ) && $patient_old ) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient_update = Patient :: findOne ( $model -> patient_id );
$patient_update -> gender = $patient -> gender ;
$patient_update -> nation = $patient -> nation ;
$patient_update -> birthdate = $patient -> birthdate ;
$patient_update -> age = $patient -> age ;
$patient_update -> age_unit = $patient -> age_unit ;
$patient_update -> hospital_id = $patient -> hospital_id ;
$patient_update -> h_n = $patient -> h_n ;
$patient_update -> id_card = $patient -> id_card ;
$patient_update -> save ( false );
$patient = $patient_update ;
} else {
$patient -> given_name = $model -> given_name ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> surname = $model -> surname ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> title_id = $model -> title_id ;
$patient -> gender = $model -> gender ;
$patient -> nation = $model -> nation ;
$patient -> birthdate = $model -> birthdate ;
$patient -> age = $model -> age ;
$patient -> age_unit = $model -> age_unit ;
$patient -> hospital_id = $model -> hospital_id ;
$patient -> h_n = $model -> h_n ;
$patient -> id_card = $model -> id_card ;
//$patient->name = $model->autocomplete_patient; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
$patient -> hospital_id = $model -> hospital_id ;
if ( $patient -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'เพิ่ม/แก้ไขข้อมูลผู้ป่วยแล้ว' );
} else {
Yii :: $app -> session -> setFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . $patient -> given_name );
}
}
/*
* บันทึก CASE NonGyn
*/
$model -> patient_id = $patient -> id ;
$model -> status_id = 1 ;
$model -> pathologist_id = 1 ;
//ตรวจสอบ Side of Specimen ถ้ามีการเพิ่มใหม่ให้บันทึก Side of Specimen ใหม่
if ( ! empty ( $model -> cyto_side_of_specimen ) && empty ( $model -> side_of_specimen )) {
$specimen = new CytoSideOfSpecimen ();
$specimen -> name = $model -> cyto_side_of_specimen ;
$specimen -> save ();
$model -> side_of_specimen = $specimen -> id ;
}
//อัพโหลดไฟล์ Request
$model -> files = $model -> uploadFile ( $model , 'files' );
//อัพโหลดภาพ Specimen Container
$model -> specimen_container_img = $model -> uploadSpecimenContainer ( $model , 'specimen_container_img' );
//Upload Outlab Report
if ( $model -> is_outlab ) {
$outlab_at = $time_now ;
$model -> status_id = 15 ;
$non_gyn_diagnosis = CytoNonGynDiagnosis :: findOne ([ 'id_case' => $model -> id_case , 'report_type' => 'outlab' ]);
if ( ! $non_gyn_diagnosis ) {
$non_gyn_diagnosis = new CytoNonGynDiagnosis ();
$non_gyn_diagnosis -> id_case = $model -> id_case ;
$non_gyn_diagnosis -> report_type = 'outlab' ;
$non_gyn_diagnosis -> status_id = 11 ;
$non_gyn_diagnosis -> pathologist_at = $outlab_at ;
}
$non_gyn_diagnosis -> id_case = $model -> id_case ;
$non_gyn_diagnosis -> report_type = 'outlab' ;
$non_gyn_diagnosis -> status_id = 11 ;
$non_gyn_diagnosis -> pathologist_at = $outlab_at ;
if ( $non_gyn_diagnosis -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Upload' , 'อัพโหลดไฟล์ Cyto Non-Gyn Outlab: ' . $model -> id_case , Yii :: $app -> user -> getId (), CytoNonGynDiagnosis :: tableName ());
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
2025-03-22 10:58:33 +00:00
//var_dump($non_gyn_diagnosis->getFirstErrors());
//die();
2024-12-25 03:04:59 +00:00
}
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = $time_now ;
$model -> receive_at = $time_now ;
$hospital = ConstHospital :: findOne ( $model -> hospital_id );
if ( $model -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Create' , 'ลงทะเบียน Case Non-Gyn: ' . $model -> id_case , Yii :: $app -> user -> getId (), CaseNonGyn :: tableName ());
//หากไม่มี HN ให้ Request จาก HIS
if ( empty ( $model -> h_n )) {
Yii :: $app -> pathology -> requestHisHn ( $model -> id_case );
}
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึกข้อมูลเรียบร้อยแล้ว' );
} else {
var_dump ( $model -> getFirstErrors ());
die ;
}
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลงทะเบียน NonGyn เรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/non-gyn' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
throw new Exception ( $e -> getMessage ());
}
} // if post()
return $this -> render ( 'non-gyn' , [
'model' => $model ,
]);
}
/**
* ลงทะเบียน PAP
* @ return \yii\web\Response | string
*/
public function actionPap ()
{
$model = new CasePap ([ 'scenario' => 'register' ]);
$model -> id_case = $this -> getIdCase ( 'G' );
$model -> no_slide = 1 ;
//$operate = new CytoOperate();
//$finance = new FinanceServiceCharge();
$patient = new Patient ();
$model -> nation = 'ไทย' ;
$model -> age_unit = 'ปี' ;
$model -> receive_at = empty ( $model -> receive_at ) ? date ( 'd/m/Y' ) : $model -> receive_at ;
Yii :: $app -> session -> setFlash ( 'info' , 'ลงทะเบียน Cyto (Gyn) หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
//$ทนกำส->register_at = date('d/m/') . (date('Y') + 543) . ' ' . date('H:i:s');
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$result = ActiveForm :: validate ( $model /*, $finance*/ );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
$patient_old = Patient :: find ()
-> filterWhere ([ 'given_name' => $patient -> given_name ])
-> one ();
// บันทึกผู้ป่วย
if ( ! empty ( $model -> patient_id ) && $patient_old ) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient_update = Patient :: findOne ( $model -> patient_id );
$patient_update -> gender = $patient -> gender ;
$patient_update -> nation = $patient -> nation ;
$patient_update -> birthdate = $patient -> birthdate ;
$patient_update -> age = $patient -> age ;
$patient_update -> age_unit = $patient -> age_unit ;
$patient_update -> hospital_id = $patient -> hospital_id ;
$patient_update -> h_n = $patient -> h_n ;
$patient_update -> id_card = $patient -> id_card ;
$patient_update -> save ( false );
$patient = $patient_update ;
} else {
$patient -> given_name = $model -> given_name ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> surname = $model -> surname ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> title_id = $model -> title_id ;
$patient -> gender = $model -> gender ;
$patient -> nation = $model -> nation ;
$patient -> birthdate = $model -> birthdate ;
$patient -> age = $model -> age ;
$patient -> age_unit = $model -> age_unit ;
$patient -> h_n = $model -> h_n ;
$patient -> id_card = $model -> id_card ;
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
$patient -> hospital_id = $model -> hospital_id ;
if ( $patient -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'เพิ่ม/แก้ไขข้อมูลผู้ป่วยแล้ว' );
} else {
Yii :: $app -> session -> setFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . $patient -> given_name );
var_dump ( $patient -> getFirstErrors ());
die ();
}
}
// ได้ $patient->id ล่ะ
/**
* บันทึก CASE PAP
*/
$model -> patient_id = $patient -> id ;
$model -> status_id = 1 ;
$model -> files = $model -> uploadFile ( $model , 'files' );
//Upload Outlab Report
if ( $model -> is_outlab ) {
$outlab_at = date ( 'Y-m-d H:i:s' );
$model -> status_id = 17 ;
$pap_diagnosis = CytoPapDiagnosis :: findOne ([ 'id_case' => $model -> id_case , 'report_type' => 'outlab' ]);
if ( ! $pap_diagnosis ) {
$pap_diagnosis = new CytoPapDiagnosis ();
$pap_diagnosis -> id_case = $model -> id_case ;
$pap_diagnosis -> report_type = 'outlab' ;
$pap_diagnosis -> status_id = 11 ;
$pap_diagnosis -> pathologist_at = $outlab_at ;
}
$pap_diagnosis -> id_case = $model -> id_case ;
$pap_diagnosis -> report_type = 'outlab' ;
$pap_diagnosis -> status_id = 11 ;
$pap_diagnosis -> pathologist_at = $outlab_at ;
if ( $pap_diagnosis -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Upload' , 'อัพโหลดไฟล์ Cyto Gyn Outlab: ' . $model -> id_case , Yii :: $app -> user -> getId (), CytoPapDiagnosis :: tableName ());
//@Yii::$app->runAction('/register/hl7/result', ['id_case' => $pap_diagnosis->id_case, 'report_type' => $pap_diagnosis->report_type, 'diagnosis_id' => $pap_diagnosis->id]);
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
2025-03-22 10:58:33 +00:00
//var_dump($pap_diagnosis->getFirstErrors());
//die();
2024-12-25 03:04:59 +00:00
}
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = date ( 'Y-m-d H:i:s' );
$model -> receive_at = date ( 'Y-m-d H:i:s' );
if ( $model -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Create' , 'ลงทะเบียน Case Pap: ' . $model -> id_case , Yii :: $app -> user -> getId (), CasePap :: tableName ());
Yii :: $app -> session -> addFlash ( 'success' , 'บันทึกข้อมูล PAP เรียบร้อย' );
//หากไม่มี HN ให้ Request จาก HIS
if ( empty ( $model -> h_n )) {
Yii :: $app -> pathology -> requestHisHn ( $model -> id_case );
}
} else {
var_dump ( $model -> getFirstErrors ());
die ();
}
$transaction -> commit ();
Yii :: $app -> session -> addFlash ( 'success' , 'ลงทะเบียน PAP เรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/pap' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
throw new Exception ( $e -> getMessage ());
}
} // if post()
return $this -> render ( 'pap' , [
'model' => $model ,
]);
}
/*
* ลงทะเบียน CASE Surgical
*/
public function actionSurgical ()
{
$model = new CaseSurgical ();
$time_now = date ( 'Y-m-d H:i:s' );
$model -> id_case = $this -> getIdCase ( 'S' ); // ค้นหารหัสต่อไป
$patient = new Patient ();
$model -> nation = 'ไทย' ;
$model -> age_unit = 'ปี' ;
$model -> receive_at = empty ( $model -> receive_at ) ? date ( 'd/m/Y' ) : $model -> receive_at ;
Yii :: $app -> session -> setFlash ( 'info' , 'ลงทะเบียนงานศัลยพยาธิ หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$result = ActiveForm :: validate ( $model );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
/** echo '<pre>' ;
* var_dump ( $model );
* var_dump ( $patient );
* echo '</pre>' ;
* die (); */
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
$patient_old = Patient :: find ()
-> filterWhere ([ 'given_name' => $patient -> given_name ])
-> one ();
// บันทึกผู้ป่วย
if ( ! empty ( $model -> patient_id ) && $patient_old ) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient_update = Patient :: findOne ( $model -> patient_id );
$patient_update -> gender = $patient -> gender ;
$patient_update -> nation = $patient -> nation ;
$patient_update -> birthdate = $patient -> birthdate ;
$patient_update -> age = $patient -> age ;
$patient_update -> age_unit = $patient -> age_unit ;
$patient_update -> hospital_id = $patient -> hospital_id ;
$patient_update -> h_n = $patient -> h_n ;
$patient_update -> id_card = $patient -> id_card ;
$patient_update -> save ();
$patient = $patient_update ;
} else {
$patient -> given_name = $model -> given_name ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> surname = $model -> surname ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> title_id = $model -> title_id ;
$patient -> gender = $model -> gender ;
$patient -> nation = $model -> nation ;
$patient -> birthdate = $model -> birthdate ;
$patient -> age = $model -> age ;
$patient -> age_unit = $model -> age_unit ;
$patient -> hospital_id = $model -> hospital_id ;
$patient -> h_n = $model -> h_n ;
$patient -> id_card = $model -> id_card ;
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
if ( $patient -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'เพิ่ม/แก้ไขข้อมูลผู้ป่วยแล้ว' );
} else {
Yii :: $app -> session -> setFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . $patient -> given_name );
}
}
$model -> patient_id = $patient -> id ; // นำ ID ผู้ป่วยมากำหนดใน patient_id ใหม่
$model -> status_id = 1 ;
// ตรวจสอบก่อนว่าต้องเก็บข้อมูลเก่าไว้ไหม
//$model->hospital_id = $patient->hospital_id; // กำหนดโรงพยาบาลให้ CaseSurgical ด้วย
//แก้ไขให้ hospital อยู่ใน CaseSurgical แล้ว
//อัพโหลดภาพ Specimen Container
$model -> specimen_container_img = $model -> uploadSpecimenContainer ( $model , 'specimen_container_img' );
//อัพโหลดไฟล์ Request
$model -> files = $model -> uploadFile ( $model , 'files' );
//if case reference
if ( ! empty ( $model -> case_reference )) {
$case_reference = CaseSurgical :: findOne ([ 'id_case' => $model -> case_reference ]);
if ( $case_reference ) {
$model -> gross_description = $case_reference -> gross_description ;
$model -> microscopic_description = $case_reference -> microscopic_description ;
$model -> diagnosis = $case_reference -> diagnosis ;
$model -> additional_diagnosis = $case_reference -> additional_diagnosis ;
}
}
//Upload Outlab Report
/* if ( $model -> is_outlab ) {
$outlab_at = date ( 'Y-m-d H:i:s' );
$model -> status_id = 7 ;
$surgical_diagnosis = SurgicalDiagnosis :: findOne ([ 'id_case' => $model -> id_case , 'report_type' => 'outlab' ]);
if ( ! $surgical_diagnosis ) {
$surgical_diagnosis = new SurgicalDiagnosis ();
$surgical_diagnosis -> id_case = $model -> id_case ;
$surgical_diagnosis -> report_type = 'outlab' ;
//$surgical_diagnosis->status_id = 1;
//$surgical_diagnosis->pathologist_at = $outlab_at;
}
if ( $surgical_diagnosis -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
var_dump ( $surgical_diagnosis -> getFirstErrors ());
die ();
}
} */
2025-05-07 04:30:40 +00:00
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
2024-12-25 03:04:59 +00:00
//Upload Outlab Report
if ( $model -> is_outlab ) {
2025-05-07 04:30:40 +00:00
//$outlab_at = date('Y-m-d H:i:s');
$model -> status_id = 7 ;
2024-12-25 03:04:59 +00:00
$surgical_diagnosis = SurgicalDiagnosis :: findOne ([ 'id_case' => $model -> id_case , 'report_type' => 'outlab' ]);
if ( ! $surgical_diagnosis ) {
$surgical_diagnosis = new SurgicalDiagnosis ();
$surgical_diagnosis -> id_case = $model -> id_case ;
$surgical_diagnosis -> report_type = 'outlab' ;
2025-05-07 04:30:40 +00:00
$surgical_diagnosis -> status_id = 3 ;
//$surgical_diagnosis->pathologist_at = $outlab_at;
2024-12-25 03:04:59 +00:00
}
$surgical_diagnosis -> id_case = $model -> id_case ;
$surgical_diagnosis -> report_type = 'outlab' ;
2025-05-07 04:30:40 +00:00
$surgical_diagnosis -> status_id = 3 ;
//$surgical_diagnosis->pathologist_at = $outlab_at;
$surgical_diagnosis -> outlab_report = $model -> outlab_report ;
2024-12-25 03:04:59 +00:00
if ( $surgical_diagnosis -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Upload' , 'อัพโหลดไฟล์ Surgical Outlab: ' . $model -> id_case , Yii :: $app -> user -> getId (), SurgicalDiagnosis :: tableName ());
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
2025-03-22 10:58:33 +00:00
//var_dump($surgical_diagnosis->getFirstErrors());
//die();
2024-12-25 03:04:59 +00:00
}
}
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = date ( 'Y-m-d H:i:s' );
$model -> receive_at = $time_now ;
if ( $model -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Create' , 'ลงทะเบียน Case Surgical: ' . $model -> id_case , Yii :: $app -> user -> getId (), CaseSurgical :: tableName ());
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึกข้อมูลเรียบร้อยแล้ว' );
//หากไม่มี HN ให้ Request จาก HIS
if ( empty ( $model -> h_n )) {
Yii :: $app -> pathology -> requestHisHn ( $model -> id_case );
}
}
$transaction -> commit ();
// set flash and redirect
Yii :: $app -> session -> setFlash ( 'success' , 'ลงทะเบียน Surgical เรียบร้อยแล้ว' );
return $this -> redirect ([
'/register/case-update/surgical' ,
'id_case' => $model -> id_case
]);
} catch ( Exception $e ) {
var_dump ( $e -> getMessage ());
die ();
$transaction -> rollBack ();
throw new Exception ( $e -> getMessage ());
}
}
return $this -> render ( 'surgical' , [
'model' => $model ,
]);
}
2025-03-31 02:48:37 +00:00
/*
* ลงทะเบียน Immuno External ( EX )
*/
2025-04-20 15:44:51 +00:00
2025-03-31 02:48:37 +00:00
public function actionExternal ()
{
$model = new CaseExternal ();
2025-04-20 15:44:51 +00:00
$time_now = date ( 'Y-m-d H:i:s' );
2025-03-31 15:51:06 +00:00
$model -> id_case = $this -> getIdCase ( 'N' ); // ค้นหารหัสต่อไป
2025-03-31 02:48:37 +00:00
$patient = new Patient ();
2025-04-20 15:44:51 +00:00
$model -> nation = 'ไทย' ;
$model -> age_unit = 'ปี' ;
$model -> is_immuno_staining = 1 ;
2025-03-31 02:48:37 +00:00
2025-04-20 15:44:51 +00:00
Yii :: $app -> session -> setFlash ( 'info' , 'ลงทะเบียน External หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
2025-03-31 15:51:06 +00:00
2025-03-31 02:48:37 +00:00
$request = Yii :: $app -> getRequest ();
2025-04-20 15:44:51 +00:00
2025-03-31 02:48:37 +00:00
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$result = ActiveForm :: validate ( $model );
return $result ;
}
2025-04-20 15:44:51 +00:00
2025-03-31 02:48:37 +00:00
if ( $model -> load ( Yii :: $app -> request -> post ())) {
2025-04-20 15:44:51 +00:00
/** echo '<pre>' ;
* var_dump ( $model );
* var_dump ( $patient );
* echo '</pre>' ;
* die (); */
2025-03-31 02:48:37 +00:00
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
2025-04-20 15:44:51 +00:00
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
$patient_old = Patient :: find ()
-> filterWhere ([ 'given_name' => $patient -> given_name ])
-> one ();
// บันทึกผู้ป่วย
if ( ! empty ( $model -> patient_id ) && $patient_old ) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient_update = Patient :: findOne ( $model -> patient_id );
$patient_update -> gender = $patient -> gender ;
$patient_update -> nation = $patient -> nation ;
$patient_update -> birthdate = $patient -> birthdate ;
$patient_update -> age = $patient -> age ;
$patient_update -> age_unit = $patient -> age_unit ;
$patient_update -> hospital_id = $patient -> hospital_id ;
$patient_update -> h_n = $patient -> h_n ;
$patient_update -> id_card = $patient -> id_card ;
$patient_update -> save ();
$patient = $patient_update ;
} else {
2025-03-31 02:48:37 +00:00
2025-04-20 15:44:51 +00:00
$patient -> given_name = $model -> given_name ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> surname = $model -> surname ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> title_id = $model -> title_id ;
$patient -> gender = $model -> gender ;
$patient -> nation = $model -> nation ;
$patient -> birthdate = $model -> birthdate ;
$patient -> age = $model -> age ;
$patient -> age_unit = $model -> age_unit ;
$patient -> hospital_id = $model -> hospital_id ;
$patient -> h_n = $model -> h_n ;
$patient -> id_card = $model -> id_card ;
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
2025-03-31 02:48:37 +00:00
}
2025-04-20 15:44:51 +00:00
if ( $patient -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'เพิ่ม/แก้ไขข้อมูลผู้ป่วยแล้ว' );
} else {
Yii :: $app -> session -> setFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . $patient -> given_name );
2025-03-31 02:48:37 +00:00
}
2025-04-20 15:44:51 +00:00
}
$model -> patient_id = $patient -> id ; // นำ ID ผู้ป่วยมากำหนดใน patient_id ใหม่
$model -> status_id = 1 ;
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = date ( 'Y-m-d H:i:s' );
if ( $model -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Create' , 'ลงทะเบียน Case External: ' . $model -> id_case , Yii :: $app -> user -> getId (), CaseExternal :: tableName ());
2025-03-31 02:48:37 +00:00
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึกข้อมูลเรียบร้อยแล้ว' );
}
2025-04-20 15:44:51 +00:00
$transaction -> commit ();
// set flash and redirect
Yii :: $app -> session -> setFlash ( 'success' , 'ลงทะเบียน External เรียบร้อยแล้ว' );
return $this -> redirect ([
'/register/case-update/external' ,
'id_case' => $model -> id_case
]);
2025-03-31 02:48:37 +00:00
} catch ( Exception $e ) {
2025-04-20 15:44:51 +00:00
var_dump ( $e -> getMessage ());
die ();
2025-03-31 02:48:37 +00:00
$transaction -> rollBack ();
2025-04-20 15:44:51 +00:00
throw new Exception ( $e -> getMessage ());
2025-03-31 02:48:37 +00:00
}
}
return $this -> render ( 'external' , [
'model' => $model ,
]);
}
2024-12-25 03:04:59 +00:00
2025-04-20 15:44:51 +00:00
2024-12-25 03:04:59 +00:00
/**
* @ param $case
* @ return string
*/
protected function getIdCase ( $case )
{
2025-03-29 03:10:24 +00:00
//$year = substr(date('Y'), 2); // ปี ค.ศ. ปัจจุบัน
2024-12-25 03:04:59 +00:00
2025-03-29 03:10:24 +00:00
$year = substr ( date ( 'Y' ) + 543 , 2 );
2025-03-31 02:48:37 +00:00
2024-12-25 03:04:59 +00:00
if ( $case == 'S' ) {
$lastRecord = CaseSurgical :: find () -> where ([ 'like' , 'id_case' , 'S' . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ])
-> one ();
}
if ( $case == 'C' ) {
$lastRecord = CaseNonGyn :: find () -> where ([ 'like' , 'id_case' , 'C' . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
}
if ( $case == 'G' ) {
2025-03-21 07:44:59 +00:00
$lastRecord = CasePap :: find () -> where ([ 'like' , 'id_case' , 'G' . $year . '-' ])
2024-12-25 03:04:59 +00:00
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
}
2024-12-27 09:24:36 +00:00
if ( $case == 'F' ) {
$lastRecord = CaseFrozen :: find () -> where ([ 'like' , 'id_case' , 'F' . $year . '-' ])
2024-12-25 03:04:59 +00:00
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
}
2025-03-21 07:44:59 +00:00
if ( $case == 'X' ) {
$lastRecord = CaseFrozen :: find () -> where ([ 'like' , 'id_case' , 'X' . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
}
2024-12-25 03:04:59 +00:00
if ( $case == 'M' ) {
$lastRecord = CaseMolecular :: find () -> where ([ 'like' , 'id_case' , 'M' . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
}
2025-03-21 07:44:59 +00:00
if ( $case == 'E' ) {
2024-12-25 03:04:59 +00:00
$lastRecord = CaseFlow :: find () -> where ([ 'like' , 'id_case' , 'F' . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
}
if ( $case == 'I' ) {
$lastRecord = CaseFish :: find () -> where ([ 'like' , 'id_case' , 'I' . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
}
if ( $case == 'D' ) {
$lastRecord = CaseDish :: find () -> where ([ 'like' , 'id_case' , 'D' . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
}
if ( $case == 'A' ) {
$lastRecord = CaseAutopsy :: find () -> where ([ 'like' , 'id_case' , 'A' . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
}
if ( $case == 'N' ) {
$lastRecord = CaseNecropsy :: find () -> where ([ 'like' , 'id_case' , 'N' . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
}
if ( $case == 'H' ) {
$lastRecord = CaseHpv :: find () -> where ([ 'like' , 'id_case' , 'H' . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
}
2025-03-31 15:51:06 +00:00
if ( $case == 'N' ) {
$lastRecord = CaseExternal :: find () -> where ([ 'like' , 'id_case' , 'N' . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
}
2024-12-25 03:04:59 +00:00
if ( $lastRecord ) {
$digit = explode ( '-' , $lastRecord -> id_case );
$lastDigit = (( int ) $digit [ 1 ]); // change string to integer for +1
$lastDigit ++ ;
$lastDigit = str_pad ( $lastDigit , Yii :: $app -> params [ 'digitCase' ], '0' , STR_PAD_LEFT );
/* $digitLength = Yii :: $app -> params [ 'digitCase' ] ? ? 5 ; // Use 5 as default if digitCase is not set
$lastDigit = str_pad ( $lastDigit , $digitLength , '0' , STR_PAD_LEFT ); */
} else {
$lastDigit = '00001' ;
}
return $case . $year . '-' . $lastDigit ;
}
/**
* @ return array | mixed | null
*/
public function actionGetPapCase ()
{
Yii :: $app -> response -> format = Response :: FORMAT_RAW ;
$this -> enableCsrfValidation = false ;
$case = Yii :: $app -> request -> post ( 'case' );
$year = substr ( date ( 'Y' ), 2 );
//'EP' => 'EP - Pap:Excel', 'RP' => 'RP - Pap:Routine', 'TP' => 'TP - Thinprep', 'NP' => 'NP - Novaprep', 'CP' => 'CP - Clear Prep', 'PT' => 'PT - Path tezt', 'LP' => 'LP - Liquid based'
$lastRecord = CasePap :: find () -> where ([ 'like' , 'id_case' , $case . $year . '-' ])
-> orderBy ([ 'id_case' => SORT_DESC ]) -> one ();
if ( $lastRecord ) {
$digit = explode ( '-' , $lastRecord -> id_case );
$lastDigit = (( int ) $digit [ 1 ]); // change string to integer for +1
$lastDigit ++ ;
$lastDigit = str_pad ( $lastDigit , 6 , '0' , STR_PAD_LEFT );
} else {
$lastDigit = '000001' ;
}
return $case . $year . '-' . $lastDigit ;
}
/*
* ค้นหาผู้ป่วยตามรหัส patient . id ที่ส่งมาจาก ajax
* @ return json
*/
public
function actionGetPatient ()
{
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$patient = null ;
$request = Yii :: $app -> request ;
if ( $request -> isPost && $request -> post ( 'pid' ) !== null ) {
// $patient = Patient::find()->select(['patient.*','const_hospital.name AS hospital_name'])->leftJoin('const_hospital', 'const_hospital.id = patient.hospital_id')->where(['patient.id' => 2436])->one();
$pt = Patient :: find () -> where ([
'patient.id' => $request -> post ( 'pid' )
])
-> one ();
$hs = $pt -> hospital ;
$patient = [
'id' => $pt -> id ,
'title_id' => $pt -> title_id ,
'given_name' => $pt -> given_name ,
'gender' => $pt -> gender ,
'nation' => $pt -> nation ,
'age' => $pt -> age ,
'age_unit' => $pt -> age_unit ,
'birthdate' => $pt -> birthdate ,
'h_n' => $pt -> h_n ,
'hospital_id' => $pt -> hospital_id ,
'hospital_name' => $hs -> name ,
'id_card' => $pt -> id_card
];
}
return $patient ;
}
/*
* หารายการ Test จาก StainingTest
* ในการสั่งย้อม Case Consult
*/
public function getTest ()
{
$test_histo = StainingTest :: find () -> where ( " lab = 'histo' " ) -> all ();
$test_immuno = StainingTest :: find () -> where ( " lab = 'immuno' " ) -> all ();
return [
'arr_test_histo' => $test_histo ,
'arr_test_immuno' => $test_immuno
];
}
public function actionSurgicalTmp ()
{
foreach ( CaseSurgical :: find () -> all () as $case ) {
$surgical = SurgicalOperate :: findOne ([ 'id_case' => $case -> id_case ]);
if ( ! $surgical ) {
$surgical = new SurgicalOperate ();
$surgical -> id_case = $case -> id_case ;
$surgical -> register_at = '01/02/2563 17:45:00' ;
$surgical -> save ( false );
}
}
}
/**
* ลงทะเบียน Molecular
* @ return \yii\web\Response | string
*/
public function actionMolecular ()
{
$model = new CaseMolecular (); //['scenario' => 'register']
//$operate = new CytoOperate();
$model -> id_case = $this -> getIdCase ( 'M' );
//$model->no_slide = "1";
//$finance = new FinanceServiceCharge();
$patient = new Patient ();
$model -> nation = 'ไทย' ;
$model -> age_unit = 'ปี' ;
Yii :: $app -> session -> setFlash ( 'info' , 'ลงทะเบียนงาน Molecular หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
//$operate->register_at = $time_now;
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
//$patient->load(Yii::$app->request->post());
//$finance->load(Yii::$app->request->post());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$result = ActiveForm :: validate ( $model /*, $finance*/ );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())
//&& $patient->load(Yii::$app->request->post())
//&& $finance->load(Yii::$app->request->post())
) //$operate->load(Yii::$app->request->post())) {
{
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
$patient_old = Patient :: find ()
-> filterWhere ([ 'given_name' => $patient -> given_name ])
-> one ();
// บันทึกผู้ป่วย
if ( ! empty ( $model -> patient_id ) && $patient_old ) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient_update = Patient :: findOne ( $model -> patient_id );
$patient_update -> gender = $patient -> gender ;
$patient_update -> nation = $patient -> nation ;
$patient_update -> birthdate = $patient -> birthdate ;
$patient_update -> age = $patient -> age ;
$patient_update -> age_unit = $patient -> age_unit ;
$patient_update -> hospital_id = $patient -> hospital_id ;
$patient_update -> h_n = $patient -> h_n ;
$patient_update -> id_card = $patient -> id_card ;
$patient_update -> save ( false );
$patient = $patient_update ;
} else {
$patient -> given_name = $model -> given_name ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> surname = $model -> surname ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> title_id = $model -> title_id ;
$patient -> gender = $model -> gender ;
$patient -> nation = $model -> nation ;
$patient -> birthdate = $model -> birthdate ;
$patient -> age = $model -> age ;
$patient -> age_unit = $model -> age_unit ;
$patient -> hospital_id = $model -> hospital_id ;
$patient -> h_n = $model -> h_n ;
$patient -> id_card = $model -> id_card ;
//$patient->name = $model->autocomplete_patient; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
//$patient->hospital_id = $model->hospital_id;
if ( $patient -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'เพิ่ม/แก้ไขข้อมูลผู้ป่วยแล้ว' );
} else {
Yii :: $app -> session -> setFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . $patient -> given_name );
}
}
// ได้ $patient->id ล่ะ
/*
* บันทึก CASE NonGyn
*/
$model -> patient_id = $patient -> id ;
$model -> status_id = 1 ;
$model -> pathologist_id = 1 ;
//ตรวจสอบ Side of Specimen ถ้ามีการเพิ่มใหม่ให้บันทึก Side of Specimen ใหม่
if ( ! empty ( $model -> cyto_side_of_specimen ) && empty ( $model -> side_of_specimen )) {
$specimen = new CytoSideOfSpecimen ();
$specimen -> name = $model -> cyto_side_of_specimen ;
$specimen -> save ();
$model -> side_of_specimen = $specimen -> id ;
}
############# Next IdCase Again ##############
//$model->id_case = $this->getIdCase('FN'); // ค้นหารหัสต่อไป
$model -> files = $model -> uploadFile ( $model , 'files' );
$model -> specimen_img = $model -> uploadGross ( $model , 'specimen_img' );
if ( ! empty ( $model -> specimen_img )) {
$model -> specimen_img_at = date ( 'Y-m-d H:i:s' );
$model -> specimen_img_update_id = Yii :: $app -> user -> getId ();
}
//Upload Outlab Report
if ( $model -> is_outlab ) {
$outlab_at = date ( 'Y-m-d H:i:s' );
$model -> status_id = 7 ;
$molecular_diagnosis = MolecularDiagnosis :: findOne ([ 'id_case' => $model -> id_case , 'report_type' => 'outlab' ]);
if ( ! $molecular_diagnosis ) {
$molecular_diagnosis = new MolecularDiagnosis ();
$molecular_diagnosis -> id_case = $model -> id_case ;
$molecular_diagnosis -> report_type = 'outlab' ;
//$molecular_diagnosis->status_id = 1;
//$surgical_diagnosis->pathologist_at = $outlab_at;
}
if ( $molecular_diagnosis -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
var_dump ( $molecular_diagnosis -> getFirstErrors ());
die ();
}
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = date ( 'Y-m-d H:i:s' );
$model -> receive_at = date ( 'Y-m-d H:i:s' );
if ( $model -> save ()) {
//บันทึกข้อมูลการ Operate Case นี้ (ลงทะเบียน)
//$operate->id_case = $model->id_case;
//$operate->register_id = Yii::$app->user->getId();
//$operate->screener_id = 1;
//$operate->stain_id = 1;
//$operate->qa_id = 1;
//$operate->save(); //บันทึกการ Operate Case NonGyn
/*
* บันทึกค่าตรวจ NonGyn
*/
$hospital = ConstHospital :: findOne ( $model -> hospital_id );
/* $finance -> id_case = $model -> id_case ;
$finance -> hospital_id = $model -> hospital_id ;
$finance -> price = Yii :: $app -> pathology -> getHosPrice ( $model -> hospital_id , $finance -> charge_id );
$finance -> df = Yii :: $app -> pathology -> getHosDF ( $model -> hospital_id , $finance -> charge_id );
$finance -> occur_at = $time_now ;
$finance -> is_cash = 0 ;
$finance -> is_able = 0 ; //คิดเงิน
if ( $finance -> save ()) {
} else {
var_dump ( $finance -> getFirstErrors ());
die ();
} */
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึกข้อมูลเรียบร้อยแล้ว' );
}
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลงทะเบียน Molecular เรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/molecular' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
throw new Exception ( $e -> getMessage ());
}
} // if post()
return $this -> render ( 'molecular' , [
'model' => $model ,
//'finance' => $finance,
//'patient' => $patient,
//'operate' => $operate,
]);
}
/**
* ลงทะเบียน Necropsy
* @ return \yii\web\Response | string
*/
public function actionNecropsy ()
{
$model = new CaseNecropsy (); //['scenario' => 'register']
//$operate = new CytoOperate();
$model -> id_case = $this -> getIdCase ( 'N' );
//$model->no_slide = "1";
//$finance = new FinanceServiceCharge();
$patient = new Patient ();
$model -> nation = 'ไทย' ;
$model -> age_unit = 'ปี' ;
Yii :: $app -> session -> setFlash ( 'info' , 'ลงทะเบียนงาน Necropsy หมายเลข Case : ' . $model -> id_case . ' กรอกแบบฟอร์มได้เลยค่ะ' );
//$operate->register_at = $time_now;
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
//$patient->load(Yii::$app->request->post());
//$finance->load(Yii::$app->request->post());
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$result = ActiveForm :: validate ( $model /*, $finance*/ );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())
//$patient->load(Yii::$app->request->post())
//&& $finance->load(Yii::$app->request->post())
) //$operate->load(Yii::$app->request->post())) {
{
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
// ตรวจสอบก่อนว่าเป็นผู้ป่วยเดิมหรือเพิ่มใหม่
$patient_old = Patient :: find ()
-> filterWhere ([ 'given_name' => $patient -> given_name ])
-> one ();
// บันทึกผู้ป่วย
if ( ! empty ( $model -> patient_id ) && $patient_old ) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient_update = Patient :: findOne ( $model -> patient_id );
$patient_update -> gender = $patient -> gender ;
$patient_update -> nation = $patient -> nation ;
$patient_update -> birthdate = $patient -> birthdate ;
$patient_update -> age = $patient -> age ;
$patient_update -> age_unit = $patient -> age_unit ;
$patient_update -> hospital_id = $patient -> hospital_id ;
$patient_update -> h_n = $patient -> h_n ;
$patient_update -> id_card = $patient -> id_card ;
$patient_update -> save ( false );
$patient = $patient_update ;
} else {
$patient -> given_name = $model -> given_name ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> surname = $model -> surname ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก'
$patient -> title_id = $model -> title_id ;
$patient -> gender = $model -> gender ;
$patient -> nation = $model -> nation ;
$patient -> birthdate = $model -> birthdate ;
$patient -> age = $model -> age ;
$patient -> age_unit = $model -> age_unit ;
$patient -> hospital_id = $model -> hospital_id ;
$patient -> h_n = $model -> h_n ;
$patient -> id_card = $model -> id_card ;
//$patient->name = $model->autocomplete_patient; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
//$patient->hospital_id = $model->hospital_id;
if ( $patient -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'เพิ่ม/แก้ไขข้อมูลผู้ป่วยแล้ว' );
} else {
//var_dump($patient->getFirstErrors());
//die();
Yii :: $app -> session -> setFlash ( 'error' , 'เพิ่มผู้ป่วยไม่ได้' . $patient -> given_name );
}
}
// ได้ $patient->id ล่ะ
/*
* บันทึก CASE Necropsy
*/
$model -> patient_id = $patient -> id ;
$model -> status_id = 1 ;
$model -> pathologist_id = 1 ;
//ตรวจสอบ Side of Specimen ถ้ามีการเพิ่มใหม่ให้บันทึก Side of Specimen ใหม่
/* if ( ! empty ( $model -> cyto_side_of_specimen ) && empty ( $model -> side_of_specimen )) {
$specimen = new CytoSideOfSpecimen ();
$specimen -> name = $model -> cyto_side_of_specimen ;
$specimen -> save ();
$model -> side_of_specimen = $specimen -> id ;
} */
############# Next IdCase Again ##############
//$model->id_case = $this->getIdCase('FN'); // ค้นหารหัสต่อไป
$model -> files = $model -> uploadFile ( $model , 'files' );
//Upload Outlab Report
if ( $model -> is_outlab ) {
$outlab_at = date ( 'Y-m-d H:i:s' );
$model -> status_id = 7 ;
$necropsy_diagnosis = NecropsyDiagnosis :: findOne ([ 'id_case' => $model -> id_case , 'report_type' => 'outlab' ]);
if ( ! $necropsy_diagnosis ) {
$necropsy_diagnosis = new NecropsyDiagnosis ();
$necropsy_diagnosis -> id_case = $model -> id_case ;
$necropsy_diagnosis -> report_type = 'outlab' ;
//$necropsy_diagnosis->status_id = 1;
//$surgical_diagnosis->pathologist_at = $outlab_at;
}
if ( $necropsy_diagnosis -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
var_dump ( $necropsy_diagnosis -> getFirstErrors ());
die ();
}
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
$model -> register_id = Yii :: $app -> user -> getId ();
$model -> register_at = date ( 'Y-m-d H:i:s' );
$model -> receive_at = date ( 'Y-m-d H:i:s' );
if ( $model -> save ()) {
//บันทึกข้อมูลการ Operate Case นี้ (ลงทะเบียน)
//$operate->id_case = $model->id_case;
//$operate->register_id = Yii::$app->user->getId();
//$operate->screener_id = 1;
//$operate->stain_id = 1;
//$operate->qa_id = 1;
//$operate->save(); //บันทึกการ Operate Case NonGyn
/*
* บันทึกค่าตรวจ NonGyn
*/
$hospital = ConstHospital :: findOne ( $model -> hospital_id );
/* $finance -> id_case = $model -> id_case ;
$finance -> hospital_id = $model -> hospital_id ;
$finance -> price = Yii :: $app -> pathology -> getHosPrice ( $model -> hospital_id , $finance -> charge_id );
$finance -> df = Yii :: $app -> pathology -> getHosDF ( $model -> hospital_id , $finance -> charge_id );
$finance -> occur_at = $time_now ;
$finance -> is_cash = 0 ;
$finance -> is_able = 0 ; //คิดเงิน
if ( $finance -> save ()) {
} else {
var_dump ( $finance -> getFirstErrors ());
die ();
} */
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึกข้อมูลเรียบร้อยแล้ว' );
}
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลงทะเบียน Necropsy เรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/necropsy' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
throw new Exception ( $e -> getMessage ());
}
} // if post()
return $this -> render ( 'necropsy' , [
'model' => $model ,
]);
}
public function actionOutlabProcess ( $id_case )
{
$case = Yii :: $app -> pathology -> getCase ( $id_case );
$case_type = Yii :: $app -> pathology -> getCaseType ( $id_case );
if ( $case_type == 'surgical' ) {
$case_surgical = CaseSurgical :: findOne ([
'id_case' => $id_case ,
]);
if ( ! $case_surgical ) {
throw new NotFoundHttpException ( 'ไม่พบ Case นี้ในระบบ' );
}
$model = SurgicalDiagnosis :: find ()
-> where ([
'id_case' => $id_case ,
'report_type' => 'outlab' ,
])
-> andWhere ([ '<' , 'status_id' , 4 ])
-> one ();
if ( ! isset ( $model )) {
$model = new SurgicalDiagnosis ();
$model -> id_case = $id_case ;
$model -> report_type = 'outlab' ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$outlab_at = date ( 'Y-m-d H:i:s' );;
if ( $case -> process_site_id != Yii :: $app -> user -> identity -> site_id ) {
$model -> status_id = 1 ;
} else {
$model -> status_id = 17 ;
$model -> outlab_by = Yii :: $app -> user -> identity -> getId ();
$model -> pathologist_at = $outlab_at ;
$model -> outlab_at = $outlab_at ;
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
if ( $model -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
}
return $this -> redirect ([ 'outlab-process' , 'id_case' => $case -> id_case ]);
}
} //Surgical Outlab
//NonGyn Outlab
if ( $case_type == 'non-gyn' ) {
$case_non_gyn = CaseNonGyn :: findOne ([
'id_case' => $id_case ,
]);
if ( ! $case_non_gyn ) {
throw new NotFoundHttpException ( 'ไม่พบ Case นี้ในระบบ' );
}
$model = CytoNonGynDiagnosis :: find ()
-> where ([
'id_case' => $id_case ,
'report_type' => 'outlab' ,
])
-> andWhere ([ '<' , 'status_id' , 4 ])
-> one ();
if ( ! isset ( $model )) {
$model = new CytoNonGynDiagnosis ();
$model -> id_case = $id_case ;
$model -> report_type = 'outlab' ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$outlab_at = date ( 'Y-m-d H:i:s' );;
if ( $case -> process_site_id != Yii :: $app -> user -> identity -> site_id ) {
$model -> status_id = 1 ;
} else {
$model -> status_id = 17 ;
$model -> outlab_by = Yii :: $app -> user -> identity -> getId ();
$model -> pathologist_at = $outlab_at ;
$model -> outlab_at = $outlab_at ;
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
if ( $model -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
}
return $this -> redirect ([ 'outlab-process' , 'id_case' => $case -> id_case ]);
}
} //Non-Gyn Outlab END
//PAP Outlab START
if ( $case_type == 'pap' ) {
$case_pap = CasePap :: findOne ([
'id_case' => $id_case ,
]);
if ( ! $case_pap ) {
throw new NotFoundHttpException ( 'ไม่พบ Case นี้ในระบบ' );
}
$model = CytoPapDiagnosis :: find ()
-> where ([
'id_case' => $id_case ,
'report_type' => 'outlab' ,
])
-> andWhere ([ '<' , 'status_id' , 4 ])
-> one ();
if ( ! isset ( $model )) {
$model = new CytoPapDiagnosis ();
$model -> id_case = $id_case ;
$model -> report_type = 'outlab' ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$outlab_at = date ( 'Y-m-d H:i:s' );;
if ( $case -> process_site_id != Yii :: $app -> user -> identity -> site_id ) {
$model -> status_id = 1 ;
} else {
$model -> status_id = 17 ;
$model -> outlab_by = Yii :: $app -> user -> identity -> getId ();
$model -> pathologist_at = $outlab_at ;
$model -> outlab_at = $outlab_at ;
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
$model -> is_critical = 2 ;
if ( $model -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
return $this -> redirect ([ 'outlab-process' , 'id_case' => $case -> id_case ]);
}
}
} //Pap OutLab END
//Autopsy OutLab START
if ( $case_type == 'autopsy' ) {
2025-03-22 09:22:12 +00:00
$case_atuopsy = CaseAutopsy :: findOne ([
2024-12-25 03:04:59 +00:00
'id_case' => $id_case ,
]);
if ( ! $case_atuopsy ) {
throw new NotFoundHttpException ( 'ไม่พบ Case นี้ในระบบ' );
}
$model = AutopsyDiagnosis :: find ()
-> where ([
'id_case' => $id_case ,
'report_type' => 'outlab' ,
])
-> andWhere ([ '<' , 'status_id' , 4 ])
-> one ();
if ( ! isset ( $model )) {
$model = new AutopsyDiagnosis ();
$model -> id_case = $id_case ;
$model -> report_type = 'outlab' ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$outlab_at = date ( 'Y-m-d H:i:s' );;
if ( $case -> process_site_id != Yii :: $app -> user -> identity -> site_id ) {
$model -> status_id = 1 ;
} else {
$model -> status_id = 17 ;
$model -> outlab_by = Yii :: $app -> user -> identity -> getId ();
$model -> pathologist_at = $outlab_at ;
$model -> outlab_at = $outlab_at ;
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
$model -> is_critical = 2 ;
if ( $model -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
return $this -> redirect ([ 'outlab-process' , 'id_case' => $case -> id_case ]);
}
}
} //Autopsy END
//DISH OutLab START
if ( $case_type == 'dish' ) {
$case_dish = CaseDish :: findOne ([
'id_case' => $id_case ,
]);
if ( ! $case_dish ) {
throw new NotFoundHttpException ( 'ไม่พบ Case นี้ในระบบ' );
}
$model = DishDiagnosis :: find ()
-> where ([
'id_case' => $id_case ,
'report_type' => 'outlab' ,
])
-> andWhere ([ '<' , 'status_id' , 4 ])
-> one ();
if ( ! isset ( $model )) {
$model = new DishDiagnosis ();
$model -> id_case = $id_case ;
$model -> report_type = 'outlab' ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$outlab_at = date ( 'Y-m-d H:i:s' );;
if ( $case -> process_site_id != Yii :: $app -> user -> identity -> site_id ) {
$model -> status_id = 1 ;
} else {
$model -> status_id = 17 ;
$model -> outlab_by = Yii :: $app -> user -> identity -> getId ();
$model -> pathologist_at = $outlab_at ;
$model -> outlab_at = $outlab_at ;
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
if ( $model -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
}
return $this -> redirect ([ 'outlab-process' , 'id_case' => $case -> id_case ]);
}
} //Dish END
//FISH Outlab START
if ( $case_type == 'fish' ) {
$case_fish = CaseFish :: findOne ([
'id_case' => $id_case ,
]);
if ( ! $case_fish ) {
throw new NotFoundHttpException ( 'ไม่พบ Case นี้ในระบบ' );
}
$model = FishDiagnosis :: find ()
-> where ([
'id_case' => $id_case ,
'report_type' => 'outlab' ,
])
-> andWhere ([ '<' , 'status_id' , 4 ])
-> one ();
if ( ! isset ( $model )) {
$model = new FishDiagnosis ();
$model -> id_case = $id_case ;
$model -> report_type = 'outlab' ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$outlab_at = date ( 'Y-m-d H:i:s' );;
if ( $case -> process_site_id != Yii :: $app -> user -> identity -> site_id ) {
$model -> status_id = 1 ;
} else {
$model -> status_id = 17 ;
$model -> outlab_by = Yii :: $app -> user -> identity -> getId ();
$model -> pathologist_at = $outlab_at ;
$model -> outlab_at = $outlab_at ;
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
if ( $model -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
}
return $this -> redirect ([ 'outlab-process' , 'id_case' => $case -> id_case ]);
}
} //Fish END
//Flow Outlab START
if ( $case_type == 'flow' ) {
$case_flow = CaseFlow :: findOne ([
'id_case' => $id_case ,
]);
if ( ! $case_flow ) {
throw new NotFoundHttpException ( 'ไม่พบ Case นี้ในระบบ' );
}
$model = FlowDiagnosis :: find ()
-> where ([
'id_case' => $id_case ,
'report_type' => 'outlab' ,
])
-> andWhere ([ '<' , 'status_id' , 4 ])
-> one ();
if ( ! isset ( $model )) {
$model = new FlowDiagnosis ();
$model -> id_case = $id_case ;
$model -> report_type = 'outlab' ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$outlab_at = date ( 'Y-m-d H:i:s' );;
if ( $case -> process_site_id != Yii :: $app -> user -> identity -> site_id ) {
$model -> status_id = 1 ;
} else {
$model -> status_id = 17 ;
$model -> outlab_by = Yii :: $app -> user -> identity -> getId ();
$model -> pathologist_at = $outlab_at ;
$model -> outlab_at = $outlab_at ;
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
if ( $model -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
}
return $this -> redirect ([ 'outlab-process' , 'id_case' => $case -> id_case ]);
}
} //Flow END
//Frozen Outlab START
if ( $case_type == 'frozen' ) {
$case_frozen = CaseFrozen :: findOne ([
'id_case' => $id_case ,
]);
if ( ! $case_frozen ) {
throw new NotFoundHttpException ( 'ไม่พบ Case นี้ในระบบ' );
}
$model = FrozenDiagnosis :: find ()
-> where ([
'id_case' => $id_case ,
'report_type' => 'outlab' ,
])
-> andWhere ([ '<' , 'status_id' , 4 ])
-> one ();
if ( ! isset ( $model )) {
$model = new FrozenDiagnosis ();
$model -> id_case = $id_case ;
$model -> report_type = 'outlab' ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$outlab_at = date ( 'Y-m-d H:i:s' );;
if ( $case -> process_site_id != Yii :: $app -> user -> identity -> site_id ) {
$model -> status_id = 1 ;
} else {
$model -> status_id = 17 ;
$model -> outlab_by = Yii :: $app -> user -> identity -> getId ();
$model -> pathologist_at = $outlab_at ;
$model -> outlab_at = $outlab_at ;
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
if ( $model -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
}
return $this -> redirect ([ 'outlab-process' , 'id_case' => $case -> id_case ]);
}
} //Frozen END
//Molecular Outlab START
if ( $case_type == 'molecular' ) {
$case_molecular = CaseMolecular :: findOne ([
'id_case' => $id_case ,
]);
if ( ! $case_molecular ) {
throw new NotFoundHttpException ( 'ไม่พบ Case นี้ในระบบ' );
}
$model = MolecularDiagnosis :: find ()
-> where ([
'id_case' => $id_case ,
'report_type' => 'outlab' ,
])
-> andWhere ([ '<' , 'status_id' , 4 ])
-> one ();
if ( ! isset ( $model )) {
$model = new MolecularDiagnosis ();
$model -> id_case = $id_case ;
$model -> report_type = 'outlab' ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$outlab_at = date ( 'Y-m-d H:i:s' );;
if ( $case -> process_site_id != Yii :: $app -> user -> identity -> site_id ) {
$model -> status_id = 1 ;
} else {
$model -> status_id = 17 ;
$model -> outlab_by = Yii :: $app -> user -> identity -> getId ();
$model -> pathologist_at = $outlab_at ;
$model -> outlab_at = $outlab_at ;
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
if ( $model -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
}
return $this -> redirect ([ 'outlab-process' , 'id_case' => $case -> id_case ]);
}
} //Molecular END
//Necropsy Outlab START
if ( $case_type == 'necropsy' ) {
$case_necropsy = CaseNecropsy :: findOne ([
'id_case' => $id_case ,
]);
if ( ! $case_necropsy ) {
throw new NotFoundHttpException ( 'ไม่พบ Case นี้ในระบบ' );
}
$model = NecropsyDiagnosis :: find ()
-> where ([
'id_case' => $id_case ,
'report_type' => 'outlab' ,
])
-> andWhere ([ '<' , 'status_id' , 4 ])
-> one ();
if ( ! isset ( $model )) {
$model = new NecropsyDiagnosis ();
$model -> id_case = $id_case ;
$model -> report_type = 'outlab' ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$outlab_at = date ( 'Y-m-d H:i:s' );;
if ( $case -> process_site_id != Yii :: $app -> user -> identity -> site_id ) {
$model -> status_id = 1 ;
} else {
$model -> status_id = 17 ;
$model -> outlab_by = Yii :: $app -> user -> identity -> getId ();
$model -> pathologist_at = $outlab_at ;
$model -> outlab_at = $outlab_at ;
}
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
if ( $model -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
}
return $this -> redirect ([ 'outlab-process' , 'id_case' => $case -> id_case ]);
}
} //Necropsy END
return $this -> render ( 'outlab-process' , [
'model' => $model ,
'case_type' => $case_type ,
'case' => $case ,
]);
}
/**
* get amphur
*
* @ return void
*/
public function actionGetAmphur ()
{
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$out = [];
if ( Yii :: $app -> request -> post ( 'depdrop_parents' )) {
$parents = Yii :: $app -> request -> post ( 'depdrop_parents' );
if ( $parents != null ) {
$province_id = $parents [ 0 ];
$out = [];
foreach ( ConstLookupAddressName :: find () -> where ([ 'province' => $province_id , 'tambon' => 0 ]) -> andWhere ([ '!=' , 'amphur' , 0 ]) /*->select(['amphur AS id', 'detailtext AS name'])*/ -> orderBy ([ 'detailtext' => SORT_ASC ]) -> all () as $district ) {
$out [] = [ 'id' => $district -> amphur , 'name' => $district -> detailtext ];
}
return [ 'output' => $out , 'selected' => '' ];
}
}
return [ 'output' => '' , 'selected' => '' ];
}
/**
* get tambon
*
* @ return void
*/
public function actionGetTambon ()
{
Yii :: $app -> response -> format = Response :: FORMAT_JSON ;
$out = [];
if ( Yii :: $app -> request -> post ( 'depdrop_parents' )) {
$ids = Yii :: $app -> request -> post ( 'depdrop_parents' );
$province_id = empty ( $ids [ 0 ]) ? null : $ids [ 0 ];
$district_id = empty ( $ids [ 1 ]) ? null : $ids [ 1 ];
if ( $district_id != null ) {
$out = [];
foreach ( ConstLookupAddressName :: find () -> where ([ 'province' => $province_id , 'amphur' => $district_id ]) -> andWhere ([ '!=' , 'tambon' , 0 ]) /*->select(['tambon AS id', 'detailtext AS name'])*/ -> orderBy ([ 'detailtext' => SORT_ASC ]) -> all () as $subdistrict ) {
$out [] = [ 'id' => $subdistrict -> tambon , 'name' => $subdistrict -> detailtext ];
}
return [ 'output' => $out , 'selected' => '' ];
}
}
return [ 'output' => '' , 'selected' => '' ];
}
public function actionGetZip ( $tambon , $amphur , $province )
{
//Yii::$app->response->format = Response::FORMAT_JSON;
$subdistrict = ConstLookupAddressName :: findOne ([ 'province' => $province , 'amphur' => $amphur , 'tambon' => $tambon ]);
return isset ( $subdistrict ) ? $subdistrict -> zipcode : '' ;
}
2025-04-01 08:05:43 +00:00
2025-04-02 05:43:04 +00:00
2025-04-02 07:36:23 +00:00
/*
2025-04-02 07:03:34 +00:00
public function actionSearchPatient ( $hn = null )
2025-04-01 08:05:43 +00:00
{
Yii :: $app -> response -> format = \yii\web\Response :: FORMAT_JSON ;
2025-04-02 05:43:04 +00:00
$response = $this -> getPatientData ( $hn ); // สมมุติว่า method นี้รับ HN
2025-04-01 08:07:42 +00:00
2025-04-02 05:43:04 +00:00
if ( $response && $response [ 'status' ] === 'success' && ! empty ( $response [ 'data' ])) {
$patientRaw = $response [ 'data' ][ 0 ];
2025-04-01 08:07:42 +00:00
2025-04-02 05:43:04 +00:00
// แปลงข้อมูลให้เรียบร้อยและสะอาด
2025-04-02 05:15:03 +00:00
$data = [
2025-04-02 07:03:34 +00:00
'hn' => rtrim ( $patientRaw [ 'hn' ]),
'title' => rtrim ( $patientRaw [ 'title' ]),
'first_name' => rtrim ( $patientRaw [ 'firstName' ]),
'last_name' => rtrim ( $patientRaw [ 'lastName' ]),
'sex' => rtrim ( $patientRaw [ 'sex' ]),
2025-04-02 05:43:04 +00:00
'birthdate' => $this -> convertBirthDate ( $patientRaw [ 'birthDay' ]),
2025-04-02 07:03:34 +00:00
'race' => rtrim ( $patientRaw [ 'RACE' ]),
'nation' => rtrim ( $patientRaw [ 'NATION' ]),
'card_id' => rtrim ( $patientRaw [ 'CardID' ]),
2025-04-02 05:15:03 +00:00
];
2025-04-02 05:43:04 +00:00
2025-04-01 08:05:43 +00:00
return [
'success' => true ,
2025-04-01 08:07:42 +00:00
'html' => $this -> renderAjax ( '_patient_detail' , [ 'model' => ( object ) $data ]),
'data' => $data
2025-04-01 08:05:43 +00:00
];
2025-04-02 05:43:04 +00:00
} else {
2025-04-01 08:07:42 +00:00
return [
'success' => false ,
'message' => 'ไม่พบข้อมูลผู้ป่วย หรือ API มีปัญหา'
];
2025-04-02 05:43:04 +00:00
}
}
public function getPatientData ()
{
$url = '172.22.35.95:8083/PATHO_API/getPeople.php' ;
$postData = array_filter ([
'hn' => $this -> hn ,
], function ( $value ) {
return ! empty ( $value );
});
//var_dump($postData);
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_URL , $url );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
curl_setopt ( $ch , CURLOPT_ENCODING , 'UTF-8' );
curl_setopt ( $ch , CURLOPT_MAXREDIRS , 10 );
curl_setopt ( $ch , CURLOPT_TIMEOUT , 0 );
curl_setopt ( $ch , CURLOPT_FOLLOWLOCATION , true );
curl_setopt ( $ch , CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt ( $ch , CURLOPT_CUSTOMREQUEST , 'POST' );
curl_setopt ( $ch , CURLOPT_POSTFIELDS , http_build_query ( $postData ));
curl_setopt ( $ch , CURLOPT_HTTPHEADER , [ 'Content-Type: application/x-www-form-urlencoded' ]);
$response = curl_exec ( $ch );
if ( curl_errno ( $ch )) {
$error_msg = curl_error ( $ch );
var_dump ( $error_msg );
}
curl_close ( $ch );
//var_dump($response);
//die();
return Json :: decode ( $response , true );
2025-04-02 07:36:23 +00:00
} */
public function getPatientData ( $hn ) // รับ $hn เป็น parameter
{
$url = '172.22.35.95:8083/PATHO_API/getPeople.php' ;
$postData = array_filter ([
'hn' => $hn , // ใช้ค่าจาก parameter แทน $this->hn
], function ( $value ) {
return ! empty ( $value );
});
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_URL , $url );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
curl_setopt ( $ch , CURLOPT_ENCODING , 'UTF-8' );
curl_setopt ( $ch , CURLOPT_MAXREDIRS , 10 );
curl_setopt ( $ch , CURLOPT_TIMEOUT , 0 );
curl_setopt ( $ch , CURLOPT_FOLLOWLOCATION , true );
curl_setopt ( $ch , CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt ( $ch , CURLOPT_CUSTOMREQUEST , 'POST' );
curl_setopt ( $ch , CURLOPT_POSTFIELDS , http_build_query ( $postData ));
curl_setopt ( $ch , CURLOPT_HTTPHEADER , [ 'Content-Type: application/x-www-form-urlencoded' ]);
$response = curl_exec ( $ch );
if ( curl_errno ( $ch )) {
$error_msg = curl_error ( $ch );
var_dump ( $error_msg );
}
curl_close ( $ch );
return Json :: decode ( $response , true );
}
public function actionSearchPatient ()
{
Yii :: $app -> response -> format = \yii\web\Response :: FORMAT_JSON ;
$hn = Yii :: $app -> request -> get ( 'hn' ); // รับค่าจาก request GET
if ( $hn ) {
$response = $this -> getPatientData ( $hn ); // ส่งค่า $hn ไปยัง getPatientData()
if ( $response && $response [ 'status' ] === 'success' && ! empty ( $response [ 'data' ])) {
$patientRaw = $response [ 'data' ][ 0 ];
$data = [
'hn' => rtrim ( $patientRaw [ 'hn' ]),
'title' => rtrim ( $patientRaw [ 'title' ]),
'first_name' => rtrim ( $patientRaw [ 'firstName' ]),
'last_name' => rtrim ( $patientRaw [ 'lastName' ]),
'sex' => rtrim ( $patientRaw [ 'sex' ]),
2025-04-02 08:01:31 +00:00
'birthdate' => Yii :: $app -> pathology -> convertThaiDateToGregorian ( $patientRaw [ 'birthDay' ]),
'age' => Yii :: $app -> pathology -> calculateAgeFromDate ( $patientRaw [ 'birthDay' ]),
2025-04-02 07:36:23 +00:00
'race' => rtrim ( $patientRaw [ 'RACE' ]),
'nation' => rtrim ( $patientRaw [ 'NATION' ]),
'card_id' => rtrim ( $patientRaw [ 'CardID' ]),
];
return [
'success' => true ,
'html' => $this -> renderAjax ( '_patient_detail' , [ 'model' => ( object ) $data ]),
'data' => $data
];
} else {
return [
'success' => false ,
'message' => 'ไม่พบข้อมูลผู้ป่วย หรือ API มีปัญหา'
];
}
} else {
return [
'success' => false ,
'message' => 'HN ไม่ถูกต้อง'
];
}
2025-04-01 08:05:43 +00:00
}
2025-05-07 04:30:40 +00:00
}