Skip to content

Commit

Permalink
prescriptions_report cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bradymiller committed Nov 9, 2017
1 parent d81371d commit cecf955
Showing 1 changed file with 100 additions and 112 deletions.
212 changes: 100 additions & 112 deletions interface/reports/prescriptions_report.php
Expand Up @@ -3,73 +3,58 @@
* This report lists prescriptions and their dispensations according
* to various input selection criteria.
*
* Fix drug name search to work in a broader sense - tony@mi-squared.com 2010
*
* Copyright (C) 2005-2016 Rod Roark <rod@sunsetsystems.com>
* Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
*
* LICENSE: This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
*
* @package OpenEMR
* @author Rod Roark <rod@sunsetsystems.com>
* @author Brady Miller <brady.g.miller@gmail.com>
* @link http://www.open-emr.org
* @package OpenEMR
* @link http://www.open-emr.org
* @author Rod Roark <rod@sunsetsystems.com>
* @author Brady Miller <brady.g.miller@gmail.com>
* @copyright Copyright (c) 2005-2016 Rod Roark <rod@sunsetsystems.com>
* @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
* @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("$srcdir/options.inc.php");
require_once("../drugs/drugs.inc.php");

use OpenEMR\Core\Header;

require_once("../globals.php");
require_once("$srcdir/patient.inc");
require_once("$srcdir/options.inc.php");
require_once("../drugs/drugs.inc.php");

$form_from_date = (!empty($_POST['form_from_date'])) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-01-01');
$form_to_date = (!empty($_POST['form_to_date'])) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
$form_patient_id = trim($_POST['form_patient_id']);
$form_drug_name = trim($_POST['form_drug_name']);
$form_lot_number = trim($_POST['form_lot_number']);
$form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
$form_from_date = (!empty($_POST['form_from_date'])) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-01-01');
$form_to_date = (!empty($_POST['form_to_date'])) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
$form_patient_id = trim($_POST['form_patient_id']);
$form_drug_name = trim($_POST['form_drug_name']);
$form_lot_number = trim($_POST['form_lot_number']);
$form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
?>
<html>
<head>

<title><?php xl('Prescriptions and Dispensations', 'e'); ?></title>
<title><?php echo xlt('Prescriptions and Dispensations'); ?></title>

<?php Header::setupHeader(['datetime-picker', 'report-helper']); ?>

<script language="JavaScript">

var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';

$(document).ready(function() {
oeFixedHeaderSetup(document.getElementById('mymaintable'));
var win = top.printLogSetup ? top : opener.top;
win.printLogSetup(document.getElementById('printbutton'));

$('.datepicker').datetimepicker({
<?php $datetimepicker_timepicker = false; ?>
<?php $datetimepicker_showseconds = false; ?>
<?php $datetimepicker_formatInput = true; ?>
<?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
<?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
});

});

// The OnClick handler for receipt display.
function show_receipt(payid) {
// dlgopen('../patient_file/front_payment.php?receipt=1&payid=' + payid, '_blank', 550, 400);
return false;
}
$(document).ready(function() {
oeFixedHeaderSetup(document.getElementById('mymaintable'));
var win = top.printLogSetup ? top : opener.top;
win.printLogSetup(document.getElementById('printbutton'));

$('.datepicker').datetimepicker({
<?php $datetimepicker_timepicker = false; ?>
<?php $datetimepicker_showseconds = false; ?>
<?php $datetimepicker_formatInput = true; ?>
<?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
<?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
});
});

// The OnClick handler for receipt display.
function show_receipt(payid) {
// dlgopen('../patient_file/front_payment.php?receipt=1&payid=' + payid, '_blank', 550, 400);
return false;
}

</script>

Expand Down Expand Up @@ -106,10 +91,10 @@ function show_receipt(payid) {
<!-- Required for the popup date selectors -->
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>

<span class='title'><?php xl('Report', 'e'); ?> - <?php xl('Prescriptions and Dispensations', 'e'); ?></span>
<span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Prescriptions and Dispensations'); ?></span>

<div id="report_parameters_daterange">
<?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
<?php echo oeFormatShortDate($form_from_date) ." &nbsp; " . xlt('to') . " &nbsp; " . oeFormatShortDate($form_to_date); ?>
</div>

<form name='theform' id='theform' method='post' action='prescriptions_report.php' onsubmit='return top.restoreSession()'>
Expand All @@ -125,45 +110,45 @@ function show_receipt(payid) {
<table class='text'>
<tr>
<td class='control-label'>
<?php xl('Facility', 'e'); ?>:
<?php echo xlt('Facility'); ?>:
</td>
<td>
<?php dropdown_facility(strip_escape_custom($form_facility), 'form_facility', true); ?>
<?php dropdown_facility($form_facility, 'form_facility', true); ?>
</td>
<td class='control-label'>
<?php xl('From', 'e'); ?>:
<?php echo xlt('From'); ?>:
</td>
<td>
<input type='text' class='datepicker form-control' name='form_from_date' id="form_from_date" size='10' value='<?php echo oeFormatShortDate($form_from_date) ?>'>
<input type='text' class='datepicker form-control' name='form_from_date' id="form_from_date" size='10' value='<?php echo oeFormatShortDate($form_from_date); ?>'>
</td>
<td class='control-label'>
<?php xl('To', 'e'); ?>:
<?php echo xlt('To'); ?>:
</td>
<td>
<input type='text' class='datepicker form-control' name='form_to_date' id="form_to_date" size='10' value='<?php echo oeFormatShortDate($form_to_date) ?>'>
<input type='text' class='datepicker form-control' name='form_to_date' id="form_to_date" size='10' value='<?php echo oeFormatShortDate($form_to_date); ?>'>
</td>
</tr>
<tr>
<td class='control-label'>
<?php xl('Patient ID', 'e'); ?>:
<?php echo xlt('Patient ID'); ?>:
</td>
<td>
<input type='text' class='form-control' name='form_patient_id' size='10' maxlength='20' value='<?php echo $form_patient_id ?>'
title=<?php xl('Optional numeric patient ID', 'e', '\'', '\''); ?> />
<input type='text' class='form-control' name='form_patient_id' size='10' maxlength='20' value='<?php echo attr($form_patient_id); ?>'
title='<?php echo xla('Optional numeric patient ID'); ?>' />
</td>
<td class='control-label'>
<?php xl('Drug', 'e'); ?>:
<?php echo xlt('Drug'); ?>:
</td>
<td>
<input type='text' class='form-control' name='form_drug_name' size='10' maxlength='250' value='<?php echo $form_drug_name ?>'
title=<?php xl('Optional drug name, use % as a wildcard', 'e', '\'', '\''); ?> />
<input type='text' class='form-control' name='form_drug_name' size='10' maxlength='250' value='<?php echo attr($form_drug_name); ?>'
title='<?php echo xla('Optional drug name, use % as a wildcard'); ?>' />
</td>
<td class='control-label'>
<?php xl('Lot', 'e'); ?>:
<?php echo xlt('Lot'); ?>:
</td>
<td>
<input type='text' class='form-control' name='form_lot_number' size='10' maxlength='20' value='<?php echo $form_lot_number ?>'
title=<?php xl('Optional lot number, use % as a wildcard', 'e', '\'', '\''); ?> />
<input type='text' class='form-control' name='form_lot_number' size='10' maxlength='20' value='<?php echo attr($form_lot_number); ?>'
title='<?php echo xla('Optional lot number, use % as a wildcard'); ?>' />
</td>
</tr>
</table>
Expand Down Expand Up @@ -201,36 +186,42 @@ function show_receipt(payid) {
<div id="report_results">
<table id='mymaintable'>
<thead>
<th> <?php xl('Patient', 'e'); ?> </th>
<th> <?php xl('ID', 'e'); ?> </th>
<th> <?php xl('RX', 'e'); ?> </th>
<th> <?php xl('Drug Name', 'e'); ?> </th>
<th> <?php xl('NDC', 'e'); ?> </th>
<th> <?php xl('Units', 'e'); ?> </th>
<th> <?php xl('Refills', 'e'); ?> </th>
<th> <?php xl('Instructed', 'e'); ?> </th>
<th> <?php xl('Reactions', 'e'); ?> </th>
<th> <?php xl('Dispensed', 'e'); ?> </th>
<th> <?php xl('Qty', 'e'); ?> </th>
<th> <?php xl('Manufacturer', 'e'); ?> </th>
<th> <?php xl('Lot', 'e'); ?> </th>
<th> <?php echo xlt('Patient'); ?> </th>
<th> <?php echo xlt('ID'); ?> </th>
<th> <?php echo xlt('RX'); ?> </th>
<th> <?php echo xlt('Drug Name'); ?> </th>
<th> <?php echo xlt('NDC'); ?> </th>
<th> <?php echo xlt('Units'); ?> </th>
<th> <?php echo xlt('Refills'); ?> </th>
<th> <?php echo xlt('Instructed'); ?> </th>
<th> <?php echo xlt('Reactions'); ?> </th>
<th> <?php echo xlt('Dispensed'); ?> </th>
<th> <?php echo xlt('Qty'); ?> </th>
<th> <?php echo xlt('Manufacturer'); ?> </th>
<th> <?php echo xlt('Lot'); ?> </th>
</thead>
<tbody>
<?php
if ($_POST['form_refresh']) {
$where = "r.date_modified >= '$form_from_date' AND " .
"r.date_modified <= '$form_to_date'";
//if ($form_patient_id) $where .= " AND r.patient_id = '$form_patient_id'";
$sqlBindArray = array();

$where = "r.date_modified >= ? AND " .
"r.date_modified <= ?";
array_push($sqlBindArray, $form_from_date, $form_to_date);

if ($form_patient_id) {
$where .= " AND p.pubpid = '$form_patient_id'";
$where .= " AND p.pubpid = ?";
array_push($sqlBindArray, $form_patient_id);
}

if ($form_drug_name) {
$where .= " AND (d.name LIKE '$form_drug_name' OR r.drug LIKE '$form_drug_name')";
$where .= " AND (d.name LIKE ? OR r.drug LIKE ?)";
array_push($sqlBindArray, $form_drug_name, $form_drug_name);
}

if ($form_lot_number) {
$where .= " AND i.lot_number LIKE '$form_lot_number'";
$where .= " AND i.lot_number LIKE ?";
array_push($sqlBindArray, $form_lot_number);
}

$query = "SELECT r.id, r.patient_id, " .
Expand All @@ -247,16 +238,14 @@ function show_receipt(payid) {
"LEFT OUTER JOIN patient_data AS p ON p.pid = r.patient_id " .
"LEFT OUTER JOIN users AS u ON u.id = r.provider_id " .
"WHERE $where " .
//"ORDER BY p.lname, p.fname, r.patient_id, r.id, s.sale_id";
"ORDER BY p.lname, p.fname, p.pubpid, r.id, s.sale_id";

// echo "<!-- $query -->\n"; // debugging
$res = sqlStatement($query);
$res = sqlStatement($query, $sqlBindArray);

$last_patient_id = 0;
$last_prescription_id = 0;
while ($row = sqlFetchArray($res)) {
// If a facility is specified, ignore rows that do not match.
// If a facility is specified, ignore rows that do not match.
if ($form_facility !== '') {
if ($form_facility) {
if ($row['facility_id'] != $form_facility) {
Expand All @@ -270,20 +259,19 @@ function show_receipt(payid) {
}

$patient_name = $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'];
//$patient_id = $row['patient_id'];
$patient_id = $row['pubpid'];
$prescription_id = $row['id'];
$drug_name = empty($row['name']) ? $row['drug'] : $row['name'];
$ndc_number = $row['ndc_number'];
$drug_units = $row['size'] . ' ' .
$drug_units = text($row['size']) . ' ' .
generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['unit']);
$refills = $row['refills'];
$reactions = $row['reactions'];
$instructed = $row['dosage'] . ' ' .
$instructed = text($row['dosage']) . ' ' .
generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'), $row['form']) .
' ' .
generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'), $row['interval']);
//if ($row['patient_id'] == $last_patient_id) {
//if ($row['patient_id'] == $last_patient_id) {
if (strcmp($row['pubpid'], $last_patient_id) == 0) {
$patient_name = '&nbsp;';
$patient_id = '&nbsp;';
Expand All @@ -300,46 +288,46 @@ function show_receipt(payid) {
?>
<tr>
<td>
<?php echo $patient_name ?>
<?php echo text($patient_name); ?>
</td>
<td>
<?php echo $patient_id ?>
<?php echo text($patient_id); ?>
</td>
<td>
<?php echo $prescription_id ?>
<?php echo text($prescription_id); ?>
</td>
<td>
<?php echo $drug_name ?>
<?php echo text($drug_name); ?>
</td>
<td>
<?php echo $ndc_number ?>
<?php echo text($ndc_number); ?>
</td>
<td>
<?php echo $drug_units ?>
<?php echo $drug_units; ?>
</td>
<td>
<?php echo $refills ?>
<?php echo text($refills); ?>
</td>
<td>
<?php echo $instructed ?>
<?php echo $instructed; ?>
</td>
<td>
<?php echo $reactions ?>
<?php echo text($reactions); ?>
</td>
<td>
<a href='../drugs/dispense_drug.php?sale_id=<?php echo $row['sale_id'] ?>'
<a href='../drugs/dispense_drug.php?sale_id=<?php echo attr($row['sale_id']); ?>'
style='color:#0000ff' target='_blank'>
<?php echo oeFormatShortDate($row['sale_date']) ?>
</a>
</td>
<td>
<?php echo $row['quantity'] ?>
<?php echo text($row['quantity']); ?>
</td>
<td>
<?php echo $row['manufacturer'] ?>
<?php echo text($row['manufacturer']); ?>
</td>
<td>
<?php echo $row['lot_number'] ?>
<?php echo text($row['lot_number']); ?>
</td>
</tr>
<?php
Expand All @@ -354,7 +342,7 @@ function show_receipt(payid) {
</div> <!-- end of results -->
<?php } else { ?>
<div class='text'>
<?php echo xl('Please input search criteria above, and click Submit to view results.', 'e'); ?>
<?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?>
</div>
<?php } ?>
</form>
Expand Down

0 comments on commit cecf955

Please sign in to comment.