ESH/save_visitor_patient.php
2024-10-23 18:28:06 +05:30

86 lines
3.4 KiB
PHP

<?php
// error_reporting(E_ERROR | E_PARSE);
include ('includes/config/config.php');
include ('includes/functions.php');
include ('log_entry.php');
// print_r($_POST);
$id = $_POST ['patient_id'];
$father_name = $_POST ['father_name'];
$dob = $_POST ['dob'];
$doj = $_POST ['doj'];
$designation_id = $_POST ['emp_designation'];
$emp_code = $_POST ['emp_code'];
$gender = $_POST ['gender'];
// $address = $_POST['address'];
$personal_phone = $_POST ['personal_phone'];
$doc_type = $_POST ['doc_type'];
$visitor_company = $_POST ['visitor_company'];
$visiting_patient_id = $_POST ['visiting_patient_id'];
$emergency_contact = $_POST ['emergency_contact'];
$address = $_POST ['address'];
$email = $_POST ['email'];
$aadhar_no = $_POST ['aadhar_no'];
$ohc_type_id = $_SESSION ['current_ohcttype'];
$status = $_POST ['status'];
$blood_group = $_POST ['blood_group'];
$imgData = null;
$photoQuery = "";
if (count ( $_FILES ) > 0) {
$_FILES ['photo'] ['tmp_name'];
if (is_uploaded_file ( $_FILES ['photo'] ['tmp_name'] )) {
$info = pathinfo ( $_FILES ['photo'] ['name'] );
$ext = pathinfo ( $info, PATHINFO_EXTENSION );
$imgData = addslashes ( file_get_contents ( $_FILES ['photo'] ['tmp_name'] ) );
$imageProperties = getimageSize ( $_FILES ['photo'] ['tmp_name'] );
$photoQuery = ",photo='{$imgData}' ,image_type='{$imageProperties['mime']}'";
}
}
$data = array ();
$initial_query = "";
$end_query = "";
$emp_id = "";
if (empty ( $id ) && ! empty ( $doc_type ) && ! empty ( $aadhar_no )) {
$id = getTableFieldValue ( 'id', 'visitor_patient_master', 'doc_type', $doc_type, 'doc_no', $aadhar_no );
}
if (! empty ( $id )) {
$initial_query = "update visitor_patient_master ";
$end_query = " where id = " . $id . " ";
} else {
$initial_query = "insert into visitor_patient_master ";
$end_query = "";
}
$final_query = $initial_query . " set patient_name='" . addslashes ( $_POST ['patient_name'] ) . "', father_name = '" . addslashes ( $father_name ) . "',
personal_phone='" . addslashes ( $personal_phone ) . "', dob=STR_TO_DATE('" . $_POST ['dob'] . "', '%d/%m/%Y'),
emp_code='" . addslashes ( $emp_code ) . "', gender='$gender',primary_phone='" . addslashes ( $primary_phone ) . "',
visitor_company='" . addslashes ( $visitor_company ) . "',visiting_patient_id='" . addslashes ( $visiting_patient_id ) . "',
emergency_contact='" . addslashes ( $emergency_contact ) . "', doc_type='" . addslashes ( $doc_type ) . "',
doc_no='" . addslashes ( $aadhar_no ) . "',ohc_type_id='" . addslashes ( $ohc_type_id ) . "',
address='" . addslashes ( $address ) . "', blood_group='" . addslashes ( $blood_group ) . "'" . $photoQuery . ",
modified_by = '" . $_SESSION ['user_id'] . "' " . $end_query;
// echo $final_query;
// $data['query']=$query;
error_log ( "save visitor patient details: " . $final_query );
if (! $result = @mysqli_query($conn,$final_query )) {
$data ['status'] = 500;
exit ( mysqli_error($conn) );
} else {
$data ['status'] = 200;
$data ['patient_id'] = $id;
if (empty ( $id )) {
$query = "select max(id) patient_id from visitor_patient_master ";
// echo $query;
if (! $result = @mysqli_query($conn,$query )) {
exit ( mysqli_error($conn) );
}
if (mysqli_num_rows ( $result ) > 0) {
while ( $row = mysqli_fetch_assoc ( $result ) ) {
$id = $row ['patient_id'];
$data ['patient_id'] = $row ['patient_id'];
}
}
}
}
echo json_encode ( $data );
?>