2024-10-16 19:18:52 +05:30
< ? php
include ( 'includes/config/config.php' );
include ( 'includes/functions.php' );
include ( 'log_entry.php' );
error_log ( " Start Printing Request Attributes " );
$requestStr = " " ;
foreach ( $_REQUEST as $key => $value ) {
$requestStr .= $key . " : " . $value . " \n " ;
error_log ( $key . " : " . $value . " <br /> \r \n " );
}
error_log ( " End Printing Request Attributes " );
save_log ( $requestStr , 'Sickness' , 'SAVE' , 'save_sickness_form.php' );
error_reporting ( 0 );
// error_log("Request sickness_id id :".$_REQUEST['id']);
// error_log("Request sickness_id sickness_id p:".$_POST['sickness_id']);
// $id = ($_REQUEST['id']!=''?$_REQUEST['id']:$_REQUEST['sickness_id']);
if ( isset ( $_REQUEST [ 'sickness_id' ])) {
$id = $_REQUEST [ 'sickness_id' ];
} else {
$id = $_REQUEST [ 'flex_sickness_id' ];
}
error_log ( " Request sickness_id: " . $id );
if ( isset ( $_REQUEST [ 'sickness_id' ])) {
$emp_id = $_REQUEST [ 'emp_id' ];
} else {
$emp_id = $_REQUEST [ 'flex_opd_id' ];
}
error_log ( " sickness_id: " . $id );
$sbp = $_POST [ 'sbp' ];
$dbp = $_POST [ 'dbp' ];
$bp = ( $sbp + ( 2 * ( $dbp ))) / 3 ;
$sickness_date = $_POST [ 'appointment_date' ];
$token_no = $_POST [ 'token_no' ];
$in_time = $_POST [ 'appointment_date' ];
$out_time = $_POST [ 'out_time' ];
$from_date = $_POST [ 'date_absent' ];
$to_date = $_POST [ 'date_absent_to' ];
error_log ( '$from_date ' . $_POST [ 'date_absent' ]);
$date_absent = $_POST [ 'date_absent' ];
$date_absent_to = $_POST [ 'date_absent_to' ];
$date_return = $_POST [ 'date_return' ];
$agency = $_POST [ 'agency' ];
$ailment = $_POST [ 'ailment' ];
$des = $_POST [ 'des' ];
$attended_status = $_POST [ 'sickness_status' ];
$fitness_status = $_POST [ 'approval_status' ];
$ticket_no = $_POST [ 'past_ticket_no' ];
$comments = $_POST [ 'injury_remarks' ];
$ref_no = $_POST [ 'doc_ref_no' ];
$des_dis = $_POST [ 'des_dis' ];
$des_sick = $_POST [ 'des_sick' ];
$des_future = $_POST [ 'des_future' ];
$followup_to_opd = $_POST [ 'appointment_id' ];
$followup_id = $_POST [ 'followup_id' ];
$justifiable_from = $_POST [ 'justifiable_from' ];
$justifiable_to = $_POST [ 'justifiable_to' ];
$date_just_from = $_POST [ 'date_absents' ];
$date_justifiable_to = $_POST [ 'date_returns' ];
$date_not_just = $_POST [ 'date_not_just' ];
$date_not_just_to = $_POST [ 'date_not_just_to' ];
$approval_date = $_POST [ 'approval_date' ];
// error_reporting(E_ERROR | E_PARSE);
$height = $_POST [ 'height' ];
$weight = $_POST [ 'weight' ];
$pulse = $_POST [ 'heart_rate' ];
$blood_group = $_POST [ 'blood_group' ];
$nose = $_POST [ 'nose' ];
$throat = $_POST [ 'throat' ];
$rs = $_POST [ 'rs' ];
$cvs = $_POST [ 'cvs' ];
$ch_uex = $_POST [ 'ch_uex' ];
$ch_ex = $_POST [ 'ch_ex' ];
$half_day_value = $_POST [ 'define_half_day' ];
if ( $half_day_value == 1 || $half_day_value == 2 ) {
$half_day = 1 ;
} else {
$half_day = 0 ;
}
$cns = $_POST [ 'cns' ];
$purpose = $_POST [ 'purpose' ];
$certificate_type = $_POST [ 'certificate_type' ];
error_log ( $nose . " NOSE " );
$ailment_ids_new = strtoupper ( $_POST [ 'ailment_new' ]);
error_log ( " ailment_ids_new: " . $ailment_ids_new );
$diagnosis_config = getFieldFromTable ( 'value' , 'config' , 'key_name' , 'diagnosis_tag_switch' );
if ( ! strcmp ( strtolower ( $diagnosis_config ), " true " )) {
$ailment_ids_new = handleDynamicMasterInsertModified ( " ailment " , " ailment_name " , " ailment_id " , $ailment_ids_new , true );
error_log ( " ailment_ids_new: " . implode ( ',' , $ailment_ids_new ));
$ailment_ids_new = getMultiValuedSelectData ( $ailment_ids_new );
error_log ( " ailment_ids_new2: " . $ailment_ids_new );
}
$ailment_system = implode ( ',' , $_POST [ 'ailment_system_new' ]);
$attended_doctor = null ;
if ( $_SESSION [ 'RoleCode' ] == " DOC " ) {
$attended_doctor = $_SESSION [ 'logged_user_empid' ];
}
if ( empty ( $id )) {
if ( ! empty ( $_POST [ 'approval_date' ])) {
// here updating fitness value for old sickness
$pending_sick = " SELECT * FROM sickness where sickness_id = (SELECT max(sickness_id) FROM sickness where emp_id=' " . addslashes ( $_REQUEST [ 'emp_id' ]) . " ') and attended_status ='DRP' and fitness_status !='APPROVED' " ;
error_log ( " 2nd query select pending max id of sickness: " . $pending_sick );
$result_pending_sick = @ mysqli_query ( $conn , $pending_sick );
if ( mysqli_num_rows ( $result_pending_sick ) > 0 ) {
while ( $row_pending_sick = mysqli_fetch_assoc ( $result_pending_sick )) {
if (( $_POST [ 'date_absent' ] == null || $_POST [ 'date_absent' ] == '0000-00-00' || empty ( $_POST [ 'date_absent' ])) && ( $_POST [ 'date_absent_to' ] == null || $_POST [ 'date_absent_to' ] == '0000-00-00' || empty ( $_POST [ 'date_absent_to' ])) && ( $row_pending_sick [ 'approval_date' ] != null || $row_pending_sick [ 'approval_date' ] != '0000-00-00' )) {
$update_old_sick = " update sickness set approval_date=STR_TO_DATE(' " . $_POST [ 'approval_date' ] . " ','%d/%m/%Y') ,fitness_status=' " . $_POST [ 'approval_status' ] . " ',des=' " . $_POST [ 'des' ] . " ',attended_status=' " . $_POST [ 'sickness_status' ] . " ' where sickness_id=' " . $row_pending_sick [ 'sickness_id' ] . " ' " ;
error_log ( " update old sickness: " . $update_old_sick );
if ( ! $result_old_sick = @ mysqli_query ( $conn , $update_old_sick )) {
2024-11-02 18:03:13 +05:30
die ( error_log ( mysqli_error ( $conn )));
2024-10-16 19:18:52 +05:30
}
}
}
} else {
// user adding only fitness without previous sickness availale
if ( empty ( $date_absent ) && empty ( $date_absent_to )) {
$ticket_no = creatingTicketNofitness ();
$insert_fitness = " insert into sickness set ailment_system=' " . addslashes ( $ailment_system ) . " ',ailment_name=' " . addslashes ( $ailment_ids_new ) . " ',sickness_date = STR_TO_DATE(' " . $sickness_date . " ', '%d/%m/%Y %h:%i %p'), from_date = STR_TO_DATE(' " . $in_time . " ', '%d/%m/%Y'),to_date = STR_TO_DATE(' " . $out_time . " ', '%d/%m/%Y'),sickness_name=' $ailment_system ',des=' $des ' , emp_id=' " . $emp_id . " ',doctor_reference_no = ' $ref_no ',des_dis=' $des_dis ',des_sick=' $des_sick ',des_future=' $des_future ',ohc_type_id=' " . $_SESSION [ 'current_ohcttype' ] . " ',doctor_last_attended=' $attended_doctor ',attended_status=' $attended_status ',approval_date= STR_TO_DATE(' " . $approval_date . " ', '%d/%m/%Y'),followup_id=' " . $followup_id . " ',followup_to_opd=' $followup_to_opd ',fitness_status=' $fitness_status ',comments=' " . addslashes ( $comments ) . " ',token_no=' $token_no ',ticket_no=' $ticket_no ', modified_by=' " . $_SESSION [ 'user_id' ] . " ' , height = ' $height ' , weight = ' $weight ' , pulse = ' $pulse ' , chest_ex = ' $ch_ex ',chest_uex=' $ch_uex ', rs = ' $rs ' , cvs = ' $cvs ', bp =' $bp ' , throat = ' $throat ' , blood = ' $blood_group ' , nose = ' $nose ' , cns = ' $cns ' , purpose = ' $purpose ' " ;
error_log ( " fitness query without sickness data " . $insert_fitness );
if ( ! mysqli_query ( $conn , $insert_fitness )) {
error_log ( " error in saving fitnees data only " . $insert_fitness );
}
}
}
}
if ( empty ( $_POST [ 'date_absent' ]) && empty ( $_POST [ 'date_absent_to' ])) {
goto go_to_last_no_need_to_do_anything_else ;
}
}
$query_initial = " " ;
$query_end = " " ;
$query = " " ;
if ( ! empty ( $date_absent ) && ! empty ( $date_absent_to )) {
if ( ! empty ( $id )) {
$query_initial = " update sickness " ;
$query_end = " where sickness_id = $id " ;
} else {
$query_initial = " insert into sickness " ;
$ticket_no = creatingTicketNofitness ();
}
}
$query = " set ailment_system=' " . addslashes ( $ailment_system ) . " ',ailment_name=' " . addslashes ( $ailment_ids_new ) . " ',sickness_date = STR_TO_DATE(' " . $sickness_date . " ', '%d/%m/%Y %h:%i %p'), from_date = STR_TO_DATE(' " . $in_time . " ', '%d/%m/%Y'),
to_date = STR_TO_DATE ( '" . $out_time . "' , '%d/%m/%Y' ), justifiable_from = STR_TO_DATE ( '" . $justifiable_from . "' , '%d/%m/%Y' ), justifiable_to = STR_TO_DATE ( '" . $justifiable_to . "' , '%d/%m/%Y' ),
not_justifiable_from = STR_TO_DATE ( '" . $date_not_just . "' , '%d/%m/%Y' ), not_justifiable_to = STR_TO_DATE ( '" . $date_not_just_to . "' , '%d/%m/%Y' ), agency = '$agency' , sickness_name = '$ailment_system' , des = '$des' , emp_id = '" . $emp_id . "' , doctor_reference_no = '$ref_no' , des_dis = '$des_dis' , des_sick = '$des_sick' , des_future = '$des_future' ,
ohc_type_id = '" . $_SESSION[' current_ohcttype '] . "' , doctor_last_attended = '$attended_doctor' , attended_status = '$attended_status' , approval_date = STR_TO_DATE ( '" . $approval_date . "' , '%d/%m/%Y' ), followup_id = '" . $followup_id . "' , followup_to_opd = '$followup_to_opd' ,
fitness_status = '$fitness_status' , comments = '" . addslashes($comments) . "' , token_no = '$token_no' , ticket_no = '$ticket_no' , modified_by = '" . $_SESSION[' user_id '] . "' , height = '$height' , weight = '$weight' , pulse = '$pulse' , chest_ex = '$ch_ex' , chest_uex = '$ch_uex' , rs = '$rs' , cvs = '$cvs' , bp = '$bp' , throat = '$throat' , blood = '$blood_group' , nose = '$nose' , cns = '$cns' , purpose = '$purpose' , certificate_type = '$certificate_type' " ;
if ( ! empty ( $half_day_value ) && $half_day_value != 0 ) {
$query .= " ,half_day=' $half_day ',half_day_value=' " . $half_day_value . " ' " ;
}
if ( ! empty ( $date_absent )) {
$query .= " ,date_absent = STR_TO_DATE(' " . $date_absent . " ', '%d/%m/%Y') " ;
}
if ( ! empty ( $date_absent_to )) {
$query .= " ,date_absent_to = STR_TO_DATE(' " . $date_absent_to . " ', '%d/%m/%Y'),date_return = STR_TO_DATE(' " . $date_absent_to . " ', '%d/%m/%Y') " ;
}
if ( ! empty ( $date_absent ) && ! empty ( $date_absent_to )) {
$query = $query_initial . " " . $query . " " . $query_end ;
error_log ( " sickness main query " . $query );
if ( ! $result = @ mysqli_query ( $conn , $query )) {
2024-11-02 18:03:13 +05:30
die ( error_log ( mysqli_error ( $conn )));
2024-10-16 19:18:52 +05:30
}
}
go_to_last_no_need_to_do_anything_else :
$data = array ();
if ( empty ( $id )) {
$query = " select max(sickness_id) sickness_id from sickness where emp_id = ' " . addslashes ( $_REQUEST [ 'emp_id' ]) . " ' " ;
error_log ( " last query to get data : " . $query );
if ( ! $result = @ mysqli_query ( $conn , $query )) {
2024-11-02 18:03:13 +05:30
die ( error_log ( mysqli_error ( $conn )));
2024-10-16 19:18:52 +05:30
}
if ( mysqli_num_rows ( $result ) > 0 ) {
while ( $row = mysqli_fetch_assoc ( $result )) {
$data [ 'sickness_id' ] = $row ;
// $sickness_id = $row['sickness_id'];
}
}
} else {
$data [ 'sickness_id' ] = $_REQUEST [ 'sickness_id' ];
}
error_log ( " data: " . print_r ( $data , true ));
echo json_encode ( $data );