Issue Type list gui improvements
[openemr.git] / library / lists.inc
blobf3d9aeed4235fbfa3710001bace90b928c43d998
1 <?php
2 /**
3  * Issue list functions and data structure building.
4  *
5  * The data structure is the $ISSUE_TYPES array.
6  * The $ISSUE_TYPES array is built from the issue_types sql table and provides
7  * abstraction of issue types to allow customization.
8  * <pre>Attributes of the $ISSUE_TYPES array are:
9  *  key - The identifier. (Do NOT create element with token 'prescription_erx' since this is reserved by NewCropRx Module that leverages lists_touch table to support MU calculations)
10  *  0   - The plural title.
11  *  1   - The singular title.
12  *  2   - The abbreviated title (one letter abbreviation). 
13  *  3   - Style ('0 - Normal; 1 - Simplified: only title, start date, comments and an Active checkbox;no diagnosis, occurrence, end date, referred-by or sports fields.; 2 - Football Injury; 3 and 4 are IPPF specific)
14  *  4   - Force show this issue category in the patient summary screen even if empty (setting to 1 will force it to show and setting it to 0 will turn this off).
15  *
16  *
17  * Note there is a mechanism to show whether a category is explicitly set to
18  * 'Nothing' via the getListTouch() and setListTouch() functions that store
19  * applicable information in the lists_touch sql table.
20  *
21  *  </pre>
22  *
23  * LICENSE: This program is free software; you can redistribute it and/or
24  * modify it under the terms of the GNU General Public License
25  * as published by the Free Software Foundation; either version 2
26  * of the License, or (at your option) any later version.
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU General Public License for more details.
31  * You should have received a copy of the GNU General Public License
32  * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
33  *
34  * @package OpenEMR
35  * @author  Rod Roark <rod@sunsetsystems.com>
36  * @author  Brady Miller <brady@sparmy.com>
37  * @author  Teny <teny@zhservices.com>
38  * @link    http://www.open-emr.org
39  */
41 $ISSUE_TYPE_CATEGORIES = array(
42   'default' => xl('Default'),             // Normal OpenEMR use
43   'athletic_team' => xl('Athletic Team'), // For Sports Team use
44   'ippf_specific' => xl('IPPF')           // For IPPF use
47 $ISSUE_TYPE_STYLES = array(
48   0 => xl('Standard'),                    // Standard
49   1 => xl('Simplified'),                  // Simplified: only title, start date, comments and an Active checkbox;no diagnosis, occurrence, end date, referred-by or sports fields.
50   2 => xl('Football Injury'),             // Football Injury
51   3 => xl('IPPF Abortion'),               // IPPF specific (abortions issues)
52   4 => xl('IPPF Contraception')           // IPPF specific (contraceptions issues)
55 /**
56  * Will return the current issue type category that is being used.
57  * @return  string  The current issue type category that is being used.
58  */
59 function collect_issue_type_category() {
60   if (!empty($GLOBALS['ippf_specific'])) { // IPPF version
61     return "ippf_specific";
62   }
63   else if (!empty($GLOBALS['athletic_team'])) { // Athletic team version
64     return "athletic_team";
65   }
66   else { // Default version
67     return "default";
68   }
71 // Build the $ISSUE_TYPES array (see script header for description)
72 $res = sqlStatement("SELECT * FROM `issue_types` WHERE active=1 AND `category`=? ORDER BY `ordering` ASC", array( collect_issue_type_category() ));
73 while($row = sqlFetchArray($res)){
74   $ISSUE_TYPES[$row['type']] = array(xl($row['plural']),xl($row['singular']),xl($row['abbreviation']),$row['style'],$row['force_show']);
77 $ISSUE_CLASSIFICATIONS = array(
78   0   => xl('Unknown or N/A'),
79   1   => xl('Trauma'),
80   2   => xl('Overuse')
83 function getListById ($id, $cols = "*")
85         return sqlQuery("select $cols from lists where id='$id' order by date DESC limit 0,1");
88 function getListByType ($pid, $type, $cols = "*", $active = "all", $limit = "all", $offset="0")
90         if($active == "all")
91                 $sql = "select $cols from lists where pid='$pid' and type='$type' order by date DESC";
92         else
93                 $sql = "select $cols from lists where pid='$pid' and type='$type' and activity='$active' order by date DESC";
94         if ($limit != "all")
95                 $sql .= " limit $offset,$limit";
96         
98         $res = sqlStatement($sql);
99         for($iter =0;$row = sqlFetchArray($res);$iter++)
100                 $all[$iter] = $row;
101         return $all;
105 function addList ($pid, $type, $title, $comments, $activity = "1")
107         return sqlInsert("insert into lists (date, pid, type, title, activity, comments, user, groupname) values (NOW(), '$pid', '$type', '$title', '$activity', '$comments', '".$_SESSION['authUser']."', '".$_SESSION['authProvider']."')");
110 function disappearList ($id)
112         sqlStatement("update lists set activity = '0' where id='$id'");
113         return true;
116 function reappearList ($id)
118         sqlStatement("update lists set activity = '1' where id='$id'");
119         return true;
122 function getListTouch ($patient_id,$type)
124         $ret = sqlQuery("SELECT `date` FROM `lists_touch` WHERE pid=? AND type=?", array($patient_id,$type) );
126         if (!empty($ret)) {
127                 return $ret['date'];
128         }
129         else {
130                 return false;
131         }
134 function setListTouch ($patient_id,$type)
136         $ret = sqlQuery("SELECT `date` FROM `lists_touch` WHERE pid=? AND type=?", array($patient_id,$type) );
138         if (!empty($ret)) {
139                 // Already touched, so can exit
140                 return;
141         }
142         else {
143                 sqlStatement("INSERT INTO `lists_touch` ( `pid`,`type`,`date` ) VALUES ( ?, ?, NOW() )", array($patient_id,$type) );
144         }