59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
|
|
$defaultStartDate = date('Y-m-d', strtotime('-1 month'));
|
|
$defaultEndDate = date('Y-m-d');
|
|
|
|
if (!empty($_POST['startDate'])) {
|
|
$defaultStartDate = date('Y-m-d', strtotime($_POST['startDate']));
|
|
}
|
|
|
|
if (!empty($_POST['endDate'])) {
|
|
$defaultEndDate = date('Y-m-d', strtotime($_POST['endDate']));
|
|
}
|
|
|
|
if (!empty($_POST['patCat'])) {
|
|
$cat = $_POST['patCat'];
|
|
}
|
|
|
|
$totalMedicalExamName = array();
|
|
$totalMedicalExam = array();
|
|
|
|
$sql = "SELECT * FROM checkup_type WHERE type_status='Active' AND type_state!='Yes'";
|
|
$result = mysqli_query($conn, $sql);
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
array_push($totalMedicalExamName, $row['checkup_type_name']);
|
|
array_push($totalMedicalExam, $row['checkup_type_id']);
|
|
}
|
|
|
|
$checkupData = array();
|
|
|
|
foreach ($totalMedicalExam as $examId) {
|
|
$query = "SELECT COUNT(checkup_id) FROM checkup_form LEFT JOIN patient_master p ON checkup_form.emp_id = p.id WHERE DATE(checkup_date) >= '$defaultStartDate' AND DATE(checkup_date) <= '$defaultEndDate' AND checkup_type_id = '$examId'";
|
|
|
|
if (!empty($cat)) {
|
|
$query .= " AND p.patient_cat_id='$cat'";
|
|
}
|
|
|
|
if (!$result = mysqli_query($conn, $query)) {
|
|
error_log("Error in medical chart: " . mysqli_error($conn));
|
|
continue;
|
|
}
|
|
error_log('medical query' . $query);
|
|
$row = mysqli_fetch_array($result);
|
|
|
|
if ($row) {
|
|
array_push($checkupData, $row[0]);
|
|
} else {
|
|
array_push($checkupData, 0);
|
|
}
|
|
}
|
|
|
|
$data = array(
|
|
'checkup_data' => $checkupData,
|
|
'medical_exam_name' => $totalMedicalExamName,
|
|
);
|
|
error_log('data' . json_encode($data));
|
|
echo json_encode($data);
|