2024-10-16 19:18:52 +05:30
< ? php
include ( 'includes/config/config.php' );
include ( 'includes/functions.php' );
$data = array ();
$sql_patient_physical_parameters = " select a.*,b.* from checkup_form a left join patient_master b on b.id=a.emp_id where a.checkup_id=' " . $_REQUEST [ 'checkup_id' ] . " ' " ;
//echo $sql_patient_physical_parameters;
error_log ( " PARAMS: " . $sql_patient_physical_parameters );
if ( ! $result_patient_physical_parameters = @ mysqli_query ( $conn , $sql_patient_physical_parameters )) {
2024-11-02 18:03:13 +05:30
die ( mysqli_error ( $conn ));
2024-10-16 19:18:52 +05:30
}
//echo mysqli_num_rows($result_stock_issue_item);
if ( mysqli_num_rows ( $result_patient_physical_parameters ) > 0 ) {
while ( $row_patient_physical_parameters = mysqli_fetch_assoc ( $result_patient_physical_parameters )) {
$row_patient_physical_parameters [ 'checkup_date' ] = date_format ( date_create ( $row_patient_physical_parameters [ 'checkup_date' ]), " d-M-Y " );
if ( ! empty ( $row_patient_physical_parameters [ 'doj' ])){ $row_patient_physical_parameters [ 'doj' ] = date_format ( date_create ( $row_patient_physical_parameters [ 'doj' ]), " d-M-Y " );
} else {
$row_patient_physical_parameters [ 'doj' ] = '' ;
}
$row_patient_physical_parameters [ 'designation' ] = getFieldFromTable ( 'designation_name' , 'designation' , 'designation_id' , $row_patient_physical_parameters [ 'designation_id' ]);
$row_patient_physical_parameters [ 'dept' ] = getFieldFromTable ( 'dept_name' , 'department' , 'dept_id' , $row_patient_physical_parameters [ 'dept_id' ]);
$row_patient_physical_parameters [ 'bu_name' ] = getTableFieldValue ( 'bussiness_unit' , 'bu_name' , 'bu_id' , $row_patient_physical_parameters [ 'bu_id' ], '' );
$row_patient_physical_parameters [ 'dob' ] =! empty ( $row_patient_physical_parameters [ 'dob' ]) ? date_format ( date_create ( $row_patient_physical_parameters [ 'dob' ]), " d-M-Y " ) : '' ;
$row_patient_physical_parameters [ 'age' ] = " " ;
if ( ! empty ( $row_patient_physical_parameters [ 'dob' ])) {
$dob = $row_patient_physical_parameters [ 'dob' ];
$row_patient_physical_parameters [ 'age' ] = ( date ( 'Y' ) - date ( 'Y' , strtotime ( $dob )));
}
$row_patient_physical_parameters [ 'gender' ] = $row_patient_physical_parameters [ 'gender' ] == 'm' || $row_patient_physical_parameters [ 'gender' ] == 'M' ? 'MALE' : 'FEMALE' ;
$data [ 'checkup_form' ] = $row_patient_physical_parameters ;
// $sql_sign = "select * from employee_signature where emp_id='" . $row_patient_physical_parameters['doc_attend'] . "'";
// $result_sign = mysqli_query($conn, $sql_sign);
// $row_sign = mysqli_fetch_assoc($result_sign);
// error_log("sign query " . $sql_sign);
// $data['approval']=$row_sign;
// parameters and sections
$checkup_section_ids = $row_patient_physical_parameters [ 'checkup_section_ids' ];
$param_present = ( explode ( ',' , $row_patient_physical_parameters [ 'checkup_section_ids' ]));
$param_present = array_unique ( $param_present );
$data [ 'sections' ] = $param_present ;
$data [ 'sections_count' ] = count ( $param_present );
foreach ( $param_present as $x => $val ) {
$data [ 'sections-' . $val ] = getFieldFromTable ( 'section_name' , 'checkup_form_section' , 'section_id' , $val );
$units = 0 ;
$ranges = 0 ;
$notes = '' ;
$comments = '' ;
$notes .= getTableFieldValue ( 'checkup_form_section' , 'notes' , 'section_id' , $val );
$comments .= ( getTableFieldValue (
'checkup_form_section' ,
'comments' ,
'section_id' ,
$val
));
$param_n = 0 ;
//query to load fields for each section
$sql_param = " select a.*,b.* from checkup_parameter a left join checkup_form_key_value b on a.column_name = b.checkup_form_key where checkup_form_id = ' $checkup_id ' and checkup_form_section_id = ' $val ' order by column_order " ;
error_log ( " //query to load fields for each section@@@@@@@!!!! " . $sql_param );
$result_param = mysqli_query ( $conn , $sql_param );
$param_name = array ();
$param_id = array ();
$param_ranges = array ();
$param_value = array ();
$param_unit = array ();
$min = array ();
$max = array ();
while ( $row_param = mysqli_fetch_assoc ( $result_param )) {
array_push ( $param_name , $row_param [ 'parameter_name' ]);
array_push ( $param_id , $row_param [ 'column_name' ]);
array_push ( $min , $row_param [ 'starting_range' ]);
array_push ( $max , $row_param [ 'ending_range' ]);
array_push ( $param_ranges , trim ( $row_param [ 'ref_ranges' ]));
array_push ( $param_unit , getFieldFromTable ( 'unit_name' , 'checkup_parameter_unit_master' , 'unit_id' , $row_param [ 'unit' ]));
if ( $row_param [ 'input_type' ] == 'select' ) {
array_push ( $param_value , getFieldFromTable ( 'parameter_value_name' , 'checkup_parameter_value' , 'parameter_value_id' , $row_param [ 'checkup_form_value' ]));
} else if ( $row_param [ 'input_type' ] == 'multiselect' ) {
array_push ( $param_value , getCommaSeperatedValuesForInClause ( " select parameter_value_name from checkup_parameter_value " , 'parameter_value_id' , $row_param [ 'checkup_form_value' ]));
} else {
array_push ( $param_value , $row_param [ 'checkup_form_value' ]);
}
}
$sql_group_ids = " select count(distinct(a.group_id)) as field_value from checkup_parameter a left join checkup_form_key_value b on a.column_name = b.checkup_form_key where checkup_form_id = ' $checkup_id ' and checkup_form_section_id = ' $val ' order by column_order " ;
$result_grp = mysqli_query ( $conn , $sql_group_ids );
$row_grp = mysqli_fetch_assoc ( $result_grp );
$total_group_ids = $row_grp [ 'field_value' ];
//echo 'hellooooooooooooooooooo';
error_log ( " total group ids: " . $total_group_ids );
$group_ids = array ();
for ( $i = 1 ; $i <= $total_group_ids ; $i ++ ) {
$group_id = " select count(group_id) from checkup_parameter where group_id = ' $i ' and enabled!='N' and checkup_form_section_id = ' $val ' " ;
error_log ( " group id len query: " . $group_id );
$result_group_id = mysqli_query ( $conn , $group_id );
$row_group_id = mysqli_fetch_array ( $result_group_id );
array_push ( $group_ids , $row_group_id [ '0' ]);
}
$max_len = max ( $group_ids );
error_log ( " max len : " . $max_len );
error_log ( " group ids : " . print_r ( $group_ids , true ));
$k = 0 ;
for ( $i = 0 ; $i < $total_group_ids ; $i ++ ) {
$grp = $i + 1 ;
$tital = getTableFieldValue ( 'checkup_parameter_group' , 'group_tital' , 'group_section' , $val , 'group_no' , $grp );
if (( $tital != '' || $tital != null ) && ( $param_value [ $k ] != 0 || $param_value [ $k ] != null || $param_value [ $k ] != '' )) {
if (( $tital != '' || $tital != null ) && ( $param_value [ $k ] != 0 || $param_value [ $k ] != null || $param_value [ $k ] != '' )) {
$data [ $val . '-' . $k . '-tital' ] = $tital ;
}
}
$value = $group_ids [ $i ];
$value2 = $max_len - $value ;
while ( $value != 0 ) {
if ( $param_value [ $k ] != null && $param_value [ $k ] != '' ) {
$param_n ++ ;
$data [ $val . '-' . $k . '-param_name' ] = $param_name [ $k ] ;
$color = '' ;
$color = getTableFieldValue ( 'medical_examination_highlighted' , 'highlighted_color' , 'highlighted_fieils' , " ' " . $param_id [ $k ] . " ' " , 'medical_exam_id' , $checkup_id );
$data [ $val . '-' . $k . '-color' ] = $color ;
$data [ $val . '-' . $k . '-value' ] = $param_value [ $k ];
if ( $param_unit [ $k ] != '' && $param_unit [ $k ] != null ) {
$units ++ ;
}
if ( is_numeric ( $param_value [ $k ]) == 1 ) {
$data [ $val . '-' . $k . '-unit' ] = $param_unit [ $k ];
} else {
$data [ $val . '-' . $k . '-unit' ] = $param_unit [ $k ];
}
if ( $param_ranges [ $k ] != '' && $param_ranges [ $k ] != null ) {
$ranges ++ ;
}
$rangs = explode ( '$' , $param_ranges [ $k ]);
for ( $r = 0 ; $r < count ( $rangs ); $r ++ ) {
if ( $rangs != null && $rangs != '' ) {
$data [ $val . '-' . $k . '-range' ] = '<p>' . $rangs [ $r ] . '</p>' ;
}
}
}
$k ++ ;
$value -- ;
} while ( $value2 != 0 ) {
$value2 -- ;
}
}
$data [ $val . '_k' ] = $k ;
//
}
}
} else {
$data [ 'status' ] = 200 ;
$data [ 'message' ] = " Data not found! " ;
}
error_log ( 'full View Data ' . print_r ( $data , true ));
echo json_encode ( $data );
// echo $data;
// UPDATE `checkup_parameter` SET `ref_ranges` = REPLACE(`ref_ranges`,"ÔÇô",'-');