4 * This module creates the Barbados Daily Record.
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2009 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("../../library/patient.inc.php");
18 use OpenEMR\Common\Acl\AclMain
;
19 use OpenEMR\Common\Csrf\CsrfUtils
;
20 use OpenEMR\Common\Twig\TwigContainer
;
21 use OpenEMR\Core\Header
;
22 use OpenEMR\Services\FacilityService
;
25 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
26 CsrfUtils
::csrfNotVerified();
30 // Might want something different here.
32 if (! AclMain
::aclCheckCore('acct', 'rep')) {
33 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Clinic Daily Record")]);
37 $facilityService = new FacilityService();
39 $from_date = (isset($_POST['form_from_date'])) ?
DateToYYYYMMDD($_POST['form_from_date']) : date('Y-m-d');
41 $form_facility = isset($_POST['form_facility']) ?
$_POST['form_facility'] : '';
42 $form_output = isset($_POST['form_output']) ?
0 +
$_POST['form_output'] : 1;
44 $report_title = xl('Clinic Daily Record');
45 $report_col_count = 12;
47 // This will become the array of reportable values.
50 // This accumulates the bottom line totals.
55 function genStartRow($att)
57 global $cellcount, $form_output;
58 if ($form_output != 3) {
68 if ($form_output == 3) {
75 // Usually this generates one cell, but allows for two or more.
77 function genAnyCell($data, $right = false, $class = '')
79 global $cellcount, $form_output;
80 if (!is_array($data)) {
81 $data = array(0 => $data);
84 foreach ($data as $datum) {
85 if ($form_output == 3) {
90 echo '"' . $datum . '"';
94 echo " class='" . attr($class) . "'";
98 echo " align='right'";
101 echo ">" . text($datum) . "</td>\n";
108 function genHeadCell($data, $right = false)
110 genAnyCell($data, $right, 'dehead');
113 // Create an HTML table cell containing a numeric value, and track totals.
115 function genNumCell($num, $cnum)
117 global $atotals, $form_output;
118 $atotals[$cnum] +
= $num;
119 if (empty($num) && $form_output != 3) {
123 genAnyCell($num, true, 'detail');
126 // If we are doing the CSV export then generate the needed HTTP headers.
127 // Otherwise generate HTML.
129 if ($form_output == 3) {
130 header("Pragma: public");
131 header("Expires: 0");
132 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
133 header("Content-Type: application/force-download");
134 header("Content-Disposition: attachment; filename=service_statistics_report.csv");
135 header("Content-Description: File Transfer");
136 } else { // not export
140 <title
><?php
echo text($report_title); ?
></title
>
142 <?php Header
::setupHeader('datetime-picker'); ?
>
145 body
{ font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:normal
}
146 .dehead
{ color
:var(--black
); font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:bold
}
147 .detail
{ color
:var(--black
); font
-family
:sans
-serif
; font
-size
:10pt
; font
-weight
:normal
}
152 $
('.datepicker').datetimepicker({
153 <?php
$datetimepicker_timepicker = false; ?
>
154 <?php
$datetimepicker_showseconds = false; ?
>
155 <?php
$datetimepicker_formatInput = true; ?
>
156 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
157 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
163 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
167 <h2
><?php
echo text($report_title); ?
></h2
>
169 <form name
='theform' method
='post' action
='ippf_daily.php?t=<?php echo attr_url($report_type); ?>' onsubmit
='return top.restoreSession()'>
170 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
172 <table border
='0' cellspacing
='5' cellpadding
='1'>
174 <td valign
='top' class='detail' nowrap
>
175 <?php
echo xlt('Facility'); ?
>:
177 <td valign
='top' class='detail'>
179 // Build a drop-down list of facilities.
181 $fres = $facilityService->getAllFacility();
182 echo " <select name='form_facility'>\n";
183 echo " <option value=''>-- All Facilities --\n";
184 foreach ($fres as $frow) {
185 $facid = $frow['id'];
186 echo " <option value='" . attr($facid) . "'";
187 if ($facid == $_POST['form_facility']) {
191 echo ">" . text($frow['name']) . "\n";
197 <td colspan
='2' class='detail' nowrap
>
198 <?php
echo xlt('Date'); ?
>
199 <input type
='text' class='datepicker' name
='form_from_date' id
='form_from_date' size
='10' value
='<?php echo attr(oeFormatShortDate($from_date)); ?>' />
201 <td valign
='top' class='dehead' nowrap
>
202 <?php
echo xlt('To{{Destination}}'); ?
>:
204 <td colspan
='3' valign
='top' class='detail' nowrap
>
206 foreach (array(1 => 'Screen', 2 => 'Printer', 3 => 'Export File') as $key => $value) {
207 echo " <input type='radio' name='form_output' value='" . attr($key) . "'";
208 if ($key == $form_output) {
212 echo " />" . text($value) . " ";
216 <td align
='right' valign
='top' class='detail' nowrap
>
217 <input type
='submit' name
='form_submit' value
='<?php echo xla('Submit
'); ?>'
218 title
='<?php echo xla('Click to generate the report
'); ?>' />
222 <td colspan
='5' height
="1">
229 if ($_POST['form_submit']) {
230 $lores = sqlStatement("SELECT option_id, title FROM list_options WHERE " .
231 "list_id = 'contrameth' AND activity = 1 ORDER BY title");
232 while ($lorow = sqlFetchArray($lores)) {
233 $areport[$lorow['option_id']] = array($lorow['title'],
234 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
237 $areport['zzz'] = array('Unknown', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
239 $sqlBindArray = array();
241 // This gets us all MA codes, with encounter and patient
242 // info attached and grouped by patient and encounter.
244 "fe.pid, fe.encounter, fe.date AS encdate, fe.pc_catid, " .
245 "pd.regdate, b.code_type, b.code " .
246 "FROM form_encounter AS fe " .
247 "JOIN patient_data AS pd ON pd.pid = fe.pid " .
248 "LEFT JOIN billing AS b ON " .
249 "b.pid = fe.pid AND b.encounter = fe.encounter AND b.activity = 1 " .
250 "AND b.code_type = 'MA' " .
251 "WHERE fe.date >= ? AND " .
253 array_push($sqlBindArray, $from_date . ' 00:00:00', $from_date . ' 23:59:59');
255 if ($form_facility) {
256 $query .= "AND fe.facility_id = ? ";
257 array_push($sqlBindArray, $form_facility);
260 $query .= "ORDER BY fe.pid, fe.encounter, b.code";
261 $res = sqlStatement($query, $sqlBindArray);
264 $last_contra_pid = '0';
265 $last_encounter = '0';
268 while ($row = sqlFetchArray($res)) {
269 if ($row['code_type'] === 'MA') {
270 // Logic for individual patients.
272 if ($row['pid'] != $last_pid) { // new patient
273 $last_pid = $row['pid'];
275 $crow = sqlQuery("SELECT lc.new_method " .
276 "FROM lists AS l, lists_ippf_con AS lc WHERE " .
277 "l.pid = ? AND l.begdate <= ? AND " .
278 "( l.enddate IS NULL OR l.enddate > ? ) AND " .
279 "l.activity = 1 AND l.type = 'contraceptive' AND lc.id = l.id " .
280 "ORDER BY l.begdate DESC LIMIT 1", array($last_pid, $from_date, $from_date));
281 $amethods = explode('|', empty($crow) ?
'zzz' : $crow['new_method']);
283 // TBD: We probably want to select the method with highest CYP here,
284 // but for now we'll settle for the first one that appears.
285 $method = $amethods[0];
287 if (empty($areport[$method])) {
288 // This should not happen.
289 $areport[$method] = array("Unlisted method '$method'",
290 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
293 // Count total clients.
294 ++
$areport[$method][3];
296 // Count as new or old client.
297 if ($row['regdate'] == $from_date) {
298 ++
$areport[$method][1];
300 ++
$areport[$method][2];
303 /*************************************************************
304 // Maybe count as old Client First Visit this year.
305 $regyear = substr($row['regdate'], 0, 4);
306 $thisyear = substr($from_date, 0, 4);
307 if ($regyear && $regyear < $thisyear) {
308 $trow = sqlQuery("SELECT count(*) AS count FROM form_encounter " .
309 "WHERE date >= '$thisyear-01-01 00:00:00' AND " .
310 "date < '" . $row['encdate'] . " 00:00:00'");
311 if (empty($trow['count'])) ++$areport[$method][5];
313 *************************************************************/
318 if ($row['encounter'] != $last_encounter) { // new visit
319 $last_encounter = $row['encounter'];
321 // Count unique clients coming for supply or re-supply.
322 if ($row['pc_catid'] == '10' && $last_pid != $last_contra_pid) {
323 $last_contra_pid = $last_pid;
324 ++
$areport[$method][4];
328 // Logic for specific services.
330 $code = 0 +
$row['code'];
331 if ($code == 255004) {
332 ++
$areport[$method][5]; // pap smear
335 if ($code == 256101) {
336 ++
$areport[$method][6]; // preg test
339 if ($code == 375008) {
340 ++
$areport[$method][7]; // dr's check
343 if ($code == 375015) {
344 ++
$areport[$method][8]; // dr's visit (was 375014)
347 if ($code == 375011) {
348 ++
$areport[$method][9]; // advice
351 if ($code == 19916) {
352 ++
$areport[$method][10]; // couns by method
355 if ($code == 39916) {
356 ++
$areport[$method][11]; // infert couns
359 if ($code == 19911) {
360 ++
$areport[$method][12]; // std/aids couns
365 if ($form_output != 3) {
366 echo "<table border='0' cellpadding='1' cellspacing='2' width='98%'>\n";
367 } // end not csv export
369 // Generate headings.
370 genStartRow("bgcolor='#dddddd'");
371 genHeadCell(xl('Method'));
372 genHeadCell(xl('New Clients'), true);
373 genHeadCell(xl('Old Clients'), true);
374 genHeadCell(xl('Total Clients'), true);
375 genHeadCell(xl('Contra Clients'), true);
376 // genHeadCell(xl('O.A.F.V.' ), true);
377 genHeadCell(xl('Pap Smear'), true);
378 genHeadCell(xl('Preg Test'), true);
379 genHeadCell(xl('Dr Check'), true);
380 genHeadCell(xl('Dr Visit'), true);
381 genHeadCell(xl('Advice'), true);
382 genHeadCell(xl('Couns by Method'), true);
383 genHeadCell(xl('Infert Couns'), true);
384 genHeadCell(xl('STD/AIDS Couns'), true);
389 foreach ($areport as $key => $varr) {
390 $bgcolor = (++
$encount & 1) ?
"#ddddff" : "#ffdddd";
391 genStartRow("bgcolor='" . attr($bgcolor) . "'");
392 genAnyCell($varr[0], false, 'detail');
393 // Generate data and accumulate totals for this row.
394 for ($cnum = 0; $cnum < $report_col_count; ++
$cnum) {
395 genNumCell($varr[$cnum +
1], $cnum);
401 if ($form_output != 3) {
402 // Generate the line of totals.
403 genStartRow("bgcolor='#dddddd'");
404 genHeadCell(xl('Totals'));
405 for ($cnum = 0; $cnum < $report_col_count; ++
$cnum) {
406 genHeadCell($atotals[$cnum], true);
415 if ($form_output != 3) {
421 <?php
if ($form_output == 2) { ?
>
422 var win
= top
.printLogPrint ? top
: opener
.top
;
423 win
.printLogPrint(window
);