6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2009-2010 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 require_once("../globals.php");
15 require_once("$srcdir/patient.inc");
16 require_once("$srcdir/acl.inc");
18 function formatcyp($amount)
21 return sprintf("%.2f", $amount);
27 function display_desc($desc)
29 if (preg_match('/^\S*?:(.+)$/', $desc, $matches)) {
36 function thisLineItem($patient_id, $encounter_id, $description, $transdate, $qty, $cypfactor, $irnumber = '')
38 global $product, $productcyp, $producttotal, $productqty, $grandtotal, $grandqty;
40 $invnumber = empty($irnumber) ?
"$patient_id.$encounter_id" : $irnumber;
41 $rowcyp = sprintf('%01.2f', $cypfactor);
42 $rowresult = sprintf('%01.2f', $rowcyp * $qty);
44 $rowproduct = $description;
46 $rowproduct = 'Unknown';
49 if ($product != $rowproduct) {
51 // Print product total.
52 if ($_POST['form_csvexport']) {
53 if (! $_POST['form_details']) {
54 echo '"' . display_desc($product) . '",';
55 echo '"' . $productqty . '",';
56 echo '"' . formatcyp($productcyp) . '",';
57 echo '"' . formatcyp($producttotal) . '"' . "\n";
62 <tr bgcolor
="#ddddff">
63 <td
class="detail" colspan
="<?php echo $_POST['form_details'] ? 3 : 1; ?>">
65 if ($_POST['form_details']) {
66 echo xl('Total for ');
68 echo display_desc($product) ?
>
70 <td
class="dehead" align
="right">
71 <?php
echo $productqty; ?
>
73 <td
class="dehead" align
="right">
74 <?php
echo formatcyp($productcyp); ?
>
76 <td
class="dehead" align
="right">
77 <?php
echo formatcyp($producttotal); ?
>
81 } // End not csv export
86 $product = $rowproduct;
87 $productleft = $product;
88 $productcyp = $rowcyp;
91 if ($_POST['form_details']) {
92 if ($_POST['form_csvexport']) {
93 echo '"' . display_desc($product) . '",';
94 echo '"' . oeFormatShortDate(display_desc($transdate)) . '",';
95 echo '"' . display_desc($invnumber) . '",';
96 echo '"' . display_desc($qty) . '",';
97 echo '"' . formatcyp($rowcyp) . '",';
98 echo '"' . formatcyp($rowresult) . '"' . "\n";
104 <?php
echo display_desc($productleft);
105 $productleft = " "; ?
>
108 <?php
echo text(oeFormatShortDate($transdate)); ?
>
111 <?php
echo $invnumber; ?
>
113 <td
class="dehead" align
="right">
116 <td
class="dehead" align
="right">
117 <?php
echo formatcyp($rowcyp); ?
>
119 <td
class="dehead" align
="right">
120 <?php
echo formatcyp($rowresult); ?
>
124 } // End not csv export
126 $producttotal +
= $rowresult;
127 $grandtotal +
= $rowresult;
132 if (! acl_check('acct', 'rep')) {
133 die(xl("Unauthorized access."));
136 $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
137 $form_to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
138 $form_facility = $_POST['form_facility'];
140 if ($_POST['form_csvexport']) {
141 header("Pragma: public");
142 header("Expires: 0");
143 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
144 header("Content-Type: application/force-download");
145 header("Content-Disposition: attachment; filename=ippf_cyp_report.csv");
146 header("Content-Description: File Transfer");
148 if ($_POST['form_details']) {
154 echo '"Result"' . "\n";
159 echo '"Result"' . "\n";
161 } else { // not export
165 <?php
html_header_show();?
>
167 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
168 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.min.css">
170 <title
><?php
xl('CYP Report', 'e') ?
></title
>
172 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-1-9-1/jquery.min.js"></script
>
173 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js"></script
>
175 <script language
="JavaScript">
176 $
(document
).ready(function() {
177 var win
= top
.printLogSetup ? top
: opener
.top
;
178 win
.printLogSetup(document
.getElementById('printbutton'));
180 $
('.datepicker').datetimepicker({
181 <?php
$datetimepicker_timepicker = false; ?
>
182 <?php
$datetimepicker_showseconds = false; ?
>
183 <?php
$datetimepicker_formatInput = false; ?
>
184 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
185 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
192 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
195 <h2
><?php
xl('CYP Report', 'e')?
></h2
>
197 <form method
='post' action
='ippf_cyp_report.php'>
199 <table border
='0' cellpadding
='3'>
204 // Build a drop-down list of facilities.
206 $query = "SELECT id, name FROM facility ORDER BY name";
207 $fres = sqlStatement($query);
208 echo " <select name='form_facility'>\n";
209 echo " <option value=''>-- All Facilities --\n";
210 while ($frow = sqlFetchArray($fres)) {
211 $facid = $frow['id'];
212 echo " <option value='$facid'";
213 if ($facid == $form_facility) {
217 echo ">" . $frow['name'] . "\n";
222  
;<?
xl('From:','e')?
>
223 <input type
='text' class='datepicker' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
226 <input type
='text' class='datepicker' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
229 <input type
='checkbox' name
='form_details' value
='1'<?php
echo ($_POST['form_details']) ?
" checked" : ""; ?
>><?php
xl('Details', 'e') ?
>
231 <input type
='submit' name
='form_refresh' value
="<?php xl('Refresh', 'e') ?>">
233 <input type
='submit' name
='form_csvexport' value
="<?php xl('Export to CSV', 'e') ?>">
235 <input type
='button' value
='<?php echo xla('Print'); ?>' id
='printbutton' />
246 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
248 <tr bgcolor
="#dddddd">
250 <?php
xl('Item', 'e') ?
>
252 <?php
if ($_POST['form_details']) { ?
>
254 <?php
xl('Date', 'e') ?
>
257 <?php
xl('Invoice', 'e') ?
>
260 <td
class="dehead" align
="right">
261 <?php
xl('Qty', 'e') ?
>
263 <td
class="dehead" align
="right">
264 <?php
xl('CYP', 'e') ?
>
266 <td
class="dehead" align
="right">
267 <?php
xl('Result', 'e') ?
>
273 // If generating a report.
275 if ($_POST['form_refresh'] ||
$_POST['form_csvexport']) {
276 $from_date = $form_from_date;
277 $to_date = $form_to_date;
282 $producttotal = 0; // total of results for product
283 $grandtotal = 0; // grand total of results
287 $query = "SELECT b.pid, b.encounter, b.code_type, b.code, b.units, " .
288 "b.code_text, c.cyp_factor, fe.date, fe.facility_id, fe.invoice_refno " .
289 "FROM billing AS b " .
290 "JOIN codes AS c ON c.code_type = '12' AND c.code = b.code AND c.modifier = b.modifier AND c.cyp_factor > 0 " .
291 "JOIN form_encounter AS fe ON fe.pid = b.pid AND fe.encounter = b.encounter " .
292 "WHERE b.code_type = 'MA' AND b.activity = 1 AND " .
293 "fe.date >= '$from_date 00:00:00' AND fe.date <= '$to_date 23:59:59'";
294 // If a facility was specified.
295 if ($form_facility) {
296 $query .= " AND fe.facility_id = '$form_facility'";
299 $query .= " ORDER BY b.code, fe.date, fe.id";
301 $res = sqlStatement($query);
302 while ($row = sqlFetchArray($res)) {
306 $row['code'] . ' ' . $row['code_text'],
307 substr($row['date'], 0, 10),
310 $row['invoice_refno']
315 $query = "SELECT s.sale_date, s.quantity, s.pid, s.encounter, " .
316 "d.name, d.cyp_factor, fe.date, fe.facility_id, fe.invoice_refno " .
317 "FROM drug_sales AS s " .
318 "JOIN drugs AS d ON d.drug_id = s.drug_id AND d.cyp_factor > 0 " .
319 "JOIN form_encounter AS fe ON " .
320 "fe.pid = s.pid AND fe.encounter = s.encounter AND " .
321 "fe.date >= '$from_date 00:00:00' AND fe.date <= '$to_date 23:59:59' " .
323 // If a facility was specified.
324 if ($form_facility) {
325 $query .= " AND fe.facility_id = '$form_facility'";
328 $query .= " ORDER BY d.name, fe.date, fe.id";
330 $res = sqlStatement($query);
331 while ($row = sqlFetchArray($res)) {
336 substr($row['date'], 0, 10),
339 $row['invoice_refno']
343 if ($_POST['form_csvexport']) {
344 if (! $_POST['form_details']) {
345 echo '"' . display_desc($product) . '",';
346 echo '"' . $productqty . '",';
347 echo '"' . formatcyp($productcyp) . '",';
348 echo '"' . formatcyp($producttotal) . '"' . "\n";
353 <tr bgcolor
="#ddddff">
354 <td
class="detail" colspan
="<?php echo $_POST['form_details'] ? 3 : 1; ?>">
356 if ($_POST['form_details']) {
357 echo xl('Total for ');
359 echo display_desc($product) ?
>
361 <td
class="dehead" align
="right">
362 <?php
echo $productqty; ?
>
364 <td
class="dehead" align
="right">
365 <?php
echo formatcyp($productcyp); ?
>
367 <td
class="dehead" align
="right">
368 <?php
echo formatcyp($producttotal); ?
>
372 <tr bgcolor
="#ffdddd">
373 <td
class="detail" colspan
="<?php echo $_POST['form_details'] ? 3 : 1; ?>">
374 <?php
xl('Grand Total', 'e'); ?
>
376 <td
class="dehead" align
="right">
377 <?php
echo $grandqty; ?
>
379 <td
class="dehead" align
="right">
382 <td
class="dehead" align
="right">
383 <?php
echo formatcyp($grandtotal); ?
>
388 } // End not csv export
389 } // end report generation
391 if (! $_POST['form_csvexport']) {
400 } // End not csv export