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 time: " . date ( 'Y-m-d H:i:s' ));
// 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, 'Save Checkup Form', 'SAVE', 'save_checkup_form.php');
// error_log('$POST :' . print_r($_POST, true));
error_log ( " entered into save form " );
error_reporting ( E_ERROR | E_PARSE );
list ( $height_id , $weight_id , $bmi_id ) = explode ( " , " , $_REQUEST [ 'height_weight_bmi' ]);
updateHeightWeightBmi ( $_REQUEST [ $height_id ], $_REQUEST [ $weight_id ], $_REQUEST [ $bmi_id ], $_REQUEST [ 'emp_id' ]);
$highlight_color = [];
$checkup_id = $_POST [ 'checkup_id' ];
// error_log("checkup_section" . $checkup_id);
$role_code = $_SESSION [ 'RoleCode' ];
$checkdown_date = $_POST [ 'checkdown_date' ];
$checkup_type_id = $_POST [ 'checkup_type_id' ];
$ysql = " select * from checkup_form where checkup_id=' " . $checkup_id . " ' " ;
$yresult = mysqli_query ( $conn , $ysql );
$yrow = mysqli_fetch_array ( $yresult );
$checkup_type_id_db = $yrow [ 'checkup_type_id' ];
// error_log("checkup_type_id" . $checkup_type_id);
// echo $checkup_id;
$checkup_section = $_POST [ 'checkup_section_ids' ];
// error_log("checkup_section" . $checkup_section);
$checkup_section_ids = implode ( ',' , array_unique ( $checkup_section ));
if ( $checkup_section_ids == " " || $checkup_section_ids == Null ) {
// error_log("enter the check up sections");
echo json_encode ( " FAILURE " );
2024-11-02 18:03:13 +05:30
die ( mysqli_error ( $conn ));
2024-10-16 19:18:52 +05:30
} else {
//echo "checkup_section_ids" . $checkup_section_ids;
$emp_id = $_REQUEST [ 'checkup_emp_id' ];
$patient_id = $emp_id ;
// echo $emp_id;
// error_log("type of date " . gettype($checkdown_date));
$valid_upto = $_POST [ 'valid_upto_date' ];
$approve_date = $_POST [ 'approve_date' ];
$remarks = $_POST [ 'remarks' ];
if ( $_POST [ 'checkup_type_id' ] != " " ) {
$checkup_type_id = $_POST [ 'checkup_type_id' ];
} else {
$checkup_type_id = 0 ;
}
$ticket_no = $_REQUEST [ 'ticket_no' ];
// echo $ticket_no;
$health_risk_id = strtoupper ( $_POST [ 'health_risk_name' ]);
$health_risk_id = handleDynamicMasterInsert ( " health_risk " , " health_risk_name " , " health_risk_id " , $health_risk_id , true );
// error_log("health_risk_id:" . implode(',', $health_risk_id));
$health_risk_id = getMultiValuedSelectData ( $health_risk_id );
// error_log("health_risk_id2:" . $health_risk_id);
$health_advice_id = strtoupper ( $_POST [ 'health_advice_name' ]);
$health_advice_id = handleDynamicMasterInsert ( " health_advice " , " health_advice_name " , " health_advice_id " , $health_advice_id , true );
// error_log("health_advice_id:" . implode(',', $health_advice_id));
$health_advice_id = getMultiValuedSelectData ( $health_advice_id );
// error_log("health_advice_id2:" . $health_advice_id);
$past_present_illness = strtoupper ( $_POST [ 'past_present_illness_data' ]);
$past_present_illness = handleDynamicMasterInsert ( " history_parameter " , " param_name " , " param_id " , $past_present_illness , true );
// error_log("past_present_illness:" . implode(',', $past_present_illness));
$past_present_illness = getMultiValuedSelectData ( $past_present_illness );
// error_log("past_present_illness:" . $past_present_illness);
$abnormalities_data_val = strtoupper ( $_POST [ 'abnormalities_data' ]);
$abnormalities_data_val = handleDynamicMasterInsert ( " abnormality " , " abnormality_name " , " abnormality_id " , $abnormalities_data_val , true );
// error_log("abnormalities_data:" . implode(',', $abnormalities_data_val));
$abnormalities_data_val = getMultiValuedSelectData ( $abnormalities_data_val );
// error_log("abnormalities_data:" . $abnormalities_data_val);
$habits_data_val = $_POST [ 'habits_data' ];
$habits_data_val = handleDynamicMasterInsertIgnoreCase ( " habits " , " habit " , " habit_id " , $habits_data_val , true );
// error_log("habits_data:" . implode(',', $habits_data_val));
$habits_data_val = getMultiValuedSelectData ( $habits_data_val );
// error_log("habits_data:" . $habits_data_val);
$fit_status = $_POST [ 'fit_state' ];
$program_id = $_POST [ 'program_id' ];
$program_status = $_POST [ 'program_status' ];
$health_score = $_POST [ 'health_index' ];
$referred_by_doc = $_POST [ 'ref_by_doc' ];
$query_initial = " " ;
$query_mid = " " ;
$endquery = " " ;
$tobacco_1 = " 10 " ;
$_SESSION [ 'status' ] = $status ;
begin ();
$status = $_POST [ 'attendedStatus' ];
// error_log('-ATENDED' . $status);
if ( empty ( $status )) {
if ( $_SESSION [ 'RoleCode' ] == 'LAB' ) {
$status = $__STATUS_MEDICAL_ATTENDED ;
// error_log("entered for Lab");
} elseif ( $_SESSION [ 'RoleCode' ] == 'DOC' ) {
$status = $__STATUS_DOCTOR_ATTENDED ;
// error_log("entered for Doc");
} elseif ( $_SESSION [ 'RoleCode' ] == 'RCP' ) {
$status = $__STATUS_RECEPTIONIST_ATTENDED ;
// error_log("entered for Rcp");
}
}
$comment = $_POST [ 'comments' ];
$findings = $_POST [ 'findings' ];
$doc_findings = $_POST [ 'doc_findings' ];
$doc_comments = $_POST [ 'doc_comments' ];
$attended_by = $_SESSION [ 'logged_user_empid' ];
$department = getFieldFromTable ( 'dept_id' , 'patient_master' , 'id' , $emp_id );
$designation = getFieldFromTable ( 'designation_id' , 'patient_master' , 'id' , $emp_id );
// error_log("program id " . $program_id);
if ( ! empty ( $program_id ) && $program_id != '' ) {
$check_previous_program_query = " select program_id from checkup_form where program_id =' " . $program_id . " ' and emp_id=' " . $emp_id . " ' and program_status = 'N' " ;
$result_program_query = mysqli_query ( $conn , $check_previous_program_query );
error_log ( " previous query " . $check_previous_program_query );
$row_program_query = mysqli_fetch_assoc ( $result_program_query );
$check_previous_program = $row_program_query [ 'program_id' ];
error_log ( " previous schedule pro " . $check_previous_program . " bool " . empty ( $check_previous_program ));
if ( empty ( $check_previous_program )) {
if ( ! empty ( $checkup_id )) {
$schedule_id = getFieldFromTable ( 'program_id' , 'checkup_form' , 'checkup_id' , $checkup_id );
error_log ( " schedule id: " . $schedule_id );
2024-11-19 09:59:09 +05:30
if ( $schedule_id != '0' && $schedule_id != null ) {
2024-10-16 19:18:52 +05:30
$assign_training_id = getTableFieldValue ( 'assign_training' , 'assign_training_id' , 'employee_id' , $emp_id , 'training_schedule_id' , $schedule_id );
error_log ( " assign training id outside: " . $assign_training_id );
if ( ! empty ( $assign_training_id )) {
$initquery_pro = " update " ;
$endquery_pro = " where assign_training_id = ' " . $assign_training_id . " ' " ;
} else {
$initquery_pro = " insert into " ;
}
$query_program = $initquery_pro . " assign_training set credit_to = '3',employee_id=' $emp_id ',training_schedule_id=' $program_id ' ,date_assigned=now() $endquery_pro " ;
$result_program = mysqli_query ( $conn , $query_program );
error_log ( " query_program " . $query_program );
if ( ! empty ( $assign_training_id )) {
$new_schedule_id = getTableFieldValue ( 'assign_training' , 'training_schedule_id' , 'assign_training_id' , $assign_training_id , 'employee_id' , $emp_id );
$assign_training_id_new = getTableFieldValue ( 'assign_training' , 'assign_training_id' , 'employee_id' , $emp_id , 'training_schedule_id' , $new_schedule_id );
} else {
$assign_training_id_new = mysqli_insert_id ( $conn );
}
error_log ( " assign training id after updating or inserting : " . $assign_training_id_new );
if ( ! empty ( $assign_training_id_new )) {
//update case
$query_delete_employee_assign_training = " delete from employee_assign_training where assign_training_id=' $assign_training_id_new ' " ;
error_log ( " delete query " . $query_delete_employee_assign_training );
@ mysqli_query ( $conn , $query_delete_employee_assign_training );
}
$query_employee_assign_training = " insert into employee_assign_training set emp_id=' $emp_id ' ,assign_training_id=' $assign_training_id_new ',training_schedule_id=' $program_id ' ,assign_date=now() " ;
error_log ( " query_employee_assign_training " . $query_employee_assign_training );
$result_employee_assign_training = mysqli_query ( $conn , $query_employee_assign_training );
}
}
}
}
// if (!empty(addslashes($health_risk_id))) {
// updatePatientHealthInfo($patient_id, 'RSK', addslashes($health_risk_id), $checkdown_date, '', 0);
// }
// if (!empty(addslashes($health_advice_id))) {
// updatePatientHealthInfo($patient_id, 'ADC', addslashes($health_advice_id), $checkdown_date, '', 0);
// }
// if (!empty(addslashes($past_present_illness))) {
// updatePatientHealthInfo($patient_id, 'PPI', addslashes($past_present_illness), $checkdown_date, '', 0);
// }
// if (!empty(addslashes($abnormalities_data_val))) {
// updatePatientAbnormalityInfo($patient_id, $abnormalities_data_val, $checkdown_date);
// }
if ( ! empty ( $habits_data_val )) {
updatePatientHealthInfo ( $patient_id , 'HBT' , addslashes ( $habits_data_val ), $checkdown_date , '' , 0 );
}
if ( ! empty ( $checkup_id )) {
$query_initial = " update checkup_form set " ;
$endquery = " where checkup_id = ' " . $checkup_id . " ' " ;
$select_query = " select checkup_type_id from checkup_form " . $endquery . " ; " ;
} else {
$query_initial = " insert into checkup_form set checkup_type_id=' " . $checkup_type_id . " ',ohc_type_id=' " . $_SESSION [ 'current_ohcttype' ] . " ', " ;
$select_query = " " ;
}
if ( $role_code == 'DOC' ) {
$query = $select_query . $query_initial . " ticket_no =' $ticket_no ',checkup_section_ids=' " . $checkup_section_ids . " ', checkup_date=STR_TO_DATE(' " . $_POST [ 'checkdown_date' ] . " ','%d/%m/%Y %h:%i %p'),approve_date=STR_TO_DATE(' " . $_POST [ 'approve_date' ] . " ','%d/%m/%Y %h:%i %p'),valid_upto=STR_TO_DATE(' " . $_POST [ 'valid_upto_date' ] . " ','%d/%m/%Y'),emp_id=' $emp_id ',health_risk_id=' " . addslashes ( $health_risk_id ) . " ',health_advice_id=' " . addslashes ( $health_advice_id ) . " ',past_present_illness=' " . addslashes ( $past_present_illness ) . " ',abnormality_ids = ' " . addslashes ( $abnormalities_data_val ) . " ',habit_ids=' " . addslashes ( $habits_data_val ) . " ',doc_findings=' $doc_findings ',doc_comments=' $doc_comments ',findings=' $findings ',comments=' $comment ',current_status=' $status ',remarks=' $remarks ',fit_unfit_status=' $fit_status ',program_id=' $program_id ',health_index=' " . $health_score . " ',program_status=' $program_status ',bmi=' $bmi ',isHyperTensed=' $isHyperTensed ',is_test_completed=' $is_test_completed ',doc_attend=' " . $_SESSION [ 'logged_user_empid' ] . " ',department=' " . $department . " ',designation=' " . $designation . " ',modified_by=' " . $_SESSION [ 'user_id' ] . " ' " . $endquery ;
} else if ( $role_code == 'ELAB' ) {
if ( $status == 'DRP' ) {
$app_id = getTableFieldValue ( 'checkup_form' , 'appointment_id' , 'checkup_id' , $checkup_id );
$doc_q = " update employee_appointment set attended_status='DRP' ,doctor_attended_flag='N' where appointment_id=' " . $app_id . " ' " ;
error_log ( 'move to doc' . $doc_q );
if ( ! $result_doc = @ mysqli_query ( $conn , $doc_q )) {
2024-11-02 18:03:13 +05:30
die ( mysqli_error ( $conn ));
2024-10-16 19:18:52 +05:30
}
$query = $select_query . $query_initial . " ticket_no =' $ticket_no ',checkup_section_ids=' " . $checkup_section_ids . " ', checkup_date=STR_TO_DATE(' " . $_POST [ 'checkdown_date' ] . " ','%d/%m/%Y %h:%i %p'),approve_date=STR_TO_DATE(' " . $_POST [ 'approve_date' ] . " ','%d/%m/%Y %h:%i %p'),valid_upto=STR_TO_DATE(' " . $_POST [ 'valid_upto_date' ] . " ','%d/%m/%Y'),emp_id=' $emp_id ',health_risk_id=' " . addslashes ( $health_risk_id ) . " ',health_advice_id=' " . addslashes ( $health_advice_id ) . " ',past_present_illness=' " . addslashes ( $past_present_illness ) . " ',abnormality_ids = ' " . addslashes ( $abnormalities_data_val ) . " ',habit_ids=' " . addslashes ( $habits_data_val ) . " ',doc_findings=' $doc_findings ',doc_comments=' $doc_comments ',findings=' $findings ',comments=' $comment ',current_status='MRA',remarks=' $remarks ',fit_unfit_status=' $fit_status ',program_id=' $program_id ',health_index=' " . $health_score . " ',program_status=' $program_status ',bmi=' $bmi ',isHyperTensed=' $isHyperTensed ',is_test_completed=' $is_test_completed ',doc_attend=' " . $_SESSION [ 'logged_user_empid' ] . " ',referred_by=' " . $referred_by_doc . " ',department=' " . $department . " ',designation=' " . $designation . " ',modified_by=' " . $_SESSION [ 'user_id' ] . " ' " . $endquery ;
} else {
$query = $select_query . $query_initial . " ticket_no =' $ticket_no ',checkup_section_ids=' " . $checkup_section_ids . " ', checkup_date=STR_TO_DATE(' " . $_POST [ 'checkdown_date' ] . " ','%d/%m/%Y %h:%i %p'),approve_date=STR_TO_DATE(' " . $_POST [ 'approve_date' ] . " ','%d/%m/%Y %h:%i %p'),valid_upto=STR_TO_DATE(' " . $_POST [ 'valid_upto_date' ] . " ','%d/%m/%Y'),emp_id=' $emp_id ',health_risk_id=' " . addslashes ( $health_risk_id ) . " ',health_advice_id=' " . addslashes ( $health_advice_id ) . " ',past_present_illness=' " . addslashes ( $past_present_illness ) . " ',abnormality_ids = ' " . addslashes ( $abnormalities_data_val ) . " ',habit_ids=' " . addslashes ( $habits_data_val ) . " ',doc_findings=' $doc_findings ',doc_comments=' $doc_comments ',findings=' $findings ',comments=' $comment ',current_status=' $status ',remarks=' $remarks ',fit_unfit_status=' $fit_status ',program_id=' $program_id ',health_index=' " . $health_score . " ',program_status=' $program_status ',bmi=' $bmi ',isHyperTensed=' $isHyperTensed ',is_test_completed=' $is_test_completed ',doc_attend=' " . $_SESSION [ 'logged_user_empid' ] . " ',referred_by=' " . $referred_by_doc . " ',department=' " . $department . " ',designation=' " . $designation . " ',modified_by=' " . $_SESSION [ 'user_id' ] . " ' " . $endquery ;
}
} else {
$query = $select_query . $query_initial . " ticket_no =' $ticket_no ',checkup_section_ids=' " . $checkup_section_ids . " ', checkup_date=STR_TO_DATE(' " . $_POST [ 'checkdown_date' ] . " ','%d/%m/%Y %h:%i %p'),approve_date=STR_TO_DATE(' " . $_POST [ 'approve_date' ] . " ','%d/%m/%Y %h:%i %p'),valid_upto=STR_TO_DATE(' " . $_POST [ 'valid_upto_date' ] . " ','%d/%m/%Y'),emp_id=' $emp_id ',health_risk_id=' " . addslashes ( $health_risk_id ) . " ',health_advice_id=' " . addslashes ( $health_advice_id ) . " ',past_present_illness=' " . addslashes ( $past_present_illness ) . " ',abnormality_ids = ' " . addslashes ( $abnormalities_data_val ) . " ',habit_ids=' " . addslashes ( $habits_data_val ) . " ',doc_findings=' $doc_findings ',doc_comments=' $doc_comments ',findings=' $findings ',comments=' $comment ',current_status=' $status ',remarks=' $remarks ',health_index=' " . $health_score . " ',fit_unfit_status=' $fit_status ',program_id=' $program_id ',program_status=' $program_status ',bmi=' $bmi ',isHyperTensed=' $isHyperTensed ',is_test_completed=' $is_test_completed ', medical_attend = ' " . $_SESSION [ 'logged_user_empid' ] . " ',referred_by=' " . $referred_by_doc . " ',department=' " . $department . " ',designation=' " . $designation . " ',modified_by=' " . $_SESSION [ 'user_id' ] . " ' " . $endquery ;
}
error_log ( " save check up form or update query " . $query );
if ( ! $result = $conn -> multi_query ( $query )) {
error_log ( " query failed: ( " . $conn -> errno . " ) " . $conn -> error );
} else if ( ! empty ( $checkup_id )) {
do {
if ( $result = $conn -> store_result ()) {
while ( $row = $result -> fetch_row ()) {
$select_checkup_type_id = $row [ 0 ];
}
$result -> free ();
}
} while ( $conn -> next_result ());
}
// echo $query;
if ( ! empty ( $checkup_id )) {
$id = $checkup_id ;
} else {
$id = $conn -> insert_id ;
}
$sql_for_checkup_field = " select column_name from checkup_parameter where checkup_form_section_id IN ( " . implode ( " , " , $checkup_section ) . " ) and enabled='Y' " ;
$result_for_checkup_field = $conn -> query ( $sql_for_checkup_field );
$insert_query_key_value = " " ;
$update_query_key_value = " " ;
// prepare statement start
$sql_for_checkup = " select * from checkup_form_key_value where checkup_form_id = ? and checkup_form_key=? " ;
$stmt_for_checkup = $conn -> prepare ( $sql_for_checkup );
$query_initial_key_value = " insert into checkup_form_key_value set checkup_form_id=?, checkup_form_key=?,checkup_form_value=? " ;
$update_query_key_value = " update checkup_form_key_value set checkup_form_value=? " ;
$endquery_key_value = " where checkup_form_id = ? and checkup_form_key=? " ;
$stmt_insert_query_key_value = $conn -> prepare ( $query_initial_key_value );
$stmt_update_query_key_value = $conn -> prepare ( $update_query_key_value . $endquery_key_value );
//end
// error_log("Saving or updating start in checkup form key value at " . microtime(true));
while ( $row_for_checkup_field = mysqli_fetch_array ( $result_for_checkup_field )) {
$row_value = $row_for_checkup_field [ 'column_name' ];
$row_insert_value = getMultiValuedSelectData ( $_REQUEST [ $row_value ]);
if ( $row_insert_value == '' ) {
$row_insert_value = $_REQUEST [ $row_value ];
}
if ( $select_checkup_type_id == $checkup_type_id ) {
if ( ! empty ( $checkup_id )) {
// error_log("getting already saved values start form checkup form key value at " . microtime(true));
$stmt_for_checkup -> bind_param ( " ss " , $checkup_id , $row_value );
$stmt_for_checkup -> execute ();
$result22 = $stmt_for_checkup -> get_result ();
$row22 = $result22 -> fetch_assoc ();
$nrows = $result22 -> num_rows ;
// error_log("got already saved values end form checkup form key value at " . microtime(true));
if ( $nrows == 0 ) {
if ( $row_insert_value != null && $row_insert_value != '' ) {
$highlight_color [ $row_value ] = $_REQUEST [ 'color_' . $row_value ];
// error_log("insertion start at " . microtime(true));
$stmt_insert_query_key_value -> bind_param ( " sss " , $id , $row_value , $row_insert_value );
$stmt_insert_query_key_value -> execute ();
if ( $stmt_insert_query_key_value -> errno ) {
error_log ( " Some error while saving key value data: " . $stmt_insert_query_key_value -> error );
rollback ();
}
}
// error_log("insertion start end " . microtime(true));
// error_log("Making insert because checkup exists but key value data does not exist");
} else {
if ( ! empty ( trim ( $row22 [ 'checkup_form_value' ])) || ! empty ( trim ( $row_insert_value ))) {
// error_log("old val ". $row22['checkup_form_value'] . " new val ".$row_insert_value);
// error_log("updating start at " . microtime(true));
$highlight_color [ $row_value ] = $_REQUEST [ 'color_' . $row_value ];
if ( trim ( $row22 [ 'checkup_form_value' ]) != trim ( $row_insert_value )) {
$stmt_update_query_key_value -> bind_param ( " sss " , $row_insert_value , $id , $row_value );
$stmt_update_query_key_value -> execute ();
if ( $stmt_update_query_key_value -> errno ) {
error_log ( " Some error while saving key value data: " . $stmt_update_query_key_value -> error );
rollback ();
}
}
// error_log("updating end at " . microtime(true));
}
// error_log("Making update because checkup exists and key value data also exist");
}
} else {
if ( $row_insert_value != null && $row_insert_value != '' ) {
$highlight_color [ $row_value ] = $_REQUEST [ 'color_' . $row_value ];
// error_log("insertion start at " . microtime(true));
$stmt_insert_query_key_value -> bind_param ( " sss " , $id , $row_value , $row_insert_value );
$stmt_insert_query_key_value -> execute ();
if ( $stmt_insert_query_key_value -> errno ) {
error_log ( " Some error while saving key value data: " . $stmt_insert_query_key_value -> error );
rollback ();
}
}
}
}
}
// error_log("Saving or updating end in checkup form key value at " . microtime(true));
// Additional Parameter saving logic start
// error_log("Saving or updating additional start in checkup form key value at " . microtime(true));
$add_param_ids = trim ( getFieldFromTable ( 'add_param_ids' , 'checkup_form' , 'checkup_id' , $id ));
error_log ( " additional param " . $add_param_ids );
if ( ! empty ( $add_param_ids )) {
$sql_add_param = " select * from checkup_parameter a where a.checkup_parameter_id in ( " . $add_param_ids . " ) " ;
error_log ( " additional param query " . $sql_add_param );
$result_add_param = mysqli_query ( $conn , $sql_add_param );
while ( $row_add_param = mysqli_fetch_assoc ( $result_add_param )) {
$row_value = $row_add_param [ 'column_name' ];
$row_insert_value = getMultiValuedSelectData ( $_REQUEST [ $row_value ]);
if ( $row_insert_value == '' ) {
$row_insert_value = $_REQUEST [ $row_value ];
}
if ( ! empty ( $checkup_id )) {
// error_log("getting already saved values start form checkup form key value at " . microtime(true));
$stmt_for_checkup -> bind_param ( " ss " , $checkup_id , $row_value );
$stmt_for_checkup -> execute ();
$result22 = $stmt_for_checkup -> get_result ();
$row22 = $result22 -> fetch_assoc ();
$nrows = $result22 -> num_rows ;
// error_log("got already saved values end form checkup form key value at " . microtime(true));
if ( $nrows == 0 ) {
if ( $row_insert_value != null && $row_insert_value != '' ) {
$highlight_color [ $row_value ] = $_REQUEST [ 'color_' . $row_value ];
// error_log("insertion start at " . microtime(true));
$stmt_insert_query_key_value -> bind_param ( " sss " , $id , $row_value , $row_insert_value );
$stmt_insert_query_key_value -> execute ();
if ( $stmt_insert_query_key_value -> errno ) {
error_log ( " Some error while saving key value data: " . $stmt_insert_query_key_value -> error );
rollback ();
}
}
// error_log("insertion end at " . microtime(true));
// error_log("Making insert because checkup exists but key value data does not exist");
} else {
if ( ! empty ( trim ( $row22 [ 'checkup_form_value' ])) || ! empty ( trim ( $row_insert_value ))) {
// error_log("old val ". $row22['checkup_form_value'] . " new val ".$row_insert_value);
$highlight_color [ $row_value ] = $_REQUEST [ 'color_' . $row_value ];
// error_log("updating start at " . microtime(true));
if ( trim ( $row22 [ 'checkup_form_value' ]) != trim ( $row_insert_value )) {
$stmt_update_query_key_value -> bind_param ( " sss " , $row_insert_value , $id , $row_value );
$stmt_update_query_key_value -> execute ();
if ( $stmt_update_query_key_value -> errno ) {
error_log ( " Some error while saving key value data: " . $stmt_update_query_key_value -> error );
rollback ();
}
}
}
// error_log("updating end at " . microtime(true));
}
} else {
if ( $row_insert_value != null && $row_insert_value != '' ) {
$highlight_color [ $row_value ] = $_REQUEST [ 'color_' . $row_value ];
// error_log("insertion start at " . microtime(true));
$stmt_insert_query_key_value -> bind_param ( " sss " , $id , $row_value , $row_insert_value );
$stmt_insert_query_key_value -> execute ();
if ( $stmt_insert_query_key_value -> errno ) {
error_log ( " Some error while saving key value data: " . $stmt_insert_query_key_value -> error );
rollback ();
}
}
// error_log("insertion end at " . microtime(true));
}
}
}
// error_log("Saving or updating additional end in checkup form key value at " . microtime(true));
//end
if ( $stmt_for_checkup != null ) {
$stmt_for_checkup -> close ();
}
if ( $stmt_insert_query_key_value != null ) {
$stmt_insert_query_key_value -> close ();
}
if ( $stmt_update_query_key_value != null ) {
$stmt_update_query_key_value -> close ();
}
$rows_highlighted = " DELETE FROM medical_examination_highlighted where medical_exam_id = ? " ;
$stmt_rows_highlighted = $conn -> prepare ( $rows_highlighted );
$stmt_rows_highlighted -> bind_param ( " s " , $id );
$stmt_rows_highlighted -> execute ();
if ( $stmt_rows_highlighted -> errno ) {
error_log ( " deleteHighlightedParams: " . $stmt_rows_highlighted -> error );
}
if ( ! empty ( $_REQUEST [ 'hiddenHighlighter' ])) {
$keys = array_keys ( $highlight_color );
// error_log("array keys for highlighted param " . print_r($keys, true));
$color_query = " insert into medical_examination_highlighted set medical_exam_id=?, highlighted_fields=?, highlighted_color =? " ;
$stmt_color_query = $conn -> prepare ( $color_query );
// error_log("insertion for color start at " . microtime(true));
2024-11-02 18:03:13 +05:30
for ( $i = 0 ; $i < count ( $keys ); $i ++ ) {
2024-10-16 19:18:52 +05:30
if ( ! empty ( $highlight_color [ $keys [ $i ]])) {
$stmt_color_query -> bind_param ( " sss " , $id , $keys [ $i ], $highlight_color [ $keys [ $i ]]);
$stmt_color_query -> execute ();
if ( $stmt_color_query -> errno ) {
error_log ( " saveHighlightedParams: " . $stmt_color_query -> error );
rollback ();
}
}
}
// error_log("insertion for color end at " . microtime(true));
$stmt_color_query -> close ();
}
commit ();
mysqli_close ( $conn );
// echo $sql1;
echo json_encode ( $id );
error_log ( " end time: " . date ( 'Y-m-d H:i:s' ));
}