}
        $patient_image_url = $patient_image;
    }
    if (isset($_FILES['diagnosis']) && !empty($_FILES['diagnosis']) && $_FILES['diagnosis']['size'] != 0) {
        if ($_FILES['diagnosis']['size'] > 0) {
            $diagnosis_report = load_documets($_FILES['diagnosis'], 'diagnosis', 'report');
        }
    }
    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'insert') {
        if (!email_exists($_POST['email']) && !username_exists($_POST['username'])) {
            $result = $user_object->hmgt_add_user($_POST);
            $user_object->upload_diagnosis_report($result, $diagnosis_report);
            $returnans = update_user_meta($result, 'hmgt_user_avatar', $patient_image_url);
            if ($result) {
                $guardian_data = array('patient_id' => $result, 'doctor_id' => $_POST['doctor'], 'symptoms' => $_POST['symptoms'], 'inpatient_create_date' => date("Y-m-d H:i:s"), 'inpatient_create_by' => get_current_user_id());
                $inserted = add_guardian($guardian_data, $id);
                if ($inserted) {
                    wp_redirect(home_url() . '?dashboard=user&page=outpatient&tab=outpatientlist&message=1');
                }
            }
        } else {
            ?>
					<div id="message" class="updated below-h2">
					<p><p><?php 
            _e('Username Or Emailid All Ready Exist', 'hospital_mgt');
            ?>
</p></p>
					</div>
		  <?php 
        }
    }
<?php

// This is Dashboard at admin side!!!!!!!!!
$role = 'patient';
$patient_id = 0;
if (isset($_REQUEST['patient_id'])) {
    $patient_id = $_REQUEST['patient_id'];
}
$patient_no = get_user_meta($patient_id, 'patient_id', true);
if (isset($_POST['save_patient_step2'])) {
    $guardian_data = array('guardian_id' => $_POST['guardian_id'], 'patient_id' => $_REQUEST['patient_id'], 'first_name' => $_POST['first_name'], 'middle_name' => $_POST['middle_name'], 'last_name' => $_POST['last_name'], 'gr_gender' => $_POST['gender'], 'gr_address' => $_POST['address'], 'gr_city' => $_POST['city_name'], 'gr_phone' => $_POST['phone'], 'gr_mobile' => $_POST['mobile'], 'gr_relation' => $_POST['guardian_realtion'], 'image' => $_POST['hmgt_user_avatar'], 'inpatient_create_date' => date("Y-m-d H:i:s"), 'inpatient_create_by' => get_current_user_id());
    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') {
        $result = update_guardian($guardian_data, $_REQUEST['patient_id']);
        wp_redirect(admin_url() . 'admin.php?page=hmgt_patient&tab=addpatient_step3&patient_id=' . $_REQUEST['patient_id'] . '&action=edit');
    } else {
        $result = add_guardian($guardian_data);
        if ($result) {
            wp_redirect(admin_url() . 'admin.php?page=hmgt_patient&tab=addpatient_step3&patient_id=' . $_REQUEST['patient_id']);
        }
    }
}
?>
	<script type="text/javascript">
$(document).ready(function() {
	$('#guardian_form').validationEngine();
	$('#birth_date').datepicker({
		  changeMonth: true,
	        changeYear: true,
	        yearRange:'-65:+0',	
	        onChangeMonthYear: function(year, month, inst) {
	            $(this).val(month + "/" + year);