public function patient_history_ajax() { $patient_id = $this->input->post('patient_id'); $patient_details = Patients::get_patient_history($patient_id); // echo "<pre>";print_r($patient_details); /*$p_dets = array(); foreach ($patient_details as $key => $value) { $id = $value['id']; $firstname = $value['firstname']; $lastname = $value['lastname']; $date_of_birth = $value['date_of_birth']; $date_of_birth_string = date('F, m Y', strtotime($date_of_birth)); $gender = $value['gender']; $name = $firstname.' '.$lastname; $gender = ($gender=='1') ? 'Male' : 'Female'; $name_and_number = $name .' | '.$patient_number; $p_dets[] = array($patient_number,$name,$gender,$date_of_birth_string,$name_and_number,$id); } echo json_encode($p_dets[0]);*/ $result_table = ""; $result_table .= ' <table class="table table-bordered row-fluid datatable"> <thead> <th>Patient Name</th> <th>Commodity Name</th> <th>Units Dispensed</th> <th>Date Dispensed</th> </thead> <tbody>'; if (count($patient_details) > 0) { foreach ($patient_details as $data) { $result_table .= '<tr> <td>' . $data['firstname'] . ' ' . $data['lastname'] . '</td> <td>' . $data['commodity_name'] . '</td> <td>' . $data['units_dispensed'] . '</td> <td>' . date('Y-M-d', strtotime($data['date_created'])) . '</td> </tr>'; } } else { $result_table .= '<tr><td colspan="4"><b>There is no history on this patient</b></td></tr>'; } $result_table .= '</tbody></table>'; echo $result_table; }
public function patient_history_ajax() { $patient_id = $this->input->post('patient_id'); $patient_details = Patients::get_patient_history($patient_id); $result_table = ""; $total = 0; $result_table .= ' <table class="table table-bordered row-fluid datatable" id="ajax_history_table"> <thead> <th>Patient Name</th> <th>Commodity Name</th> <th>Units Dispensed</th> <th>Date Dispensed</th> </thead> <tbody>'; if (count($patient_details) > 0) { foreach ($patient_details as $data) { $total += intval($data['units_dispensed']); $result_table .= '<tr> <td>' . $data['firstname'] . ' ' . $data['lastname'] . '</td> <td>' . $data['commodity_name'] . '</td> <td>' . $data['units_dispensed'] . '</td> <td>' . date('Y-M-d', strtotime($data['date_created'])) . '</td> </tr>'; } } else { $result_table .= '<tr><td><b>There is no history on this patient</b></td><td></td><td></td><td></td></tr>'; } $result_table .= '<tr><td>--</td><td><b>Total:</b></td><td><b>' . $total . '</b></td><td></td></tr>'; $result_table .= '</tbody></table>'; echo $result_table; }