567 lines
31 KiB
PHP
567 lines
31 KiB
PHP
<?php
|
|
|
|
use Com\Tecnick\Barcode\Type\Square\QrCode\Split;
|
|
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING);
|
|
// include log entry header file
|
|
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, 'Save_OPD', 'SAVE', 'save_opd.php');
|
|
// error_reporting(E_ERROR | E_PARSE);
|
|
if ($_REQUEST['appointment_id'] == null || $_REQUEST['appointment_id'] == '' || $_REQUEST['appointment_id'] == '0' ) {
|
|
$appointment_id = $_REQUEST['appoint'];
|
|
} else {
|
|
$appointment_id = $_REQUEST['appointment_id'];
|
|
}
|
|
// echo $appointment_id;
|
|
$data = array();
|
|
$appointment_date = $_POST['appointment_date'];
|
|
$isTreatmentOnly = $_POST['isTreatmentOnly'];
|
|
|
|
error_log('isTreatmentOnly:' . $isTreatmentOnly);
|
|
if ($isTreatmentOnly == 'Y') {
|
|
$sql_update_status = " update employee_appointment set attended_status='PHA', clearance_time=STR_TO_DATE('" . $_POST['out_time'] . "', '%d/%m/%Y %h:%i %p') where appointment_id='" . $appointment_id . "'";
|
|
error_log("is treatment only if yes query " . $sql_update_status);
|
|
if (!$result_update_status = @mysqli_query($conn, $sql_update_status)) {
|
|
// main insert fails
|
|
|
|
error_log("Exception:" . mysqli_error($conn));
|
|
error_log("Appointment Status Update Failed : " . $sql_update_status);
|
|
rollback();
|
|
exit(error_log(mysqli_error($conn)));
|
|
|
|
}
|
|
goto treatment_section;
|
|
}
|
|
|
|
$ailment_ids_new = strtoupper($_POST['ailment_new']);
|
|
error_log("ailment_ids_new:" . $ailment_ids_new);
|
|
|
|
$complaint_ids = strtoupper($_POST['complaints']);
|
|
$finding_ids = strtoupper($_POST['examination_remarks']);
|
|
$referral_ids = ($_POST['referral_point']);
|
|
$referred_by = $_POST['referred_by'];
|
|
$disease_type = $_POST['disease_type'];
|
|
// $ailment_system_ids_new = strtoupper($_POST['ailment_system_new']);
|
|
// $ailment_ids_new = implode ( ',', $_POST ['ailment_new'] );
|
|
$ailment_system_ids_new = implode(',', $_POST['ailment_system_new']);
|
|
$injuryTypes_new = implode(',', $_POST['injury_type_new']);
|
|
$injuryClasses_new = implode(',', $_POST['injury_class_new']);
|
|
|
|
if ($_REQUEST['appointment_type'] == 'O') {
|
|
$injuryParts_new = strtoupper($_POST['injury_part_new']);
|
|
}
|
|
if ($_REQUEST['appointment_type'] == 'I') {
|
|
$injuryParts_new = strtoupper($_POST['injury_part']);
|
|
}
|
|
|
|
$injury_mech = implode(',', $_POST['injury_mech_new']);
|
|
$health_advice_names_new = strtoupper($_POST['health_advice_name_new']);
|
|
$tests_new = strtoupper($_POST['recommended_test_new']);
|
|
|
|
$ailment_ids_new = $_REQUEST['ailment_new'];
|
|
$ailment_ids_new = implode(',', $ailment_ids_new);
|
|
error_log("ailment_ids_new config off : " . print_r($ailment_ids_new, true));
|
|
|
|
|
|
$finding_ids = $_REQUEST['examination_remarks'];
|
|
$finding_ids = implode(',', $finding_ids);
|
|
error_log("$finding_ids config off : " . print_r($finding_ids, true));
|
|
|
|
$complaint_ids = $_REQUEST['complaints'];
|
|
$complaint_ids = implode(',', $complaint_ids);
|
|
error_log("$complaint ids config off : " . print_r($complaint_ids, true));
|
|
|
|
|
|
// $referral_ids = handleDynamicMasterInsert("referral_point", "referral_point_name", "referral_point_id", $referral_ids, true);
|
|
// error_log("referral_ids:" . implode(',', $referral_ids));
|
|
// $referral_ids = getMultiValuedSelectData($referral_ids);
|
|
// error_log("referral_ids2:" . $referral_ids);
|
|
|
|
// handleDynamicMasterInsert("ailment_system","ailment_sys_name","ailment_sys_id",$ailment_system_ids_new);
|
|
/*
|
|
* handleDynamicMasterInsert("injury_type","injury_type_name","injury_type_id",$injuryTypes_new);
|
|
* handleDynamicMasterInsert("injury_class","inj_class_name","inj_class_id",$injuryClasses_new);
|
|
* handleDynamicMasterInsert("injury_part","inj_name","inj_id",$injuryParts_new);
|
|
*/
|
|
// handleDynamicMasterInsert("injury_part","inj_name","inj_id",$injuryParts_new);
|
|
handleDynamicMasterInsert("health_advice", "health_advice_name", "health_advice_id", $health_advice_names_new);
|
|
handleDynamicMasterInsert("recommended_tests", "test_name", "test_id", $tests_new);
|
|
|
|
handleDynamicMasterInsert("injury_part", "inj_name", "inj_id", $injuryParts_new);
|
|
|
|
$weight = $_POST['weight'];
|
|
$height = $_POST['height'];
|
|
$spoc2_percent = $_POST['spoc2_percent'];
|
|
$sbp = $_POST['sbp'];
|
|
$dbp = $_POST['dbp'];
|
|
$temperature = $_POST['temperature'];
|
|
$bmi = $_POST['bmi'];
|
|
$respiratory_rate = $_POST['resp_rate'];
|
|
$urine_output = $_POST['urine_output'];
|
|
$avpu = $_POST['avpu'];
|
|
$trama = $_POST['trama'];
|
|
$mobility = $_POST['mobility'];
|
|
$abnormalitys = $_POST['abnormality'];
|
|
$oxygen_supply = $_POST['oxygen_supply'];
|
|
$glasgow_scale = $_POST['glasgow_coma_scale'];
|
|
$total_cholesterol = $_POST['total_cholesterol'];
|
|
$external_treatments = $_POST['external_treatments'];
|
|
$activity = $_POST['activity'];
|
|
$ppe = $_POST['ppe'];
|
|
$any_medication = $_POST['any_medication'];
|
|
$drug_allergy = $_POST['drug_allergy'];
|
|
$injury_remarks = $_POST['injury_remarks'];
|
|
$doc_comment = $_POST['doc_comment'];
|
|
$is_admitted = $_POST['is_admitted'];
|
|
$ambulance_used = $_POST['ambulance_used'];
|
|
$forUpdate = $_POST['forUpdate'];
|
|
$deu_date = $_POST['deu_date'];
|
|
|
|
if ($_REQUEST['ipd'] == 1 || $_REQUEST['ipd'] == '1' ) {
|
|
$reporting_time = $_POST['appointment_date'];
|
|
|
|
$detention_master = 'insert into detention_master set reporting_time=STR_TO_DATE("' . $reporting_time . '","%d/%m/%Y %h:%i %p") ,opd_id="' . $appointment_id . '",modified_by="' . $_SESSION['user_id'] . '" ';
|
|
error_log('Forward to detention ' . $detention_master);
|
|
if (!$result_detention_master = @mysqli_query($conn, $detention_master)) {
|
|
exit(mysqli_error($conn));
|
|
}
|
|
|
|
$attended_status = 'PHP';
|
|
$isDetention = 'Y';
|
|
} else {
|
|
$attended_status = $_REQUEST['attendedStatus'];
|
|
$isDetention = 'N';
|
|
}
|
|
|
|
|
|
$health_index = calculateHealthIndex($sbp, $dbp, $bmi, $fbs, $total_cholesterol);
|
|
// $ailment_ids = getMultiValuedSelectData(strtoupper($_POST['ailment']));
|
|
// $ailment_system_ids = getMultiValuedSelectData(strtoupper($_POST['ailment_system']));
|
|
// $injuryTypes = getMultiValuedSelectData(strtoupper($_POST['injury_type']));
|
|
// $injuryClasses = getMultiValuedSelectData(strtoupper($_POST['injury_class']));
|
|
// $injuryParts = getMultiValuedSelectData(strtoupper($_POST['injury_part']));
|
|
$health_advice_names = getMultiValuedSelectData(strtoupper($_POST['health_advice_name']));
|
|
$health_risk_names = getMultiValuedSelectData(strtoupper($_POST['health_risk_name']));
|
|
$medicine_disbursement = $_POST['medicine_disbursement'];
|
|
$tests = getMultiValuedSelectData(strtoupper($_POST['recommended_test']));
|
|
|
|
$query = "";
|
|
$query_initial = "";
|
|
$query_mid = "";
|
|
$query_end = " ";
|
|
begin();
|
|
|
|
|
|
$department = getFieldFromTable('dept_id', 'patient_master', 'id', $_REQUEST['emp_id']);
|
|
|
|
|
|
$designation = getFieldFromTable('designation_id', 'patient_master', 'id', $_REQUEST['emp_id']);
|
|
// if this is only for saving treatment information we should skip saving OPD information.
|
|
|
|
if (!empty($appointment_id) && $appointment_id!='' && $appointment_id!=null && $appointment_id!=' ' ) {
|
|
|
|
$data['message'] = "update";
|
|
$query_initial = " update employee_appointment ";
|
|
$query_end = " where appointment_id = '" . $appointment_id . "' ";
|
|
error_log( "hhhhhhhhhhhhhh".$query_initial);
|
|
} else {
|
|
|
|
$row_existing = runSqlGenericSingleRow("select appointment_id from employee_appointment where emp_id='" . addslashes($_REQUEST['emp_id']) . "' and ohc_type_id='".$_SESSION['current_ohcttype']."',
|
|
and appointment_type='" . $_REQUEST['appointment_type'] . "' and DATE(NOW()) = DATE(appointment_date) ");
|
|
if ($row_existing != null) {
|
|
$appointment_id = $row_existing['appointment_id'];
|
|
$data['message'] = "update";
|
|
$query_initial = " update employee_appointment ";
|
|
$query_end = " where appointment_id = '" . $appointment_id . "' ";
|
|
} else {
|
|
$query_initial = "insert into employee_appointment ";
|
|
$query_mid = " ,ohc_type_id='" . $_SESSION['current_ohcttype'] . "'";
|
|
$data['message'] = "save";
|
|
}
|
|
// echo "yyyyyyyyyyyyyyy".$query_initial;
|
|
}
|
|
if (($tests_new!='' || $tests_new!=null ) && $_REQUEST['attendedStatus'] != 'CLS') {
|
|
|
|
$lab_checkup_ticket_no = creatingCheckupTicketNo();
|
|
error_log("tests " . $tests_new);
|
|
|
|
$userEntriesArray = explode(",", $tests_new);
|
|
$userEntriesArray = array_map('trim', $userEntriesArray);
|
|
|
|
error_log("user entries array" . $userEntriesArray);
|
|
|
|
// getting checkup lab test master id
|
|
// $checkup_type_id_sql = "select checkup_type_id from checkup_type where checkup_form_section_ids in (select section_id from checkup_form_section where section_name in ('" . join("','", $userEntriesArray) . "'))";
|
|
$checkup_type_id_sql = "select checkup_type_id from checkup_type where checkup_type_code='LAB_TEST'";
|
|
if ($result_checkup = mysqli_query($conn, $checkup_type_id_sql)) {
|
|
error_log("error in getting checkup type id " . mysqli_error($conn) . " query is " . $checkup_type_id_sql);
|
|
}
|
|
$row_checkup = mysqli_fetch_assoc($result_checkup);
|
|
$checkup_type_id = $row_checkup['checkup_type_id'];
|
|
|
|
error_log("checkup type id " . $checkup_type_id);
|
|
// getting checkup lab test master id end -- ----
|
|
|
|
// getting checkup lab section ids
|
|
$sql_existing_entries_test = "SELECT group_concat(section_id) as test_id from checkup_form_section where section_name in('" . join("','", $userEntriesArray) . "')";
|
|
|
|
error_log("existing entries query in MRP status:" . $sql_existing_entries_test);
|
|
|
|
if (!$result_existing_entries_test = @mysqli_query($conn, $sql_existing_entries_test)) {
|
|
error_log("error retrieving:" . mysqli_error($conn) . " sql_existing_entries_test:" . $sql_existing_entries);
|
|
}
|
|
$row_test = mysqli_fetch_assoc($result_existing_entries_test);
|
|
$test_section_ids = $row_test['test_id'];
|
|
// getting checkup lab section id end -----
|
|
$SESSION_emp_id = getTableFieldValue("doctors_master", "doctor_id", "doctor_emp_id", getTableFieldValue("tbl_users", "emp_id", "user_id", $_SESSION["user_id"]));
|
|
$curr_ohc_type_id = getFieldFromTable('ohc_type_id', 'employee_appointment', 'appointment_id', $appointment_id);
|
|
// inserting for lab record
|
|
$lab_entry = "insert into checkup_form set checkup_date=STR_TO_DATE('" . $appointment_date . "','%d/%m/%Y %h:%i %p') , ticket_no='" . $lab_checkup_ticket_no . "' , emp_id='" . $_REQUEST['emp_id'] . "' , checkup_type_id='" . $checkup_type_id . "' ,referred_by='" . $SESSION_emp_id . "', checkup_section_ids='" . $test_section_ids . "' , current_status='MRP' , ohc_type_id='" . $curr_ohc_type_id . "' ,appointment_id='" . $appointment_id . "', modified_by='" . $_SESSION['user_id'] . "'";
|
|
|
|
error_log("saving lab entry in save opd " . $lab_entry);
|
|
|
|
if (!$result_lab = mysqli_query($conn, $lab_entry)) {
|
|
error_log("error while saving lab entry in save opd " . mysqli_error($conn) . " query is " . $lab_entry);
|
|
}
|
|
}
|
|
|
|
$query = " SET emp_id='" . addslashes($_REQUEST['emp_id']) . "',medi_disbursement='$medicine_disbursement',doctor_attended_flag='$doctor_attended_flag',ticket_no='$ticket_no',remarks_rece='" . $_POST['remarks_rece'] . "',ecg_findings='" . $_POST['ecg_finding'] . "',add_remarks='" . $_POST['add_remarks'] . "',appointment_type='" . addslashes($_REQUEST['appointment_type']) . "',ailment_ids='" . $ailment_ids . "',ailment_system_ids='" . $ailment_system_ids . "',IsEmergency='" . addslashes($_REQUEST['isEmergency']) . "',IsChargeable='" . addslashes($_REQUEST['isChargeable']) . "',
|
|
complaints='" . addslashes($complaint_ids) . "',referred_by = '$referred_by',referred_to='" . $_POST['referred_to'] . "',clinical_opinion = '" . $_POST['clinical_opinion'] . "',
|
|
examination_remarks='" . addslashes($finding_ids) . "',
|
|
bp_sbp ='" . $_REQUEST['sbp'] . "',disease_type = '$disease_type',injury_area_cat='" . $_POST['injury_area_cat'] . "',injury_area_type = '" . $_POST['injury_area_type'] . "',
|
|
heart_rate='" . $_POST['heart_rate'] . "',height='$height',weight='$weight',
|
|
bp_dbp ='" . $_REQUEST['dbp'] . "',ipd ='" . $_REQUEST['ipd'] . "',
|
|
blood_sugar_fbs ='" . $_REQUEST['fbs'] . "',blood_sugar_rbs ='" . $_REQUEST['rbs'] . "',
|
|
blood_sugar_ppbs ='" . $_REQUEST['ppbs'] . "',
|
|
referral ='" . ($referral_ids) . "',
|
|
followup =STR_TO_DATE('" . $_POST['followup'] . "','%Y-%m-%d'),case_type='" . $_POST['case_type'] . "',shift_type='" . $_POST['shift_type'] . "',injury_def='" . $_POST['injury_def'] . "',
|
|
remarks ='$remarks',activity='$activity',ppe='$ppe',any_medication='$any_medication',
|
|
drug_allergy='$drug_allergy',injury_remarks = '$injury_remarks',doc_comment='$doc_comment',is_admitted='$is_admitted',discharge_time=STR_TO_DATE('" . $_POST['discharge_time'] . "', '%d/%m/%Y %h:%i %p'),referral_doc='".$_POST['referral_doc']."',report_time=STR_TO_DATE('" . $_POST['report_time'] . "', '%d/%m/%Y %h:%i %p'),ambulance_used='$ambulance_used',safety_officer = '" . $_POST['safety_officer'] . "',
|
|
deu_date ='" . $deu_date . "',
|
|
appointment_date =STR_TO_DATE('" . $_POST['appointment_date'] . "', '%d/%m/%Y %h:%i %p'),
|
|
clearance_time =STR_TO_DATE('" . $_POST['out_time'] . "', '%d/%m/%Y %h:%i %p'),
|
|
injury_time =STR_TO_DATE('" . $_POST['injury_time'] . "', '%d/%m/%Y %h:%i %p'),
|
|
rest_from_time =STR_TO_DATE('" . $_POST['rest_from_time'] . "', '%d/%m/%Y %h:%i %p'),
|
|
rest_to_time =STR_TO_DATE('" . $_POST['rest_to_time'] . "', '%d/%m/%Y %h:%i %p'),injury_mech='$injury_mech',
|
|
modified_by='" . $_SESSION['user_id'] . "' ,
|
|
injury_types='" . $injuryTypes . "', injury_classes='" . $injuryClasses . "',
|
|
injury_parts='" . $injuryParts . "', injury_form='" . $_REQUEST['injury_form'] . "', absence_start=STR_TO_DATE('" . $_POST['absence_start'] . "', '%d/%m/%Y'),
|
|
absence_end=STR_TO_DATE('" . $_POST['absence_end'] . "', '%d/%m/%Y'), injury_firm='" . $_REQUEST['injury_firm'] . "',incident_location='" . addslashes($_REQUEST['incident_location']) . "',
|
|
injury_sbu='" . $_REQUEST['injury_sbu'] . "', injury_section='" . $_REQUEST['injury_section'] . "',doctor_discussed='" . $_REQUEST['doctor_discussed'] . "', doctor_last_attended='" . $_REQUEST['doctor_last_attended'] . "',
|
|
injury_sub_section='" . $_REQUEST['injury_sub_section'] . "',tests='" . $tests . "',injury_procedure= '" . addslashes($_REQUEST['pro_remarks']) . "',
|
|
hospital_treatment='" . $_REQUEST['hospital_treatment'] . "' ,health_advices='" . $health_advice_names . "' ,
|
|
total_amount='" . $_POST['order_level_total'] . "', abnormalitys='" . implode(",",$abnormalitys) . "', token_no='" . addslashes($_REQUEST['token_no']) . "',
|
|
ailments_new='" . addslashes($ailment_ids_new) . "',ailment_systems_new='" . addslashes($ailment_system_ids_new) . "',
|
|
injury_types_new='" . addslashes($injuryTypes_new) . "',injury_classes_new='" . addslashes($injuryClasses_new) . "',
|
|
injury_parts_new='" . addslashes($injuryParts_new) . "',recommended_tests_new='" . addslashes($tests_new) . "',bmi='" . addslashes($bmi) . "',respiratory_rate = '" . addslashes($respiratory_rate) . "',
|
|
urine_output = '" . addslashes($urine_output) . "',avpu = '" . addslashes($avpu) . "',trama='" . addslashes($trama) . "',mobility='" . addslashes($mobility) . "',oxygen_supply='" . addslashes($oxygen_supply) . "',glasgow_coma_scale='" . addslashes($glasgow_coma_scale) . "',total_cholesterol = '" . addslashes($total_cholesterol) . "',health_index = '" . addslashes($health_index) . "',
|
|
temperature='" . addslashes($temperature) . "',spo2_percent='" . addslashes($spoc2_percent) . "',
|
|
external_treatments='" . addslashes($external_treatments) . "',attended_status='" . addslashes($attended_status) . "',is_detention = '" . addslashes($isDetention) . "',branch_area='" . $_POST['branch_area'] . "',dept='" . $_POST['dept'] . "',injury_cause='" . $_POST['injury_cause'] . "',
|
|
followup_to_opd='" . addslashes($_REQUEST['followup_to_opd']) . "', followup_remarks='" . addslashes($_REQUEST['followup_remarks']) . "',
|
|
health_advices_new='" . addslashes($health_advice_names_new) . "',department='" . $department . "',designation='" . $designation . "'";
|
|
|
|
$query = $query_initial . " " . $query . " " . $query_mid . " " . $query_end;
|
|
|
|
error_log("Appointment Save: " . $query);
|
|
|
|
if (!$result = @mysqli_query($conn, $query)) {
|
|
// main insert fails
|
|
|
|
error_log("Exception:" . mysqli_error($conn));
|
|
error_log("Appointment Save: " . $query);
|
|
rollback();
|
|
exit(error_log(mysqli_error($conn)));
|
|
} else {
|
|
|
|
if (empty($appointment_id) || $appointment_id=='' || $appointment_id==null || $appointment_id==' ') {
|
|
$query = "select max(appointment_id) appointment_id from employee_appointment where emp_id = '" . addslashes($_REQUEST['emp_id']) . "' ";
|
|
// echo $query;
|
|
error_log("max appointment_id query: " . $query);
|
|
if (!$result = @mysqli_query($conn, $query)) {
|
|
rollback();
|
|
exit(error_log(mysqli_error($conn)));
|
|
}
|
|
if (mysqli_num_rows($result) > 0) {
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
$appointment_id = $row['appointment_id'];
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
// if this is only for saving treatment information we should skip saving OPD information.
|
|
treatment_section:
|
|
error_log("at treatment section");
|
|
$curr_ohc_id = getFieldFromTable('ohc_type_id', 'employee_appointment', 'appointment_id', $appointment_id);
|
|
if ($_SESSION['current_ohcttype'] == $curr_ohc_id) {
|
|
error_log("getting inside because current ohc is matching with ohc present for this appointment");
|
|
/* for reset Item Stock At Dispensary Level */
|
|
if($_SESSION['RoleCode']=='DIS'){
|
|
resetItemStockAtDispensaryLevel($appointment_id, $_SESSION['current_ohcttype']);
|
|
}else{
|
|
resetItemStockAtStoreLevel($appointment_id, $_SESSION['current_ohcttype']);
|
|
}
|
|
/* delete all child table during update records */
|
|
if (!@mysqli_query($conn, "delete from appointment_stock_history where appointment_id='" . $appointment_id . "'")) {
|
|
rollback();
|
|
error_log("Exception:" . mysqli_error($conn));
|
|
exit(error_log(mysqli_error($conn)));
|
|
}
|
|
if (!@mysqli_query($conn, "delete from treatment where appointment_id='" . $appointment_id . "' ")) {
|
|
rollback();
|
|
error_log("Exception:" . mysqli_error($conn));
|
|
exit(error_log(mysqli_error($conn)));
|
|
}
|
|
|
|
if ($isTreatmentOnly != 'Y' && !@mysqli_query($conn, "delete from treatment_external where appointment_id='" . $appointment_id . "' ")) {
|
|
rollback();
|
|
error_log("Exception:" . mysqli_error($conn));
|
|
exit(error_log(mysqli_error($conn)));
|
|
}
|
|
|
|
/* insert all child table during save or update records */
|
|
|
|
error_log("treatment row count:" . $_REQUEST['count_treatment_item']);
|
|
for ($i = 0; $i <= $_REQUEST['count_treatment_item']; $i++) {
|
|
|
|
error_log("treatment_item:" . $i . ":" . ${"treatment_item$i"});
|
|
|
|
if (${"treatment_item$i"} != null && ${"treatment_item$i"} != "") {
|
|
// To Check Item is Dressing Or Not
|
|
// echo "adarsh";
|
|
$is_dressing_item = toCheckDressingItem(${"treatment_item$i"});
|
|
error_log("is_dressing_item:" . $is_dressing_item);
|
|
|
|
if ($is_dressing_item == 'P') {
|
|
|
|
// echo ${"group_child_flag_$i"};
|
|
if (${"group_child_flag_$i"} == '1') {
|
|
//When found form elements for the group items.. select udpated values from form.
|
|
|
|
$result_for_group_items = getGroupItems(${"treatment_item$i"});
|
|
$no_rows_group_child = mysqli_num_rows($result_for_group_items);
|
|
error_log("no_rows_group_child:" . $no_rows_group_child);
|
|
for ($j = 0; $j < $no_rows_group_child; $j++) {
|
|
$treatment_given_by='';
|
|
|
|
if(addslashes($_POST['child_item_qty_gvn' . $i . '_' . $j])!=0 || addslashes($_POST['chihld_item_qty_gvn' . $i . '_' . $j])!='' || addslashes($_POST['child_item_qty_gvn' . $i . '_' . $j])!=null ){
|
|
$treatment_given_by=",issue_by='" . $_SESSION['user_id'] . "'";
|
|
}
|
|
|
|
error_log("Child Item:" . $_POST['child_item_' . $i . '_' . $j]);
|
|
$group_item_id = getFieldFromTable('group_id', 'group_items', 'item_id', $_POST['child_item_' . $i . '_' . $j]);
|
|
error_log("group_item_id:" . $group_item_id);
|
|
error_log("childitem:" . $_POST['child_item_' . $i . '_' . $j]);
|
|
$query_treatment = "insert into treatment set appointment_id='" . $appointment_id . "',is_display='N',group_item_id='" . $group_item_id . "',
|
|
item_id='" . addslashes($_POST['child_item_' . $i . '_' . $j]) . "',item_qty='" . addslashes($_POST['child_item_qty_gvn' . $i . '_' . $j]) . "',
|
|
issued_qty='" . addslashes($_POST['child_item_qty_gvn' . $i . '_' . $j]) . "', modified_by='" . $_SESSION['user_id'] . "'" .$treatment_given_by;
|
|
|
|
error_log("query_treatment: " . $query_treatment);
|
|
if (!$result = @mysqli_query($conn, $query_treatment)) {
|
|
|
|
error_log("Exception:" . mysqli_error($conn));
|
|
error_log("Failed query_treatment: " . $query_treatment);
|
|
rollback();
|
|
exit(error_log(mysqli_error($conn)));
|
|
}
|
|
// echo $query_treatment;
|
|
$query_stock_history = " insert into appointment_stock_history set appointment_id='" . $appointment_id . "',
|
|
item_qty='" . addslashes($_POST['child_item_qty_gvn' . $i . '_' . $j]) . "', item_id='" . addslashes($_POST['child_item_' . $i . '_' . $j]) . "',
|
|
issued_qty='" . addslashes($_POST['child_item_qty_gvn' . $i . '_' . $j]) . "'".$treatment_given_by;
|
|
error_log("query_stock_history: " . $query_stock_history);
|
|
if (!@mysqli_query($conn, $query_stock_history)) {
|
|
rollback();
|
|
error_log("issues while updating appointment_stock_history: " . $query_stock_history);
|
|
error_log("Exception:" . mysqli_error($conn));
|
|
exit(mysqli_error($conn));
|
|
}
|
|
// to update Dispensary Items
|
|
if($_SESSION("RoleCode")=='DIS'){
|
|
resetItemStockAtDispensaryLevelForGroupItems(-$_POST['child_item_qty_gvn' . $i . '_' . $j], $_POST['child_item_' . $i . '_' . $j], $_SESSION['current_ohcttype']);
|
|
}else{
|
|
resetItemStockAtStoreLevelForGroupItems(-$_POST['child_item_qty_gvn' . $i . '_' . $j], $_POST['child_item_' . $i . '_' . $j], $_SESSION['current_ohcttype'],$_POST['item_batch_no'. $i]);
|
|
}
|
|
}
|
|
} else {
|
|
//When nothing is returned from the form for the group items.. we use the calculated item qty from dressing item definitions
|
|
|
|
|
|
|
|
$result_for_group_items = getGroupItems(${"treatment_item$i"});
|
|
while ($row_for_group_items = mysqli_fetch_array($result_for_group_items)) {
|
|
|
|
$treatment_qty_given_by='';
|
|
|
|
if($doctor_attended_flag=='Y' && (($_SESSION['RoleCode']=='DIS')|| in_array('DIS',explode(',',$_SESSION ['RoleCode'])) )){
|
|
if(addslashes($row_for_group_items['qty'])==0 || addslashes($row_for_group_items['qty'])=='' || addslashes($row_for_group_items['qty'])==null ){
|
|
$treatment_qty_given_by=",issue_by='" . $_SESSION['user_id'] . "'";
|
|
error_log('trtr');
|
|
}}
|
|
$query_treatment = "insert into treatment set appointment_id='" . $appointment_id . "',is_display='N',group_item_id='" . $row_for_group_items['group_id'] . "',
|
|
item_id='" . addslashes($row_for_group_items['item_id']) . "',item_qty='" . addslashes($row_for_group_items['qty']) . "',
|
|
issued_qty='" . addslashes($row_for_group_items['qty']) . "', modified_by='" . $_SESSION['user_id'] . "'".$treatment_qty_given_by;
|
|
|
|
if (!@mysqli_query($conn, $query_treatment)) {
|
|
error_log("issues while updating treatment: " . $query_treatment);
|
|
error_log("Exception:" . mysqli_error($conn));
|
|
rollback();
|
|
exit(mysqli_error($conn));
|
|
}
|
|
// echo $query_treatment;
|
|
$query_stock_history = " insert into appointment_stock_history set appointment_id='" . $appointment_id . "',
|
|
item_qty='" . addslashes($row_for_group_items['qty']) . "', item_id='" . addslashes($row_for_group_items['item_id']) . "',
|
|
issued_qty='" . addslashes($row_for_group_items['qty']) . "'".$treatment_qty_given_by;
|
|
if (!@mysqli_query($conn, $query_stock_history)) {
|
|
rollback();
|
|
error_log("Appointment stock history saving error::" . mysqli_error($conn) . "Failed query::" . $query_stock_history);
|
|
exit(mysqli_error($conn));
|
|
}
|
|
}
|
|
}
|
|
} //end for handling of dressing items
|
|
$treatment_qty_given_by='';
|
|
|
|
|
|
|
|
if($doctor_attended_flag=='Y' && (($_SESSION['RoleCode']=='DIS')|| in_array('DIS',explode(',',$_SESSION ['RoleCode'])) )){
|
|
if(addslashes(${"treatment_item_qtygvn$i"})!=0 || addslashes(${"treatment_item_qtygvn$i"})!='' || addslashes(${"treatment_item_qtygvn$i"})!=null ){
|
|
$treatment_qty_given_by=",issue_by='" . $_SESSION['user_id'] . "'";
|
|
|
|
error_log('trtr');
|
|
}
|
|
}
|
|
|
|
$query_treatment = "insert into treatment SET appointment_id='" . $appointment_id . "',
|
|
item_id='" . addslashes(${"treatment_item$i"}) . "',item_qty='" . addslashes(${"dose_qty$i"}) . "',
|
|
issued_qty='" . addslashes(${"treatment_item_qtygvn$i"}) . "', item_batch_no='" . addslashes(${"item_batch_no$i"}) . "',dosage='" . addslashes(${"dosage$i"}) . "',
|
|
for_days='" . addslashes(${"treatment_item_days$i"}) . "', frequency_id='" . ${"treatment_item_dosage$i"} . "', timing_id = '" . ${"timings$i"} . "',
|
|
dosage_category_id='" . ${"treatment_item_dosage_category$i"} . "', modified_by='" . $_SESSION['user_id'] . "'".$treatment_qty_given_by;
|
|
error_log("query_treatment: " . $query_treatment);
|
|
if (!$result = @mysqli_query($conn, $query_treatment)) {
|
|
|
|
error_log("Error Saving Treatment data: " . mysqli_error($conn) . " Failed Query:" . $query_treatment);
|
|
rollback();
|
|
exit(mysqli_error($conn));
|
|
}
|
|
|
|
// insert or update the cost details start
|
|
if ($is_dressing_item != 'P') {
|
|
$past_appointment_id = getTableFieldValue('treatment_cost_master', 'appointment_id', 'item_id', ${"treatment_item$i"}, 'appointment_id', $appointment_id);
|
|
|
|
if ($past_appointment_id != "" || $past_appointment_id != null) {
|
|
error_log("update case for cost saving");
|
|
$initquery = "update ";
|
|
$endquery = " where item_id='" . ${"treatment_item$i"} . "' and appointment_id='" . $appointment_id . "'";
|
|
} else {
|
|
$initquery = "insert into ";
|
|
$endquery = "";
|
|
}
|
|
|
|
$present_per_unit_cost = getTableFieldValue('item_cost', 'item_rate_latest', 'ohc_type_id', $_SESSION['current_ohcttype'], 'item_id', ${"treatment_item$i"});
|
|
|
|
$total_cost = round($present_per_unit_cost * ${"treatment_item_qtygvn$i"});
|
|
|
|
error_log("latest rate for item id " . getItemWithFormName(${"treatment_item$i"}) . " " . $present_per_unit_cost . " total sum for this item " . $total_cost);
|
|
|
|
$insert_treatment_cost = $initquery . " treatment_cost_master set appointment_id='" . $appointment_id . "',ohc_type_id='" . $_SESSION['current_ohcttype'] . "',issued_item_cost='" . $total_cost . "',item_id='" . ${"treatment_item$i"} . "' $endquery";
|
|
|
|
error_log("cost saving query for opd " . $insert_treatment_cost);
|
|
|
|
if (!$insert_treatment_cost_result = mysqli_query($conn, $insert_treatment_cost)) {
|
|
error_log("error in cost saving query for opd " . mysqli_error($conn));
|
|
}
|
|
} else {
|
|
|
|
$past_appointment_id = getTableFieldValue('treatment_cost_master', 'appointment_id', 'item_id', ${"treatment_item$i"}, 'appointment_id', $appointment_id);
|
|
|
|
if ($past_appointment_id != "" || $past_appointment_id != null) {
|
|
error_log("update case for cost saving");
|
|
$initquery = "update ";
|
|
$endquery = " where item_id='" . ${"treatment_item$i"} . "' and appointment_id='" . $appointment_id . "'";
|
|
} else {
|
|
$initquery = "insert into ";
|
|
$endquery = "";
|
|
}
|
|
|
|
$present_per_unit_cost = getTableFieldValue('group_items', 'cost', 'group_id', ${"treatment_item$i"});
|
|
|
|
$total_cost = round($present_per_unit_cost * ${"treatment_item_qtygvn$i"});
|
|
|
|
error_log("latest rate for item id " . getItemWithFormName(${"treatment_item$i"}) . " " . $present_per_unit_cost . " total sum for this item " . $total_cost);
|
|
|
|
$insert_treatment_cost = $initquery . " treatment_cost_master set appointment_id='" . $appointment_id . "',ohc_type_id='" . $_SESSION['current_ohcttype'] . "',issued_item_cost='" . $total_cost . "',item_id='" . ${"treatment_item$i"} . "' $endquery";
|
|
|
|
error_log("cost saving query for opd " . $insert_treatment_cost);
|
|
|
|
if (!$insert_treatment_cost_result = mysqli_query($conn, $insert_treatment_cost)) {
|
|
error_log("error in cost saving query for opd " . mysqli_error($conn));
|
|
}
|
|
}
|
|
// insert or update the cost details end
|
|
$treatment_qty_given_by='';
|
|
|
|
|
|
if($doctor_attended_flag=='Y' && (($_SESSION['RoleCode']=='DIS')|| in_array('DIS',explode(',',$_SESSION ['RoleCode'])) )){
|
|
if(addslashes(${"treatment_item_qtygvn$i"})!=0 || addslashes(${"treatment_item_qtygvn$i"})!='' || addslashes(${"treatment_item_qtygvn$i"})!=null ){
|
|
$treatment_qty_given_by=",issue_by='" . $_SESSION['user_id'] . "'";
|
|
error_log('trtr');
|
|
}
|
|
}
|
|
$query_stock_history = " insert into appointment_stock_history set appointment_id='" . $appointment_id . "', current_stock='" . addslashes(${"current_stock$i"}) . "',item_qty='" . addslashes(${"frequency_qty$i"}) . "', item_id='" . addslashes(${"treatment_item$i"}) . "',issued_qty='" . addslashes(${"treatment_item_qtygvn$i"}) . "'".$treatment_qty_given_by;
|
|
error_log(" appointment_stock_history update details: " . $query_stock_history);
|
|
if (!@mysqli_query($conn, $query_stock_history)) {
|
|
rollback();
|
|
error_log("Error updating appointment_stock_history: " . $query_stock_history);
|
|
error_log("Exception:" . mysqli_error($conn));
|
|
exit(error_log(mysqli_error($conn)));
|
|
}
|
|
|
|
if (${"group_child_flag_$i"} != '1')
|
|
updaterItemStock($_SESSION['current_ohcttype'], addslashes(${"treatment_item$i"}), ${"treatment_item_qtygvn$i"},${"item_batch_no$i"});
|
|
|
|
|
|
|
|
/*
|
|
* //$item_batch_no=getMinExpiaryDateItem($_SESSION['current_ohcttype'], addslashes(${"treatment_item$i"}));
|
|
* $current_stock_qty=getStockQtyAtDispensaryLevel(${"treatment_item$i"},$_SESSION['current_ohcttype']);
|
|
* // echo $current_stock_qty;
|
|
* $stock_qty = floatval ( $current_stock_qty ) - (floatval ( ${"treatment_item_qtygvn$i"} ));
|
|
* //echo $stock_qty;
|
|
* $current_stock_query = "update item_stock_dispensary set stock_qty='".$stock_qty."' where item_id='".${"treatment_item$i"}."' and item_batch_no='".$item_batch_no."' and ohc_location_id='".$_SESSION['current_ohcttype']."' ";
|
|
* // echo $current_stock_query;
|
|
* mysqli_query($conn,$current_stock_query );
|
|
*/
|
|
} else if ($isTreatmentOnly != 'Y' && ${"treatment_item_external$i"} != null && ${"treatment_item_external$i"} != "") {
|
|
|
|
$query_treatment = "insert into treatment_external SET appointment_id='" . $appointment_id . "',
|
|
item_name='" . addslashes(${"treatment_item_external$i"}) . "',item_qty='" . addslashes(${"dose_qty$i"}) . "',timing = '" . addslashes(${"timings$i"}) . "',dosage='" . addslashes(${"treatment_item_dosage$i"}) . "',
|
|
for_days='" . addslashes(${"treatment_item_days$i"}) . "', dosage_category_id='" . ${"treatment_item_dosage_category$i"} . "', modified_by='" . $_SESSION['user_id'] . "' ";
|
|
|
|
if (!@mysqli_query($conn, $query_treatment)) {
|
|
|
|
error_log("error saving treamemnt external : " . $query_treatment);
|
|
error_log("Exception:" . mysqli_error($conn));
|
|
|
|
exit(error_log(mysqli_error($conn)));
|
|
rollback();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
commit();
|
|
$data['appointment_id'] = $appointment_id;
|
|
error_log(print_r($data), true);
|
|
echo json_encode($data); |