134 lines
5.3 KiB
PHP
134 lines
5.3 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
include('log_entry.php');
|
|
error_log("Start Printing Request Attributes");
|
|
$requestStr = "";
|
|
foreach ($_REQUEST as $key => $value) {
|
|
$requestStr .= $key . " : " . $value . "\n";
|
|
error_log($key . " : " . $value . "<br />\r\n");
|
|
}
|
|
error_log("End Printing Request Attributes");
|
|
save_log($requestStr, 'Disease Master', 'SAVE', 'save_disease_list.php');
|
|
$noOfRows = $_POST['count_items'];
|
|
error_log("rows: " . $noOfRows);
|
|
|
|
$id = $_REQUEST['id_first'];
|
|
$medicine_idddd = $_REQUEST['medicine_frequency0'];
|
|
|
|
$abnormality_id = $_REQUEST['abnormality_id'];
|
|
$patient_name = "'" . $_REQUEST['patient_name'] . "'";
|
|
$emp_id = $_REQUEST['patient_id'];
|
|
$diag_date = $_REQUEST['diag_date'];
|
|
$remission_date = $_REQUEST['remission_date'];
|
|
error_log("date " . $diag_date);
|
|
|
|
// $date = DateTime::createFromFormat('Y-m-d', $diag_date);
|
|
// Format the date in "d/m/Y" format
|
|
// if ($date === false) {
|
|
// // Handle the case where the date could not be parsed correctly
|
|
// error_log("Error: Failed to create DateTime object from date");
|
|
// } else {
|
|
// $newDateFormat = $date->format('d/m/Y');
|
|
// }
|
|
error_log("date " . $diag_date);
|
|
|
|
$query_initial = "";
|
|
$endquery = "";
|
|
begin();
|
|
$prescription_id = $_REQUEST['id'];
|
|
error_log($id . "ididid");
|
|
error_log($prescription_id . "id");
|
|
|
|
if (!empty($prescription_id)) {
|
|
$query_initial = "update ";
|
|
$endquery = " where prescription_id = '" . $prescription_id . "' ";
|
|
} else {
|
|
$query_initial = "insert into ";
|
|
}
|
|
|
|
|
|
//check if its in problem_response or not if not than add it
|
|
|
|
// $exist_sql = "select b.rid,b.rvalue,b.diagnosis_date from problem_response a inner join problem_response_details b on a.rid = b.rid where a.pid=(select pid from problem_master where pcode='ABT') and a.patient_id = '" . $emp_id . "' and b.rvalue = '" . $abnormality_id . "'";
|
|
|
|
// error_log("problem response checking sql " . $exist_sql);
|
|
|
|
// $result_sql = mysqli_query($conn, $exist_sql);
|
|
|
|
// if (mysqli_num_rows($result_sql) > 0) {
|
|
// error_log("record exists for this chronic illness update case ");
|
|
// updatePatientHealthInfo($emp_id, 'ABT', $abnormality_id, $newDateFormat, '', 1);
|
|
// } else {
|
|
// error_log("record does not exists for this chronic illness insert case ");
|
|
// updatePatientHealthInfo($emp_id, 'ABT', $abnormality_id, $newDateFormat, '', 1);
|
|
// }
|
|
|
|
for ($i = 0; $i < $noOfRows; $i++) {
|
|
error_log("in the foreach loop");
|
|
|
|
if (${"medicine_name$i"} != null || ${"medicine_name$i"} != '') {
|
|
error_log("in the condition");
|
|
|
|
$health_advice_ids = implode(",", ${"health_advice_name_new$i"});
|
|
error_log("advices " . ${"health_advice_name_new$i"});
|
|
|
|
// update or insert this chronic illness with diagnosis mapping table
|
|
$exist_map_sql = "select * from diagnosis_chronic_mapping where chronic_id ='" . $abnormality_id . "' ";
|
|
$result_map_sql = mysqli_query($conn, $exist_map_sql);
|
|
$map_rows = mysqli_num_rows($result_map_sql);
|
|
|
|
$chronic_name = getFieldFromTable('abnormality_name', 'abnormality', 'abnormality_id', $abnormality_id);
|
|
$map_diag_id_sql = "select ailment_id from ailment where ailment_name = lower(trim('$chronic_name')) and is_active='Y' limit 1";
|
|
error_log("map_diag_id_sql" . $map_diag_id_sql);
|
|
$result_map_diag_sql = mysqli_query($conn, $map_diag_id_sql);
|
|
$row_map_diag_sql = mysqli_fetch_assoc($result_map_diag_sql);
|
|
|
|
$map_diag_id = $row_map_diag_sql['ailment_id'];
|
|
|
|
if ($map_diag_id != '' && $map_diag_id != null && $map_diag_id != '0') {
|
|
|
|
if ($map_rows > 0) {
|
|
$delete_map = "delete from diagnosis_chronic_mapping where chronic_id ='" . $abnormality_id . "'";
|
|
error_log("delete map query " . $delete_map);
|
|
$result_delete_map = mysqli_query($conn, $delete_map);
|
|
|
|
$insert_map_sql = "insert into diagnosis_chronic_mapping set chronic_id='" . $abnormality_id . "' , ailment_id='" . $map_diag_id . "'";
|
|
error_log("map query " . $insert_map_sql);
|
|
$result_insert_map = mysqli_query($conn, $insert_map_sql);
|
|
} else {
|
|
$insert_map_sql = "insert into diagnosis_chronic_mapping set chronic_id='" . $abnormality_id . "' , ailment_id='" . $map_diag_id . "'";
|
|
error_log("map query " . $insert_map_sql);
|
|
$result_insert_map = mysqli_query($conn, $insert_map_sql);
|
|
}
|
|
}
|
|
|
|
|
|
$query = $query_initial . " prescription_master set diseases = '$abnormality_id',emp_id='$emp_id', medicine_name = '" . ${"medicine_name$i"} . "', medicine_frequency = '" . ${"medicine_frequency$i"} . "',medicine_timing = '" . ${"medicine_timing$i"} . "' , admin_route = '" . ${"admin_route$i"} . "' , duration = '" . ${"duration$i"} . "' ,health_advices='" . $health_advice_ids . "', dose_qty = '" . ${"dose_qty$i"} . "',diagnosis_date = STR_TO_DATE('" . $diag_date . "','%Y-%m-%d') " . $endquery;
|
|
|
|
error_log("final query " . $query);
|
|
error_log($query . "save query");
|
|
if (!$result = @mysqli_query($conn, $query)) {
|
|
rollback();
|
|
exit(error_log(mysqli_error($conn)));
|
|
}
|
|
if($remission_date!='' && $remission_date!=null &&$remission_date!='1970-01-01' &&$remission_date!='0000-00-00' ){
|
|
|
|
$query_rem = "update prescription_master set remission_date = STR_TO_DATE('" . $remission_date . "','%Y-%m-%d') where diseases = '$abnormality_id' and emp_id='$emp_id'";
|
|
|
|
error_log("final query_rem " . $query_rem);
|
|
error_log($query_rem . "save query_rem");
|
|
if (!$result_rem = @mysqli_query($conn, $query_rem)) {
|
|
rollback();
|
|
exit(error_log(mysqli_error($conn)));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
commit();
|