$value) { $requestStr .= $key . " : " . $value . "\n"; error_log($key . " : " . $value . "
\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 = trim($_REQUEST['abnormality_id']); $patient_name = "'" . $_REQUEST['patient_name'] . "'"; $emp_id = trim($_REQUEST['patient_id']); $diag_date = $_REQUEST['diag_date']; $remission_date = $_REQUEST['remission_date']; $ohc_type_id = $_SESSION['current_ohcttype']; error_log("date " . $diag_date); $remark = $_REQUEST['remark']; 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 "; } $entered_med = false; for ($i = 0; $i < $noOfRows; $i++) { error_log("in the foreach loop"); if ((${"medicine_name$i"} != null && ${"medicine_name$i"} != '') || (${"other_med$i"} != null && trim(${"other_med$i"}) != '')) { error_log("in the condition " . " flag is " . $entered_med); $entered_med = true; $health_advice_ids = implode(",", ${"health_advice_name_new$i"}); error_log("advices " . ${"health_advice_name_new$i"}); updateChronicDiagnosisMapping($abnormality_id, $GLOBALS['conn']); $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"} . "' ,other_med = '" . ${"other_med$i"} . "',remark='" . trim($remark) . "',health_advices='" . $health_advice_ids . "',ohc_type_id='" . $ohc_type_id . "', 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(); die(error_log(mysqli_error($conn))); } } } if ($entered_med == false) { if (!empty($abnormality_id) && !empty($emp_id)) { updateChronicDiagnosisMapping($abnormality_id, $GLOBALS['conn']); $query = $query_initial . " prescription_master set diseases = '" . $abnormality_id . "',emp_id='" . $emp_id . "',remark='" . trim($remark) . "',health_advices='" . $health_advice_ids . "',ohc_type_id='" . $ohc_type_id . "',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(); die(error_log(mysqli_error($conn))); } } } updateRemissionDate($remission_date, $GLOBALS['conn'], $abnormality_id, $emp_id); function updateRemissionDate($remission_date, $conn, $abnormality_id, $emp_id) { // 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(); die(error_log(mysqli_error($conn))); } // } } function updateChronicDiagnosisMapping($abnormality_id, $conn) { // 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); } } } commit();