function process_ntp() { if (func_num_args() > 0) { $arg_list = func_get_args(); $menu_id = $arg_list[0]; $post_vars = $arg_list[1]; $get_vars = $arg_list[2]; $validuser = $arg_list[3]; $isadmin = $arg_list[4]; //print_r($arg_list); } $patient_id = healthcenter::get_patient_id($get_vars["consult_id"]); switch ($post_vars["submitntp"]) { case "Assign Lab Exam": if ($post_vars["labs"] && $post_vars["registry_id"]) { foreach ($post_vars["labs"] as $key => $value) { print $sql = "insert into m_consult_ntp_labs_request (consult_id, patient_id, ntp_id, request_id, user_id, request_timestamp) " . "values ('" . $get_vars["consult_id"] . "', '{$patient_id}', '" . $post_vars["registry_id"] . "', '{$value}', '" . $_SESSION["userid"] . "', sysdate())"; $result = mysql_query($sql); } header("location: " . $_SERVER["PHP_SELF"] . "?page=" . $get_vars["page"] . "&menu_id=" . $get_vars["menu_id"] . "&consult_id=" . $get_vars["consult_id"] . "&ptmenu=" . $get_vars["ptmenu"] . "&module=" . $get_vars["module"] . "&ntp=" . $get_vars["ntp"] . "&ntp_id=" . $get_vars["ntp_id"]); } break; case "Add Follow-up Date": if ($post_vars["treatment_actual_date"]) { list($month, $day, $year) = explode("/", $post_vars["treatment_actual_date"]); $actual_date = $year . "-" . str_pad($month, 2, "0", STR_PAD_LEFT) . "-" . str_pad($day, 2, "0", STR_PAD_LEFT); print $sql = "update m_consult_ntp_due_dates set " . "treatment_actual_date = '{$actual_date}', " . "remarks = '" . addslashes($post_vars["remarks"]) . "' " . "where ntp_id = '" . $post_vars["ntp_id"] . "'"; if ($result = mysql_query($sql)) { header("location: " . $_SERVER["PHP_SELF"] . "?page=" . $get_vars["page"] . "&menu_id=" . $get_vars["menu_id"] . "&consult_id=" . $get_vars["consult_id"] . "&ptmenu=" . $get_vars["ptmenu"] . "&module=" . $get_vars["module"] . "&ntp=" . $get_vars["ntp"] . "&ntp_id=" . $get_vars["ntp_id"]); } } break; case "Save NTP Data": if ($post_vars["occupation"] && $post_vars["region"] && $post_vars["bcg_scar"] && $post_vars["contact_person"] && $post_vars["treatment_category"] && $post_vars["treatment_outcome"] && $post_vars["treatment_partner"]) { // always use what's existing $body_weight = healthcenter::get_body_weight($get_vars["consult_id"]); $bcg_scar = $post_vars["bcg_scar"] ? "Y" : "N"; $previous_tx = $post_vars["previous_treatment_flag"] ? "Y" : "N"; // save previous treatment drugs in one field if ($post_vars["previous_treatment_drugs"]) { foreach ($post_vars["previous_treatment_drugs"] as $key => $drug) { $tx_drugs .= $drug; } } /*$sql_first = "insert into m_patient_ntp (patient_id, occupation_id, ". "household_contacts, region_id, body_weight, bcg_scar, ". "previous_treatment_flag, previous_treatment_duration, ". "previous_treatment_drugs, treatment_category_id, ". "contact_person, outcome_id, patient_type_id, ". "treatment_partner_id, healthcenter_id, ntp_timestamp, ". "ntp_consult_date, user_id, tb_class, source_patient, refer_physician, tbdc_review) ". "values ('$patient_id', '".$post_vars["occupation"]."', ". "'".$post_vars["hh_contacts"]."', '".$post_vars["region"]."', ". "'$body_weight', '$bcg_scar', '$previous_tx', ". "'".$post_vars["previous_treatment_duration"]."', '$tx_drugs', ". "'".$post_vars["treatment_category"]."', ". "'".$post_vars["contact_person"]."', ". "'".$post_vars["treatment_outcome"]."', ". "'".$post_vars["patient_type"]."', ". "'".$post_vars["treatment_partner"]."', ". "'".$_SESSION["datanode"]["code"]."', sysdate(), ". "sysdate(), '".$_SESSION["userid"]."', ". "'".$post_vars["tb_class"]."')"; */ $healthcenter = $_SESSION["datanode"]["code"]; $sql_first = "INSERT INTO m_patient_ntp SET patient_id='{$patient_id}',occupation_id='{$post_vars['occupation']}',household_contacts='{$post_vars['hh_contacts']}',region_id='{$post_vars['region']}',body_weight='{$body_weight}',bcg_scar='{$bcg_scar}',previous_treatment_flag='{$previous_tx}',previous_treatment_duration='{$post_vars['previous_treatment_duration']}',previous_treatment_drugs='{$tx_drugs}',treatment_category_id='{$post_vars['treatment_category']}',contact_person='{$post_vars['contact_person']}',outcome_id='{$post_vars['treatment_outcome']}',patient_type_id='{$post_vars['patient_type']}',treatment_partner_id='{$post_vars['treatment_partner']}',healthcenter_id='{$healthcenter}',ntp_timestamp=sysdate(),ntp_consult_date=sysdate(),user_id='{$_SESSION['userid']}',tb_class='{$post_vars['tb_class']}',source_patient='{$post_vars['source_px']}',refer_physician='{$post_vars['refer_physician']}',tbdc_review='{$post_vars['tbdc_review']}'"; if ($result_first = mysql_query($sql_first)) { header("location: " . $_SERVER["PHP_SELF"] . "?page=" . $get_vars["page"] . "&menu_id=" . $get_vars["menu_id"] . "&consult_id=" . $get_vars["consult_id"] . "&ptmenu=" . $get_vars["ptmenu"] . "&module=" . $get_vars["module"]); } } break; case "Update NTP Data": if ($post_vars["occupation"] && $post_vars["region"] && $post_vars["bcg_scar"] && $post_vars["contact_person"] && $post_vars["treatment_category"] && $post_vars["treatment_outcome"] && $post_vars["treatment_partner"]) { // always use what's existing $body_weight = healthcenter::get_body_weight($get_vars["consult_id"]); $bcg_scar = $post_vars["bcg_scar"] ? "Y" : "N"; // if treatment outcome is any other than TX end this course $course_end_flag = $post_vars["treatment_outcome"] != "TX" ? "Y" : "N"; if ($course_end_flag == "Y") { if (empty($post_vars["date_outcome"])) { $treatment_end_date = date("Y-m-d"); } else { list($tm, $td, $ty) = explode('/', $post_vars["date_outcome"]); $treatment_end_date = $ty . '-' . $tm . '-' . $td; } } else { $treatment_end_date = '0000-00-00'; } $previous_tx = $post_vars["previous_treatment_flag"] ? "Y" : "N"; if ($post_vars["previous_treatment_drugs"]) { foreach ($post_vars["previous_treatment_drugs"] as $key => $drug) { $tx_drugs .= $drug; } } $sql_first = "update m_patient_ntp set " . "occupation_id = '" . $post_vars["occupation"] . "', " . "household_contacts = '" . $post_vars["hh_contacts"] . "', " . "region_id = '" . $post_vars["region"] . "', " . "bcg_scar = '{$bcg_scar}', " . "body_weight = '{$body_weight}', " . "previous_treatment_flag = '{$previous_tx}', " . "previous_treatment_duration = '" . $post_vars["previous_treatment_duration"] . "', " . "previous_treatment_drugs = '{$tx_drugs}', " . "treatment_category_id = '" . $post_vars["treatment_category"] . "', " . "contact_person = '" . $post_vars["contact_person"] . "', " . "outcome_id = '" . $post_vars["treatment_outcome"] . "', " . "course_end_flag = '{$course_end_flag}', " . "treatment_end_date = '{$treatment_end_date}', " . "patient_type_id = '" . $post_vars["patient_type"] . "', " . "treatment_partner_id = '" . $post_vars["treatment_partner"] . "', " . "ntp_timestamp = sysdate(), " . "user_id = '" . $_SESSION["userid"] . "', " . "tb_class = '" . $post_vars["tb_class"] . "', " . "source_patient = '" . $post_vars["source_px"] . "', " . "refer_physician = '" . $post_vars["refer_physician"] . "', " . "tbdc_review = '" . $post_vars["tbdc_review"] . "' " . " where ntp_id = '" . $post_vars["ntp_id"] . "' "; $result_first = mysql_query($sql_first) or die("Cannot query 876 " . mysql_error()); if ($result_first) { header("location: " . $_SERVER["PHP_SELF"] . "?page=" . $get_vars["page"] . "&menu_id=" . $get_vars["menu_id"] . "&consult_id=" . $get_vars["consult_id"] . "&ptmenu=" . $get_vars["ptmenu"] . "&module=ntp&ntp=VISIT1&ntp_id=" . $get_vars["ntp_id"]); } } break; case "Delete NTP Data": // this is a dummy entry // real delete code is in ntp::display_course(); break; case "Save Intensive Data": if ($post_vars["treatment_date"]) { $start_date = ntp::get_start_date($post_vars["registry_id"]); $intake = $post_vars["intake_flag"] ? "Y" : "N"; list($month, $day, $year) = explode("/", $post_vars["treatment_date"]); $intake_date = $year . "-" . str_pad($month, 2, "0", STR_PAD_LEFT) . "-" . str_pad($day, 2, "0", STR_PAD_LEFT); $sql = "insert into m_consult_ntp_intake_intensive (ntp_id, consult_id, patient_id, user_id, treatment_month, treatment_week, treatment_date, intake_flag, remarks) " . "values ('" . $post_vars["registry_id"] . "', '" . $get_vars["consult_id"] . "', '{$patient_id}', '" . $_SESSION["userid"] . "', (month(sysdate())+1)-month('{$start_date}'), (week(sysdate())+1)-week('{$start_date}'), '{$intake_date}', '{$intake}', '" . addslashes($post_vars["remarks"]) . "')"; if ($result = mysql_query($sql)) { // if first treatment day, // put in projected dates if (ntp::get_intensive_date($post_vars["registry_id"]) == "0000-00-00") { // get regimen and determine projected dates // sputum exam intervals are given 1 week (7 days) lead time $regimen = ntp::get_treatment_regimen($post_vars["registry_id"]); switch ($regimen) { case 1: $interval_sputum1 = "49 day"; // towards end of 2nd month $interval_sputum2 = "105 day"; // towards end of 4th month //$interval_sputum3 = "161 day"; // towards end of 6th month $interval_sputum3 = "140 day"; // in the beginning of 6th month //$interval_intensive = "42 day"; $interval_intensive = "56 day"; //$interval_maintenance = "154 day"; $interval_maintenance = "168 day"; $sql_ntp = "update m_patient_ntp set " . "intensive_start_date = '{$intake_date}', " . "intensive_projected_end_date = '{$intake_date}' + interval {$interval_intensive}, " . "maintenance_projected_end_date = '{$intake_date}' + interval {$interval_maintenance}, " . "sputum1_date = '{$intake_date}' + interval {$interval_sputum1}, " . "sputum2_date = '{$intake_date}' + interval {$interval_sputum2}, " . "sputum3_date = '{$intake_date}' + interval {$interval_sputum3} " . "where ntp_id = '" . $post_vars["registry_id"] . "'"; break; case 3: $interval_sputum1 = "49 day"; // towards end of 2nd month //$interval_intensive = "42 day"; //$interval_maintenance = "154 day"; $interval_intensive = "56 day"; $interval_maintenance = "168 day"; $sql_ntp = "update m_patient_ntp set " . "intensive_start_date = '{$intake_date}', " . "intensive_projected_end_date = '{$intake_date}' + interval {$interval_intensive}, " . "maintenance_projected_end_date = '{$intake_date}' + interval {$interval_maintenance}, " . "sputum1_date = '{$intake_date}' + interval {$interval_sputum1} " . "where ntp_id = '" . $post_vars["registry_id"] . "'"; break; case 2: $interval_sputum1 = "77 day"; // towards end of 3rd month $interval_sputum2 = "133 day"; // towards end of 5th month //$interval_sputum3 = "217 day"; // towards end of 8th month $interval_sputum3 = "196 day"; // beginning of 8th month $interval_intensive = "84 day"; $interval_maintenance = "224 day"; $sql_ntp = "update m_patient_ntp set " . "intensive_start_date = '{$intake_date}', " . "intensive_projected_end_date = '{$intake_date}' + interval {$interval_intensive}, " . "maintenance_projected_end_date = '{$intake_date}' + interval {$interval_maintenance}, " . "sputum1_date = '{$intake_date}' + interval {$interval_sputum1}, " . "sputum2_date = '{$intake_date}' + interval {$interval_sputum2}, " . "sputum3_date = '{$intake_date}' + interval {$interval_sputum3} " . "where ntp_id = '" . $post_vars["registry_id"] . "'"; break; } $result_ntp = mysql_query($sql_ntp) or die(mysql_error()); } // set appointment only if treatment date is today // useless if treatment date is the past // caution: do not enter first treatment date on a weekend if ($intake_date == date("Y-m-d")) { // if day today is a friday, add 3 days // if saturday add 2 days if (date("w") == 5) { $interval = 3; // monday } elseif (date("w") == 6) { $interval = 2; // 1 day } else { $interval = 1; // 1 day } $sql_appt = "insert into m_consult_appointments (visit_date, " . "consult_id, schedule_timestamp, user_id, patient_id, " . "appointment_id) values (sysdate() + interval {$interval} day, " . "'" . $get_vars["consult_id"] . "', sysdate(), '" . $_SESSION["userid"] . "', " . "'{$patient_id}', 'NTPI')"; $result_app = mysql_query($sql_appt); } header("location: " . $_SERVER["PHP_SELF"] . "?page=" . $get_vars["page"] . "&menu_id=" . $get_vars["menu_id"] . "&consult_id=" . $get_vars["consult_id"] . "&ptmenu=" . $get_vars["ptmenu"] . "&module=" . $get_vars["module"] . "&ntp=" . $get_vars["ntp"] . "&ntp_id=" . $get_vars["ntp_id"] . "#intensive_form"); } } else { print "<font color='red'>No treatment date</font><br/>"; } break; case "Save Maintenance Data": $start_date = ntp::get_start_date($post_vars["registry_id"]); $intake = $post_vars["intake_flag"] ? "Y" : "N"; // treatment date if ($post_vars["treatment_date"] && $post_vars["followup_date"]) { // treatment date list($txmonth, $txday, $txyear) = explode("/", $post_vars["treatment_date"]); $intake_date = $txyear . "-" . str_pad($txmonth, 2, "0", STR_PAD_LEFT) . "-" . str_pad($txday, 2, "0", STR_PAD_LEFT); // followup date list($ffmonth, $ffday, $ffyear) = explode("/", $post_vars["followup_date"]); $followup_date = $ffyear . "-" . str_pad($ffmonth, 2, "0", STR_PAD_LEFT) . "-" . str_pad($ffday, 2, "0", STR_PAD_LEFT); $sql = "insert into m_consult_ntp_collection_maintenance (ntp_id, consult_id, patient_id, user_id, treatment_month, treatment_week, treatment_date, intake_flag, remarks) " . "values ('" . $post_vars["registry_id"] . "', '" . $get_vars["consult_id"] . "', '{$patient_id}', '" . $_SESSION["userid"] . "', (month(sysdate())+1)-month('{$start_date}'), (week(sysdate())+1)-week('{$start_date}'), '{$intake_date}', '{$intake}', '" . addslashes($post_vars["remarks"]) . "')"; if ($result = mysql_query($sql)) { if (ntp::get_maintenance_date($post_vars["registry_id"]) == "0000-00-00") { $sql_ntp = "update m_patient_ntp set " . "maintenance_start_date = '{$intake_date}' " . "where ntp_id = '" . $post_vars["registry_id"] . "'"; $result_ntp = mysql_query($sql_ntp); } if ($followup_date) { // set appointment based on followup date // maintenance phase appointments are more flexible $sql_appt = "insert into m_consult_appointments (visit_date, " . "consult_id, schedule_timestamp, user_id, patient_id, " . "appointment_id) values ('{$followup_date}', " . "'" . $get_vars["consult_id"] . "', sysdate(), '" . $_SESSION["userid"] . "', " . "'{$patient_id}', 'NTPM')"; $result_app = mysql_query($sql_appt); } header("location: " . $_SERVER["PHP_SELF"] . "?page=" . $get_vars["page"] . "&menu_id=" . $get_vars["menu_id"] . "&consult_id=" . $get_vars["consult_id"] . "&ptmenu=" . $get_vars["ptmenu"] . "&module=" . $get_vars["module"] . "&ntp=" . $get_vars["ntp"] . "&ntp_id=" . $get_vars["ntp_id"] . "#maintenance_form"); } } else { print "<font color='red'>Incomplete date(s)</font><br/>"; } break; case "Send Request": if ($post_vars["registry_id"]) { //print_r($post_vars); //$sql_lab = mysql_query("INSERT INTO m_consult_lab SET consult_id='$get_vars[consult_id]', patient_id='$get_vars[patient_id]', lab_id, request_timestamp, request_user_id ") foreach ($post_vars["ntp_lab"] as $key => $value) { $sql_lab = "insert into m_consult_lab (consult_id, patient_id, lab_id, request_timestamp, request_user_id) " . "values ('" . $get_vars["consult_id"] . "', '{$patient_id}', '{$value}', sysdate(), '" . $_SESSION["userid"] . "')"; if ($result_lab = mysql_query($sql_lab)) { // try to insert in ntp lab registry $insert_id = mysql_insert_id(); $sql_ntp = "insert into m_consult_ntp_labs_request (consult_id, patient_id, ntp_id, request_id, user_id, request_timestamp) " . "values ('" . $get_vars["consult_id"] . "', '{$patient_id}', '" . $post_vars["registry_id"] . "', '{$insert_id}', '" . $_SESSION["userid"] . "', sysdate())"; $result_ntp = mysql_query($sql_ntp); } } //header("location: ".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=".$get_vars["ptmenu"]."&module=".$get_vars["module"].($get_vars["ntp_id"]?"&ntp_id=".$get_vars["ntp_id"]:""."&ntp=LABS"")); } break; case "Save TB Symptomatic": //echo 'no symptomatic record, therefore create'; list($xm, $xd, $xy) = explode('/', $_POST["date_referred_xray"]); $xray_referred = $xy . '-' . $xm . '-' . $xd; list($ym, $yd, $yy) = explode('/', $_POST["date_received_xray"]); $xray_received = $yy . '-' . $ym . '-' . $yd; list($seen_m, $seen_d, $seen_y) = explode('/', $_POST["date_symptomatic"]); $date_seen = $seen_y . '-' . $seen_m . '-' . $seen_d; $insert_symp = mysql_query("INSERT INTO m_consult_ntp_symptomatics SET ntp_id='{$_POST['select_ntp_tx']}',consult_id='{$_GET['consult_id']}',patient_id='{$_POST['pxid']}',sputum_diag1='{$_POST['sputum_diag1']}',sputum_diag2='{$_POST['sputum_diag2']}',xray_date_referred='{$xray_referred}',xray_date_received='{$xray_received}',xray_result='{$_POST['xray_result']}',remarks='{$_POST['symptomatic_remarks']}',symptomatic_flag='{$_POST['sel_symp']}',enroll_flag='{$_POST['enroll_flag']}',user_id='{$_SESSION['useid']}',date_updated=NOW(),date_seen='{$date_seen}'") or die("Cannot query: 1000 " . mysql_error()); echo "<script language='Javascript'>"; if ($insert_symp) { echo "window.alert('Record for TB Symptomatic was successfully been saved!')"; } else { echo "window.alert('Record for TB Symptomatic not saved. Kindly check the entries')"; } echo "</script>"; break; case "Update TB Symptomatic": list($xm, $xd, $xy) = explode('/', $_POST["date_referred_xray"]); $xray_referred = $xy . '-' . $xm . '-' . $xd; list($ym, $yd, $yy) = explode('/', $_POST["date_received_xray"]); $xray_received = $yy . '-' . $ym . '-' . $yd; list($seen_m, $seen_d, $seen_y) = explode('/', $_POST["date_symptomatic"]); $date_seen = $seen_y . '-' . $seen_m . '-' . $seen_d; if ($_POST["enroll_flag"] == 'Y' && $_POST["select_ntp_tx"] == '') { echo "<script language='Javascript'>"; echo "window.alert('Upon enrollment of patient, do no forget to update LINK TO NTP TREATMENT by selecting the treatment date.')"; echo "</script>"; } $update_symp = mysql_query("UPDATE m_consult_ntp_symptomatics SET ntp_id='{$_POST['select_ntp_tx']}',date_seen='{$date_seen}',sputum_diag1='{$_POST['sputum_diag1']}',sputum_diag2='{$_POST['sputum_diag2']}',xray_date_referred='{$xray_referred}',xray_date_received='{$xray_received}',xray_result='{$_POST['xray_result']}',remarks='{$_POST['symptomatic_remarks']}',symptomatic_flag='{$_POST['sel_symp']}',enroll_flag='{$_POST['enroll_flag']}' WHERE symptomatic_id='{$_POST['sel_symp_rec']}'") or die("Cannot query 998 " . mysql_error()); echo "<script language='Javascript'>"; if ($update_symp) { echo "window.alert('Update of TB Symptomatic record was successful!')"; } else { echo "window.alert('Update of TB Symptomatic record was not successful. Please check entries.')"; } echo "</script>"; case "View TB SYMP Record": //print_r($_POST); break; case "Import Sputum Test": //print_r($_POST); if ($_POST[sel_import_ntp] != '') { $pxid = healthcenter::get_patient_id($_GET["consult_id"]); $q_import = mysql_query("INSERT into m_consult_ntp_labs_request SET consult_id='{$_GET['consult_id']}',patient_id='{$pxid}',ntp_id='{$_GET['ntp_id']}',request_id='{$_POST['sel_import_ntp']}',user_id='{$_SESSION['userid']}',request_timestamp='NOW()'") or die("Cannot query 1080 " . mysql_error()); if ($q_import) { echo "<script language='Javascript'>"; echo "window.alert('Sputum exam was successfully imported! Please check the tables below.')"; echo "</script>"; } } else { echo "<script language='Javascript'>"; echo "window.alert('No sputum exam was imported.')"; echo "</script>"; } break; case "Print Referral": break; } }
function process_ntp() { if (func_num_args()>0) { $arg_list = func_get_args(); $menu_id = $arg_list[0]; $post_vars = $arg_list[1]; $get_vars = $arg_list[2]; $validuser = $arg_list[3]; $isadmin = $arg_list[4]; //print_r($arg_list); } $patient_id = healthcenter::get_patient_id($get_vars["consult_id"]); switch($post_vars["submitntp"]) { case "Assign Lab Exam": if ($post_vars["labs"] && $post_vars["registry_id"]) { foreach($post_vars["labs"] as $key=>$value) { print $sql = "insert into m_consult_ntp_labs_request (consult_id, patient_id, ntp_id, request_id, user_id, request_timestamp) ". "values ('".$get_vars["consult_id"]."', '$patient_id', '".$post_vars["registry_id"]."', '$value', '".$_SESSION["userid"]."', sysdate())"; $result = mysql_query($sql); } header("location: ".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=".$get_vars["ptmenu"]."&module=".$get_vars["module"]."&ntp=".$get_vars["ntp"]."&ntp_id=".$get_vars["ntp_id"]); } break; case "Add Follow-up Date": if ($post_vars["treatment_actual_date"]) { list($month,$day,$year) = explode("/", $post_vars["treatment_actual_date"]); $actual_date = $year."-".str_pad($month, 2, "0", STR_PAD_LEFT)."-".str_pad($day, 2, "0", STR_PAD_LEFT); print $sql = "update m_consult_ntp_due_dates set ". "treatment_actual_date = '$actual_date', ". "remarks = '".addslashes($post_vars["remarks"])."' ". "where ntp_id = '".$post_vars["ntp_id"]."'"; if ($result = mysql_query($sql)) { header("location: ".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=".$get_vars["ptmenu"]."&module=".$get_vars["module"]."&ntp=".$get_vars["ntp"]."&ntp_id=".$get_vars["ntp_id"]); } } break; case "Save NTP Data": if ($post_vars["occupation"] && $post_vars["region"] && $post_vars["bcg_scar"] && $post_vars["contact_person"] && $post_vars["treatment_category"] && $post_vars["treatment_outcome"] && $post_vars["treatment_partner"]) { // always use what's existing $body_weight = healthcenter::get_body_weight($get_vars["consult_id"]); $bcg_scar = ($post_vars["bcg_scar"]?"Y":"N"); $previous_tx = ($post_vars["previous_treatment_flag"]?"Y":"N"); // save previous treatment drugs in one field if ($post_vars["previous_treatment_drugs"]) { foreach($post_vars["previous_treatment_drugs"] as $key=>$drug) { $tx_drugs .= $drug; } } $sql_first = "insert into m_patient_ntp (patient_id, occupation_id, ". "household_contacts, region_id, body_weight, bcg_scar, ". "previous_treatment_flag, previous_treatment_duration, ". "previous_treatment_drugs, treatment_category_id, ". "contact_person, outcome_id, patient_type_id, ". "treatment_partner_id, healthcenter_id, ntp_timestamp, ". "ntp_consult_date, user_id, tb_class) ". "values ('$patient_id', '".$post_vars["occupation"]."', ". "'".$post_vars["hh_contacts"]."', '".$post_vars["region"]."', ". "'$body_weight', '$bcg_scar', '$previous_tx', ". "'".$post_vars["previous_treatment_duration"]."', '$tx_drugs', ". "'".$post_vars["treatment_category"]."', ". "'".$post_vars["contact_person"]."', ". "'".$post_vars["treatment_outcome"]."', ". "'".$post_vars["patient_type"]."', ". "'".$post_vars["treatment_partner"]."', ". "'".$_SESSION["datanode"]["code"]."', sysdate(), ". "sysdate(), '".$_SESSION["userid"]."', ". "'".$post_vars["tb_class"]."')"; if ($result_first = mysql_query($sql_first)) { header("location: ".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=".$get_vars["ptmenu"]."&module=".$get_vars["module"]); } } break; case "Update NTP Data": if ($post_vars["occupation"] && $post_vars["region"] && $post_vars["bcg_scar"] && $post_vars["contact_person"] && $post_vars["treatment_category"] && $post_vars["treatment_outcome"] && $post_vars["treatment_partner"]) { // always use what's existing $body_weight = healthcenter::get_body_weight($get_vars["consult_id"]); $bcg_scar = ($post_vars["bcg_scar"]?"Y":"N"); // if treatment outcome is any other than TX end this course $course_end_flag = ($post_vars["treatment_outcome"]<>"TX"?"Y":"N"); if ($course_end_flag=="Y") { $treatment_end_date = date("Y-m-d"); } else { $treatment_end_date = '0000-00-00'; } $previous_tx = ($post_vars["previous_treatment_flag"]?"Y":"N"); if ($post_vars["previous_treatment_drugs"]) { foreach($post_vars["previous_treatment_drugs"] as $key=>$drug) { $tx_drugs .= $drug; } } $sql_first = "update m_patient_ntp set ". "occupation_id = '".$post_vars["occupation"]."', ". "household_contacts = '".$post_vars["hh_contacts"]."', ". "region_id = '".$post_vars["region"]."', ". "bcg_scar = '$bcg_scar', ". "body_weight = '$body_weight', ". "previous_treatment_flag = '$previous_tx', ". "previous_treatment_duration = '".$post_vars["previous_treatment_duration"]."', ". "previous_treatment_drugs = '$tx_drugs', ". "treatment_category_id = '".$post_vars["treatment_category"]."', ". "contact_person = '".$post_vars["contact_person"]."', ". "outcome_id = '".$post_vars["treatment_outcome"]."', ". "course_end_flag = '$course_end_flag', ". "treatment_end_date = '$treatment_end_date', ". "patient_type_id = '".$post_vars["patient_type"]."', ". "treatment_partner_id = '".$post_vars["treatment_partner"]."', ". "ntp_timestamp = sysdate(), ". "user_id = '".$_SESSION["userid"]."', ". "tb_class = '".$post_vars["tb_class"]."' ". "where ntp_id = '".$post_vars["ntp_id"]."' "; if ($result_first = mysql_query($sql_first)) { header("location: ".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=".$get_vars["ptmenu"]."&module=ntp&ntp=VISIT1&ntp_id=".$get_vars["ntp_id"]); } } break; case "Delete NTP Data": // this is a dummy entry // real delete code is in ntp::display_course(); break; case "Save Intensive Data": if ($post_vars["treatment_date"]) { $start_date = ntp::get_start_date($post_vars["registry_id"]); $intake = ($post_vars["intake_flag"]?"Y":"N"); list($month,$day,$year) = explode("/", $post_vars["treatment_date"]); $intake_date = $year."-".str_pad($month, 2, "0", STR_PAD_LEFT)."-".str_pad($day, 2, "0", STR_PAD_LEFT); $sql = "insert into m_consult_ntp_intake_intensive (ntp_id, consult_id, patient_id, user_id, treatment_month, treatment_week, treatment_date, intake_flag, remarks) ". "values ('".$post_vars["registry_id"]."', '".$get_vars["consult_id"]."', '$patient_id', '".$_SESSION["userid"]."', (month(sysdate())+1)-month('$start_date'), (week(sysdate())+1)-week('$start_date'), '$intake_date', '$intake', '".addslashes($post_vars["remarks"])."')"; if ($result = mysql_query($sql)) { // if first treatment day, // put in projected dates if (ntp::get_intensive_date($post_vars["registry_id"])=="0000-00-00") { // get regimen and determine projected dates // sputum exam intervals are given 1 week (7 days) lead time $regimen = ntp::get_treatment_regimen($post_vars["registry_id"]); switch ($regimen) { case 1: $interval_sputum1 = "49 day"; // towards end of 2nd month $interval_sputum2 = "105 day"; // towards end of 4th month //$interval_sputum3 = "161 day"; // towards end of 6th month $interval_sputum3 = "140 day"; // in the beginning of 6th month //$interval_intensive = "42 day"; $interval_intensive = "56 day"; //$interval_maintenance = "154 day"; $interval_maintenance = "168 day"; $sql_ntp = "update m_patient_ntp set ". "intensive_start_date = '$intake_date', ". "intensive_projected_end_date = '$intake_date' + interval $interval_intensive, ". "maintenance_projected_end_date = '$intake_date' + interval $interval_maintenance, ". "sputum1_date = '$intake_date' + interval $interval_sputum1, ". "sputum2_date = '$intake_date' + interval $interval_sputum2, ". "sputum3_date = '$intake_date' + interval $interval_sputum3 ". "where ntp_id = '".$post_vars["registry_id"]."'"; break; case 3: $interval_sputum1 = "49 day"; // towards end of 2nd month //$interval_intensive = "42 day"; //$interval_maintenance = "154 day"; $interval_intensive = "56 day"; $interval_maintenance = "168 day"; $sql_ntp = "update m_patient_ntp set ". "intensive_start_date = '$intake_date', ". "intensive_projected_end_date = '$intake_date' + interval $interval_intensive, ". "maintenance_projected_end_date = '$intake_date' + interval $interval_maintenance, ". "sputum1_date = '$intake_date' + interval $interval_sputum1 ". "where ntp_id = '".$post_vars["registry_id"]."'"; break; case 2: $interval_sputum1 = "77 day"; // towards end of 3rd month $interval_sputum2 = "133 day"; // towards end of 5th month //$interval_sputum3 = "217 day"; // towards end of 8th month $interval_sputum3 = "196 day"; // beginning of 8th month $interval_intensive = "84 day"; $interval_maintenance = "224 day"; $sql_ntp = "update m_patient_ntp set ". "intensive_start_date = '$intake_date', ". "intensive_projected_end_date = '$intake_date' + interval $interval_intensive, ". "maintenance_projected_end_date = '$intake_date' + interval $interval_maintenance, ". "sputum1_date = '$intake_date' + interval $interval_sputum1, ". "sputum2_date = '$intake_date' + interval $interval_sputum2, ". "sputum3_date = '$intake_date' + interval $interval_sputum3 ". "where ntp_id = '".$post_vars["registry_id"]."'"; break; } $result_ntp = mysql_query($sql_ntp) or die(mysql_error()); } // set appointment only if treatment date is today // useless if treatment date is the past // caution: do not enter first treatment date on a weekend if ($intake_date == date("Y-m-d")) { // if day today is a friday, add 3 days // if saturday add 2 days if (date("w")==5) { $interval = 3; // monday } elseif(date("w")==6) { $interval = 2; // 1 day } else { $interval = 1; // 1 day } $sql_appt = "insert into m_consult_appointments (visit_date, ". "consult_id, schedule_timestamp, user_id, patient_id, ". "appointment_id) values (sysdate() + interval $interval day, ". "'".$get_vars["consult_id"]."', sysdate(), '".$_SESSION["userid"]."', ". "'$patient_id', 'NTPI')"; $result_app = mysql_query($sql_appt); } header("location: ".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=".$get_vars["ptmenu"]."&module=".$get_vars["module"]."&ntp=".$get_vars["ntp"]."&ntp_id=".$get_vars["ntp_id"]."#intensive_form"); } } else { print "<font color='red'>No treatment date</font><br/>"; } break; case "Save Maintenance Data": $start_date = ntp::get_start_date($post_vars["registry_id"]); $intake = ($post_vars["intake_flag"]?"Y":"N"); // treatment date if ($post_vars["treatment_date"] && $post_vars["followup_date"]) { // treatment date list($txmonth,$txday,$txyear) = explode("/", $post_vars["treatment_date"]); $intake_date = $txyear."-".str_pad($txmonth, 2, "0", STR_PAD_LEFT)."-".str_pad($txday, 2, "0", STR_PAD_LEFT); // followup date list($ffmonth,$ffday,$ffyear) = explode("/", $post_vars["followup_date"]); $followup_date = $ffyear."-".str_pad($ffmonth, 2, "0", STR_PAD_LEFT)."-".str_pad($ffday, 2, "0", STR_PAD_LEFT); $sql = "insert into m_consult_ntp_collection_maintenance (ntp_id, consult_id, patient_id, user_id, treatment_month, treatment_week, treatment_date, intake_flag, remarks) ". "values ('".$post_vars["registry_id"]."', '".$get_vars["consult_id"]."', '$patient_id', '".$_SESSION["userid"]."', (month(sysdate())+1)-month('$start_date'), (week(sysdate())+1)-week('$start_date'), '$intake_date', '$intake', '".addslashes($post_vars["remarks"])."')"; if ($result = mysql_query($sql)) { if (ntp::get_maintenance_date($post_vars["registry_id"])=="0000-00-00") { $sql_ntp = "update m_patient_ntp set ". "maintenance_start_date = '$intake_date' ". "where ntp_id = '".$post_vars["registry_id"]."'"; $result_ntp = mysql_query($sql_ntp); } if ($followup_date) { // set appointment based on followup date // maintenance phase appointments are more flexible $sql_appt = "insert into m_consult_appointments (visit_date, ". "consult_id, schedule_timestamp, user_id, patient_id, ". "appointment_id) values ('$followup_date', ". "'".$get_vars["consult_id"]."', sysdate(), '".$_SESSION["userid"]."', ". "'$patient_id', 'NTPM')"; $result_app = mysql_query($sql_appt); } header("location: ".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=".$get_vars["ptmenu"]."&module=".$get_vars["module"]."&ntp=".$get_vars["ntp"]."&ntp_id=".$get_vars["ntp_id"]."#maintenance_form"); } } else { print "<font color='red'>Incomplete date(s)</font><br/>"; } break; case "Send Request": if ($post_vars["registry_id"]) { foreach($post_vars["ntp_lab"] as $key=>$value) { $sql_lab = "insert into m_consult_lab (consult_id, patient_id, lab_id, request_timestamp, request_user_id) ". "values ('".$get_vars["consult_id"]."', '$patient_id', '$value', sysdate(), '".$_SESSION["userid"]."')"; if ($result_lab = mysql_query($sql_lab)) { // try to insert in ntp lab registry $insert_id = mysql_insert_id(); $sql_ntp = "insert into m_consult_ntp_labs_request (consult_id, patient_id, ntp_id, request_id, user_id, request_timestamp) ". "values ('".$get_vars["consult_id"]."', '$patient_id', '".$post_vars["registry_id"]."', '$insert_id', '".$_SESSION["userid"]."', sysdate())"; $result_ntp = mysql_query($sql_ntp); } } header("location: ".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=".$get_vars["ptmenu"]."&module=".$get_vars["module"].($get_vars["ntp_id"]?"&ntp_id=".$get_vars["ntp_id"]:"")); } break; case "Print Referral": break; } }