<?php

$obj_medicine = new Hmgtmedicine();
if (isset($_REQUEST['save_category'])) {
    $result = $obj_medicine->hmgt_add_medicinecategory($_POST);
    if ($result) {
        ?>
			<div id="message" class="updated below-h2">
			<?php 
        _e('Record inserted successfully', 'hospital_mgt');
        ?>
</div><?php 
    }
}
if (isset($_REQUEST['save_medicine'])) {
    if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'insert' || $_REQUEST['action'] == 'edit')) {
        $result = $obj_medicine->hmgt_add_medicine($_POST);
        if ($result) {
            if ($_REQUEST['action'] == 'edit') {
                wp_redirect(home_url() . '?dashboard=user&page=medicine&tab=medicinelist&message=2');
            } else {
                wp_redirect(home_url() . '?dashboard=user&page=medicine&tab=medicinelist&message=1');
            }
        }
    }
}
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
    $result = $obj_medicine->delete_medicine($_REQUEST['medicine_id']);
    if ($result) {
        wp_redirect(home_url() . '?dashboard=user&page=medicine&tab=medicinelist&message=3');
    }
function hmgt_view_priscription()
{
    $obj_medicine = new Hmgtmedicine();
    $obj_treatment = new Hmgt_treatment();
    $obj_prescription = new Hmgtprescription();
    $result = $obj_prescription->get_prescription_data($_REQUEST['prescription_id']);
    ?>
			<div class="modal-header">
			<a href="#" class="close-btn-cat badge badge-success pull-right">X</a>
			<h4 class="modal-title"><?php 
    echo get_option('hmgt_hospital_name');
    ?>
</h4>
			</div>
			<hr>
			<div class="panel-body prescription_pop_content">
			<table width="100%" border="0">
	            <tbody><tr>
	                <td valign="top" align="left">
	                        <?php 
    _e('Patient Name', 'hospital_mgt');
    ?>
 : <?php 
    echo hmgt_get_display_name($result->patient_id);
    ?>
<br>
	                    
	                        <?php 
    _e('Sex', 'hospital_mgt');
    ?>
 : <?php 
    echo get_user_meta($result->patient_id, 'gender', true);
    ?>
 <br>
	                                    </td>
	                <td valign="top" align="right">
	                   <?php 
    _e('Doctor Name', 'hospital_mgt');
    ?>
 : <?php 
    echo hmgt_get_display_name($result->prescription_by);
    ?>
<br>
	                   <?php 
    _e('Date', 'hospital_mgt');
    ?>
 : <?php 
    echo $result->pris_create_date;
    ?>
<br>
	                  
	                </td>
	            </tr>
	        	</tbody>
        	 </table>
        	 <hr>
        	 <div class="row">
            <div class="col-md-12">

                <div data-collapsed="0" class="panel panel-primary">
                        
                    <div class="panel-body">
                            
                        <b><?php 
    _e('Case History', 'hospital_mgt');
    ?>
 : </b>
                        
                        <p><?php 
    echo $result->case_history;
    ?>
</p>                        
                        <hr>     
                         <b><?php 
    _e('Treatment', 'hospital_mgt');
    ?>
 : </b>
                        
                        <p><?php 
    echo $treatment = $obj_treatment->get_treatment_name($result->teratment_id);
    ?>
</p>   
                        <hr>                       
                        <b> <?php 
    _e('Medication', 'hospital_mgt');
    ?>
 : </b>
                        <div class="table-responsive">
                        <table class="table">
                        <tr>
                        <th><?php 
    _e('Name', 'hospital_mgt');
    ?>
</th>
                        <th><?php 
    _e('Times', 'hospital_mgt');
    ?>
</th>
                        <th><?php 
    _e('Days', 'hospital_mgt');
    ?>
</th>
                        </tr>
                        <?php 
    $all_medicine_list = json_decode($result->medication_list);
    if (!empty($all_medicine_list)) {
        foreach ($all_medicine_list as $retrieved_data) {
            ?>
                        	<tr>
											
											<td><?php 
            $medicine = $obj_medicine->get_single_medicine($retrieved_data->medication_name);
            echo $medicine->medicine_name;
            ?>
</td>
											<td><?php 
            echo $retrieved_data->time;
            ?>
</td>
											<td><?php 
            echo $retrieved_data->per_days;
            ?>
</td>
											</tr>
                        	<?php 
        }
    }
    ?>
                        
                       
                        </table>
                        </div>
                        <hr>
                        
                        <b><?php 
    _e('Extra Note', 'hospital_mgt');
    ?>
 :</b>
                        
                        <p><?php 
    echo $result->treatment_note;
    ?>
</p>
                        <?php 
    $all_entry = json_decode($result->custom_field);
    if (!empty($all_entry)) {
        foreach ($all_entry as $entry) {
            ?>
                      		<hr>
                      		<b><?php 
            echo $entry->label;
            ?>
</b>
                      		<P><?php 
            echo $entry->value;
            ?>
</P>
                      		
                      		<?php 
        }
    }
    ?>
					<hr>
                    </div>

                </div>
				<div class="print-button pull-left">
						<a  href="?page=hmgt_prescription&print=print&prescription_id=<?php 
    echo $_POST['prescription_id'];
    ?>
" target="_blank"class="btn btn-success"><?php 
    _e('Print', 'hospital_mgt');
    ?>
</a>
				</div>
            </div>
        	</div>
        	 </div>
	<?php 
    die;
}
<?php

//This is Dashboard at admin side
$obj_medicine = new Hmgtmedicine();
$medicinedata = $obj_medicine->get_all_medicine();
if (!empty($medicinedata)) {
    $medicine_array = array();
    foreach ($medicinedata as $retrieved_data) {
        $medicine_array[] = $retrieved_data->medicine_name;
    }
}
$obj_treatment = new Hmgt_treatment();
$obj_var = new Hmgtprescription();
$edit = 0;
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') {
    $edit = 1;
    $result = $obj_var->get_prescription_data($_REQUEST['prescription_id']);
}
$medicine_array = array();
?>
				
<script type="text/javascript">
$(document).ready(function() {
	$('#prescription_form').validationEngine();
	
} );
</script>	
       <div class="panel-body">
        <form name="prescription_form" action="" method="post" class="form-horizontal" id="prescription_form">
         <?php 
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'insert';