$value) { $requestStr .= $key . " : " . $value . "\n"; // error_log($key . " : " . $value . "
\r\n"); } error_log("End Printing Request Attributes"); save_log($requestStr, 'Save_OPD', 'SAVE', 'save_opd.php'); // error_reporting(E_ERROR | E_PARSE); $followup_id = $_REQUEST['followup_id']; begin(); if ($_REQUEST['appointment_id'] == null || $_REQUEST['appointment_id'] == '' || $_REQUEST['appointment_id'] == '0') { $appointment_id = $_REQUEST['appoint']; } else { $appointment_id = $_REQUEST['appointment_id']; } $edit_enable = strtolower($_REQUEST['edit_table_key']); $medicine_issued = trim($_REQUEST['med_dis_key']); // echo $appointment_id; $data = array(); $appointment_date = $_POST['appointment_date']; $isTreatmentOnly = $_POST['isTreatmentOnly']; $is_followup = $_REQUEST['followup_to_opd']; if ($is_followup == null || empty($is_followup) || $is_followup == '') { $is_followup = $followup_id; } error_log('isTreatmentOnly:' . $isTreatmentOnly); //treatment prepared statements start $query_treatment_dressing = "insert into treatment set appointment_id=?,is_display='N',group_item_id=?, followup_id = ?,item_id=?,item_qty=?, issued_qty=?, modified_by=?,issue_by=? "; $stmt_query_treatment_dressing = $conn->prepare($query_treatment_dressing); $query_stock_history_dressing = " insert into appointment_stock_history set appointment_id=?, followup_id = ?,item_qty=?, item_id=?,issued_qty=?, issue_by=?"; $stmt_query_stock_history_dressing = $conn->prepare($query_stock_history_dressing); $query_treatment = "insert into treatment SET appointment_id=?, item_id=?,item_qty=?,followup_id = ?,issued_qty=?, item_batch_no=?,dosage=?,for_days=?, frequency_id=?, timing_id = ?,dosage_category_id=?, modified_by=?,issue_by=?"; $stmt_query_treatment = $conn->prepare($query_treatment); $query_stock_history = "insert into appointment_stock_history set appointment_id=?, current_stock=?,item_qty=?,item_id=?,issued_qty=?,followup_id = ?, issue_by=?"; $stmt_query_stock_history = $conn->prepare($query_stock_history); $query_treatment_external = "insert into treatment_external SET appointment_id=?,followup_id = ?,item_name=?,item_qty=?,timing = ?,dosage=?,for_days=?, dosage_category_id=?, modified_by=? "; $stmt_query_treatment_external = $conn->prepare($query_treatment_external); //end if ($isTreatmentOnly == 'Y') { $sql_update_status_all = " update employee_appointment set attended_status='CLS', clearance_time=STR_TO_DATE(?, '%d/%m/%Y %h:%i %p'), medi_disbursement='Y' where appointment_id=?"; error_log("is treatment only if yes opd query " . $sql_update_status_all); $out_time = $_POST['out_time']; $stmt_sql_update_status_all = $conn->prepare($sql_update_status_all); if ($stmt_sql_update_status_all) { $stmt_sql_update_status_all->bind_param("ss", $out_time, $appointment_id); $stmt_sql_update_status_all->execute(); if ($stmt_sql_update_status_all->errno) { error_log("Exception:" . $stmt_sql_update_status_all->error); rollback(); exit(); } } else { error_log("Error in preparing the statement: " . $conn->error); rollback(); exit(error_log($conn->error)); } if ($stmt_sql_update_status_all != null) { $stmt_sql_update_status_all->close(); } if ($followup_id != '' && $followup_id != null && $followup_id != 0) { $sql_update_status = " update followup_details set attended_status='CLS', clearance_time=STR_TO_DATE(?, '%d/%m/%Y %h:%i %p'), medi_disbursement='Y' where followup_id=? "; error_log("is treatment only if yes followup query " . $sql_update_status . " with followup id " . $followup_id); $stmt_sql_update_status = $conn->prepare($sql_update_status); if ($stmt_sql_update_status) { $stmt_sql_update_status->bind_param("ss", $out_time, $followup_id); $stmt_sql_update_status->execute(); if ($stmt_sql_update_status->errno) { error_log("Exception:" . $stmt_sql_update_status->error); rollback(); exit(); } } else { error_log("Error in preparing the statement: " . $conn->error); rollback(); exit(error_log($conn->error)); } if ($stmt_sql_update_status != null) { $stmt_sql_update_status->close(); } goto treatment_section; } else { goto treatment_section; } } $ailment_ids_new = strtoupper($_POST['ailment_new']); error_log("ailment_ids_new:" . $ailment_ids_new); $patient_id = addslashes($_REQUEST['emp_id']); $complaint_ids = strtoupper($_POST['complaints']); $finding_ids = strtoupper($_POST['examination_remarks']); $referral_ids = ($_POST['referral_point']); $referral_consultation = trim(strtoupper($_POST['referral_consultation'])); $referred_by = $_POST['referred_by']; $disease_type = $_POST['disease_type']; $ailment_system_ids_new = implode(',', $_POST['ailment_system_new']); $injuryTypes_new = implode(',', $_POST['injury_type_new']); $injuryClasses_new = implode(',', $_POST['injury_class_new']); $injuryParts_new = trim($_POST['injury_part']); $injury_mech = trim($_POST['injury_mech_new']); $health_advice_names_new = strtoupper($_POST['health_advice_name_new']); $drug_allergy = strtoupper($_POST['drug_allergy']); $tests_new = implode(",", $_POST['recommended_test_new']); $test_param_new = implode(",", $_POST['recommended_test_param_new']); error_log("selected test param " . $test_param_new); $diagnosis_config = getFieldFromTable('value', 'config', 'key_name', 'diagnosis_tag_switch'); if (!strcmp(strtolower($diagnosis_config), "true")) { $ailment_ids_new = handleDynamicMasterInsertModified("ailment", "ailment_name", "ailment_id", $ailment_ids_new, true); error_log("ailment_ids_new:" . implode(',', $ailment_ids_new)); $ailment_ids_new = getMultiValuedSelectData($ailment_ids_new); error_log("ailment_ids_new2:" . $ailment_ids_new); } if (!strcmp(strtolower($diagnosis_config), "false")) { $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)); } $examination_remarks_config = getFieldFromTable('value', 'config', 'key_name', 'examination_tag_switch'); if (!strcmp(strtolower($examination_remarks_config), "true")) { $finding_ids = handleDynamicMasterInsert("examination_findings", "examination_finding", "id", $finding_ids, true); error_log("finding_ids:" . implode(',', $finding_ids)); $finding_ids = getMultiValuedSelectData($finding_ids); error_log("finding_ids2:" . $finding_ids); } if (!strcmp(strtolower($examination_remarks_config), "false")) { $finding_ids = $_REQUEST['examination_remarks']; $finding_ids = implode(',', $finding_ids); error_log("$finding_ids config off : " . print_r($finding_ids, true)); } $complaint_config = getFieldFromTable('value', 'config', 'key_name', 'complaint_tag_switch'); if (!strcmp(strtolower($complaint_config), "true")) { $complaint_ids = handleDynamicMasterInsertModified("complaints", "complaint", "complaint_id", $complaint_ids, true); error_log("complaint_ids:" . implode(',', $complaint_ids)); $complaint_ids = getMultiValuedSelectData($complaint_ids); error_log("complaint_ids2:" . $complaint_ids); } if (!strcmp(strtolower($complaint_config), "false")) { $complaint_ids = $_REQUEST['complaints']; $complaint_ids = implode(',', $complaint_ids); error_log("$complaint ids config off : " . print_r($complaint_ids, true)); } $injury_part_config = getFieldFromTable('value', 'config', 'key_name', 'injury_part_switch'); if (!strcmp(strtolower($injury_part_config), "true")) { $part_ids = handleDynamicMasterInsertIgnoreCase("injury_part", "inj_name", "inj_id", $injuryParts_new); error_log("part_ids:" . implode(',', $part_ids)); $part_ids = getMultiValuedSelectData($part_ids); error_log("part_ids:" . $part_ids); } if (!strcmp(strtolower($injury_part_config), "false")) { $part_ids = $_REQUEST['injury_part']; $part_ids = implode(',', $part_ids); error_log("part_ids ids config off : " . print_r($part_ids, true)); } $injury_mech_config = getFieldFromTable('value', 'config', 'key_name', 'injury_mechanism_switch'); if (!strcmp(strtolower($injury_mech_config), "true")) { $mech_ids = handleDynamicMasterInsertIgnoreCase("injury_mechanism", "injury_mech_name", "injury_mech_id", $injury_mech); error_log("mech_ids:" . implode(',', $mech_ids)); $mech_ids = getMultiValuedSelectData($mech_ids); error_log("mech_ids:" . $mech_ids); } if (!strcmp(strtolower($injury_mech_config), "false")) { $mech_ids = $_REQUEST['injury_mech_new']; $mech_ids = implode(',', $mech_ids); error_log("mech_ids ids config off : " . print_r($mech_ids, true)); } $drug_allergy = $_REQUEST['drug_allergy']; $drug_allergy = implode(',', $drug_allergy); error_log("$drug_allergy ids config off : " . print_r($drug_allergy, true)); handleDynamicMasterInsert("health_advice", "health_advice_name", "health_advice_id", $health_advice_names_new); $advise_ids = getCommaSeperatedValuesForInClauseWithSpace("select health_advice_id from health_advice ", "health_advice_name", $health_advice_names_new); error_log('$advise_ids' . $advise_ids); $height = $_POST['height']; $weight = $_POST['weight']; $bmi = $_POST['bmi']; /* updating height weight bmi */ updateHeightWeightBmi($height, $weight, $bmi, $_REQUEST['emp_id']); $spoc2_percent = $_POST['spoc2_percent']; $sbp = $_POST['sbp']; $dbp = $_POST['dbp']; $temperature = $_POST['temperature']; $respiratory_rate = $_POST['resp_rate']; $urine_output = $_POST['urine_output']; $avpu = $_POST['avpu']; $trama = $_POST['trama']; $mobility = $_POST['mobility']; $abnormalitys = $_POST['abnormalityIds']; $oxygen_supply = $_POST['oxygen_supply']; $glasgow_scale = $_POST['glasgow_coma_scale']; $grbs = $_POST['grbs']; $bac_level = $_POST['bac_level']; $total_cholesterol = $_POST['total_cholesterol']; $external_treatments = $_POST['external_treatments']; $activity = $_POST['activity']; $ppe = $_POST['ppe']; $any_medication = $_POST['any_medication']; $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') { $attended_status = 'PHP'; $isDetention = 'Y'; } else { $attended_status = $_REQUEST['attendedStatus']; $isDetention = 'N'; } // $health_index = calculateHealthIndex($sbp, $dbp, $bmi, $fbs, $total_cholesterol); $health_advice_names = getMultiValuedSelectData(strtoupper($_POST['health_advice_name'])); $health_risk_names = getMultiValuedSelectData(strtoupper($_POST['health_risk_name'])); $medicine_disbursement = $_POST['medicine_disbursement']; if (trim($medicine_disbursement) == '') { $medicine_disbursement = $medicine_issued; } $tests = getMultiValuedSelectData(strtoupper($_POST['recommended_test'])); $query = ""; $query_initial = ""; $query_mid = ""; $query_end = " "; $department = getFieldFromTable('dept_id', 'patient_master', 'id', $_REQUEST['emp_id']); $designation = getFieldFromTable('designation_id', 'patient_master', 'id', $_REQUEST['emp_id']); // Building parts for the values in the query $query_parts = array(); $query_values = array(); if (!empty($_REQUEST['emp_id'])) { $query_parts[] = "emp_id=? "; $query_values[] = $_REQUEST['emp_id']; } if (!empty($medicine_disbursement)) { $query_parts[] = "medi_disbursement=? "; $query_values[] = $medicine_disbursement; } if (!empty($doctor_attended_flag)) { $query_parts[] = "doctor_attended_flag=?"; $query_values[] = $doctor_attended_flag; } // if (!empty($ticket_no)) { // $query_parts[] = "ticket_no=?"; // $query_values[] = $ticket_no; // } if (!empty($_POST['remarks_rece'])) { $query_parts[] = "remarks_rece=? "; $query_values[] = $_POST['remarks_rece']; } if (!empty($_REQUEST['chronic_day'])) { $query_parts[] = "chronic_day=?"; $query_values[] = $_REQUEST['chronic_day']; } if (!empty($_REQUEST['doctor_discuss_id'])) { $query_parts[] = "doctor_discussed_id=?"; $query_values[] = $_REQUEST['doctor_discuss_id']; } if (!empty($_REQUEST['appointment_type'])) { $query_parts[] = "appointment_type=?"; $query_values[] = $_REQUEST['appointment_type']; } if (!empty($ailment_ids)) { $query_parts[] = "ailment_ids=?"; $query_values[] = $ailment_ids; } if (!empty($ailment_system_ids)) { $query_parts[] = "ailment_system_ids=?"; $query_values[] = $ailment_system_ids; } // if (!empty($_REQUEST['isEmergency'])) { // $query_parts[] = "IsEmergency=?"; // $query_values[] = $_REQUEST['isEmergency']; // } if (!empty($_REQUEST['isChargeable'])) { $query_parts[] = "IsChargeable=?"; $query_values[] = $_REQUEST['isChargeable']; } if (!empty($complaint_ids)) { $query_parts[] = "complaints=?"; $query_values[] = $complaint_ids; } if (!empty($referred_by)) { $query_parts[] = "referred_by=?"; $query_values[] = $referred_by; } if (!empty($_POST['referred_to'])) { $query_parts[] = "referred_to=?"; $query_values[] = $_POST['referred_to']; } if (!empty($_POST['clinical_opinion'])) { $query_parts[] = "clinical_opinion=?"; $query_values[] = $_POST['clinical_opinion']; } if (!empty($finding_ids)) { $query_parts[] = "examination_remarks=?"; $query_values[] = $finding_ids; } if (!empty($disease_type)) { $query_parts[] = "disease_type=?"; $query_values[] = $disease_type; } if (!empty($_POST['injury_area_cat'])) { $query_parts[] = "injury_area_cat=?"; $query_values[] = $_POST['injury_area_cat']; } if (!empty($_POST['injury_area_type'])) { $query_parts[] = "injury_area_type=?"; $query_values[] = $_POST['injury_area_type']; } if (!empty($_REQUEST['sbp'])) { $query_parts[] = "bp_sbp=?"; $query_values[] = $_REQUEST['sbp']; } if (!empty($_POST['heart_rate'])) { $query_parts[] = "heart_rate=?"; $query_values[] = $_POST['heart_rate']; } if (!empty($_POST['pulse_output'])) { $query_parts[] = "pulse_output=?"; $query_values[] = $_POST['pulse_output']; } if (!empty($height)) { $query_parts[] = "height=?"; $query_values[] = $height; } if (!empty($weight)) { $query_parts[] = "weight=?"; $query_values[] = $weight; } if (!empty($_POST['dbp'])) { $query_parts[] = "bp_dbp=?"; $query_values[] = $_POST['dbp']; } if (!empty($_POST['ipd'])) { $query_parts[] = "ipd=?"; $query_values[] = $_POST['ipd']; } if (!empty($_POST['fbs'])) { $query_parts[] = "blood_sugar_fbs=?"; $query_values[] = $_POST['fbs']; } if (!empty($_POST['fbs'])) { $query_parts[] = "blood_sugar_fbs=?"; $query_values[] = $_POST['fbs']; } if (!empty($_POST['rbs'])) { $query_parts[] = "blood_sugar_rbs=?"; $query_values[] = $_POST['rbs']; } if (!empty($_POST['ppbs'])) { $query_parts[] = "blood_sugar_ppbs=?"; $query_values[] = $_POST['ppbs']; } if (!empty($bmi)) { $query_parts[] = "bmi=?"; $query_values[] = $bmi; } if (!empty($respiratory_rate)) { $query_parts[] = "respiratory_rate=?"; $query_values[] = $respiratory_rate; } if (!empty($urine_output)) { $query_parts[] = "urine_output=?"; $query_values[] = $urine_output; } if (!empty($avpu)) { $query_parts[] = "avpu=?"; $query_values[] = $avpu; } if (!empty($trama)) { $query_parts[] = "trama=?"; $query_values[] = $trama; } if (!empty($mobility)) { $query_parts[] = "mobility=?"; $query_values[] = $mobility; } if (!empty($oxygen_supply)) { $query_parts[] = "oxygen_supply=?"; $query_values[] = $oxygen_supply; } if (!empty($glasgow_coma_scale)) { $query_parts[] = "glasgow_coma_scale=?"; $query_values[] = $glasgow_coma_scale; } if (!empty($total_cholesterol)) { $query_parts[] = "total_cholesterol=?"; $query_values[] = $total_cholesterol; } if (!empty($temperature)) { $query_parts[] = "temperature=?"; $query_values[] = $temperature; } if (!empty($grbs)) { $query_parts[] = "grbs=?"; $query_values[] = $grbs; } if (!empty($bac_level)) { $query_parts[] = "bac_level=?"; $query_values[] = $bac_level; } if (!empty($spoc2_percent)) { $query_parts[] = "spo2_percent=?"; $query_values[] = $spoc2_percent; } if (!empty($referral_ids)) { if (CheckReferralEmail($appointment_id) == 0) { $refferralMailFlag = 1; } else { $refferralMailFlag = 0; } $query_parts[] = "referral=?"; $query_values[] = $referral_ids; } else { $refferralMailFlag = 0; } if (!empty($referral_consultation)) { $query_parts[] = "referral_consultation=?"; $query_values[] = $referral_consultation; } if (!empty($_POST['followup'])) { $query_parts[] = "followup =STR_TO_DATE(?,'%Y-%m-%d')"; $query_values[] = $_POST['followup']; } if (!empty($_POST['case_type'])) { $query_parts[] = "case_type=?"; $query_values[] = $_POST['case_type']; } if (!empty($_POST['shift_type'])) { $query_parts[] = "shift_type=?"; $query_values[] = $_POST['shift_type']; } // if (!empty($_POST['ppe'])) { // $query_parts[] = "ppe=?"; // $query_values[] = $_POST['ppe']; // } if (!empty($_POST['injury_def'])) { $query_parts[] = "injury_def=?"; $query_values[] = $_POST['injury_def']; } if (!empty($remarks)) { $query_parts[] = "remarks=?"; $query_values[] = $remarks; } if (!empty($activity)) { $query_parts[] = "activity=?"; $query_values[] = $activity; } if (!empty($ppe)) { $query_parts[] = "ppe=?"; $query_values[] = $ppe; } if (!empty($any_medication)) { $query_parts[] = "any_medication=?"; $query_values[] = $any_medication; } if (!empty($drug_allergy)) { $query_parts[] = "drug_allergy=?"; $query_values[] = $drug_allergy; } if (!empty($injury_remarks)) { $query_parts[] = "injury_remarks=?"; $query_values[] = $injury_remarks; } if (!empty($doc_comment)) { $query_parts[] = "doc_comment=?"; $query_values[] = $doc_comment; } if (!empty($is_admitted)) { $query_parts[] = "is_admitted=?"; $query_values[] = $is_admitted; } if (!empty($_POST['additional_treatment_info'])) { $query_parts[] = "additional_treatment_info=?"; $query_values[] = $_POST["additional_treatment_info"]; } if (!empty($_POST['referral_doc'])) { $query_parts[] = "referral_doc=?"; $query_values[] = $_POST['referral_doc']; } if (!empty($_POST['is_hospitalized'])) { $query_parts[] = "is_hospitalized=?"; $query_values[] = $_POST['is_hospitalized']; } if (!empty($_POST['ambulance_in_time'])) { $query_parts[] = "ambulance_in_time=STR_TO_DATE(?, '%d/%m/%Y %h:%i %p')"; $query_values[] = $_POST['ambulance_in_time']; } if (!empty($_POST['ambulance_out_time'])) { $query_parts[] = "ambulance_out_time=STR_TO_DATE(?, '%d/%m/%Y %h:%i %p')"; $query_values[] = $_POST['ambulance_out_time']; } if (!empty($_POST['report_time'])) { $query_parts[] = "report_time=STR_TO_DATE(?, '%d/%m/%Y %h:%i %p')"; $query_values[] = $_POST['report_time']; } if (!empty($ambulance_used)) { $query_parts[] = "ambulance_used=?"; $query_values[] = $ambulance_used; } if (!empty($_POST['safety_officer'])) { $query_parts[] = "safety_officer=?"; $query_values[] = $_POST['safety_officer']; } if (!empty($deu_date)) { $query_parts[] = "deu_date=?"; $query_values[] = $deu_date; } if (!empty($_POST['appointment_date'])) { $query_parts[] = "appointment_date =STR_TO_DATE(?, '%d/%m/%Y %h:%i %p')"; $query_values[] = $_POST['appointment_date']; } if (!empty($_POST['out_time'])) { $query_parts[] = "clearance_time =STR_TO_DATE(?, '%d/%m/%Y %h:%i %p')"; $query_values[] = $_POST['out_time']; } if (!empty($_POST['injury_time'])) { $query_parts[] = "injury_time =STR_TO_DATE(?, '%d/%m/%Y %h:%i %p')"; $query_values[] = $_POST['injury_time']; } if (!empty($_POST['rest_from_time'])) { $query_parts[] = "rest_from_time =STR_TO_DATE(?, '%d/%m/%Y %h:%i %p')"; $query_values[] = $_POST['rest_from_time']; } if (!empty($_POST['rest_to_time'])) { $query_parts[] = "rest_to_time =STR_TO_DATE(?, '%d/%m/%Y %h:%i %p')"; $query_values[] = $_POST['rest_to_time']; } if (!empty($mech_ids)) { $query_parts[] = "injury_mech =?"; $query_values[] = $mech_ids; } if (!empty($_SESSION['user_id'])) { $query_parts[] = "modified_by =?"; $query_values[] = $_SESSION['user_id']; } if (!empty($_SESSION['current_ohcttype'])) { $query_parts[] = "ohc_type_id =?"; $query_values[] = $_SESSION['current_ohcttype']; } if (!empty($injuryTypes)) { $query_parts[] = "injury_types =?"; $query_values[] = $injuryTypes; } if (!empty($injuryClasses)) { $query_parts[] = "injury_classes =?"; $query_values[] = $injuryClasses; } if (!empty($injuryParts)) { $query_parts[] = "injury_parts =?"; $query_values[] = $injuryParts; } if (!empty($_REQUEST['injury_form'])) { $query_parts[] = "injury_form =?"; $query_values[] = $_REQUEST['injury_form']; } if (!empty($_POST['absence_start'])) { $query_parts[] = "absence_start=STR_TO_DATE(?, '%d/%m/%Y')"; $query_values[] = $_POST['absence_start']; } if (!empty($_POST['absence_end'])) { $query_parts[] = "absence_end=STR_TO_DATE(?, '%d/%m/%Y')"; $query_values[] = $_POST['absence_end']; } if (!empty($_REQUEST['injury_firm'])) { $query_parts[] = "injury_firm =?"; $query_values[] = $_REQUEST['injury_firm']; } if (!empty($_REQUEST['incident_location'])) { $query_parts[] = "incident_location =?"; $query_values[] = $_REQUEST['incident_location']; } if (!empty($_REQUEST['injury_sbu'])) { $query_parts[] = "injury_sbu =?"; $query_values[] = $_REQUEST['injury_sbu']; } if (!empty($_REQUEST['injury_section'])) { $query_parts[] = "injury_section =?"; $query_values[] = $_REQUEST['injury_section']; } if (!empty($_REQUEST['doctor_discussed'])) { $query_parts[] = "doctor_discussed =?"; $query_values[] = $_REQUEST['doctor_discussed']; } if (!empty($_REQUEST['doctor_last_attended'])) { $query_parts[] = "doctor_last_attended =?"; $query_values[] = $_REQUEST['doctor_last_attended']; } if (!empty($_REQUEST['injury_sub_section'])) { $query_parts[] = "injury_sub_section =?"; $query_values[] = $_REQUEST['injury_sub_section']; } if (!empty($tests)) { $query_parts[] = "tests =?"; $query_values[] = $tests; } if (!empty($_REQUEST['pro_remarks'])) { $query_parts[] = "injury_procedure =?"; $query_values[] = $_REQUEST['pro_remarks']; } if (!empty($_REQUEST['hospital_treatment'])) { $query_parts[] = "hospital_treatment =?"; $query_values[] = $_REQUEST['hospital_treatment']; } if (!empty($health_advice_names)) { $query_parts[] = "health_advice_names=?"; $query_values[] = $health_advice_names; } if (!empty($_POST['order_level_total'])) { $query_parts[] = "total_amount=?"; $query_values[] = $_POST['order_level_total']; } if (!empty($abnormalitys)) { $query_parts[] = "abnormalitys=?"; $query_values[] = $abnormalitys; } if (!empty($_REQUEST['token_no'])) { $query_parts[] = "token_no=?"; $query_values[] = $_REQUEST['token_no']; } if (!empty($ailment_ids_new)) { $query_parts[] = "ailments_new=?"; $query_values[] = $ailment_ids_new; } if (!empty($ailment_system_ids_new)) { $query_parts[] = "ailment_systems_new=?"; $query_values[] = $ailment_system_ids_new; } if (!empty($injuryTypes_new)) { $query_parts[] = "injury_types_new=?"; $query_values[] = $injuryTypes_new; } if (!empty($injuryClasses_new)) { $query_parts[] = "injury_classes_new=?"; $query_values[] = $injuryClasses_new; } if (!empty($part_ids)) { $query_parts[] = "injury_parts_new=?"; $query_values[] = $part_ids; } if (!empty($tests_new)) { $query_parts[] = "recommended_tests_new=?"; $query_values[] = $tests_new; } if (!empty($test_param_new)) { $query_parts[] = "recommended_test_param_new=?"; $query_values[] = $test_param_new; } if (!empty($health_index)) { $query_parts[] = "health_index=?"; $query_values[] = $health_index; } if (!empty($external_treatments)) { $query_parts[] = "external_treatments=?"; $query_values[] = $external_treatments; } if (!empty($attended_status)) { $query_parts[] = "attended_status=?"; $query_values[] = $attended_status; } if (!empty($isDetention)) { $query_parts[] = "is_detention=?"; $query_values[] = $isDetention; } if (!empty($_POST['branch_area'])) { $query_parts[] = "branch_area=?"; $query_values[] = $_POST['branch_area']; } if (!empty($_POST['dept'])) { $query_parts[] = "dept=?"; $query_values[] = $_POST['dept']; } if (!empty($_POST['injury_cause'])) { $query_parts[] = "injury_cause=?"; $query_values[] = $_POST['injury_cause']; } if (!empty($_REQUEST['followup_to_opd'])) { $query_parts[] = "followup_to_opd=?"; $query_values[] = $_REQUEST['followup_to_opd']; } if (!empty($_REQUEST['followup_remarks'])) { $query_parts[] = "followup_remarks=?"; $query_values[] = $_REQUEST['followup_remarks']; } if (!empty($health_advice_names_new)) { $query_parts[] = "health_advices_new=?"; $query_values[] = $health_advice_names_new; } if (!empty($department)) { $query_parts[] = "department=?"; $query_values[] = $department; } if (!empty($designation)) { $query_parts[] = "designation=?"; $query_values[] = $designation; } $rolecode = $_SESSION['RoleCode']; error_log("follow up case or not : " . $_REQUEST['followup_to_opd']); // if this is only for saving treatment information we should skip saving OPD information. $isInsertCase = ""; if ($is_followup == null || $is_followup == '' || empty($is_followup)) { if (!empty($appointment_id) && $appointment_id != '' && $appointment_id != null && $appointment_id != ' ') { $isInsertCase = false; $data['message'] = "update"; if (!empty($ticket_no)) { $query_parts[] = "ticket_no=?"; $query_values[] = $ticket_no; } // adding for update case only $query_values[] = $appointment_id; $query_initial = " update employee_appointment "; $query_end = " where appointment_id = ? "; } else { if ($_REQUEST['appointment_type'] == 'O') { $ticket_no = creatingTicketNoOPD(); } else { $ticket_no = creatingTicketNoInjury(); } if (!empty($ticket_no)) { $query_parts[] = "ticket_no=?"; $query_values[] = $ticket_no; } $isInsertCase = true; $data['message'] = "save"; $query_initial = "insert into employee_appointment "; } } else { //additional appointment_id for followup $query_parts[] = "appointment_id=?"; $query_values[] = $_REQUEST['followup_to_opd']; if ($followup_id == '' || $followup_id == null) { $ticket_no = creatingTicketNoFollowup(); if (!empty($ticket_no)) { $query_parts[] = "ticket_no=?"; $query_values[] = $ticket_no; } $isInsertCase = true; $query_initial = "insert into followup_details"; $query_end = ""; } else { $isInsertCase = false; if (!empty($ticket_no)) { $query_parts[] = "ticket_no=?"; $query_values[] = $ticket_no; } //adding for update case only $query_values[] = $followup_id; $query_initial = "update followup_details"; $query_end = "where followup_id=?"; } } error_log("parameter query" . print_r($query_parts, true) . " value " . print_r($query_values, true)); $query = ""; $query = $query_initial . " SET " . implode(", ", $query_parts) . " " . $query_end; error_log("final query " . $query); $stmt_insert_update_opd = $conn->prepare($query); if ($stmt_insert_update_opd) { $types = str_repeat('s', count($query_values)); $stmt_insert_update_opd->bind_param($types, ...$query_values); $stmt_insert_update_opd->execute(); if ($stmt_insert_update_opd->errno) { error_log("Error in opd or followup saving " . $stmt_insert_update_opd->error); rollback(); } } else { error_log("Error in preparing the statement: " . $conn->error); rollback(); exit(error_log($conn->error)); } if (isset($is_followup) && !empty($is_followup)) { $appointment_id = addslashes($_REQUEST['followup_to_opd']); if (!$stmt_insert_update_opd->errno) { if (empty($followup_id)) { $query = "select max(followup_id) followup_id from followup_details where emp_id = '" . addslashes($_REQUEST['emp_id']) . "' "; error_log("max followup_id_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)) { $followup_id = $row['followup_id']; } } } error_log("FOLLOWUP ID::" . $followup_id); error_log("---------FOLLOW-UP SECTION STARTS EXECUTING-------------"); $app_update = "update employee_appointment set followup_to_opd=?,attended_status=? where appointment_id=?"; $stmt_app_update = $conn->prepare($app_update); if ($stmt_app_update) { $stmt_app_update->bind_param("sss", $_REQUEST['followup_to_opd'], $attended_status, $_REQUEST['followup_to_opd']); $stmt_app_update->execute(); if ($stmt_app_update->errno) { error_log("Error in saving followup entry in opd " . $stmt_app_update->error); rollback(); } } else { error_log("Error in preparing the statement " . $conn->error); rollback(); } if ($stmt_app_update != null) { $stmt_app_update->close(); } if (!empty($advise_ids)) { updatePatientHealthInfo($patient_id, 'ADC', $advise_ids, $appointment_date, '', 0); } if (!empty($drug_allergy)) { updatePatientHealthInfo($patient_id, 'ALG', $drug_allergy, $appointment_date, '', 0); } if (!empty($abnormalitys)) { updatePatientAbnormalityInfo($patient_id, $abnormalitys, $appointment_date); } if (!empty($injuryTypes_new)) { updatePatientHealthInfo($patient_id, 'INJ', $injuryTypes_new, $appointment_date, '', 0); } // if this is only for saving treatment information we should skip saving OPD information. goto treatment_section; } } if ($is_followup == '' || $is_followup == 0 || empty($is_followup)) { $followup_id = '0'; if ($stmt_insert_update_opd->errno) { error_log("APPOINTMENT QUERY FAILING"); // main insert fails error_log("Exception:" . $stmt_insert_update_opd->error); error_log("Appointment Save: " . $query); rollback(); } else { if (!empty($advise_ids)) { updatePatientHealthInfo($patient_id, 'ADC', $advise_ids, $appointment_date, '', 0); } if (!empty($drug_allergy)) { updatePatientHealthInfo($patient_id, 'ALG', $drug_allergy, $appointment_date, '', 0); } // error_log('abbb 3 ' . $abnormalitys); // error_log('abbb ' . implode(",", $abnormalitys)); // if (!empty(implode(",", $abnormalitys))) { // updatePatientAbnormalityInfo($patient_id,$abnormalitys, $appointment_date); // } if (!empty($abnormalitys)) { updatePatientAbnormalityInfo($patient_id, $abnormalitys, $appointment_date); } if (!empty($injuryTypes_new)) { updatePatientHealthInfo($patient_id, 'INJ', $injuryTypes_new, $appointment_date, '', 0); } if (empty($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']; } } } $health_program_enrolment_ids = $_REQUEST['health_program_enrolment']; $health_program_enrolment_ids = implode(',', $_REQUEST['health_program_enrolment']); error_log("health program names " . print_r($health_program_enrolment_ids, true)); $query_del_waiting_training = " delete from waiting_health_program_enrolment where emp_id = '" . $_REQUEST['emp_id'] . "' and appointment_id = '" . $appointment_id . "' and status='W' "; error_log("delete waiting Training: " . $query_del_waiting_training); if (!$result_del = @mysqli_query($conn, $query_del_waiting_training)) { exit(error_log(mysqli_error($conn))); rollback(); } for ($t = 0; $t < count($_REQUEST['health_program_enrolment']); $t++) { $query_insert_waiting_training = " insert into waiting_health_program_enrolment set emp_id = '" . $_REQUEST['emp_id'] . "' , appointment_id = '" . $appointment_id . "', status='W' , training_id='" . $_REQUEST['health_program_enrolment'][$t] . "' ,modified_by='" . $_SESSION["user_id"] . "' "; error_log("insert waiting Training: " . $query_insert_waiting_training); if (!$result_insertl = @mysqli_query($conn, $query_insert_waiting_training)) { exit(error_log(mysqli_error($conn))); rollback(); } } // if this is only for saving treatment information we should skip saving OPD information. goto treatment_section; } } treatment_section: error_log("at treatment section"); //lab test saving logic start if ($rolecode == 'DOC' && $_POST['recommended_test_new'] != '' && $_POST['recommended_test_new'] != null) { // Check if the lab entry already exists $exists_lab_sql = "SELECT * FROM checkup_form WHERE appointment_id=? AND followup_id=?"; $stmt_exists_lab_sql = $conn->prepare($exists_lab_sql); if ($stmt_exists_lab_sql) { $stmt_exists_lab_sql->bind_param("ss", $appointment_id, $followup_id); $stmt_exists_lab_sql->execute(); // Check for errors if ($stmt_exists_lab_sql->errno) { error_log("Error in exist lab query " . $stmt_exists_lab_sql->error); } else { $result_lab_sql = $stmt_exists_lab_sql->get_result(); $num_rows_lab = $result_lab_sql->num_rows; $row_lab_sql = $result_lab_sql->fetch_assoc(); } // Close the statement if ($stmt_exists_lab_sql != null) { $stmt_exists_lab_sql->close(); } } else { error_log("Error in preparing exist lab query stmt " . $conn->error); } $lab_init_query = ""; $lab_end_query = ""; $lab_checkup_ticket_no = ""; if ($num_rows_lab > 0) { $lab_checkup_ticket_no = $row_lab_sql['ticket_no']; $lab_init_query = "update checkup_form set "; $lab_end_query = " where appointment_id=? and checkup_id=? and followup_id=?"; } else { $lab_checkup_ticket_no = creatingCheckupTicketNo(); $lab_init_query = "insert into checkup_form set appointment_id=?, followup_id=?, "; $lab_end_query = ""; } 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_type_code='LAB_TEST'"; $stmt_checkup_type_id = $conn->prepare($checkup_type_id_sql); if ($stmt_checkup_type_id) { $stmt_checkup_type_id->execute(); $result_checkup = $stmt_checkup_type_id->get_result(); // Check for errors if ($stmt_checkup_type_id->errno) { error_log("Error in getting checkup type id " . $stmt_checkup_type_id->error); } else { $row_checkup = $result_checkup->fetch_assoc(); $checkup_type_id = $row_checkup['checkup_type_id']; } // Close the statement if ($stmt_checkup_type_id != null) { $stmt_checkup_type_id->close(); } } else { error_log("Error in preparing checkup type id query stmt " . $conn->error); } error_log("checkup type id " . $checkup_type_id); // Inserting or updating lab record $lab_entry = $lab_init_query . " checkup_date=STR_TO_DATE(?, '%d/%m/%Y %h:%i %p'), ticket_no=?, emp_id=?, checkup_type_id=?, referred_by=?, checkup_section_ids=?, current_status='MRP', ohc_type_id=?, modified_by=?" . $lab_end_query; error_log("saving lab entry in save opd " . $lab_entry); $stmt_save_lab = $conn->prepare($lab_entry); if ($stmt_save_lab) { if ($num_rows_lab > 0) { $stmt_save_lab->bind_param("sssssssssss", $appointment_date, $lab_checkup_ticket_no, $_REQUEST['emp_id'], $checkup_type_id, $SESSION_emp_id, $tests_new, $_SESSION['current_ohcttype'], $_SESSION['user_id'], $appointment_id, $row_lab_sql['checkup_id'], $followup_id); } else { $stmt_save_lab->bind_param("ssssssssss", $appointment_id, $followup_id, $appointment_date, $lab_checkup_ticket_no, $_REQUEST['emp_id'], $checkup_type_id, $SESSION_emp_id, $tests_new, $_SESSION['current_ohcttype'], $_SESSION['user_id']); } $stmt_save_lab->execute(); // Check for errors if ($stmt_save_lab->errno) { error_log("Error while saving lab entry in save opd " . $stmt_save_lab->error); } // Close the statement if ($stmt_save_lab != null) { $stmt_save_lab->close(); } } else { error_log("Error in preparing save lab query stmt " . $conn->error); } } //lab test saving logic end // EDIT TREATMENT IS NOT ALLOWED IF KEY IS FALSE AND ROLE CODE IS DOC error_log("role code " . $_SESSION['RoleCode']); if ($edit_enable == 'true' || $isTreatmentOnly == 'Y' || $isInsertCase == true || $medicine_issued != 'Y') { $curr_ohc_id = getTableFieldValue('employee_appointment', 'ohc_type_id', '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 ($followup_id == null || $followup_id == '' || empty($followup_id)) { $followup_id = 0; } if ($_SESSION["RoleCode"] == 'DIS') { resetItemStockAtDispensaryLevelForFollowup($appointment_id, $_SESSION['current_ohcttype'], $followup_id); } else { resetItemStockAtStoreLevelForFollowup($appointment_id, $_SESSION['current_ohcttype'], $followup_id); } /* delete all child table during update records */ if (!@mysqli_query($conn, "delete from appointment_stock_history where appointment_id='" . $appointment_id . "' and followup_id = '" . $followup_id . "'")) { error_log("Exception:" . mysqli_error($conn)); exit(error_log(mysqli_error($conn))); rollback(); } if (!@mysqli_query($conn, "delete from treatment where appointment_id='" . $appointment_id . "' and followup_id = '" . $followup_id . "' ")) { error_log("Exception:" . mysqli_error($conn)); exit(error_log(mysqli_error($conn))); rollback(); } if ($isTreatmentOnly != 'Y' && !@mysqli_query($conn, "delete from treatment_external where appointment_id='" . $appointment_id . "' and followup_id = '" . $followup_id . "'")) { error_log("Exception:" . mysqli_error($conn)); exit(error_log(mysqli_error($conn))); rollback(); } /* 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++) { if (${"treatment_item$i"} != "" && ${"treatment_item$i"} != null) { $batch_stock = getBatchStock(${"treatment_item$i"}, ${"item_batch_no$i"}); if ($batch_stock == null || $batch_stock == '') { $batch_stock = 0; } error_log("selected batch stock " . $batch_stock); error_log("Issued qty for this " . ${"treatment_item_qtygvn$i"} . " item id is => " . ${"treatment_item$i"}); if ($batch_stock < ${"treatment_item_qtygvn$i"}) { $issued_qty = ${"treatment_item_qtygvn$i"} - $batch_stock; ///// error_log("treatment_item:" . $i . ":" . ${"treatment_item$i"} . ": remaining issued qty " . $issued_qty); if (${"treatment_item$i"} != null && ${"treatment_item$i"} != "") { // To Check Item is Dressing Or Not $is_dressing_item = toCheckDressingItem(${"treatment_item$i"}); error_log("is_dressing_item:" . $is_dressing_item); if ($is_dressing_item == 'P') { if (${"group_child_flag_$i"} == '1') { $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['child_item_qty_gvn' . $i . '_' . $j]) != '' || addslashes($_POST['child_item_qty_gvn' . $i . '_' . $j]) != null) { $treatment_given_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]); if ($stmt_query_treatment_dressing) { $stmt_query_treatment_dressing->bind_param("ssssssss", $appointment_id, $group_item_id, $followup_id, $_POST['child_item_' . $i . '_' . $j], $_POST['child_item_qty_gvn' . $i . '_' . $j], $_POST['child_item_qty_gvn' . $i . '_' . $j], $_SESSION['user_id'], $treatment_given_by); $stmt_query_treatment_dressing->execute(); if ($stmt_query_treatment_dressing->errno) { error_log("Error in adding dressing item treatment " . $stmt_query_treatment_dressing->error); rollback(); } } else { error_log("Error in preparing statement " . $conn->error); rollback(); } error_log("query_treatment:1 " . $query_treatment_dressing); if ($stmt_query_stock_history_dressing) { $stmt_query_stock_history_dressing->bind_param("ssssss", $appointment_id, $followup_id, $_POST['child_item_qty_gvn' . $i . '_' . $j], $_POST['child_item_' . $i . '_' . $j], $_POST['child_item_qty_gvn' . $i . '_' . $j], $treatment_given_by); $stmt_query_stock_history_dressing->execute(); if ($stmt_query_stock_history_dressing->errno) { error_log("issues while updating appointment_stock_history: " . $stmt_query_stock_history_dressing->error); rollback(); } } else { error_log("Error in preparing statement for stock history " . $conn->error); rollback(); } error_log("query_stock_history: " . $query_stock_history_dressing); // to update Dispensary Items if ($_SESSION("RoleCode") == 'DIS' || in_array('DIS', explode(',', $_SESSION['RoleCode']))) { 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 ((($_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 = $_SESSION['user_id']; } } if ($stmt_query_treatment_dressing) { $stmt_query_treatment_dressing->bind_param("ssssssss", $appointment_id, $row_for_group_items['group_id'], $followup_id, $row_for_group_items['item_id'], $row_for_group_items['qty'], $row_for_group_items['qty'], $_SESSION['user_id'], $treatment_qty_given_by); $stmt_query_treatment_dressing->execute(); if ($stmt_query_treatment_dressing->errno) { error_log("Error in updating dressing item treatment " . $stmt_query_treatment_dressing->error); rollback(); } } else { error_log("Error in preparing statement " . $conn->error); rollback(); } if ($stmt_query_stock_history_dressing) { $stmt_query_stock_history_dressing->bind_param("ssssss", $appointment_id, $followup_id, $row_for_group_items['qty'], $row_for_group_items['item_id'], $row_for_group_items['qty'], $treatment_qty_given_by); $stmt_query_stock_history_dressing->execute(); if ($stmt_query_stock_history_dressing->errno) { error_log("issues while updating appointment_stock_history: " . $stmt_query_stock_history_dressing->error); rollback(); } } else { error_log("Error in preparing statement for stock history " . $conn->error); rollback(); } } } } //end for handling of dressing items $treatment_qty_given_by = ''; if ((($_SESSION['RoleCode'] == 'DIS') || in_array('DIS', explode(',', $_SESSION['RoleCode'])))) { if (addslashes($batch_stock) != 0 || addslashes($batch_stock) != '' || addslashes($batch_stock) != null) { $treatment_qty_given_by = $_SESSION['user_id']; } } if ($stmt_query_treatment) { if (${"item_batch_no$i"} == null || empty(${"item_batch_no$i"})) { ${"item_batch_no$i"} = ''; } $stmt_query_treatment->bind_param("sssssssssssss", $appointment_id, ${"treatment_item$i"}, ${"dose_qty$i"}, $followup_id, $batch_stock, ${"item_batch_no$i"}, ${"dosage$i"}, ${"treatment_item_days$i"}, ${"treatment_item_dosage$i"}, ${"timings$i"}, ${"treatment_item_dosage_category$i"}, $_SESSION['user_id'], $treatment_qty_given_by); $stmt_query_treatment->execute(); if ($stmt_query_treatment->errno) { error_log("Error Saving Treatment data for opd when dealing with multiple batches : " . $stmt_query_treatment->error); rollback(); } } else { error_log("Error in preparing statement for treatment data " . $conn->error); rollback(); } error_log("query_treatment:3 " . $query_treatment); $treatment_qty_given_by = ''; if ((($_SESSION['RoleCode'] == 'DIS') || in_array('DIS', explode(',', $_SESSION['RoleCode'])))) { if (addslashes($batch_stock) != 0 || addslashes($batch_stock) != '' || addslashes($batch_stock) != null) { $treatment_qty_given_by = $_SESSION['user_id']; } } if ($stmt_query_stock_history) { $stmt_query_stock_history->bind_param("sssssss", $appointment_id, ${"current_stock$i"}, ${"frequency_qty$i"}, ${"treatment_item$i"}, $batch_stock, $followup_id, $treatment_qty_given_by); $stmt_query_stock_history->execute(); if ($stmt_query_stock_history->errno) { error_log("issues while updating appointment_stock_history for opd when dealing with multiple batches :: " . $stmt_query_stock_history->error); rollback(); } } else { error_log("Error in preparing statement for stock history " . $conn->error); rollback(); } error_log("query_stock_history: " . $query_stock_history); if (${"group_child_flag_$i"} != '1') updaterItemStock($_SESSION['current_ohcttype'], addslashes(${"treatment_item$i"}), $batch_stock, ${"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 ( $batch_stock )); * //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"} != "") { if ($stmt_query_treatment_external) { $stmt_query_treatment_external->bind_param("", $appointment_id, $followup_id, ${"treatment_item_external$i"}, ${"dose_qty$i"}, ${"timings$i"}, ${"treatment_item_dosage$i"}, ${"treatment_item_days$i"}, ${"treatment_item_dosage_category$i"}, $_SESSION['user_id']); $stmt_query_treatment_external->execute(); if ($stmt_query_treatment_external->errno) { error_log("Error in saving external treatment " . $stmt_query_treatment_external->error); rollback(); } } else { error_log("Error in preparing the statement for external " . $conn->error); rollback(); } } ///// $batches = getItemBatch(${"treatment_item$i"}, ${"item_batch_no$i"}); error_log("remaining batches " . print_r($batches, true)); error_log("size of array remaining batches " . sizeof($batches)); for ($b = 0; $b < sizeof($batches); $b++) { if ($issued_qty > 0 && $batches[$b] != null && !empty($batches[$b]) && $batches[$b] != '') { error_log('$issued_qty in while loop ' . $issued_qty); $this_batch_stock = getBatchStock(${"treatment_item$i"}, $batches[$b]); if ($issued_qty > $this_batch_stock) { $remain = $issued_qty - $this_batch_stock; } else { $remain = 0; } $issue = $issued_qty - $remain; error_log('remain ' . $issued_qty); ///// error_log("treatment_item: in while loop for multiple batches start " . $i . ":" . ${"treatment_item$i"}); if (${"treatment_item$i"} != null && ${"treatment_item$i"} != "") { // To Check Item is Dressing Or Not $is_dressing_item = toCheckDressingItem(${"treatment_item$i"}); error_log("is_dressing_item:" . $is_dressing_item); if ($is_dressing_item == 'P') { if (${"group_child_flag_$i"} == '1') { $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['child_item_qty_gvn' . $i . '_' . $j]) != '' || addslashes($_POST['child_item_qty_gvn' . $i . '_' . $j]) != null) { $treatment_given_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]); if ($stmt_query_treatment_dressing) { $stmt_query_treatment_dressing->bind_param("ssssssss", $appointment_id, $group_item_id, $followup_id, $_POST['child_item_' . $i . '_' . $j], $_POST['child_item_qty_gvn' . $i . '_' . $j], $_POST['child_item_qty_gvn' . $i . '_' . $j], $_SESSION['user_id'], $treatment_given_by); $stmt_query_treatment_dressing->execute(); if ($stmt_query_treatment_dressing->errno) { error_log("Error in adding dressing item treatment " . $stmt_query_treatment_dressing->error); rollback(); } } else { error_log("Error in preparing statement " . $conn->error); rollback(); } error_log("query_treatment:1 " . $query_treatment_dressing); if ($stmt_query_stock_history_dressing) { $stmt_query_stock_history_dressing->bind_param("ssssss", $appointment_id, $followup_id, $_POST['child_item_qty_gvn' . $i . '_' . $j], $_POST['child_item_' . $i . '_' . $j], $_POST['child_item_qty_gvn' . $i . '_' . $j], $treatment_given_by); $stmt_query_stock_history_dressing->execute(); if ($stmt_query_stock_history_dressing->errno) { error_log("issues while updating appointment_stock_history: " . $stmt_query_stock_history_dressing->error); rollback(); } } else { error_log("Error in preparing statement for stock history " . $conn->error); rollback(); } error_log("query_stock_history: " . $query_stock_history_dressing); // to update Dispensary Items if ($_SESSION("RoleCode") == 'DIS' || in_array('DIS', explode(',', $_SESSION['RoleCode']))) { 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 ((($_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 = $_SESSION['user_id']; } } if ($stmt_query_treatment_dressing) { $stmt_query_treatment_dressing->bind_param("ssssssss", $appointment_id, $row_for_group_items['group_id'], $followup_id, $row_for_group_items['item_id'], $row_for_group_items['qty'], $row_for_group_items['qty'], $_SESSION['user_id'], $treatment_qty_given_by); $stmt_query_treatment_dressing->execute(); if ($stmt_query_treatment_dressing->errno) { error_log("Error in updating dressing item treatment " . $stmt_query_treatment_dressing->error); rollback(); } } else { error_log("Error in preparing statement " . $conn->error); rollback(); } if ($stmt_query_stock_history_dressing) { $stmt_query_stock_history_dressing->bind_param("ssssss", $appointment_id, $followup_id, $row_for_group_items['qty'], $row_for_group_items['item_id'], $row_for_group_items['qty'], $treatment_qty_given_by); $stmt_query_stock_history_dressing->execute(); if ($stmt_query_stock_history_dressing->errno) { error_log("issues while updating appointment_stock_history: " . $stmt_query_stock_history_dressing->error); rollback(); } } else { error_log("Error in preparing statement for stock history " . $conn->error); rollback(); } } } } //end for handling of dressing items $treatment_qty_given_by = ''; if ((($_SESSION['RoleCode'] == 'DIS') || in_array('DIS', explode(',', $_SESSION['RoleCode'])))) { if (addslashes($batch_stock) != 0 || addslashes($batch_stock) != '' || addslashes($batch_stock) != null) { $treatment_qty_given_by = $_SESSION['user_id']; } } if ($stmt_query_treatment) { if ($batches[$b] == null || empty($batches[$b])) { $batches[$b] = ''; } $stmt_query_treatment->bind_param("sssssssssssss", $appointment_id, ${"treatment_item$i"}, ${"dose_qty$i"}, $followup_id, $issue, $batches[$b], ${"dosage$i"}, ${"treatment_item_days$i"}, ${"treatment_item_dosage$i"}, ${"timings$i"}, ${"treatment_item_dosage_category$i"}, $_SESSION['user_id'], $treatment_qty_given_by); $stmt_query_treatment->execute(); if ($stmt_query_treatment->errno) { error_log("Error Saving Treatment data: " . $stmt_query_treatment->error); rollback(); } } else { error_log("Error in preparing statement for treatment data " . $conn->error); rollback(); } error_log("query_treatment:3 " . $query_treatment); $treatment_qty_given_by = ''; if ((($_SESSION['RoleCode'] == 'DIS') || in_array('DIS', explode(',', $_SESSION['RoleCode'])))) { if (addslashes($batch_stock) != 0 || addslashes($batch_stock) != '' || addslashes($batch_stock) != null) { $treatment_qty_given_by = $_SESSION['user_id']; } } if ($stmt_query_stock_history) { $stmt_query_stock_history->bind_param("sssssss", $appointment_id, $issue, ${"frequency_qty$i"}, ${"treatment_item$i"}, $batch_stock, $followup_id, $treatment_qty_given_by); $stmt_query_stock_history->execute(); if ($stmt_query_stock_history->errno) { error_log("issues while updating appointment_stock_history: " . $stmt_query_stock_history->error); rollback(); } } else { error_log("Error in preparing statement for stock history " . $conn->error); rollback(); } error_log("query_stock_history: " . $query_stock_history); if (${"group_child_flag_$i"} != '1') updaterItemStock($_SESSION['current_ohcttype'], addslashes(${"treatment_item$i"}), $issue, $batches[$b]); /* * //$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 ( $batch_stock )); * //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"} != "") { if ($stmt_query_treatment_external) { $stmt_query_treatment_external->bind_param("", $appointment_id, $followup_id, ${"treatment_item_external$i"}, ${"dose_qty$i"}, ${"timings$i"}, ${"treatment_item_dosage$i"}, ${"treatment_item_days$i"}, ${"treatment_item_dosage_category$i"}, $_SESSION['user_id']); $stmt_query_treatment_external->execute(); if ($stmt_query_treatment_external->errno) { error_log("Error in saving external treatment " . $stmt_query_treatment_external->error); rollback(); } } else { error_log("Error in preparing the statement for external " . $conn->error); rollback(); } } error_log("treatment_item: in while loop for multiple batches end " . $i . ":" . ${"treatment_item$i"}); ///// $issued_qty = $remain; error_log('$issued_qty ' . $issued_qty); } } } else { ///// error_log("start treatment_item: if issued qty is less than available batch stocks qty" . $i . ":" . ${"treatment_item$i"}); if (${"treatment_item$i"} != null && ${"treatment_item$i"} != "") { // To Check Item is Dressing Or Not $is_dressing_item = toCheckDressingItem(${"treatment_item$i"}); error_log("is_dressing_item:" . $is_dressing_item); if ($is_dressing_item == 'P') { if (${"group_child_flag_$i"} == '1') { $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['child_item_qty_gvn' . $i . '_' . $j]) != '' || addslashes($_POST['child_item_qty_gvn' . $i . '_' . $j]) != null) { $treatment_given_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]); if ($stmt_query_treatment_dressing) { $stmt_query_treatment_dressing->bind_param("ssssssss", $appointment_id, $group_item_id, $followup_id, $_POST['child_item_' . $i . '_' . $j], $_POST['child_item_qty_gvn' . $i . '_' . $j], $_POST['child_item_qty_gvn' . $i . '_' . $j], $_SESSION['user_id'], $treatment_given_by); $stmt_query_treatment_dressing->execute(); if ($stmt_query_treatment_dressing->errno) { error_log("Error in adding dressing item treatment " . $stmt_query_treatment_dressing->error); rollback(); } } else { error_log("Error in preparing statement " . $conn->error); rollback(); } error_log("query_treatment:1 " . $query_treatment_dressing); if ($stmt_query_stock_history_dressing) { $stmt_query_stock_history_dressing->bind_param("ssssss", $appointment_id, $followup_id, $_POST['child_item_qty_gvn' . $i . '_' . $j], $_POST['child_item_' . $i . '_' . $j], $_POST['child_item_qty_gvn' . $i . '_' . $j], $treatment_given_by); $stmt_query_stock_history_dressing->execute(); if ($stmt_query_stock_history_dressing->errno) { error_log("issues while updating appointment_stock_history: " . $stmt_query_stock_history_dressing->error); rollback(); } } else { error_log("Error in preparing statement for stock history " . $conn->error); rollback(); } error_log("query_stock_history: " . $query_stock_history_dressing); // to update Dispensary Items if ($_SESSION("RoleCode") == 'DIS' || in_array('DIS', explode(',', $_SESSION['RoleCode']))) { 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 ((($_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 = $_SESSION['user_id']; } } if ($stmt_query_treatment_dressing) { $stmt_query_treatment_dressing->bind_param("ssssssss", $appointment_id, $row_for_group_items['group_id'], $followup_id, $row_for_group_items['item_id'], $row_for_group_items['qty'], $row_for_group_items['qty'], $_SESSION['user_id'], $treatment_qty_given_by); $stmt_query_treatment_dressing->execute(); if ($stmt_query_treatment_dressing->errno) { error_log("Error in updating dressing item treatment " . $stmt_query_treatment_dressing->error); rollback(); } } else { error_log("Error in preparing statement " . $conn->error); rollback(); } if ($stmt_query_stock_history_dressing) { $stmt_query_stock_history_dressing->bind_param("ssssss", $appointment_id, $followup_id, $row_for_group_items['qty'], $row_for_group_items['item_id'], $row_for_group_items['qty'], $treatment_qty_given_by); $stmt_query_stock_history_dressing->execute(); if ($stmt_query_stock_history_dressing->errno) { error_log("issues while updating appointment_stock_history: " . $stmt_query_stock_history_dressing->error); rollback(); } } else { error_log("Error in preparing statement for stock history " . $conn->error); rollback(); } } } } //end for handling of dressing items $treatment_qty_given_by = ''; if ((($_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 = $_SESSION['user_id']; } } if ($stmt_query_treatment) { if (${"item_batch_no$i"} == null || empty(${"item_batch_no$i"})) { ${"item_batch_no$i"} = ''; } $stmt_query_treatment->bind_param("sssssssssssss", $appointment_id, ${"treatment_item$i"}, ${"dose_qty$i"}, $followup_id, ${"treatment_item_qtygvn$i"}, ${"item_batch_no$i"}, ${"dosage$i"}, ${"treatment_item_days$i"}, ${"treatment_item_dosage$i"}, ${"timings$i"}, ${"treatment_item_dosage_category$i"}, $_SESSION['user_id'], $treatment_qty_given_by); $stmt_query_treatment->execute(); if ($stmt_query_treatment->errno) { error_log("Error Saving Treatment data for opd : " . $stmt_query_treatment->error); rollback(); } } else { error_log("Error in preparing statement for treatment data " . $conn->error); rollback(); } error_log("query_treatment:3 " . $query_treatment); $treatment_qty_given_by = ''; if ((($_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 = $_SESSION['user_id']; } } if ($stmt_query_stock_history) { $stmt_query_stock_history->bind_param("sssssss", $appointment_id, ${"current_stock$i"}, ${"frequency_qty$i"}, ${"treatment_item$i"}, ${"treatment_item_qtygvn$i"}, $followup_id, $treatment_qty_given_by); $stmt_query_stock_history->execute(); if ($stmt_query_stock_history->errno) { error_log("issues while updating appointment_stock_history for opd: " . $stmt_query_stock_history->error); rollback(); } } else { error_log("Error in preparing statement for stock history " . $conn->error); rollback(); } error_log("query_stock_history: " . $query_stock_history); 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 ( $batch_stock )); * //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"} != "") { if ($stmt_query_treatment_external) { $stmt_query_treatment_external->bind_param("sssssssss", $appointment_id, $followup_id, ${"treatment_item_external$i"}, ${"dose_qty$i"}, ${"timings$i"}, ${"treatment_item_dosage$i"}, ${"treatment_item_days$i"}, ${"treatment_item_dosage_category$i"}, $_SESSION['user_id']); $stmt_query_treatment_external->execute(); if ($stmt_query_treatment_external->errno) { error_log("Error in saving external treatment " . $stmt_query_treatment_external->error); rollback(); } } else { error_log("Error in preparing the statement for external " . $conn->error); rollback(); } } ///// error_log("end treatment_item: if issued qty is less than available batch stocks qty " . $i . ":" . ${"treatment_item$i"}); } } else if ($isTreatmentOnly != 'Y' && ${"treatment_item_external$i"} != null && ${"treatment_item_external$i"} != "") { if ($stmt_query_treatment_external) { $stmt_query_treatment_external->bind_param("sssssssss", $appointment_id, $followup_id, ${"treatment_item_external$i"}, ${"dose_qty$i"}, ${"timings$i"}, ${"treatment_item_dosage$i"}, ${"treatment_item_days$i"}, ${"treatment_item_dosage_category$i"}, $_SESSION['user_id']); $stmt_query_treatment_external->execute(); if ($stmt_query_treatment_external->errno) { error_log("Error in saving external treatment " . $stmt_query_treatment_external->error); rollback(); } } else { error_log("Error in preparing the statement for external " . $conn->error); rollback(); } } } } } if ($_REQUEST['ipd'] == 1 || $_REQUEST['ipd'] == '1') { $reporting_time = $_POST['appointment_date']; $is_detaind = getTableFieldValue('detention_master', 'id', 'opd_id', "'" . $appointment_id . "'"); if (isset($is_detaind)) { $detention_master = 'update detention_master set reporting_time=STR_TO_DATE(?,"%d/%m/%Y %h:%i %p") ,opd_id=?,modified_by=? where opd_id="' . $appointment_id . '"'; } else { $detention_master = 'insert into detention_master set reporting_time=STR_TO_DATE(?,"%d/%m/%Y %h:%i %p") ,opd_id=?,modified_by=? '; } $detention_master = 'insert into detention_master set reporting_time=STR_TO_DATE(?,"%d/%m/%Y %h:%i %p") ,opd_id=?,modified_by=? '; error_log('Forward to detention ' . $detention_master); $stmt_detention_master = $conn->prepare($detention_master); if ($stmt_detention_master) { $stmt_detention_master->bind_param("sss", $reporting_time, $appointment_id, $_SESSION['user_id']); $stmt_detention_master->execute(); if ($stmt_detention_master->errno) { error_log("Executing detention master sql " . $stmt_detention_master->error); exit(error_log($conn->error)); } } else { error_log("Error in preparing the statement: " . $conn->error); rollback(); exit(error_log($conn->error)); } } commit(); if ($stmt_detention_master != null) { $stmt_detention_master->close(); } if ($stmt_query_treatment_dressing != null) { $stmt_query_treatment_dressing->close(); } if ($stmt_query_stock_history_dressing != null) { $stmt_query_stock_history_dressing->close(); } if ($stmt_query_treatment != null) { $stmt_query_treatment->close(); } if ($stmt_query_stock_history != null) { $stmt_query_stock_history->close(); } if ($stmt_query_treatment_external != null) { $stmt_query_treatment_external->close(); } $data['followup_id'] = $followup_id; $data['appointment_id'] = $appointment_id; $data['referralMailFlag'] = $refferralMailFlag; // error_log(print_r($data), true); echo json_encode($data);