3 * This module creates the Barbados Daily Record.
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 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("../../library/patient.inc");
16 require_once("../../library/acl.inc");
18 use OpenEMR\Services\FacilityService
;
20 // Might want something different here.
22 if (! acl_check('acct', 'rep')) {
23 die("Unauthorized access.");
26 $facilityService = new FacilityService();
28 $from_date = fixDate($_POST['form_from_date']);
29 $form_facility = isset($_POST['form_facility']) ?
$_POST['form_facility'] : '';
30 $form_output = isset($_POST['form_output']) ?
0 +
$_POST['form_output'] : 1;
32 $report_title = xl('Clinic Daily Record');
33 $report_col_count = 12;
35 // This will become the array of reportable values.
38 // This accumulates the bottom line totals.
43 function genStartRow($att)
45 global $cellcount, $form_output;
46 if ($form_output != 3) {
56 if ($form_output == 3) {
63 // Usually this generates one cell, but allows for two or more.
65 function genAnyCell($data, $right = false, $class = '')
67 global $cellcount, $form_output;
68 if (!is_array($data)) {
69 $data = array(0 => $data);
72 foreach ($data as $datum) {
73 if ($form_output == 3) {
78 echo '"' . $datum . '"';
82 echo " class='$class'";
86 echo " align='right'";
89 echo ">$datum</td>\n";
96 function genHeadCell($data, $right = false)
98 genAnyCell($data, $right, 'dehead');
101 // Create an HTML table cell containing a numeric value, and track totals.
103 function genNumCell($num, $cnum)
105 global $atotals, $form_output;
106 $atotals[$cnum] +
= $num;
107 if (empty($num) && $form_output != 3) {
111 genAnyCell($num, true, 'detail');
114 // If we are doing the CSV export then generate the needed HTTP headers.
115 // Otherwise generate HTML.
117 if ($form_output == 3) {
118 header("Pragma: public");
119 header("Expires: 0");
120 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
121 header("Content-Type: application/force-download");
122 header("Content-Disposition: attachment; filename=service_statistics_report.csv");
123 header("Content-Description: File Transfer");
124 } else { // not export
128 <?php
html_header_show(); ?
>
129 <title
><?php
echo $report_title; ?
></title
>
131 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
132 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
134 <style type
="text/css">
135 body
{ font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:normal
}
136 .dehead
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:bold }
137 .detail
{ color
:#000000; font-family:sans-serif; font-size:10pt; font-weight:normal }
140 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
141 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
142 <script type
="text/javascript" src
="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script
>
144 <script language
="JavaScript">
145 $
(document
).ready(function() {
146 $
('.datepicker').datetimepicker({
147 <?php
$datetimepicker_timepicker = false; ?
>
148 <?php
$datetimepicker_showseconds = false; ?
>
149 <?php
$datetimepicker_formatInput = false; ?
>
150 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
151 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
157 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
161 <h2
><?php
echo $report_title; ?
></h2
>
163 <form name
='theform' method
='post'
164 action
='ippf_daily.php?t=<?php echo $report_type ?>'>
166 <table border
='0' cellspacing
='5' cellpadding
='1'>
168 <td valign
='top' class='detail' nowrap
>
169 <?php
xl('Facility', 'e'); ?
>:
171 <td valign
='top' class='detail'>
173 // Build a drop-down list of facilities.
175 $fres = $facilityService->getAll();
176 echo " <select name='form_facility'>\n";
177 echo " <option value=''>-- All Facilities --\n";
178 foreach ($fres as $frow) {
179 $facid = $frow['id'];
180 echo " <option value='$facid'";
181 if ($facid == $_POST['form_facility']) {
185 echo ">" . $frow['name'] . "\n";
191 <td colspan
='2' class='detail' nowrap
>
192 <?php
xl('Date', 'e'); ?
>
193 <input type
='text' class='datepicker' name
='form_from_date' id
='form_from_date' size
='10' value
='<?php echo $from_date ?>'
194 title
='Report date yyyy-mm-dd' />
196 <td valign
='top' class='dehead' nowrap
>
197 <?php
xl('To', 'e'); ?
>:
199 <td colspan
='3' valign
='top' class='detail' nowrap
>
201 foreach (array(1 => 'Screen', 2 => 'Printer', 3 => 'Export File') as $key => $value) {
202 echo " <input type='radio' name='form_output' value='$key'";
203 if ($key == $form_output) {
207 echo " />$value ";
211 <td align
='right' valign
='top' class='detail' nowrap
>
212 <input type
='submit' name
='form_submit' value
='<?php xl('Submit
', 'e
'); ?>'
213 title
='<?php xl('Click to generate the report
', 'e
'); ?>' />
217 <td colspan
='5' height
="1">
224 if ($_POST['form_submit']) {
225 $lores = sqlStatement("SELECT option_id, title FROM list_options WHERE " .
226 "list_id = 'contrameth' AND activity = 1 ORDER BY title");
227 while ($lorow = sqlFetchArray($lores)) {
228 $areport[$lorow['option_id']] = array($lorow['title'],
229 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
232 $areport['zzz'] = array('Unknown', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
234 // This gets us all MA codes, with encounter and patient
235 // info attached and grouped by patient and encounter.
237 "fe.pid, fe.encounter, fe.date AS encdate, fe.pc_catid, " .
238 "pd.regdate, b.code_type, b.code " .
239 "FROM form_encounter AS fe " .
240 "JOIN patient_data AS pd ON pd.pid = fe.pid " .
241 "LEFT JOIN billing AS b ON " .
242 "b.pid = fe.pid AND b.encounter = fe.encounter AND b.activity = 1 " .
243 "AND b.code_type = 'MA' " .
244 "WHERE fe.date >= '$from_date 00:00:00' AND " .
245 "fe.date <= '$from_date 23:59:59' ";
247 if ($form_facility) {
248 $query .= "AND fe.facility_id = '$form_facility' ";
251 $query .= "ORDER BY fe.pid, fe.encounter, b.code";
252 $res = sqlStatement($query);
255 $last_contra_pid = '0';
256 $last_encounter = '0';
259 while ($row = sqlFetchArray($res)) {
260 if ($row['code_type'] === 'MA') {
261 // Logic for individual patients.
263 if ($row['pid'] != $last_pid) { // new patient
264 $last_pid = $row['pid'];
266 $crow = sqlQuery("SELECT lc.new_method " .
267 "FROM lists AS l, lists_ippf_con AS lc WHERE " .
268 "l.pid = '$last_pid' AND l.begdate <= '$from_date' AND " .
269 "( l.enddate IS NULL OR l.enddate > '$from_date' ) AND " .
270 "l.activity = 1 AND l.type = 'contraceptive' AND lc.id = l.id " .
271 "ORDER BY l.begdate DESC LIMIT 1");
272 $amethods = explode('|', empty($crow) ?
'zzz' : $crow['new_method']);
274 // TBD: We probably want to select the method with highest CYP here,
275 // but for now we'll settle for the first one that appears.
276 $method = $amethods[0];
278 if (empty($areport[$method])) {
279 // This should not happen.
280 $areport[$method] = array("Unlisted method '$method'",
281 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
284 // Count total clients.
285 ++
$areport[$method][3];
287 // Count as new or old client.
288 if ($row['regdate'] == $from_date) {
289 ++
$areport[$method][1];
291 ++
$areport[$method][2];
294 /*************************************************************
295 // Maybe count as old Client First Visit this year.
296 $regyear = substr($row['regdate'], 0, 4);
297 $thisyear = substr($from_date, 0, 4);
298 if ($regyear && $regyear < $thisyear) {
299 $trow = sqlQuery("SELECT count(*) AS count FROM form_encounter " .
300 "WHERE date >= '$thisyear-01-01 00:00:00' AND " .
301 "date < '" . $row['encdate'] . " 00:00:00'");
302 if (empty($trow['count'])) ++$areport[$method][5];
304 *************************************************************/
309 if ($row['encounter'] != $last_encounter) { // new visit
310 $last_encounter = $row['encounter'];
312 // Count unique clients coming for supply or re-supply.
313 if ($row['pc_catid'] == '10' && $last_pid != $last_contra_pid) {
314 $last_contra_pid = $last_pid;
315 ++
$areport[$method][4];
319 // Logic for specific services.
321 $code = 0 +
$row['code'];
322 if ($code == 255004) {
323 ++
$areport[$method][5]; // pap smear
326 if ($code == 256101) {
327 ++
$areport[$method][6]; // preg test
330 if ($code == 375008) {
331 ++
$areport[$method][7]; // dr's check
334 if ($code == 375015) {
335 ++
$areport[$method][8]; // dr's visit (was 375014)
338 if ($code == 375011) {
339 ++
$areport[$method][9]; // advice
342 if ($code == 19916) {
343 ++
$areport[$method][10]; // couns by method
346 if ($code == 39916) {
347 ++
$areport[$method][11]; // infert couns
350 if ($code == 19911) {
351 ++
$areport[$method][12]; // std/aids couns
356 if ($form_output != 3) {
357 echo "<table border='0' cellpadding='1' cellspacing='2' width='98%'>\n";
358 } // end not csv export
360 // Generate headings.
361 genStartRow("bgcolor='#dddddd'");
362 genHeadCell(xl('Method'));
363 genHeadCell(xl('New Clients'), true);
364 genHeadCell(xl('Old Clients'), true);
365 genHeadCell(xl('Total Clients'), true);
366 genHeadCell(xl('Contra Clients'), true);
367 // genHeadCell(xl('O.A.F.V.' ), true);
368 genHeadCell(xl('Pap Smear'), true);
369 genHeadCell(xl('Preg Test'), true);
370 genHeadCell(xl('Dr Check'), true);
371 genHeadCell(xl('Dr Visit'), true);
372 genHeadCell(xl('Advice'), true);
373 genHeadCell(xl('Couns by Method'), true);
374 genHeadCell(xl('Infert Couns'), true);
375 genHeadCell(xl('STD/AIDS Couns'), true);
380 foreach ($areport as $key => $varr) {
381 $bgcolor = (++
$encount & 1) ?
"#ddddff" : "#ffdddd";
382 genStartRow("bgcolor='$bgcolor'");
383 genAnyCell($varr[0], false, 'detail');
384 // Generate data and accumulate totals for this row.
385 for ($cnum = 0; $cnum < $report_col_count; ++
$cnum) {
386 genNumCell($varr[$cnum +
1], $cnum);
392 if ($form_output != 3) {
393 // Generate the line of totals.
394 genStartRow("bgcolor='#dddddd'");
395 genHeadCell(xl('Totals'));
396 for ($cnum = 0; $cnum < $report_col_count; ++
$cnum) {
397 genHeadCell($atotals[$cnum], true);
406 if ($form_output != 3) {
411 <script language
='JavaScript'>
412 <?php
if ($form_output == 2) { ?
>
413 var win
= top
.printLogPrint ? top
: opener
.top
;
414 win
.printLogPrint(window
);