some portal work
[openemr.git] / library / gprelations.inc.php
blobfbf822c550b5510407b293df04335cf89eb79f55
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)
30 $tmp = sqlQuery("SELECT count(*) AS count FROM gprelations WHERE " .
31 "type1 = ? AND id1 = ? AND " .
32 "type2 = ? AND id2 = ?", array($type1, $id1, $type2, $id2));
33 return !empty($tmp['count']);
36 function setGpRelation($type1, $id1, $type2, $id2, $set = true)
38 if (isGpRelation($type1, $id1, $type2, $id2)) {
39 if (!$set) {
40 sqlStatement("DELETE FROM gprelations WHERE " .
41 "type1 = ? AND id1 = ? AND type2 = ? AND id2 = ?", array($type1, $id1, $type2, $id2));
43 } else {
44 if ($set) {
45 sqlStatement("INSERT INTO gprelations " .
46 "( type1, id1, type2, id2 ) VALUES " .
47 "( ?, ?, ?, ? )", array($type1, $id1, $type2, $id2));