2 ////////////////////////////////////////////////////////////////////
3 // Form: Psychiatrisch Onderzoek - Autosave
4 // Package: Psychiatric Research - Dutch specific form
5 // Created by: Larry Lart
6 // Version: 1.0 - 29-03-2008
7 ////////////////////////////////////////////////////////////////////
10 include_once("../../globals.php");
11 include_once("$srcdir/api.inc");
12 include_once("$srcdir/forms.inc");
16 foreach ($_POST as $k => $var) {
17 $_POST[$k] = add_escape_custom($var);
22 // here we check to se if there was an autosave version prior to the real save
23 $vectAutosave = sqlQuery("SELECT id, autosave_flag, autosave_datetime FROM form_psychiatrisch_onderzoek
24 WHERE pid = ".$_SESSION["pid"].
25 " AND groupname='".$_SESSION["authProvider"].
26 "' AND user='".$_SESSION["authUser"]."' AND
27 authorized=$userauthorized AND activity=1
29 ORDER by id DESC limit 1");
31 // if yes then update this else insert
32 if ($vectAutosave['autosave_flag'] == 1 ||
$_POST["mode"] == "update") {
33 if ($_POST["mode"] == "update") {
34 $newid = $_POST["id"];
36 $newid = $vectAutosave['id'];
39 $strSql = "UPDATE form_psychiatrisch_onderzoek
40 SET pid = ".$_SESSION["pid"].", groupname='".$_SESSION["authProvider"]."', user='".$_SESSION["authUser"]."',
41 authorized=$userauthorized, activity=1, date = NOW(),
42 datum_onderzoek='".$_POST["datum_onderzoek"]."',
43 reden_van_aanmelding='".$_POST["reden_van_aanmelding"]."',
44 conclusie_van_intake='".$_POST["conclusie_van_intake"]."',
45 medicatie='".$_POST["medicatie"]."',
46 anamnese='".$_POST["anamnese"]."',
47 psychiatrisch_onderzoek='".$_POST["psychiatrisch_onderzoek"]."',
48 beschrijvende_conclusie='".$_POST["beschrijvende_conclusie"]."',
49 behandelvoorstel='".$_POST["behandelvoorstel"]."',
51 autosave_datetime=NOW()
52 WHERE id = ".$newid.";";
56 //echo "DEBUG :: id=$newid, sql=$strSql<br>";
58 $newid = formSubmit("form_psychiatrisch_onderzoek", $_POST, $_GET["id"], $userauthorized);
59 addForm($encounter, "Psychiatric Examination", $newid, "psychiatrisch_onderzoek", $pid, $userauthorized);
61 //echo "Debug :: insert<br>";
66 $result = sqlQuery("SELECT autosave_datetime FROM form_psychiatrisch_onderzoek
67 WHERE pid = ".$_SESSION["pid"].
68 " AND groupname='".$_SESSION["authProvider"].
69 "' AND user='".$_SESSION["authUser"]."' AND
70 authorized=$userauthorized AND activity=1 AND id=$newid
72 ORDER by id DESC limit 1");
73 //$timestamp = mysql_result($result, 0);
76 echo xl('Last Saved') . ': '.$result['autosave_datetime'];