2024-12-25 03:04:59 +00:00
< ? php
namespace frontend\modules\register\controllers ;
2025-04-01 09:27:47 +00:00
use Yii ;
use yii\web\Response ;
use yii\base\Exception ;
use common\models\CaseHpv ;
use common\models\CasePap ;
use common\models\Patient ;
2024-12-25 03:04:59 +00:00
use common\models\CaseDish ;
use common\models\CaseFish ;
use common\models\CaseFlow ;
2025-04-01 09:27:47 +00:00
use yii\widgets\ActiveForm ;
use common\models\CaseFrozen ;
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-04-01 09:27:47 +00:00
use common\models\CytoSpecimen ;
2024-12-25 03:04:59 +00:00
use common\models\StainingTest ;
2025-04-01 09:27:47 +00:00
use common\models\CaseMolecular ;
2024-12-25 03:04:59 +00:00
use common\models\ConstHospital ;
use common\models\DishDiagnosis ;
use common\models\FishDiagnosis ;
use common\models\FlowDiagnosis ;
2025-04-01 09:27:47 +00:00
use common\models\HistoStaining ;
use common\models\ImmunoStaining ;
2024-12-25 03:04:59 +00:00
use common\models\FrozenDiagnosis ;
2025-04-01 09:27:47 +00:00
use common\models\AutopsyDiagnosis ;
use common\models\CytoPapDiagnosis ;
2024-12-25 03:04:59 +00:00
use common\models\NecropsyDiagnosis ;
use common\models\SurgicalContainer ;
use common\models\SurgicalDiagnosis ;
2025-04-01 09:27:47 +00:00
use common\models\ConstServiceCharge ;
use common\models\MolecularDiagnosis ;
use common\models\CytoNonGynContainer ;
use common\models\CytoNonGynDiagnosis ;
use common\models\FinanceServiceCharge ;
use common\models\ConstLookupAddressName ;
2024-12-25 03:04:59 +00:00
/**
* Class CaseUpdateController
* @ package frontend\modules\register\controllers
*/
class CaseUpdateController extends \yii\web\Controller
{
/**
* @ param $id_case
* @ return Response
*/
public function actionSwitchCase ( $id_case )
{
$case_type = Yii :: $app -> pathology -> getCaseType ( $id_case );
if ( $case_type == 'surgical' ) {
return $this -> redirect ([ 'surgical' , 'id_case' => $id_case ]);
}
if ( $case_type == 'pap' ) {
return $this -> redirect ([ 'pap' , 'id_case' => $id_case ]);
}
if ( $case_type == 'liquid-based' ) {
return $this -> redirect ([ 'pap' , 'id_case' => $id_case ]);
}
if ( $case_type == 'non-gyn' ) {
return $this -> redirect ([ 'non-gyn' , 'id_case' => $id_case ]);
}
if ( $case_type == 'frozen' ) {
return $this -> redirect ([ 'frozen' , 'id_case' => $id_case ]);
}
if ( $case_type == 'fish' ) {
return $this -> redirect ([ 'fish' , 'id_case' => $id_case ]);
}
if ( $case_type == 'dish' ) {
return $this -> redirect ([ 'dish' , 'id_case' => $id_case ]);
}
if ( $case_type == 'flow' ) {
return $this -> redirect ([ 'flow' , 'id_case' => $id_case ]);
}
if ( $case_type == 'autopsy' ) {
return $this -> redirect ([ 'autopsy' , 'id_case' => $id_case ]);
}
if ( $case_type == 'molecular' ) {
return $this -> redirect ([ 'molecular' , 'id_case' => $id_case ]);
}
if ( $case_type == 'necropsy' ) {
return $this -> redirect ([ 'necropsy' , 'id_case' => $id_case ]);
}
if ( $case_type == 'hpv' ) {
return $this -> redirect ([ 'hpv' , 'id_case' => $id_case ]);
}
2025-04-01 09:27:47 +00:00
if ( $case_type == 'external' ) {
return $this -> redirect ([ 'external' , 'id_case' => $id_case ]);
}
2024-12-25 03:04:59 +00:00
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่พบ Case นี้' );
return $this -> redirect ([ '/register/center/case-all' ]);
}
2025-01-02 01:33:33 +00:00
2024-12-25 03:04:59 +00:00
/**
* update PAP
* @ param string $id_case
* @ return \yii\web\Response | string
*/
public function actionPap ( $id_case )
{
$model = CasePap :: findOne ([ 'id_case' => $id_case ]);
/* $finance = FinanceServiceCharge :: find () -> joinWith ([ 'charge' ])
-> andFilterWhere ([ 'id_case' => $model -> id_case , 'const_service_charge.lab' => 'pap' ]) -> one (); //$model->finance;
if ( ! $finance ) {
$finance = new FinanceServiceCharge ([ 'id_case' => $model -> id_case ]);
}
$finance -> scenario = 'update_register' ; */
$patient = Patient :: findOne ( $model -> patient_id ); //$model->patient;
//$operate = CytoOperate::findOne(['id_case' => $model->id_case]);
//$model->race = 'ไทย';
//$patient = $model->patient;
//$model->scenario = 'update';
$request = Yii :: $app -> getRequest ();
if ( $request -> isPost && $request -> post ( 'ajax' ) !== null ) {
$model -> load ( Yii :: $app -> request -> post ());
//$patient->load(Yii::$app->request->post());
//$operate->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 ;
}
$model -> specimen_name = isset ( $model -> specimen_id ) ? CytoSpecimen :: findOne ( $model -> specimen_id ) -> name : null ;
//$model->scenario = 'register';
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
$patient -> hospital_id = $model -> hospital_id ;
$model -> receive_at = empty ( $model -> receive_at ) ? date ( 'd/m/Y' ) : $model -> receive_at ;
if ( $patient -> save ()) {
Yii :: $app -> session -> addFlash ( 'success' , 'บันทึกข้อมูล ผู้ป่วย เรียบร้อย' );
} else {
Yii :: $app -> session -> addFlash ( 'error' , 'บันทึกข้อมูล ผู้ป่วย ไม่ได้' );
}
/*
* บันทึก CASE PAP
*/
/* var_dump ( $model );
die (); */
/* $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 = 15 ;
$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 = 3 ;
//$pap_diagnosis->pathologist_at = $outlab_at;
}
$pap_diagnosis -> id_case = $model -> id_case ;
$pap_diagnosis -> report_type = 'outlab' ;
$pap_diagnosis -> status_id = 3 ;
//$pap_diagnosis->pathologist_at = $outlab_at;
if ( $pap_diagnosis -> save ()) {
//@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 {
var_dump ( $pap_diagnosis -> getFirstErrors ());
die ();
}
} */
$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 = 7 ;
$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 = 3 ;
//$surgical_diagnosis->is_outlab_release = 1;
//$surgical_diagnosis->pathologist_at = $outlab_at;
}
$pap_diagnosis -> id_case = $model -> id_case ;
$pap_diagnosis -> report_type = 'outlab' ;
$pap_diagnosis -> status_id = 3 ;
//$surgical_diagnosis->is_outlab_release = 1;
//$model->outlab_report = $model->uploadReport($model, 'outlab_report');
//$surgical_diagnosis->outlab_report = $surgical_diagnosis->uploadReport($surgical_diagnosis, 'outlab_report');
$pap_diagnosis -> outlab_report = $model -> outlab_report ;
//$surgical_diagnosis->pathologist_at = $outlab_at;
if ( $pap_diagnosis -> save ()) {
//@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 {
var_dump ( $pap_diagnosis -> getFirstErrors ());
var_dump ( $model -> getFirstErrors ());
die ();
}
}
//Upload Outlab Report
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
if ( empty ( $model -> register_id )) {
$model -> register_id = Yii :: $app -> user -> getId ();
}
if ( empty ( $model -> register_at )) {
$model -> register_at = date ( 'Y-m-d H:i:s' );
}
if ( empty ( $model -> receive_at )) {
$model -> receive_at = date ( 'Y-m-d H:i:s' );
}
if ( $model -> save ()) {
Yii :: $app -> session -> addFlash ( 'success' , 'บันทีกข้อมูล PAP เรียบร้อยแล้ว' );
Yii :: $app -> pathology -> setLog ( 'Update' , 'แก้ไขข้อมูลคนไข้: ' . $model -> id_case , Yii :: $app -> user -> getId (), CasePap :: tableName ());
if ( $model -> status_id < 17 ) {
$model -> register_at = ! empty ( $model -> register_at ) ? $model -> register_at : $time_now ;
}
} else {
Yii :: $app -> session -> addFlash ( 'error' , 'บันทึกข้อมูล PAP ไม่ได้' );
}
/*
* บันทึกค่าตรวจ PAP
*/
/* $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 ;
if ( $finance -> save ()) {
Yii :: $app -> session -> addFlash ( 'success' , 'บันทึกข้อมูลการเงินเรียบร้อยแล้ว' );
} else {
/* var_dump ( $finance -> 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 ,
//'finance' => $finance,
//'patient' => $patient,
//'operate' => $operate,
//'case_next' => $this->getNext($id_case),
//'case_previous' => $this->getPrevious($id_case),
]);
}
public function actionFrozen ( $id_case )
{
$model = CaseFrozen :: findOne ([ 'id_case' => $id_case ]);
$time_now = date ( 'Y-m-d H:i:s' );
2025-01-02 03:31:23 +00:00
$model -> autocomplete_hospital = $model -> hospital -> name ;
2024-12-25 03:04:59 +00:00
2025-01-02 03:31:23 +00:00
//$model->autocomplete_ward = isset($model->ward) ? $model->ward->name : '';
//$model->autocomplete_patient = $model->patient->name;
$sc_surgical_container = new SurgicalContainer ();
$sc_surgical_container -> items = SurgicalContainer :: find () -> where ([ 'id_case' => $model -> id_case ]) -> all ();
2024-12-25 03:04:59 +00:00
2025-01-02 03:31:23 +00:00
$patient = $model -> patient ;
2024-12-25 03:04:59 +00:00
2025-01-02 03:31:23 +00:00
$model -> scenario = 'update' ;
2024-12-25 03:04:59 +00:00
$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 ;
2025-01-02 03:31:23 +00:00
$result = ActiveForm :: validate ( $model );
2024-12-25 03:04:59 +00:00
return $result ;
}
2025-01-02 03:31:23 +00:00
if ( $model -> load ( Yii :: $app -> request -> post ())) {
2024-12-25 03:04:59 +00:00
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
2025-01-02 03:31:23 +00:00
//บันทึกผู้ป่วย
2024-12-25 03:04:59 +00:00
$patient -> hospital_id = $model -> hospital_id ;
2025-01-02 03:31:23 +00:00
$patient -> save ();
2024-12-25 03:04:59 +00:00
2025-01-02 03:31:23 +00:00
$sc = Yii :: $app -> request -> post ();
2024-12-25 03:04:59 +00:00
2025-01-02 03:31:23 +00:00
//SurgicalContainer
if ( isset ( $sc [ 'SurgicalContainer' ][ 'items' ]) && ( is_array ( $sc [ 'SurgicalContainer' ][ 'items' ]) ? count ( $sc [ 'SurgicalContainer' ][ 'items' ]) : 0 ) > 0 ) {
foreach ( $sc [ 'SurgicalContainer' ][ 'items' ] as $key => $value ) {
$surgical_container = SurgicalContainer :: findOne ([ 'id_case' => $model -> id_case , 'id' => $value [ 'id' ]]);
if ( ! $surgical_container ) {
$surgical_container = new SurgicalContainer ();
}
$surgical_container -> id_case = $model -> id_case ;
$surgical_container -> container_type = $value [ 'container_type' ];
$surgical_container -> amount = $value [ 'amount' ];
$surgical_container -> specimen_size = $value [ 'specimen_size' ];
$surgical_container -> remark = $value [ 'remark' ];
2024-12-25 03:04:59 +00:00
2025-01-02 03:31:23 +00:00
if ( $surgical_container -> save ( false )) {
}
}
} //SurgicalContainer
//อัพโหลดภาพ Specimen Container
$model -> specimen_container_img = $model -> uploadSpecimenContainer ( $model , 'specimen_container_img' );
2024-12-25 03:04:59 +00:00
2025-01-02 03:31:23 +00:00
//อัพโหลดไฟล์ Request
2024-12-25 03:04:59 +00:00
$model -> files = $model -> uploadFile ( $model , 'files' );
2025-01-02 03:31:23 +00:00
//ถ้าวัน receive ว่างให้บันทึกเป็นวันปัจจุบัน
$model -> receive_at = empty ( $model -> receive_at ) ? date ( 'd/m/Y' ) : $model -> receive_at ;
if ( ! empty ( $model -> case_reference )) {
$case_reference = CaseFrozen :: findOne ([ 'id_case' => $model -> case_reference ]);
if ( $case_reference ) {
if ( empty ( $model -> gross_description ) || $model -> is_re_reference == true ) {
$model -> gross_description = $case_reference -> gross_description ;
}
if ( empty ( $model -> microscopic_description ) || $model -> is_re_reference == true ) {
$model -> microscopic_description = $case_reference -> microscopic_description ;
}
if ( empty ( $model -> diagnosis ) || $model -> is_re_reference == true ) {
$model -> diagnosis = $case_reference -> diagnosis ;
}
2024-12-25 03:04:59 +00:00
2025-01-02 03:31:23 +00:00
if ( empty ( $model -> additional_diagnosis ) || $model -> is_re_reference == true ) {
$model -> additional_diagnosis = $case_reference -> additional_diagnosis ;
}
}
2024-12-25 03:04:59 +00:00
}
2025-01-02 03:31:23 +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 ) {
$model -> status_id = 7 ;
2025-01-02 03:31:23 +00:00
$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 = 3 ;
2024-12-25 03:04:59 +00:00
}
2025-01-02 03:31:23 +00:00
$surgical_diagnosis -> id_case = $model -> id_case ;
$surgical_diagnosis -> report_type = 'outlab' ;
$surgical_diagnosis -> status_id = 3 ;
//$surgical_diagnosis->is_outlab_release = 1;
//$model->outlab_report = $model->uploadReport($model, 'outlab_report');
//$surgical_diagnosis->outlab_report = $surgical_diagnosis->uploadReport($surgical_diagnosis, 'outlab_report');
$surgical_diagnosis -> outlab_report = $model -> outlab_report ;
//$surgical_diagnosis->pathologist_at = $outlab_at;
if ( $surgical_diagnosis -> save ()) {
//@Yii::$app->runAction('/register/hl7/result', ['id_case' => $pap_diagnosis->id_case, 'report_type' => $pap_diagnosis->report_type, 'diagnosis_id' => $pap_diagnosis->id]);
2024-12-25 03:04:59 +00:00
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
2025-01-02 03:31:23 +00:00
var_dump ( $surgical_diagnosis -> getFirstErrors ());
var_dump ( $model -> getFirstErrors ());
2024-12-25 03:04:59 +00:00
die ();
}
}
2025-01-02 03:31:23 +00:00
// เปลี่ยนสถานะในหน้าส่งทำ Slide อย่างเดียว
2024-12-25 03:04:59 +00:00
2025-01-02 03:31:23 +00:00
if ( $model -> status_id == 10 ) {
$model -> status_at = date ( 'Y-m-d H:i:s' );
}
2024-12-25 03:04:59 +00:00
2025-01-02 03:31:23 +00:00
if ( empty ( $model -> register_id )) {
$model -> register_id = Yii :: $app -> user -> getId ();
}
if ( empty ( $model -> register_at )) {
$model -> register_at = date ( 'Y-m-d H:i:s' );
}
if ( $model -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Update' , 'แก้ไขข้อมูลคนไข้: ' . $model -> id_case , Yii :: $app -> user -> getId (), CaseSurgical :: tableName ());
2024-12-25 03:04:59 +00:00
} else {
var_dump ( $model -> getFirstErrors ());
die ();
} //
2025-01-02 03:31:23 +00:00
if ( $model -> is_histo_staining == 1 ) { //ส่งย้อม Histo
$staining = HistoStaining :: findOne ([ 'id_case' => $model -> id_case ]);
if ( ! $staining ) {
$staining = new HistoStaining ();
$staining -> id_case = $model -> id_case ;
$staining -> block_no = '' ;
$staining -> note = '' ;
$staining -> is_able = 0 ;
$staining -> is_routine = 0 ;
$staining -> status_1 = 1 ;
$staining -> in_at = $time_now ;
$staining -> save ();
}
}
if ( $model -> is_immuno_staining == 1 ) { //ส่งย้อม Immuno
$staining = ImmunoStaining :: findOne ([ 'id_case' => $model -> id_case ]);
if ( ! $staining ) {
$staining = new ImmunoStaining ();
$staining -> id_case = $model -> id_case ;
$staining -> block_no = '' ;
$staining -> note = '' ;
$staining -> status_1 = 1 ;
$staining -> is_able = 0 ;
$staining -> in_at = $time_now ;
$staining -> save ();
}
}
2024-12-25 03:04:59 +00:00
2025-01-02 03:31:23 +00:00
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'แก้ไขข้อมูลเรียบร้อยแล้ว' );
2024-12-25 03:04:59 +00:00
return $this -> redirect ([ '/register/case-update/frozen' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
}
2025-01-02 03:31:23 +00:00
}
2024-12-25 03:04:59 +00:00
return $this -> render ( 'frozen' , [
'model' => $model ,
'patient' => $patient ,
2025-01-02 03:31:23 +00:00
'sc_surgical_container' => $sc_surgical_container ,
2024-12-25 03:04:59 +00:00
//'finance' => $finance,
2025-01-02 03:31:23 +00:00
//'surgical_operate' => $surgical_operate,
'case_next' => $this -> getNext ( $id_case ),
'case_previous' => $this -> getPrevious ( $id_case ),
2024-12-25 03:04:59 +00:00
]);
}
/**
* @ param $id_case
* @ return array | string | void | Response
*/
public function actionFish ( $id_case )
{
$model = CaseFish :: findOne ([ 'id_case' => $id_case ]);
$time_now = date ( 'Y-m-d H:i:s' );
if ( ! $model ) {
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่พบ Case นี้ในระบบ' );
return $this -> redirect ([ '/register/case/fish' ]);
}
//$operate = CytoOperate::findOne(['id_case' => $model->id_case]);
//$finance = $model->finance;
//$patient = $model->patient;
/* $finance = FinanceServiceCharge :: find () -> joinWith ([ 'charge' ])
-> andFilterWhere ([ 'id_case' => $model -> id_case , 'const_service_charge.lab' => 'fish' ]) -> one (); //$model->finance;
if ( ! $finance ) {
$finance = new FinanceServiceCharge ([ 'id_case' => $model -> id_case ]);
}
$finance -> scenario = 'update_register' ; */
$patient = Patient :: findOne ( $model -> patient_id );
//$patient->race = 'ไทย';
$model -> autocomplete_hospital = $model -> hospital -> name ;
//$model->autocomplete_ward = isset($model->ward) ? $model->ward->name : '';
$model -> autocomplete_patient = $model -> patient -> getFullname ();
$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 ())
//$operate->load(Yii::$app->request->post()) &&
//$patient->load(Yii::$app->request->post()) &&
//$finance->load(Yii::$app->request->post())
) {
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
/* if ( intval ( $model -> patient_id )) { // ถ้ามีผู้ป่วยอยู่แล้วก็ Select มา
$patient = Patient :: findOne ( $model -> patient_id );
} else { // ถ้ายังไม่มีก็ให้ Save ใหม่
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
$patient -> name = $model -> patient_id ;
$patient -> save ();
} */
// ได้ $patient->id ล่ะ
//$patient->validate();
$patient -> hospital_id = $model -> hospital_id ;
$patient -> save ( false );
/* if ( $patient -> save ()){
echo 'yes' ;
} else {
echo 'no' ;
} */
/*
* บันทึก CASE NonGyn
*/
//$model->patient_id = $patient->id;
//$model->status_id = 1;
if ( $model -> status_id == 1 ) {
//$cyto_operate = CytoOperate::findOne(['id_case' => $model->id_case]);
//$cyto_operate->register_at = $time_now;
//$cyto_operate->save();
}
$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' );
if ( $model -> save ()) {
//$operate->save();
if ( empty ( $model -> register_id )) {
$model -> register_id = Yii :: $app -> user -> getId ();
}
if ( empty ( $model -> register_at )) {
$model -> register_at = date ( 'Y-m-d H:i:s' );
}
if ( empty ( $model -> receive_at )) {
$model -> receive_at = date ( 'Y-m-d H:i:s' );
}
/* $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 ;
if ( $finance -> save ()) {
Yii :: $app -> session -> addFlash ( 'success' , 'บันทึกข้อมูลการเงินเรียบร้อยแล้ว' );
} else {
var_dump ( $finance -> getFirstErrors ());
die ();
} */
} else {
var_dump ( $model -> getFirstErrors ());
die ();
} //
/*
* บันทึกค่าตรวจ FISH
*/
$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 ();
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่สามารถลงทะเบียน Case ได้' );
return $this -> redirect ([ '/register/case/fish' ]);
}
} // if post()
return $this -> render ( 'fish' , [
'model' => $model ,
'patient' => $patient ,
//'finance' => $finance,
//'operate' => $operate,
//'case_next' => $this->getNext($id_case),
//'case_previous' => $this->getPrevious($id_case),
]);
}
public function actionFlow ( $id_case )
{
$model = CaseFlow :: findOne ([ 'id_case' => $id_case ]);
$time_now = date ( 'Y-m-d H:i:s' );
if ( ! $model ) {
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่พบ Case นี้ในระบบ' );
return $this -> redirect ([ '/register/case/flow' ]);
}
//$operate = CytoOperate::findOne(['id_case' => $model->id_case]);
//$finance = $model->finance;
//$patient = $model->patient;
/* $finance = FinanceServiceCharge :: find () -> joinWith ([ 'charge' ])
-> andFilterWhere ([ 'id_case' => $model -> id_case , 'const_service_charge.lab' => 'flow' ]) -> one (); //$model->finance;
if ( ! $finance ) {
$finance = new FinanceServiceCharge ([ 'id_case' => $model -> id_case ]);
}
$finance -> scenario = 'update_register' ;
*/
$patient = Patient :: findOne ( $model -> patient_id );
//$patient->race = 'ไทย';
$model -> autocomplete_hospital = $model -> hospital -> name ;
//$model->autocomplete_ward = isset($model->ward) ? $model->ward->name : '';
$model -> autocomplete_patient = $model -> patient -> getFullname ();
$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 ())
//$operate->load(Yii::$app->request->post()) &&
//$patient->load(Yii::$app->request->post()) &&
//$finance->load(Yii::$app->request->post())
) {
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
/* if ( intval ( $model -> patient_id )) { // ถ้ามีผู้ป่วยอยู่แล้วก็ Select มา
$patient = Patient :: findOne ( $model -> patient_id );
} else { // ถ้ายังไม่มีก็ให้ Save ใหม่
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
$patient -> name = $model -> patient_id ;
$patient -> save ();
} */
// ได้ $patient->id ล่ะ
//$patient->validate();
$patient -> hospital_id = $model -> hospital_id ;
$patient -> save ( false );
/* if ( $patient -> save ()){
echo 'yes' ;
} else {
echo 'no' ;
} */
/*
* บันทึก CASE NonGyn
*/
//$model->patient_id = $patient->id;
//$model->status_id = 1;
if ( $model -> status_id == 1 ) {
//$cyto_operate = CytoOperate::findOne(['id_case' => $model->id_case]);
//$cyto_operate->register_at = $time_now;
//$cyto_operate->save();
}
$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' );
if ( $model -> save ()) {
//$operate->save();
if ( empty ( $model -> register_id )) {
$model -> register_id = Yii :: $app -> user -> getId ();
}
if ( empty ( $model -> register_at )) {
$model -> register_at = date ( 'Y-m-d H:i:s' );
}
if ( empty ( $model -> receive_at )) {
$model -> receive_at = date ( 'Y-m-d H:i:s' );
}
/* $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 ;
if ( $finance -> save ()) {
Yii :: $app -> session -> addFlash ( 'success' , 'บันทึกข้อมูลการเงินเรียบร้อยแล้ว' );
} else {
var_dump ( $finance -> getFirstErrors ());
die ();
} */
} else {
var_dump ( $model -> getFirstErrors ());
die ();
} //
/*
* บันทึกค่าตรวจ FISH
*/
$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 ();
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่สามารถลงทะเบียน Case ได้' );
return $this -> redirect ([ '/register/case/flow' ]);
}
} // if post()
return $this -> render ( 'flow' , [
'model' => $model ,
'patient' => $patient ,
//'finance' => $finance,
//'operate' => $operate,
//'case_next' => $this->getNext($id_case),
//'case_previous' => $this->getPrevious($id_case),
]);
}
/**
* @ param $id_case
* @ return array | string | void | Response
*/
public function actionDish ( $id_case )
{
$model = CaseDish :: findOne ([ 'id_case' => $id_case ]);
$time_now = date ( 'Y-m-d H:i:s' );
if ( ! $model ) {
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่พบ Case นี้ในระบบ' );
return $this -> redirect ([ '/register/case/dish' ]);
}
//$operate = CytoOperate::findOne(['id_case' => $model->id_case]);
//$finance = $model->finance;
//$patient = $model->patient;
/* $finance = FinanceServiceCharge :: find () -> joinWith ([ 'charge' ])
-> andFilterWhere ([ 'id_case' => $model -> id_case , 'const_service_charge.lab' => 'test-dish' ]) -> one (); //$model->finance;
if ( ! $finance ) {
$finance = new FinanceServiceCharge ([ 'id_case' => $model -> id_case ]);
}
$finance -> scenario = 'update_register' ; */
$patient = Patient :: findOne ( $model -> patient_id );
//$patient->race = 'ไทย';
$model -> autocomplete_hospital = $model -> hospital -> name ;
//$model->autocomplete_ward = isset($model->ward) ? $model->ward->name : '';
$model -> autocomplete_patient = isset ( $model -> patient ) ? $model -> patient -> getFullname () : '' ;
//$model->autocomplete_patient = $model->patient->getFullname();
$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 ())
//$operate->load(Yii::$app->request->post()) &&
//$patient->load(Yii::$app->request->post()) &&
//$finance->load(Yii::$app->request->post())
) {
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
/* if ( intval ( $model -> patient_id )) { // ถ้ามีผู้ป่วยอยู่แล้วก็ Select มา
$patient = Patient :: findOne ( $model -> patient_id );
} else { // ถ้ายังไม่มีก็ให้ Save ใหม่
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
$patient -> name = $model -> patient_id ;
$patient -> save ();
} */
// ได้ $patient->id ล่ะ
//$patient->validate();
$patient -> hospital_id = $model -> hospital_id ;
$patient -> save ( false );
/* if ( $patient -> save ()){
echo 'yes' ;
} else {
echo 'no' ;
} */
/*
* บันทึก CASE NonGyn
*/
//$model->patient_id = $patient->id;
//$model->status_id = 1;
if ( $model -> status_id == 1 ) {
//$cyto_operate = CytoOperate::findOne(['id_case' => $model->id_case]);
//$cyto_operate->register_at = $time_now;
//$cyto_operate->save();
}
$model -> files = $model -> uploadFile ( $model , 'files' );
$model -> specimen_img = $model -> uploadGross ( $model , 'specimen_img' );
if ( $model -> specimen_img != $model -> getOldAttribute ( '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
//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' );
if ( $model -> save ()) {
//$operate->save();
if ( empty ( $model -> register_id )) {
$model -> register_id = Yii :: $app -> user -> getId ();
}
if ( empty ( $model -> register_at )) {
$model -> register_at = date ( 'Y-m-d H:i:s' );
}
if ( empty ( $model -> receive_at )) {
$model -> receive_at = date ( 'Y-m-d H:i:s' );
}
/* $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 ;
if ( $finance -> save ()) {
Yii :: $app -> session -> addFlash ( 'success' , 'บันทึกข้อมูลการเงินเรียบร้อยแล้ว' );
} else {
var_dump ( $finance -> getFirstErrors ());
die ();
} */
} else {
var_dump ( $model -> getFirstErrors ());
die ();
} //
/*
* บันทึกค่าตรวจ FISH
*/
$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 ();
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่สามารถลงทะเบียน Case ได้' );
return $this -> redirect ([ '/register/case/dish' ]);
}
} // if post()
return $this -> render ( 'dish' , [
'model' => $model ,
'patient' => $patient ,
//'finance' => $finance,
//'operate' => $operate,
//'case_next' => $this->getNext($id_case),
//'case_previous' => $this->getPrevious($id_case),
]);
}
/**
* ลงทะเบียน HPV
* @ param $case
* @ return string
*/
public function actionHpv ( $id_case )
{
$model = CaseHpv :: findOne ([ 'id_case' => $id_case ]);
if ( ! $model ) {
Yii :: $app -> session -> setFlash ( 'error' , 'ไมีมีเบอร์นี้ในระบบ' );
return $this -> redirect ([ '/register' ]);
}
$patient = Patient :: findOne ( $model -> patient_id );
$model -> autocomplete_patient = $patient -> given_name ;
$finance = FinanceServiceCharge :: findOne ([ 'id_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 ())) {
$time_now = date ( 'Y-m-d H:i:s' );
//$transaction = Yii::$app->db->beginTransaction();
$action = Yii :: $app -> request -> post ( 'hpv' );
if ( $action == 'sendpatho' ) {
if ( empty ( $model -> pathologist_at )) {
$model -> status_id = 4 ;
$model -> pathologist_at = $time_now ;
}
$model -> save ();
//$transaction->commit();
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึกข้อมูลและกำลังแสดงตัวอย่างรายงาน' );
return $this -> redirect ([ '/register/case-update/hpv' , 'id_case' => $model -> id_case ]);
}
try {
// บันทึก 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 ( $patient -> h_n != $model -> h_n ) {
$pt = Patient :: findOne ([ 'h_n' => $model -> h_n ]);
if ( ! $pt ) {
$pt = new Patient ();
$pt -> title_id = $patient -> title_id ;
$pt -> given_name = $model -> given_name ;
$pt -> surname = $model -> surname ;
$pt -> hospital_id = $model -> hospital_id ;
$pt -> h_n = $patient -> h_n ;
$pt -> age = $patient -> age ;
$pt -> age_unit = $patient -> age_unit ;
$pt -> birthdate = $patient -> birthdate ;
$pt -> id_card = $patient -> id_card ;
$pt -> gender = $patient -> gender ;
$pt -> race = $patient -> race ;
$pt -> save ();
$model -> patient_id = $pt -> id ;
}
}
$patient -> save ( false );
if ( $model -> save ( false )) {
/* $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 (); */
Yii :: $app -> session -> addFlash ( 'success' , 'บันทึกข้อมูลการลงทะเบียน HPV เรียบร้อยแล้ว' );
}
//$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
]);
}
public function actionAutopsy ( $id_case )
{
$model = CaseAutopsy :: findOne ([ 'id_case' => $id_case ]);
$time_now = date ( 'Y-m-d H:i:s' );
if ( ! $model ) {
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่พบ Case นี้ในระบบ' );
return $this -> redirect ([ '/register/case/autopsy' ]);
}
$patient = Patient :: findOne ( $model -> patient_id );
//$patient->race = 'ไทย';
$model -> scenario = 'update' ;
$model -> autocomplete_hospital = $model -> hospital -> name ;
//$model->autocomplete_ward = isset($model->ward) ? $model->ward->name : '';
$model -> autocomplete_patient = isset ( $model -> patient ) ? $model -> patient -> getFullname () : '' ;
$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->validate();
$patient -> hospital_id = $model -> hospital_id ;
$patient -> save ( false );
/*
* บันทึก CASE NonGyn
*/
if ( $model -> status_id == 1 ) {
}
//อัพโหลดไฟล์ 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 = 3 ;
// $autopsy_diagnosis->pathologist_at = $outlab_at;
}
$autopsy_diagnosis -> id_case = $model -> id_case ;
$autopsy_diagnosis -> report_type = 'outlab' ;
$autopsy_diagnosis -> status_id = 3 ;
//$autopsy_diagnosis->pathologist_at = $outlab_at;
if ( $autopsy_diagnosis -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
var_dump ( $autopsy_diagnosis -> getFirstErrors ());
die ();
}
}
if ( empty ( $model -> register_id )) {
$model -> register_id = Yii :: $app -> user -> getId ();
}
if ( empty ( $model -> register_at )) {
$model -> register_at = date ( 'Y-m-d H:i:s' );
}
if ( empty ( $model -> receive_at )) {
$model -> receive_at = date ( 'Y-m-d H:i:s' );
}
if ( $model -> save ()) {
//$operate->save();
Yii :: $app -> pathology -> setLog ( 'Update' , 'แก้ไขข้อมูลคนไข้: ' . $model -> id_case , Yii :: $app -> user -> getId (), CaseAutopsy :: tableName ());
/* $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 ;
if ( $finance -> save ()) {
Yii :: $app -> session -> addFlash ( 'success' , 'บันทึกข้อมูลการเงินเรียบร้อยแล้ว' );
} else {
var_dump ( $finance -> getFirstErrors ());
die ();
} */
} else {
var_dump ( $model -> getFirstErrors ());
die ();
} //
/*
* บันทึกค่าตรวจ autopsy
*/
$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 ();
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่สามารถลงทะเบียน Case ได้' );
return $this -> redirect ([ '/register/case/autopsy' ]);
}
} // if post()
return $this -> render ( 'autopsy' , [
'model' => $model ,
'patient' => $patient ,
]);
}
/**
* ปรับปรุงข้อมุล NonGyn
* @ return \yii\web\Response | string
*/
public function actionNonGyn ( $id_case )
{
$model = CaseNonGyn :: findOne ([ 'id_case' => $id_case ]);
$time_now = date ( 'Y-m-d H:i:s' );
if ( ! $model ) {
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่พบ Case นี้ในระบบ' );
return $this -> redirect ([ '/register/case/non-gyn' ]);
}
2025-01-21 02:56:57 +00:00
$cyto_non_gyn_container = new CytoNonGynContainer ();
$cyto_non_gyn_container -> items = CytoNonGynContainer :: find () -> where ([ 'id_case' => $model -> id_case ]) -> all ();
2025-04-20 17:28:22 +00:00
2024-12-25 03:04:59 +00:00
$patient = Patient :: findOne ( $model -> patient_id );
//$patient->race = 'ไทย';
$model -> scenario = 'update' ;
//$model->autocomplete_hospital = $model->hospital->name;
$model -> autocomplete_hospital = isset ( $model -> hospital ) ? $model -> hospital -> name : '' ;
//$model->autocomplete_ward = isset($model->ward) ? $model->ward->name : '';
//$model->autocomplete_patient = $model->patient->getFullname();
$model -> autocomplete_patient = isset ( $model -> patient ) ? $model -> patient -> getFullname () : '' ;
$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' );
$model -> receive_at = empty ( $model -> receive_at ) ? date ( 'd/m/Y' ) : $model -> receive_at ;
$ng = Yii :: $app -> request -> post ();
//NonGynContainer
if ( isset ( $ng [ 'CytoNonGynContainer' ][ 'items' ]) && ( is_array ( $ng [ 'CytoNonGynContainer' ][ 'items' ]) ? count ( $ng [ 'CytoNonGynContainer' ][ 'items' ]) : 0 ) > 0 ) {
foreach ( $ng [ 'CytoNonGynContainer' ][ 'items' ] as $key => $value ) {
$non_gyn_container = CytoNonGynContainer :: findOne ([ 'id_case' => $model -> id_case , 'id' => $value [ 'id' ]]);
if ( ! $non_gyn_container ) {
$non_gyn_container = new CytoNonGynContainer ();
}
$non_gyn_container -> id_case = $model -> id_case ;
$non_gyn_container -> container_type = $value [ 'container_type' ];
$non_gyn_container -> amount = $value [ 'amount' ];
$non_gyn_container -> specimen_size = $value [ 'specimen_size' ];
$non_gyn_container -> remark = $value [ 'remark' ];
if ( $non_gyn_container -> save ( false )) {
}
}
} //NonGymContainer
$patient -> hospital_id = $model -> hospital_id ;
$patient -> save ( false );
/*
* บันทึก CASE NonGyn
*/
//อัพโหลดไฟล์ Request
$model -> files = $model -> uploadFile ( $model , 'files' );
//อัพโหลดภาพ Specimen Container
$model -> specimen_container_img = $model -> uploadSpecimenContainer ( $model , 'specimen_container_img' );
//อัพโหลดภาพ Outlab Report
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
//Upload Outlab Report
if ( $model -> is_outlab ) {
$model -> status_id = 7 ;
$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 = 3 ;
}
$non_gyn_diagnosis -> id_case = $model -> id_case ;
$non_gyn_diagnosis -> report_type = 'outlab' ;
$non_gyn_diagnosis -> status_id = 3 ;
$non_gyn_diagnosis -> outlab_report = $model -> outlab_report ;
if ( $non_gyn_diagnosis -> save ()) {
Yii :: $app -> session -> setFlash ( 'success' , 'บันทึก Outlab เรียบร้อย' );
} else {
var_dump ( $non_gyn_diagnosis -> getFirstErrors ());
var_dump ( $model -> getFirstErrors ());
die ();
}
}
if ( empty ( $model -> register_id )) {
$model -> register_id = Yii :: $app -> user -> getId ();
}
if ( empty ( $model -> register_at )) {
$model -> register_at = $time_now ;
}
if ( empty ( $model -> receive_at )) {
$model -> receive_at = $time_now ;
}
if ( $model -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Update' , 'แก้ไขข้อมูลคนไข้: ' . $model -> id_case , Yii :: $app -> user -> getId (), CaseNonGyn :: tableName ());
} 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 ) {
2025-04-01 09:27:47 +00:00
2024-12-25 03:04:59 +00:00
$transaction -> rollBack ();
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่สามารถลงทะเบียน Case ได้' );
2025-01-21 02:56:57 +00:00
/* var_dump ( $model -> getFirstErrors ());
die ();
throw new Exception ( $e -> getMessage ()); */
return $this -> redirect ([ '/register/case-update/non-gyn' , 'id_case' => $model -> id_case ]);
2024-12-25 03:04:59 +00:00
}
} // if post()
return $this -> render ( 'non-gyn' , [
'model' => $model ,
'patient' => $patient ,
2025-01-21 02:56:57 +00:00
'cyto_non_gyn_container' => $cyto_non_gyn_container ,
2024-12-25 03:04:59 +00:00
]);
}
/*
* Update Surgical
*/
public function actionSurgical ( $id_case )
{
$model = CaseSurgical :: findOne ([ 'id_case' => $id_case ]);
$time_now = date ( 'Y-m-d H:i:s' );
$model -> autocomplete_hospital = $model -> hospital -> name ;
//$model->autocomplete_ward = isset($model->ward) ? $model->ward->name : '';
//$model->autocomplete_patient = $model->patient->name;
$sc_surgical_container = new SurgicalContainer ();
$sc_surgical_container -> items = SurgicalContainer :: find () -> where ([ 'id_case' => $model -> id_case ]) -> all ();
$patient = $model -> patient ;
2025-04-01 15:25:25 +00:00
//$model->scenario = 'update';
2024-12-25 03:04:59 +00:00
$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 );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
//บันทึกผู้ป่วย
$patient -> hospital_id = $model -> hospital_id ;
$patient -> save ();
$sc = Yii :: $app -> request -> post ();
//SurgicalContainer
2025-03-22 08:09:27 +00:00
if ( isset ( $sc [ 'SurgicalContainer' ][ 'items' ]) && ( is_array ( $sc [ 'SurgicalContainer' ][ 'items' ]) ? count ( $sc [ 'SurgicalContainer' ][ 'items' ]) : 0 ) > 0 ) {
2024-12-25 03:04:59 +00:00
foreach ( $sc [ 'SurgicalContainer' ][ 'items' ] as $key => $value ) {
$surgical_container = SurgicalContainer :: findOne ([ 'id_case' => $model -> id_case , 'id' => $value [ 'id' ]]);
if ( ! $surgical_container ) {
$surgical_container = new SurgicalContainer ();
}
$surgical_container -> id_case = $model -> id_case ;
$surgical_container -> container_type = $value [ 'container_type' ];
$surgical_container -> amount = $value [ 'amount' ];
$surgical_container -> specimen_size = $value [ 'specimen_size' ];
$surgical_container -> remark = $value [ 'remark' ];
if ( $surgical_container -> save ( false )) {
}
}
2025-03-22 08:09:27 +00:00
} //SurgicalContainer
2024-12-25 03:04:59 +00:00
//อัพโหลดภาพ Specimen Container
$model -> specimen_container_img = $model -> uploadSpecimenContainer ( $model , 'specimen_container_img' );
//อัพโหลดไฟล์ Request
$model -> files = $model -> uploadFile ( $model , 'files' );
//ถ้าวัน receive ว่างให้บันทึกเป็นวันปัจจุบัน
$model -> receive_at = empty ( $model -> receive_at ) ? date ( 'd/m/Y' ) : $model -> receive_at ;
if ( ! empty ( $model -> case_reference )) {
$case_reference = CaseSurgical :: findOne ([ 'id_case' => $model -> case_reference ]);
if ( $case_reference ) {
if ( empty ( $model -> gross_description ) || $model -> is_re_reference == true ) {
$model -> gross_description = $case_reference -> gross_description ;
}
if ( empty ( $model -> microscopic_description ) || $model -> is_re_reference == true ) {
$model -> microscopic_description = $case_reference -> microscopic_description ;
}
if ( empty ( $model -> diagnosis ) || $model -> is_re_reference == true ) {
$model -> diagnosis = $case_reference -> diagnosis ;
}
if ( empty ( $model -> additional_diagnosis ) || $model -> is_re_reference == true ) {
$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' ;
//$non_gyn_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 ();
}
} */
$model -> outlab_report = $model -> uploadReport ( $model , 'outlab_report' );
//Upload Outlab Report
if ( $model -> is_outlab ) {
$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 = 3 ;
}
$surgical_diagnosis -> id_case = $model -> id_case ;
$surgical_diagnosis -> report_type = 'outlab' ;
$surgical_diagnosis -> status_id = 3 ;
//$surgical_diagnosis->is_outlab_release = 1;
//$model->outlab_report = $model->uploadReport($model, 'outlab_report');
//$surgical_diagnosis->outlab_report = $surgical_diagnosis->uploadReport($surgical_diagnosis, 'outlab_report');
$surgical_diagnosis -> outlab_report = $model -> outlab_report ;
//$surgical_diagnosis->pathologist_at = $outlab_at;
if ( $surgical_diagnosis -> save ()) {
//@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 {
var_dump ( $surgical_diagnosis -> getFirstErrors ());
var_dump ( $model -> getFirstErrors ());
die ();
}
}
// เปลี่ยนสถานะในหน้าส่งทำ Slide อย่างเดียว
if ( $model -> status_id == 10 ) {
$model -> status_at = date ( 'Y-m-d H:i:s' );
}
if ( empty ( $model -> register_id )) {
$model -> register_id = Yii :: $app -> user -> getId ();
}
if ( empty ( $model -> register_at )) {
$model -> register_at = date ( 'Y-m-d H:i:s' );
}
if ( $model -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Update' , 'แก้ไขข้อมูลคนไข้: ' . $model -> id_case , Yii :: $app -> user -> getId (), CaseSurgical :: tableName ());
} else {
var_dump ( $model -> getFirstErrors ());
die ();
} //
if ( $model -> is_histo_staining == 1 ) { //ส่งย้อม Histo
$staining = HistoStaining :: findOne ([ 'id_case' => $model -> id_case ]);
if ( ! $staining ) {
$staining = new HistoStaining ();
$staining -> id_case = $model -> id_case ;
$staining -> block_no = '' ;
$staining -> note = '' ;
$staining -> is_able = 0 ;
$staining -> is_routine = 0 ;
$staining -> status_1 = 1 ;
$staining -> in_at = $time_now ;
$staining -> save ();
}
}
if ( $model -> is_immuno_staining == 1 ) { //ส่งย้อม Immuno
$staining = ImmunoStaining :: findOne ([ 'id_case' => $model -> id_case ]);
if ( ! $staining ) {
$staining = new ImmunoStaining ();
$staining -> id_case = $model -> id_case ;
$staining -> block_no = '' ;
$staining -> note = '' ;
$staining -> status_1 = 1 ;
$staining -> is_able = 0 ;
$staining -> in_at = $time_now ;
$staining -> save ();
}
}
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'แก้ไขข้อมูลเรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/surgical' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
}
}
return $this -> render ( 'surgical' , [
'model' => $model ,
'patient' => $patient ,
'sc_surgical_container' => $sc_surgical_container ,
//'finance' => $finance,
//'surgical_operate' => $surgical_operate,
'case_next' => $this -> getNext ( $id_case ),
'case_previous' => $this -> getPrevious ( $id_case ),
]);
}
/* public function actionSurgicalContainerDelete ()
{
$s = Yii :: $app -> request -> post ();
$surgical_container = SurgicalContainer :: findOne ([ 'id_case' => $s [ 'id_case' ], 'id' => $s [ 'id' ]]);
if ( ! $surgical_container ) { // || !$immuno_staining_detail
echo 'error' ;
} else {
if ( $surgical_container ) {
$surgical_container -> delete ();
}
echo 'success' ;
}
} */
2025-04-01 09:27:47 +00:00
/** */
/*
* Update Staining Case
*/
2025-04-20 17:28:22 +00:00
2025-04-01 09:27:47 +00:00
public function actionExternal ( $id_case )
2025-04-20 17:28:22 +00:00
{
$model = CaseExternal :: findOne ([ 'id_case' => $id_case ]);
$time_now = date ( 'Y-m-d H:i:s' );
$model -> autocomplete_hospital = $model -> hospital -> name ;
//$model->autocomplete_ward = isset($model->ward) ? $model->ward->name : '';
//$model->autocomplete_patient = $model->patient->name;
$patient = $model -> patient ;
//$model->scenario = 'update';
$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 );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
//บันทึกผู้ป่วย
$patient -> hospital_id = $model -> hospital_id ;
$patient -> save ();
// เปลี่ยนสถานะในหน้าส่งทำ Slide อย่างเดียว
if ( $model -> status_id == 10 ) {
$model -> status_at = date ( 'Y-m-d H:i:s' );
}
if ( empty ( $model -> register_id )) {
$model -> register_id = Yii :: $app -> user -> getId ();
}
if ( empty ( $model -> register_at )) {
$model -> register_at = date ( 'Y-m-d H:i:s' );
}
if ( $model -> save ()) {
Yii :: $app -> pathology -> setLog ( 'Update' , 'แก้ไขข้อมูลคนไข้: ' . $model -> id_case , Yii :: $app -> user -> getId (), CaseSurgical :: tableName ());
} else {
var_dump ( $model -> getFirstErrors ());
die ();
} //
if ( $model -> is_histo_staining == 1 ) { //ส่งย้อม Histo
$staining = HistoStaining :: findOne ([ 'id_case' => $model -> id_case ]);
if ( ! $staining ) {
$staining = new HistoStaining ();
$staining -> id_case = $model -> id_case ;
$staining -> block_no = '' ;
$staining -> note = '' ;
$staining -> is_able = 0 ;
$staining -> is_routine = 0 ;
$staining -> status_1 = 1 ;
$staining -> in_at = $time_now ;
$staining -> save ();
}
}
if ( $model -> is_immuno_staining == 1 ) { //ส่งย้อม Immuno
$staining = ImmunoStaining :: findOne ([ 'id_case' => $model -> id_case ]);
if ( ! $staining ) {
$staining = new ImmunoStaining ();
$staining -> id_case = $model -> id_case ;
$staining -> block_no = '' ;
$staining -> note = '' ;
$staining -> status_1 = 1 ;
$staining -> is_able = 0 ;
$staining -> in_at = $time_now ;
$staining -> save ();
}
}
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'แก้ไขข้อมูลเรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/external' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
}
}
return $this -> render ( 'external' , [
'model' => $model ,
]);
}
/** */
public function actionExternalOld ( $id_case )
2025-04-01 09:27:47 +00:00
{
$time_now = date ( 'Y-m-d H:i:s' );
$model = CaseExternal :: findOne ([ 'id_case' => $id_case ]);
if ( ! $model ) {
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่มี Case นี้ในระบบ' );
return $this -> redirect ([ '/site/index' ]);
}
$model -> autocomplete_patient = '-' ;
$model -> autocomplete_title = '-55' ;
$patient = isset ( $model -> patient ) ? $model -> patient : new Patient ();
$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 ())) {
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
if ( $model -> status == 1 ) {
$model -> status_id = 16 ; //ยกเลิกcase
}
if ( $model -> status == 0 ) {
$model -> status_id = 1 ; //ยกเลิก การยกเลิกcase
}
$valid = true ;
if ( $model -> is_histo_staining == 0 && $model -> is_immuno_staining == 0 ) {
$model -> addError ( 'is_histo_staining' , 'กรุณาเลือกการย้อม' );
$model -> addError ( 'is_immuno_staining' , 'กรุณาเลือกการย้อม' );
$valid = false ;
}
//บันทึกผู้ป่วย
if ( intval ( $model -> patient_id )) { // เลือกผู้ป่วยที่มีอยู่แล้ว
$patient = Patient :: findOne ( $model -> patient_id );
$patient -> load ( Yii :: $app -> request -> post ());
$patient -> save ( false );
} else {
if ( $model -> autocomplete_patient == '-' ) {
$model -> patient_id = null ;
} else {
$patient = new Patient ();
$patient -> load ( Yii :: $app -> request -> post ()); //เมื่อมีการใส่ชื่อค่อยโหลด
$patient -> title_id = $_POST [ 'CaseExternal' ][ 'autocomplete_title' ];
$patient -> name = $model -> autocomplete_patient ; // หากเพิ่มผู้ป่วยใหม่ให้กำหนดชื่อให้ patient แล้วบันทึก
$patient -> create_at = $time_now ;
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
$patient -> save ( false );
$model -> patient_id = $patient -> id ;
}
}
if ( $model -> save ()) {
if ( $model -> is_histo_staining == 1 ) { //ส่งย้อม Histo
$staining = HistoStaining :: findOne ([ 'id_case' => $model -> id_case ]);
if ( ! $staining ) {
$staining = new HistoStaining ();
$staining -> id_case = $model -> id_case ;
$staining -> block_no = '' ;
$staining -> note = '' ;
$staining -> is_able = 0 ;
$staining -> is_routine = 0 ;
$staining -> status_1 = 1 ;
$staining -> in_at = $time_now ;
$staining -> save ();
}
} else {
$histo = HistoStaining :: findOne ([ 'id_case' => $model -> id_case ]);
if ( $histo ) {
foreach ( HistoStaining :: find () -> where ([ 'id_case' => $model -> id_case ]) -> all () as $hs ) {
$hifi = FinanceServiceCharge :: findOne ([ 'from_id' => $hs -> id , 'id_case' => $model -> id_case ]);
if ( $hifi ) {
$hifi -> delete ();
}
HistoStaining :: findOne ([ 'id_case' => $model -> id_case , 'id' => $hs -> id ]) -> delete ();
}
}
}
if ( $model -> is_immuno_staining == 1 ) { //ส่งย้อม Immuno
$staining = new ImmunoStaining ();
$staining -> id_case = $model -> id_case ;
$staining -> block_no = '' ;
$staining -> note = '' ;
$staining -> status_1 = 1 ;
$staining -> is_able = 0 ;
$staining -> in_at = $time_now ;
$staining -> save ();
} else {
$immu = ImmunoStaining :: findOne ([ 'id_case' => $model -> id_case ]);
if ( $immu ) {
foreach ( ImmunoStaining :: find () -> where ([ 'id_case' => $model -> id_case ]) -> all () as $is ) {
$imfi = FinanceServiceCharge :: findOne ([ 'from_id' => $is -> id , 'id_case' => $model -> id_case ]);
if ( $imfi ) {
$imfi -> delete ();
}
ImmunoStaining :: findOne ([ 'id_case' => $model -> id_case , 'id' => $is -> id ]) -> delete ();
}
}
}
}
//หากเปลี่ยน รพ. ให้ update all finance_service_charge ให้เป็น รพ.ใหม่ทั้งหมด
FinanceServiceCharge :: updateAll ([ 'hospital_id' => $model -> hospital_id ], 'id_case = \'' . $model -> id_case . '\'' );
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'แก้ไขข้อมูลเรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/external' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
}
}
2025-04-20 17:28:22 +00:00
return $this -> render ( 'external-old' , [
2025-04-01 09:27:47 +00:00
'model' => $model ,
'patient' => $patient ,
]);
}
/** */
2024-12-25 03:04:59 +00:00
public function actionSurgicalContainerDelete ()
{
Yii :: $app -> response -> format = \yii\web\Response :: FORMAT_JSON ;
$s = Yii :: $app -> request -> post ();
$surgical_container = SurgicalContainer :: findOne ([ 'id_case' => $s [ 'id_case' ], 'id' => $s [ 'id' ]]);
if ( ! $surgical_container ) {
return [
'status' => 'error' ,
'message' => 'Surgical container not found' ,
];
}
if ( $surgical_container -> delete ()) {
return [
'status' => 'success' ,
'message' => 'Surgical container deleted successfully' ,
];
} else {
return [
'status' => 'error' ,
'message' => 'Failed to delete surgical container' ,
];
}
}
public function actionCytoNonGynContainerDelete ()
{
Yii :: $app -> response -> format = \yii\web\Response :: FORMAT_JSON ;
$n = Yii :: $app -> request -> post ();
$non_gyn_container = CytoNonGynContainer :: findOne ([ 'id_case' => $n [ 'id_case' ], 'id' => $n [ 'id' ]]);
if ( ! $non_gyn_container ) {
return [
'status' => 'error' ,
'message' => 'Non-Gyn container not found' ,
];
}
if ( $non_gyn_container -> delete ()) {
return [
'status' => 'success' ,
'message' => 'Non-Gyn container deleted successfully' ,
];
} else {
return [
'status' => 'error' ,
'message' => 'Failed to delete non-gyn container' ,
];
}
}
/**
* @ param $id_case
* @ return false | string
*/
public function getNext ( $id_case )
{
$case_type = Yii :: $app -> pathology -> getCaseType ( $id_case );
if ( $case_type == 'surgical' ) {
$case = CaseSurgical :: findOne ([ 'id_case' => $id_case ]);
}
if ( $case_type == 'non-gyn' ) {
$case = CaseNonGyn :: findOne ([ 'id_case' => $id_case ]);
}
if ( $case_type == 'pap' ) {
$case = CasePap :: findOne ([ 'id_case' => $id_case ]);
}
2025-01-02 01:33:33 +00:00
if ( $case_type == 'frozen' ) {
$case = CaseFrozen :: findOne ([ 'id_case' => $id_case ]);
}
2024-12-25 03:04:59 +00:00
if ( $case_type ) {
$digit = explode ( '-' , $id_case );
$nextDigit = (( int ) $digit [ 1 ]); // change string to integer for +1
$nextDigit ++ ;
$nextDigit = str_pad ( $nextDigit , 6 , '0' , STR_PAD_LEFT );
$next_id_case = $digit [ 0 ] . '-' . $nextDigit ;
if ( $case_type == 'surgical' ) {
$next_case = CaseSurgical :: findOne ([ 'id_case' => $next_id_case ]);
}
if ( $case_type == 'non-gyn' ) {
$next_case = CaseNonGyn :: findOne ([ 'id_case' => $next_id_case ]);
}
if ( $case_type == 'pap' ) {
$next_case = CasePap :: findOne ([ 'id_case' => $next_id_case ]);
}
2025-01-02 01:33:33 +00:00
if ( $case_type == 'frozen' ) {
$next_case = CaseFrozen :: findOne ([ 'id_case' => $next_id_case ]);
}
2024-12-25 03:04:59 +00:00
if ( $next_case ) {
return $next_id_case ;
} else {
return false ;
}
} else {
return false ;
}
}
/**
* @ param $id_case
* @ return false | string
*/
public function getPrevious ( $id_case )
{
$case_type = Yii :: $app -> pathology -> getCase ( $id_case );
if ( $case_type == 'surgical' ) {
$case = CaseSurgical :: findOne ([ 'id_case' => $id_case ]);
}
if ( $case_type == 'non-gyn' ) {
$case = CaseNonGyn :: findOne ([ 'id_case' => $id_case ]);
}
if ( $case_type == 'pap' ) {
$case = CasePap :: findOne ([ 'id_case' => $id_case ]);
}
2025-01-02 01:33:33 +00:00
if ( $case_type == 'frozen' ) {
$case = CaseFrozen :: findOne ([ 'id_case' => $id_case ]);
}
2024-12-25 03:04:59 +00:00
if ( $case_type ) {
$digit = explode ( '-' , $id_case );
$previousDigit = (( int ) $digit [ 1 ]); // change string to integer for +1
$previousDigit -- ;
$previousDigit = str_pad ( $previousDigit , 6 , '0' , STR_PAD_LEFT );
$previous_id_case = $digit [ 0 ] . '-' . $previousDigit ;
if ( $case_type == 'surgical' ) {
$previous_case = CaseSurgical :: findOne ([ 'id_case' => $previous_id_case ]);
}
if ( $case_type == 'non-gyn' ) {
$previous_case = CaseNonGyn :: findOne ([ 'id_case' => $previous_id_case ]);
}
if ( $case_type == 'pap' ) {
$previous_case = CasePap :: findOne ([ 'id_case' => $previous_id_case ]);
}
2025-01-02 01:33:33 +00:00
if ( $case_type == 'frozen' ) {
$previous_case = CaseFrozen :: findOne ([ 'id_case' => $previous_id_case ]);
}
2024-12-25 03:04:59 +00:00
if ( isset ( $previous_case )) {
return $previous_id_case ;
} else {
return false ;
}
} else {
return false ;
}
}
/*
* หารายการ 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
];
}
protected function getCasePrefix ( $id_case )
{
return substr ( $id_case , 0 , 1 );
}
public function actionFileDel ( $file , $id , $id_case )
{
$case_type = Yii :: $app -> pathology -> getCaseType ( $id_case );
if ( $case_type === 'surgical' ) { //ลบไฟล์ Surgical
$model = CaseSurgical :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/surgical/file/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'surgical' , 'id_case' => $id_case ]);
}
if ( $case_type === 'non-gyn' ) { //ลบไฟล์ Surgical
$model = CaseNonGyn :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/cyto/non-gyn/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'non-gyn' , 'id_case' => $id_case ]);
}
if ( $case_type === 'pap' ) { //ลบไฟล์ Surgical
$model = CasePap :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/cyto/pap/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'pap' , 'id_case' => $id_case ]);
}
if ( $case_type === 'liquid-based' ) { //ลบไฟล์ Surgical
$model = CasePap :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/cyto/pap/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'pap' , 'id_case' => $id_case ]);
}
if ( $case_type === 'frozen' ) { //ลบไฟล์ frozen
$model = CaseFrozen :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/frozen/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'frozen' , 'id_case' => $id_case ]);
}
if ( $case_type === 'dish' ) { //ลบไฟล์ fish
$model = CaseDish :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/dish/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'dish' , 'id_case' => $id_case ]);
}
if ( $case_type === 'fish' ) { //ลบไฟล์ fish
$model = CaseFish :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/fish/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'fish' , 'id_case' => $id_case ]);
}
if ( $case_type === 'autopsy' ) { //ลบไฟล์ autopsy
$model = CaseAutopsy :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/autopsy/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'autopsy' , 'id_case' => $id_case ]);
}
if ( $case_type === 'flow' ) { //ลบไฟล์ flow
$model = CaseFlow :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/flow/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'flow' , 'id_case' => $id_case ]);
}
if ( $case_type === 'molecular' ) { //ลบไฟล์ molecular
$model = CaseMolecular :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/molecular/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'molecular' , 'id_case' => $id_case ]);
}
if ( $case_type === 'necropsy' ) { //ลบไฟล์ necropsy
$model = CaseNecropsy :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/necropsy/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'necropsy' , 'id_case' => $id_case ]);
}
}
public function actionDeleteGrossImg ( $img , $id_case )
{
$case_type = Yii :: $app -> pathology -> getCaseType ( $id_case );
if ( $case_type == 'surgical' ) { //ลบไฟล์ Surgical
$model = CaseSurgical :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> gross_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/surgical/gross/' . $img );
$files = implode ( ',' , $files );
$model -> gross_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/surgical' , 'id_case' => $id_case ]);
}
if ( $case_type == 'non-gyn' ) { //ลบไฟล์ Surgical
$model = CaseNonGyn :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> specimen_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/cyto/non-gyn/img/' . $img );
$files = implode ( ',' , $files );
$model -> specimen_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/non-gyn' , 'id_case' => $id_case ]);
}
if ( $case_type == 'pap' ) { //ลบไฟล์ Surgical
$model = CasePap :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> gross_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/cyto/pap/gross/' . $img );
$files = implode ( ',' , $files );
$model -> gross_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/pap' , 'id_case' => $id_case ]);
}
if ( $case_type == 'frozen' ) { //ลบไฟล์ frozen
$model = CaseFrozen :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> specimen_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/frozen/specimen/' . $img );
$files = implode ( ',' , $files );
$model -> specimen_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/frozen' , 'id_case' => $id_case ]);
}
if ( $case_type == 'dish' ) { //ลบไฟล์ dish
$model = CaseDish :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> specimen_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . 'uploads/dish/specimen' . $img );
$files = implode ( ',' , $files );
$model -> specimen_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/dish' , 'id_case' => $id_case ]);
}
if ( $case_type == 'molecular' ) { //ลบไฟล์ molecular
$model = CaseMolecular :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> specimen_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . 'uploads/molecular/specimen' . $img );
$files = implode ( ',' , $files );
$model -> specimen_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/molecular' , 'id_case' => $id_case ]);
}
if ( $case_type == 'autopsy' ) { //ลบไฟล์ autopsy
$model = CaseAutopsy :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> gross_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/autopsy/specimen/' . $img );
$files = implode ( ',' , $files );
$model -> gross_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/autopsy' , 'id_case' => $id_case ]);
}
}
public function actionDeleteSpecimenImg ( $img , $id_case )
{
$case_type = Yii :: $app -> pathology -> getCaseType ( $id_case );
if ( $case_type == 'surgical' ) { //ลบไฟล์ Surgical
$model = CaseSurgical :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> specimen_container_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/surgical/specimen-container-img/' . $img );
$files = implode ( ',' , $files );
$model -> specimen_container_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/surgical' , 'id_case' => $id_case ]);
}
if ( $case_type == 'non-gyn' ) { //ลบไฟล์ Surgical
$model = CaseNonGyn :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> specimen_container_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/cyto/non-gyn/specimen-container-img/' . $img );
$files = implode ( ',' , $files );
$model -> specimen_container_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/non-gyn' , 'id_case' => $id_case ]);
}
/* if ( $case_type == 'pap' ) { //ลบไฟล์ Surgical
$model = CasePap :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> specimen_container_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/cyto/pap/gross/' . $img );
$files = implode ( ',' , $files );
$model -> specimen_container_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/pap' , 'id_case' => $id_case ]);
} */
if ( $case_type == 'frozen' ) { //ลบไฟล์ frozen
$model = CaseFrozen :: findOne ([ 'id_case' => $id_case ]);
2025-03-22 11:17:18 +00:00
$files = explode ( ',' , $model -> specimen_container_img );
2024-12-25 03:04:59 +00:00
$files = array_diff ( $files , array ( $img ));
2025-03-22 11:17:18 +00:00
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/frozen/specimen-container-img/' . $img );
2024-12-25 03:04:59 +00:00
$files = implode ( ',' , $files );
2025-03-22 11:17:18 +00:00
$model -> specimen_container_img = $files ;
2024-12-25 03:04:59 +00:00
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/frozen' , 'id_case' => $id_case ]);
}
if ( $case_type == 'dish' ) { //ลบไฟล์ dish
$model = CaseDish :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> specimen_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . 'uploads/dish/specimen' . $img );
$files = implode ( ',' , $files );
$model -> specimen_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/dish' , 'id_case' => $id_case ]);
}
if ( $case_type == 'molecular' ) { //ลบไฟล์ molecular
$model = CaseMolecular :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> specimen_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . 'uploads/molecular/specimen' . $img );
$files = implode ( ',' , $files );
$model -> specimen_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/molecular' , 'id_case' => $id_case ]);
}
if ( $case_type == 'autopsy' ) { //ลบไฟล์ autopsy
$model = CaseAutopsy :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> specimen_container_img );
$files = array_diff ( $files , array ( $img ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/autopsy/specimen-container-img/' . $img );
$files = implode ( ',' , $files );
$model -> specimen_container_img = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'case-update/autopsy' , 'id_case' => $id_case ]);
}
}
public function actionReportDel ( $file , $id , $id_case )
{
$case_type = Yii :: $app -> pathology -> getCaseType ( $id_case );
if ( $case_type === 'surgical' ) { //ลบไฟล์ Surgical
$model = CaseSurgical :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> outlab_report );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/surgical/report/' . $file );
$files = implode ( ',' , $files );
$model -> outlab_report = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'surgical' , 'id_case' => $id_case ]);
}
if ( $case_type === 'non-gyn' ) { //ลบไฟล์ Surgical
$model = CaseNonGyn :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> outlab_report );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/cyto/report/' . $file );
$files = implode ( ',' , $files );
$model -> outlab_report = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'non-gyn' , 'id_case' => $id_case ]);
}
if ( $case_type === 'pap' ) { //ลบไฟล์ Surgical
$model = CasePap :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> outlab_report );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/cyto/report/' . $file );
$files = implode ( ',' , $files );
$model -> outlab_report = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'pap' , 'id_case' => $id_case ]);
}
if ( $case_type === 'liquid-based' ) { //ลบไฟล์ Surgical
$model = CasePap :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> outlab_report );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/cyto/report/' . $file );
$files = implode ( ',' , $files );
$model -> outlab_report = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'pap' , 'id_case' => $id_case ]);
}
2025-03-22 11:17:18 +00:00
/*
2024-12-25 03:04:59 +00:00
if ( $case_type === 'frozen' ) { //ลบไฟล์ frozen
$model = CaseFrozen :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/frozen/report/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
2025-03-22 11:17:18 +00:00
return $this -> redirect ([ 'frozen' , 'id_case' => $id_case ]);
} */
if ( $case_type === 'frozen' ) { //ลบไฟล์ Surgical
$model = CaseFrozen :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> outlab_report );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/frozen/report/' . $file );
$files = implode ( ',' , $files );
$model -> outlab_report = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
2024-12-25 03:04:59 +00:00
return $this -> redirect ([ 'frozen' , 'id_case' => $id_case ]);
}
if ( $case_type === 'dish' ) { //ลบไฟล์ fish
$model = CaseDish :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/dish/report/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'dish' , 'id_case' => $id_case ]);
}
if ( $case_type === 'fish' ) { //ลบไฟล์ fish
$model = CaseFish :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/fish/report/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'fish' , 'id_case' => $id_case ]);
}
if ( $case_type === 'autopsy' ) { //ลบไฟล์ autopsy
$model = CaseAutopsy :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> files );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/autopsy/report/' . $file );
$files = implode ( ',' , $files );
$model -> files = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'autopsy' , 'id_case' => $id_case ]);
}
if ( $case_type === 'flow' ) { //ลบไฟล์ flow
$model = CaseFlow :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> outlab_report );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/flow/report/' . $file );
$files = implode ( ',' , $files );
$model -> outlab_report = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'flow' , 'id_case' => $id_case ]);
}
if ( $case_type === 'molecular' ) { //ลบไฟล์ molecular
$model = CaseMolecular :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> outlab_report );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/molecular/report/' . $file );
$files = implode ( ',' , $files );
$model -> outlab_report = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'molecular' , 'id_case' => $id_case ]);
}
if ( $case_type === 'necropsy' ) { //ลบไฟล์ necropsy
$model = CaseNecropsy :: findOne ([ 'id_case' => $id_case ]);
$files = explode ( ',' , $model -> outlab_report );
$files = array_diff ( $files , array ( $file ));
@ unlink ( Yii :: getAlias ( '@webroot' ) . '/uploads/necropsy/report/' . $file );
$files = implode ( ',' , $files );
$model -> outlab_report = $files ;
$model -> save ();
Yii :: $app -> session -> setFlash ( 'success' , 'ลบไฟล์เรียบร้อยแล้ว' );
return $this -> redirect ([ 'necropsy' , 'id_case' => $id_case ]);
}
}
/*
* ค้นหารหัสต่อไป
* เลือกเอารหัสล่าสุดแล้วบวกเพิ่มอีก 1
*/
protected function getIdCase ( $case )
{
$year = substr ( date ( 'Y' ) + 543 , 2 );
$prefix = [ 'N' => 'N' , 'C' => 'C' , 'S' => 'S' ,];
if ( $case == 'S' ) {
$lastRecord = CaseSurgical :: find () -> where ([
'like' ,
'id_case' ,
'S' . $year . '-'
])
-> orderBy ([
'id' => SORT_DESC
])
-> one ();
}
if ( $case = 'C' ) {
$lastRecord = CasePap :: find () -> where ([ 'like' , 'id_case' , 'C' . $year . '-' ])
-> orderBy ([ 'id' => SORT_DESC ]) -> one ();
}
if ( $case == 'N' ) {
$lastRecord = CaseNonGyn :: find () -> where ([ 'like' , 'id_case' , 'N' . $year . '-' ])
-> orderBy ([ 'id' => 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 = '000001' ;
}
return $prefix [ $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 ;
}
public function actionEmpty ( $id = NULL , $id_case = NULL , $hospital_id = NULL )
{
if ( ! $id ) {
$p = new Patient ();
$p -> title_id = 3 ;
$p -> race = 'ไทย' ;
$p -> name = '***รอแก้ไข***' ;
$p -> age = 1 ;
$p -> age_unit = 'ปี' ;
$p -> hospital_id = $hospital_id ;
$p -> save ( false );
return $this -> redirect ([ 'empty' , 'id' => $p -> id , 'id_case' => $id_case ]);
}
if ( $id != " " and $id_case != '' ) {
$case_type = Yii :: $app -> pathology -> getCaseType ( $id_case );
$lab = substr ( $id_case , 0 , 1 );
switch ( $case_type ) {
case 'surgical' :
$model = CaseSurgical :: findOne ([ 'id_case' => $id_case ]);
$model -> patient_id = $id ;
$model -> save ( false );
return $this -> redirect ([ 'case-update/surgical' , 'id_case' => $id_case ]);
break ;
case 'pap' :
$model = CasePap :: findOne ([ 'id_case' => $id_case ]);
$model -> patient_id = $id ;
$model -> save ( false );
return $this -> redirect ([ 'case-update/pap' , 'id_case' => $id_case ]);
break ;
case 'non-gyn' :
$model = CaseNonGyn :: findOne ([ 'id_case' => $id_case ]);
$model -> patient_id = $id ;
$model -> save ( false );
return $this -> redirect ([ 'case-update/non-gyn' , 'id_case' => $id_case ]);
break ;
}
}
}
/**
* ปรับปรุงข้อมุล molecular
* @ return \yii\web\Response | string
*/
public function actionMolecular ( $id_case )
{
$model = CaseMolecular :: findOne ([ 'id_case' => $id_case ]);
$time_now = date ( 'Y-m-d H:i:s' );
if ( ! $model ) {
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่พบ Case นี้ในระบบ' );
return $this -> redirect ([ '/register/case/molecular' ]);
}
//$operate = CytoOperate::findOne(['id_case' => $model->id_case]);
//$finance = $model->finance;
//$patient = $model->patient;
/* $finance = FinanceServiceCharge :: find () -> joinWith ([ 'charge' ])
-> andFilterWhere ([ 'id_case' => $model -> id_case , 'const_service_charge.lab' => 'molecular' ]) -> one (); //$model->finance;
if ( ! $finance ) {
$finance = new FinanceServiceCharge ([ 'id_case' => $model -> id_case ]);
}
$finance -> scenario = 'update_register' ; */
$patient = Patient :: findOne ( $model -> patient_id );
//$patient->race = 'ไทย';
$model -> autocomplete_hospital = $model -> hospital -> name ;
//$model->autocomplete_ward = isset($model->ward) ? $model->ward->name : '';
$model -> autocomplete_patient = $model -> patient -> getFullname ();
$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 ())
//$operate->load(Yii::$app->request->post()) &&
//$patient->load(Yii::$app->request->post()) &&
// $finance->load(Yii::$app->request->post())
) {
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
$time_now = date ( 'Y-m-d H:i:s' );
// บันทึกผู้ป่วยก่อน Patient
/* if ( intval ( $model -> patient_id )) { // ถ้ามีผู้ป่วยอยู่แล้วก็ Select มา
$patient = Patient :: findOne ( $model -> patient_id );
} else { // ถ้ายังไม่มีก็ให้ Save ใหม่
if ( empty ( $patient -> age )) {
$patient -> age = 0 ;
}
$patient -> name = $model -> patient_id ;
$patient -> save ();
} */
// ได้ $patient->id ล่ะ
//$patient->validate();
$patient -> hospital_id = $model -> hospital_id ;
$patient -> save ( false );
/* if ( $patient -> save ()){
echo 'yes' ;
} else {
echo 'no' ;
} */
/*
* บันทึก CASE NonGyn
*/
//$model->patient_id = $patient->id;
//$model->status_id = 1;
if ( $model -> status_id == 1 ) {
//$cyto_operate = CytoOperate::findOne(['id_case' => $model->id_case]);
//$cyto_operate->register_at = $time_now;
//$cyto_operate->save();
}
$model -> files = $model -> uploadFile ( $model , 'files' );
$model -> specimen_img = $model -> uploadGross ( $model , 'specimen_img' );
if ( $model -> specimen_img != $model -> getOldAttribute ( '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' );
if ( $model -> save ()) {
//$operate->save();
if ( empty ( $model -> register_id )) {
$model -> register_id = Yii :: $app -> user -> getId ();
}
if ( empty ( $model -> register_at )) {
$model -> register_at = date ( 'Y-m-d H:i:s' );
}
if ( empty ( $model -> receive_at )) {
$model -> receive_at = date ( 'Y-m-d H:i:s' );
}
/* $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 ; */
/* if ( $finance -> save ()) {
Yii :: $app -> session -> addFlash ( 'success' , 'บันทึกข้อมูลการเงินเรียบร้อยแล้ว' );
} else {
var_dump ( $finance -> getFirstErrors ());
die ();
} */
} else {
var_dump ( $model -> getFirstErrors ());
die ();
} //
/*
* บันทึกค่าตรวจ NonGyn
*/
$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 ();
Yii :: $app -> session -> setFlash ( 'error' , 'ไม่สามารถลงทะเบียน Case ได้' );
return $this -> redirect ([ '/register/case/molecular' ]);
}
} // if post()
return $this -> render ( 'molecular' , [
'model' => $model ,
'patient' => $patient ,
//'finance' => $finance,
//'operate' => $operate,
//'case_next' => $this->getNext($id_case),
//'case_previous' => $this->getPrevious($id_case),
]);
}
/**
* ปรับปรุงข้อมุล necropsy
* @ return \yii\web\Response | string
*/
public function actionNecropsy ( $id_case )
{
$model = CaseNecropsy :: findOne ([ 'id_case' => $id_case ]);
$time_now = date ( 'Y-m-d H:i:s' );
$model -> autocomplete_hospital = $model -> hospital -> name ;
$patient = $model -> patient ;
$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 );
return $result ;
}
if ( $model -> load ( Yii :: $app -> request -> post ())) {
$transaction = Yii :: $app -> db -> beginTransaction ();
try {
//บันทึกผู้ป่วย
$patient -> hospital_id = $model -> hospital_id ;
$patient -> save ();
$model -> gross_img = $model -> uploadGross ( $model , 'gross_img' );
if ( $model -> gross_img != $model -> getOldAttribute ( 'gross_img' )) {
$model -> gross_img_at = date ( 'Y-m-d H:i:s' );
$model -> gross_img_update_id = Yii :: $app -> user -> getId ();
}
$model -> files = $model -> uploadFile ( $model , 'files' );
//if case reference
//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' ;
}
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' );
// เปลี่ยนสถานะในหน้าส่งทำ Slide อย่างเดียว
if ( $model -> status_id == 10 ) {
$model -> status_at = date ( 'Y-m-d H:i:s' );
}
if ( empty ( $model -> register_id )) {
$model -> register_id = Yii :: $app -> user -> getId ();
}
if ( empty ( $model -> register_at )) {
$model -> register_at = date ( 'Y-m-d H:i:s' );
}
if ( empty ( $model -> receive_at )) {
$model -> receive_at = date ( 'Y-m-d H:i:s' );
}
$model -> save ();
$transaction -> commit ();
Yii :: $app -> session -> setFlash ( 'success' , 'แก้ไขข้อมูลเรียบร้อยแล้ว' );
return $this -> redirect ([ '/register/case-update/necropsy' , 'id_case' => $model -> id_case ]);
} catch ( Exception $e ) {
$transaction -> rollBack ();
}
}
return $this -> render ( 'necropsy' , [
'model' => $model ,
'patient' => $patient ,
]);
}
/**
* 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-20 17:28:22 +00:00
}