forked from LibreHealthIO/lh-ehr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgprelations.inc.php
50 lines (48 loc) · 1.7 KB
/
gprelations.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
// Copyright (C) 2009 Rod Roark <[email protected]>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This module supports use of the gprelations table to maintain
// many-to-many relationships (linkings) among the following other
// tables. For each, a corresponding type code is assigned:
//
// 1 documents
// 2 form_encounter (visits)
// 3 immunizations
// 4 lists (issues)
// 5 libreehr_postcalendar_events (appointments)
// 6 pnotes
// 7 prescriptions
// 8 transactions (e.g. referrals)
//
// By convention we require that type1 must be less than or equal to type2.
//
// As of this writing (2009-11-11), only documents-to-pnotes relations are
// used. However expansion is anticipated, as well as the opportunity to
// obsolete the issue_encounter table.
function isGpRelation($type1, $id1, $type2, $id2) {
$tmp = sqlQuery("SELECT count(*) AS count FROM gprelations WHERE " .
"type1 = ? AND id1 = ? AND " .
"type2 = ? AND id2 = ?", array($type1, $id1, $type2, $id2) );
return !empty($tmp['count']);
}
function setGpRelation($type1, $id1, $type2, $id2, $set=TRUE) {
if (isGpRelation($type1, $id1, $type2, $id2)) {
if (!$set) {
sqlStatement("DELETE FROM gprelations WHERE " .
"type1 = ? AND id1 = ? AND type2 = ? AND id2 = ?", array($type1, $id1, $type2, $id2) );
}
}
else {
if ($set) {
sqlStatement("INSERT INTO gprelations " .
"( type1, id1, type2, id2 ) VALUES " .
"( ?, ?, ?, ? )", array($type1, $id1, $type2, $id2) );
}
}
}
?>