Highway to PSR2
[openemr.git] / interface / patient_file / link_issue_to_encounter.php
blob7713e3551d2118d29ad9cf9b36fc2401374bd27e
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.
9 // This links a specified or newly created GCAC issue to a specified
10 // encounter. It is invoked from pos_checkout.php via a jquery getScript().
12 require_once("../globals.php");
13 require_once("$srcdir/lists.inc");
14 require_once("$srcdir/acl.inc");
16 $issue = 0 + (empty($_REQUEST['issue']) ? 0 : $_REQUEST['issue']);
17 $thispid = 0 + (empty($_REQUEST['thispid']) ? $pid : $_REQUEST['thispid']);
18 $thisenc = 0 + (empty($_REQUEST['thisenc']) ? 0 : $_REQUEST['thisenc']);
20 if (!acl_check('patients', 'med')) {
21 echo "alert('" . xl('Not authorized') . ".');\n";
22 exit();
25 if (!($thisenc && $thispid)) {
26 echo "alert('" . xl('Internal error: pid or encounter is missing.') . ".');\n";
27 exit();
30 $msg = xl('Internal error!');
32 if ($issue) {
33 $msg = xl('Issue') . " $issue " . xl('has been linked to visit') .
34 " $thispid.$thisenc.";
35 } else {
36 $issue = sqlInsert("INSERT INTO lists ( " .
37 "date, pid, type, title, activity, comments, begdate, user, groupname " .
38 ") VALUES ( " .
39 "NOW(), " .
40 "'$thispid', " .
41 "'ippf_gcac', " .
42 "'" . xl('Auto-generated') . "', " .
43 "1, " .
44 "'', " .
45 "'" . date('Y-m-d') . "', " .
46 "'" . $_SESSION['authUser'] . "', " .
47 "'" . $_SESSION['authProvider'] . "' " .
48 ")");
50 if ($issue) {
51 sqlStatement("INSERT INTO lists_ippf_gcac ( id ) VALUES ( $issue )");
52 $msg = xl('An incomplete GCAC issue has been created and linked. Someone will need to complete it later.');
56 if ($issue) {
57 $query = "INSERT INTO issue_encounter ( " .
58 "pid, list_id, encounter " .
59 ") VALUES ( " .
60 "'$thispid', '$issue', '$thisenc'" .
61 ")";
62 sqlStatement($query);
65 echo "alert('$msg');\n";