Skip to content

Commit

Permalink
Allows encounters report to show esigned and non-esigned encounters, …
Browse files Browse the repository at this point in the history
…take 2.
  • Loading branch information
teryhill authored and bradymiller committed Sep 26, 2015
1 parent 7400663 commit 7df34d4
Showing 1 changed file with 119 additions and 50 deletions.
169 changes: 119 additions & 50 deletions interface/reports/encounters_report.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
<?php
// Copyright (C) 2007-2010 Rod Roark <[email protected]>
//
// 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 2
// of the License, or (at your option) any later version.

// This report shows past encounters with filtering and sorting.
/*
* Encounters report. (/interface/reports/encounters_report.php
*
*
* This report shows past encounters with filtering and sorting,
* Added filtering to show encounters not e-signed, encounters e-signed and forms e-signed.
*
* Copyright (C) 2015 Terry Hill <[email protected]>
* Copyright (C) 2007-2010 Rod Roark <[email protected]>
*
* 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:https://opensource.org/licenses/gpl-license.php>;.
*
* @package OpenEMR
* @author Terry Hill <[email protected]>
* @author Rod Roark <[email protected]>
* @link http:https://www.open-emr.org
*
*/

require_once("../globals.php");
require_once("$srcdir/forms.inc");
Expand All @@ -25,6 +44,7 @@
'patient' => 'lower(p.lname), lower(p.fname), fe.date',
'pubpid' => 'lower(p.pubpid), fe.date',
'time' => 'fe.date, lower(u.lname), lower(u.fname)',
'encounter' => 'fe.encounter, fe.date, lower(u.lname), lower(u.fname)',
);

function bucks($amount) {
Expand All @@ -46,21 +66,42 @@ function show_doc_total($lastdocname, $doc_encounters) {
$form_facility = $_POST['form_facility'];
$form_details = $_POST['form_details'] ? true : false;
$form_new_patients = $_POST['form_new_patients'] ? true : false;
$form_esigned = $_POST['form_esigned'] ? true : false;
$form_not_esigned = $_POST['form_not_esigned'] ? true : false;
$form_encounter_esigned = $_POST['form_encounter_esigned'] ? true : false;

$form_orderby = $ORDERHASH[$_REQUEST['form_orderby']] ?
$_REQUEST['form_orderby'] : 'doctor';
$orderby = $ORDERHASH[$form_orderby];

// Get the info.
//
$esign_fields = '';
$esign_joins = '';
$esign_from = '';
if ($form_encounter_esigned) {
$esign_fields = ", es.table, es.tid ";
$esign_joins = "LEFT OUTER JOIN esign_signatures AS es ON es.tid = fe.encounter ";
}
if ($form_esigned) {
$esign_fields = ", es.table, es.tid ";
$esign_joins = "LEFT OUTER JOIN esign_signatures AS es ON es.tid = fe.encounter ";
}
if ($form_not_esigned) {
$esign_fields = ", es.table, es.tid ";
$esign_joins = "LEFT JOIN esign_signatures AS es on es.tid = fe.encounter ";
}

$query = "SELECT " .
"fe.encounter, fe.date, fe.reason, " .
"f.formdir, f.form_name, " .
"p.fname, p.mname, p.lname, p.pid, p.pubpid, " .
"u.lname AS ulname, u.fname AS ufname, u.mname AS umname " .
"FROM ( form_encounter AS fe, forms AS f ) " .
"$esign_fields" .
"FROM ( form_encounter AS fe, forms AS f $esign_from ) " .
"LEFT OUTER JOIN patient_data AS p ON p.pid = fe.pid " .
"LEFT JOIN users AS u ON u.id = fe.provider_id " .
"$esign_joins" .
"WHERE f.pid = fe.pid AND f.encounter = fe.encounter AND f.formdir = 'newpatient' ";
if ($form_to_date) {
$query .= "AND fe.date >= '$form_from_date 00:00:00' AND fe.date <= '$form_to_date 23:59:59' ";
Expand All @@ -76,14 +117,23 @@ function show_doc_total($lastdocname, $doc_encounters) {
if ($form_new_patients) {
$query .= "AND fe.date = (SELECT MIN(fe2.date) FROM form_encounter AS fe2 WHERE fe2.pid = fe.pid) ";
}
if ($form_encounter_esigned) {
$query .= "AND es.tid = fe.encounter AND es.table = 'form_encounter' ";
}
if ($form_esigned) {
$query .= "AND es.tid = fe.encounter ";
}
if ($form_not_esigned) {
$query .= "AND es.tid IS NULL ";
}
$query .= "ORDER BY $orderby";

$res = sqlStatement($query);
?>
<html>
<head>
<?php html_header_show();?>
<title><?php xl('Encounters Report','e'); ?></title>
<title><?php echo xlt('Encounters Report'); ?></title>

<style type="text/css">@import url(../../library/dynarch_calendar.css);</style>

Expand Down Expand Up @@ -144,7 +194,7 @@ function refreshme() {
<!-- 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('Encounters','e'); ?></span>
<span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Encounters'); ?></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)); ?>
Expand All @@ -161,13 +211,13 @@ function refreshme() {
<table class='text'>
<tr>
<td class='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='label'>
<?php xl('Provider','e'); ?>:
<?php echo xlt('Provider'); ?>:
</td>
<td>
<?php
Expand All @@ -181,48 +231,60 @@ function refreshme() {
$ures = sqlStatement($query);

echo " <select name='form_provider'>\n";
echo " <option value=''>-- " . xl('All') . " --\n";
echo " <option value=''>-- " . xlt('All') . " --\n";

while ($urow = sqlFetchArray($ures)) {
$provid = $urow['id'];
echo " <option value='$provid'";
echo " <option value='" . attr($provid) . "'";
if ($provid == $_POST['form_provider']) echo " selected";
echo ">" . $urow['lname'] . ", " . $urow['fname'] . "\n";
echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
}

echo " </select>\n";

?>
</td>
<td>
<input type='checkbox' name='form_new_patients' title='First-time visits only'<?php if ($form_new_patients) echo ' checked'; ?>>
<?php xl('New','e'); ?>
<label><input type='checkbox' name='form_new_patients' title='First-time visits only'<?php if ($form_new_patients) echo ' checked'; ?>>
<?php echo xlt('New'); ?></label>
</td>
<td>
<label><input type='checkbox' name='form_esigned'<?php if ($form_esigned) echo ' checked'; ?>>
<?php echo xlt('Forms Esigned'); ?></label>
</td>
<td>
<label><input type='checkbox' name='form_encounter_esigned'<?php if ($form_encounter_esigned) echo ' checked'; ?>>
<?php echo xlt('Encounter Esigned'); ?></label>
</td>
</tr>
<tr>
<td class='label'>
<?php xl('From','e'); ?>:
<?php echo xlt('From'); ?>:
</td>
<td>
<input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
<input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo attr($form_from_date) ?>'
onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
<img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
title='<?php xl('Click here to choose a date','e'); ?>'>
title='<?php echo xla('Click here to choose a date'); ?>'>
</td>
<td class='label'>
<?php xl('To','e'); ?>:
<?php echo xlt('To'); ?>:
</td>
<td>
<input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
<input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo attr($form_to_date) ?>'
onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
<img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
title='<?php xl('Click here to choose a date','e'); ?>'>
title='<?php echo xla('Click here to choose a date'); ?>'>
</td>
<td>
<input type='checkbox' name='form_details'<?php if ($form_details) echo ' checked'; ?>>
<?php xl('Details','e'); ?>
<label><input type='checkbox' name='form_details'<?php if ($form_details) echo ' checked'; ?>>
<?php echo xlt('Details'); ?></label>
</td>
<td>
<label><input type='checkbox' name='form_not_esigned'<?php if ($form_not_esigned) echo ' checked'; ?>>
<?php echo xlt('Not Esigned'); ?></label>
</td>
</tr>
</table>
Expand All @@ -237,14 +299,14 @@ function refreshme() {
<div style='margin-left:15px'>
<a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
<span>
<?php xl('Submit','e'); ?>
<?php echo xlt('Submit'); ?>
</span>
</a>

<?php if ($_POST['form_refresh'] || $_POST['form_orderby'] ) { ?>
<a href='#' class='css_button' onclick='window.print()'>
<span>
<?php xl('Print','e'); ?>
<?php echo xlt('Print'); ?>
</span>
</a>
<?php } ?>
Expand All @@ -268,35 +330,39 @@ function refreshme() {
<?php if ($form_details) { ?>
<th>
<a href="nojs.php" onclick="return dosort('doctor')"
<?php if ($form_orderby == "doctor") echo " style=\"color:#00cc00\"" ?>><?php xl('Provider','e'); ?> </a>
<?php if ($form_orderby == "doctor") echo " style=\"color:#00cc00\"" ?>><?php echo xlt('Provider'); ?> </a>
</th>
<th>
<a href="nojs.php" onclick="return dosort('time')"
<?php if ($form_orderby == "time") echo " style=\"color:#00cc00\"" ?>><?php xl('Date','e'); ?></a>
<?php if ($form_orderby == "time") echo " style=\"color:#00cc00\"" ?>><?php echo xlt('Date'); ?></a>
</th>
<th>
<a href="nojs.php" onclick="return dosort('patient')"
<?php if ($form_orderby == "patient") echo " style=\"color:#00cc00\"" ?>><?php xl('Patient','e'); ?></a>
<?php if ($form_orderby == "patient") echo " style=\"color:#00cc00\"" ?>><?php echo xlt('Patient'); ?></a>
</th>
<th>
<a href="nojs.php" onclick="return dosort('pubpid')"
<?php if ($form_orderby == "pubpid") echo " style=\"color:#00cc00\"" ?>><?php xl('ID','e'); ?></a>
<?php if ($form_orderby == "pubpid") echo " style=\"color:#00cc00\"" ?>><?php echo xlt('ID'); ?></a>
</th>
<th>
<?php echo xlt('Status'); ?>
</th>
<th>
<?php xl('Status','e'); ?>
<?php echo xlt('Encounter'); ?>
</th>
<th>
<?php xl('Encounter','e'); ?>
<a href="nojs.php" onclick="return dosort('encounter')"
<?php if ($form_orderby == "encounter") echo " style=\"color:#00cc00\"" ?>><?php echo xlt('Encounter Number'); ?></a>
</th>
<th>
<?php xl('Form','e'); ?>
<?php echo xlt('Form'); ?>
</th>
<th>
<?php xl('Coding','e'); ?>
<?php echo xlt('Coding'); ?>
</th>
<?php } else { ?>
<th><?php xl('Provider','e'); ?></td>
<th><?php xl('Encounters','e'); ?></td>
<th><?php echo xlt('Provider'); ?></td>
<th><?php echo xlt('Encounters'); ?></td>
<?php } ?>
</thead>
<tbody>
Expand Down Expand Up @@ -360,28 +426,31 @@ function refreshme() {
?>
<tr bgcolor='<?php echo $bgcolor ?>'>
<td>
<?php echo ($docname == $lastdocname) ? "" : $docname ?>&nbsp;
<?php echo ($docname == $lastdocname) ? "" : text($docname) ?>&nbsp;
</td>
<td>
<?php echo oeFormatShortDate(substr($row['date'], 0, 10)) ?>&nbsp;
<?php echo text(oeFormatShortDate(substr($row['date'], 0, 10))) ?>&nbsp;
</td>
<td>
<?php echo $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']; ?>&nbsp;
<?php echo text($row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname']); ?>&nbsp;
</td>
<td>
<?php echo $row['pubpid']; ?>&nbsp;
<?php echo text($row['pubpid']); ?>&nbsp;
</td>
<td>
<?php echo $status; ?>&nbsp;
<?php echo text($status); ?>&nbsp;
</td>
<td>
<?php echo $row['reason']; ?>&nbsp;
<?php echo text($row['reason']); ?>&nbsp;
</td>
<td>
<?php echo text($row['encounter']); ?>&nbsp;
</td>
<td>
<?php echo $encnames; ?>&nbsp;
<?php echo text($encnames); ?>&nbsp;
</td>
<td>
<?php echo $coded; ?>
<?php echo text($coded); ?>
</td>
</tr>
<?php
Expand All @@ -393,8 +462,8 @@ function refreshme() {
++$doc_encounters;
}
$lastdocname = $docname;
}

}
if (!$form_details) show_doc_total($lastdocname, $doc_encounters);
}
?>
Expand All @@ -403,11 +472,11 @@ function refreshme() {
</div> <!-- end encresults -->
<?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 } ?>

<input type="hidden" name="form_orderby" value="<?php echo $form_orderby ?>" />
<input type="hidden" name="form_orderby" value="<?php echo attr($form_orderby) ?>" />
<input type='hidden' name='form_refresh' id='form_refresh' value=''/>

</form>
Expand Down

0 comments on commit 7df34d4

Please sign in to comment.