merge in branch for direct messaging integration by EMR Direct
[openemr.git] / library / gprelations.inc.php
blob406e0c0b6bc4c7cccf4bb6867a4f0129439655ea
1 <?php
2 // Copyright (C) 2009 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This module supports use of the gprelations table to maintain
10 // many-to-many relationships (linkings) among the following other
11 // tables. For each, a corresponding type code is assigned:
13 // 1 documents
14 // 2 form_encounter (visits)
15 // 3 immunizations
16 // 4 lists (issues)
17 // 5 openemr_postcalendar_events (appointments)
18 // 6 pnotes
19 // 7 prescriptions
20 // 8 transactions (e.g. referrals)
22 // By convention we require that type1 must be less than or equal to type2.
24 // As of this writing (2009-11-11), only documents-to-pnotes relations are
25 // used. However expansion is anticipated, as well as the opportunity to
26 // obsolete the issue_encounter table.
28 function isGpRelation($type1, $id1, $type2, $id2) {
29 $tmp = sqlQuery("SELECT count(*) AS count FROM gprelations WHERE " .
30 "type1 = ? AND id1 = ? AND " .
31 "type2 = ? AND id2 = ?", array($type1, $id1, $type2, $id2) );
32 return !empty($tmp['count']);
35 function setGpRelation($type1, $id1, $type2, $id2, $set=TRUE) {
36 if (isGpRelation($type1, $id1, $type2, $id2)) {
37 if (!$set) {
38 sqlStatement("DELETE FROM gprelations WHERE " .
39 "type1 = ? AND id1 = ? AND type2 = ? AND id2 = ?", array($type1, $id1, $type2, $id2) );
42 else {
43 if ($set) {
44 sqlStatement("INSERT INTO gprelations " .
45 "( type1, id1, type2, id2 ) VALUES " .
46 "( ?, ?, ?, ? )", array($type1, $id1, $type2, $id2) );