public function getHelp($stock_type = '2', $start_date = '2013-08-01', $end_date = '2013-08-31') { /* * Loop through all respective transaction types and add beginning balance at the beginning * Outer Loop through all active drugs * Inner Loop through all respective transaction types for the outer drug */ $first_value = "AND ccc_store_sp = {$stock_type}"; $second_value = "AND dst.ccc_store_sp = {$stock_type}"; $drugs = Drugcode::getEnabledDrugs(); $transactions = Transaction_Type::getAllTypes(); $overall_array = array(); $trans_sections = array(); $prev_start = date("Y-m-d", strtotime("-1 month", strtotime($start_date))); $prev_end = date("Y-m-d", strtotime("-1 month", strtotime($end_date))); $trans_sections['Beginning Balance'] = 0; foreach ($transactions as $transaction) { $trans_sections[$transaction['Name']] = $transaction['id']; } foreach ($drugs as $drug) { $drug_id = $drug['id']; $drug_name = $drug['Drug']; foreach ($trans_sections as $section_index => $sections) { if ($sections == 0) { /* * Runs when transaction is beginngin balance * Get Beginning Balance of drug */ $sql = "SELECT SUM( dst.balance ) AS total FROM drug_stock_movement dst, \n\t\t\t\t\t\t\t(SELECT drug, batch_number, MAX( transaction_date ) AS trans_date FROM `drug_stock_movement` \n\t\t\t\t\t\t\tWHERE transaction_date BETWEEN '{$prev_start}' AND '{$prev_end}' AND drug ='{$drug_id}' {$first_value} \n\t\t\t\t\t\t\tGROUP BY batch_number) AS temp WHERE dst.drug = temp.drug AND dst.batch_number = temp.batch_number \n\t\t\t\t\t\t\tAND dst.transaction_date = temp.trans_date {$second_value}"; } else { $effect = Transaction_Type::getEffect($sections); if ($effect['Effect'] == 1) { $balance_value = "quantity"; } else { $balance_value = "quantity_out"; } $sql = "SELECT SUM({$balance_value}) AS total FROM `drug_stock_movement` \n\t\t\t\t\t\t\tWHERE transaction_date BETWEEN '{$start_date}' AND '{$end_date}' {$first_value} \n\t\t\t\t\t\t\tAND transaction_type ='{$sections}' AND drug='{$drug_id}'"; } $query = $this->db->query($sql); $results = $query->result_array(); if ($results) { if ($results[0]['total'] != null) { $overall_array[$drug_name][$section_index] = $results[0]['total']; } else { $overall_array[$drug_name][$section_index] = 0; } } else { $overall_array[$drug_name][$section_index] = 0; } } } }
public function viewDetails($record_no) { $this->session->set_userdata('record_no', $record_no); $patient = ""; $facility = ""; $sql = "SELECT p.*,\n\t\t rst.Name as service_name,\n\t\t dp.child,\n\t\t s.secondary_spouse \n\t\t FROM patient p \n\t\t LEFT JOIN regimen_service_type rst ON rst.id=p.service \n\t\t LEFT JOIN dependants dp ON p.patient_number_ccc=dp.parent \n\t\t LEFT JOIN spouses s ON p.patient_number_ccc=s.primary_spouse \n\t\t WHERE p.id='{$record_no}'\n\t\t GROUP BY p.id"; $query = $this->db->query($sql); $results = $query->result_array(); $depdendant_msg = ""; if ($results) { $results[0]['other_illnesses'] = $this->extract_illness($results[0]['other_illnesses']); $data['results'] = $results; $patient = $results[0]['patient_number_ccc']; $facility = $this->session->userdata("facility"); //Check dependedants/spouse status $child = $results[0]['child']; $spouse = $results[0]['secondary_spouse']; $patient_name = strtoupper($results[0]['first_name'] . ' ' . $results[0]['last_name']); if ($child != NULL) { $pat = $this->getDependentStatus($child); if ($pat != '') { $depdendant_msg .= "Patient {$patient_name}\\'s dependant " . $pat . " is lost to follow up "; } } if ($spouse != NULL) { $pat = $this->getDependentStatus($spouse); if ($pat != '') { $depdendant_msg .= "Patient {$patient_name}\\'s spouse " . $pat . " is lost to follow up "; } } } //Patient History $sql = "SELECT pv.dispensing_date,\n\t\t\t\t\t\t v.name AS visit, \n\t\t\t\t\t\t u.Name AS unit, \n\t\t\t\t\t\t pv.dose, \n\t\t\t\t\t\t pv.duration, \n\t\t\t\t\t\t pv.indication, \n\t\t\t\t\t\t pv.patient_visit_id AS record, \n\t\t\t\t\t\t d.drug, \n\t\t\t\t\t\t pv.quantity, \n\t\t\t\t\t\t pv.current_weight, \n\t\t\t\t\t\t pv.current_height, \n\t\t\t\t\t\t r1.regimen_desc as last_regimen, \n\t\t\t\t\t\t r.regimen_desc, \n\t\t\t\t\t\t pv.batch_number, \n\t\t\t\t\t\t pv.pill_count, \n\t\t\t\t\t\t pv.adherence, \n\t\t\t\t\t\t pv.user, \n\t\t\t\t\t\t rcp.name as regimen_change_reason \n\t\t FROM v_patient_visits pv \n\t\t\t LEFT JOIN drugcode d ON pv.drug_id = d.id \n\t\t\t LEFT JOIN drug_unit u ON d.unit = u.id \n\t\t\t LEFT JOIN regimen r ON pv.regimen_id = r.id \n\t\t\t LEFT JOIN regimen r1 ON pv.last_regimen = r1.id \n\t\t\t LEFT JOIN visit_purpose v ON pv.visit_purpose_id = v.id \n\t\t\t LEFT JOIN regimen_change_purpose rcp ON rcp.id=pv.regimen_change_reason\n\t\t WHERE pv.patient_id = '{$patient}' \n\t\t AND pv.facility = '{$facility}' \n\t\t AND pv.active='1' AND pv.pv_active='1'\n\t\t GROUP BY d.drug,pv.dispensing_date\n\t\t ORDER BY pv.patient_visit_id DESC"; $query = $this->db->query($sql); $results = $query->result_array(); if ($results) { $data['history_logs'] = $results; } else { $data['history_logs'] = ""; } $data['dependant_msg'] = $depdendant_msg; $data['districts'] = District::getPOB(); $data['genders'] = Gender::getAll(); $data['statuses'] = Patient_Status::getStatus(); $data['sources'] = Patient_Source::getSources(); $data['drug_prophylaxis'] = Drug_Prophylaxis::getAll(); $data['service_types'] = Regimen_Service_Type::getHydratedAll(); $data['facilities'] = Facilities::getAll(); $data['family_planning'] = Family_Planning::getAll(); $data['other_illnesses'] = Other_Illnesses::getAll(); $data['pep_reasons'] = Pep_Reason::getActive(); $data['drugs'] = Drugcode::getEnabledDrugs(); $data['regimens'] = Regimen::getRegimens(); $data['who_stages'] = Who_Stage::getAllHydrated(); $data['content_view'] = 'patient_details_v'; //Hide side menus $data['hide_side_menu'] = '1'; $this->base_params($data); }
public function view_balance() { $data['drugs'] = Drugcode::getEnabledDrugs(); $data['quick_link'] = "balance"; $data['title'] = "webADT | Running Balance"; $data['banner_text'] = "Running Balance Management"; $data['link'] = "auto_management"; $this->load->view('running_balance_v', $data); }