* @author Brady Miller * @copyright Copyright (c) 2006-2016 Rod Roark * @copyright Copyright (c) 2017-2019 Brady Miller * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ require_once("../globals.php"); require_once("$srcdir/patient.inc"); require_once("../drugs/drugs.inc.php"); use OpenEMR\Common\Csrf\CsrfUtils; use OpenEMR\Core\Header; if (!empty($_POST)) { if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) { CsrfUtils::csrfNotVerified(); } } $form_from_date = isset($_POST['form_from_date']) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-01-01'); // From date filter $form_to_date = isset($_POST['form_to_date']) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d'); // To date filter function processData($data) { $data['inventory_id'] = [$data['inventory_id']]; $data['lot_number'] = [$data['lot_number']]; $data['on_hand'] = [$data['on_hand']]; $data['destroy_date'] = [$data['destroy_date']]; $data['destroy_method'] = [$data['destroy_method']]; $data['destroy_witness'] = [$data['destroy_witness']]; $data['destroy_notes'] = [$data['destroy_notes']]; return $data; } function mergeData($d1, $d2) { $d1['inventory_id'] = array_merge($d1['inventory_id'], $d2['inventory_id']); $d1['lot_number'] = array_merge($d1['lot_number'], $d2['lot_number']); $d1['on_hand'] = array_merge($d1['on_hand'], $d2['on_hand']); $d1['destroy_date'] = array_merge($d1['destroy_date'], $d2['destroy_date']); $d1['destroy_method'] = array_merge($d1['destroy_method'], $d2['destroy_method']); $d1['destroy_witness'] = array_merge($d1['destroy_witness'], $d2['destroy_witness']); $d1['destroy_notes'] = array_merge($d1['destroy_notes'], $d2['destroy_notes']); return $d1; } function mapToTable($row) { if ($row) { echo "\n"; echo " " . text($row["name"]) . " \n"; echo "" . text($row["ndc_number"]) . " \n"; echo ""; foreach ($row['inventory_id'] as $key => $value) { echo "
" . "" . text($row['lot_number'][$key]) . "
"; } echo "\n"; foreach ($row['on_hand'] as $value) { $value = $value != null ? $value : "N/A"; echo "
" . text($value) . "
"; } echo "\n"; foreach ($row['destroy_date'] as $value) { $value = $value != null ? $value : "N/A"; echo "
" . text(oeFormatShortDate($value)) . "
"; } echo "\n"; foreach ($row['destroy_method'] as $value) { $value = $value != null ? $value : "N/A"; echo "
" . text($value) . "
"; } echo "\n"; foreach ($row['destroy_witness'] as $value) { $value = $value != null ? $value : "N/A"; echo "
" . text($value) . "
"; } echo "\n"; foreach ($row['destroy_notes'] as $value) { $value = $value != null ? $value : "N/A"; echo "
" . text($value) . "
"; } echo "\n\n"; } } ?> <?php echo xlt('Destroyed Drugs'); ?>

: : ' /> ' id='printbutton' />
= ? AND " . "i.destroy_date <= ?"; $query = "SELECT i.inventory_id, i.lot_number, i.on_hand, i.drug_id, " . "i.destroy_date, i.destroy_method, i.destroy_witness, i.destroy_notes, " . "d.name, d.ndc_number " . "FROM drug_inventory AS i " . "LEFT OUTER JOIN drugs AS d ON d.drug_id = i.drug_id " . "WHERE $where " . "ORDER BY d.name, i.drug_id, i.destroy_date, i.lot_number"; $res = sqlStatement($query, array($form_from_date, $form_to_date)); $prevRow = ''; while ($row = sqlFetchArray($res)) { $row = processData($row); if ($prevRow == '') { $prevRow = $row; continue; } if ($prevRow['drug_id'] == $row['drug_id']) { $row = mergeData($prevRow, $row); } else { mapToTable($prevRow); } $prevRow = $row; } mapToTable($prevRow); } ?>