use improved date selectors
[openemr.git] / interface / forms / newpatient / save.php
blob81101fb8626822e98b557a03e4f60d3f51782a15
1 <?
2 include_once("../../globals.php");
3 include_once("$srcdir/forms.inc");
4 include_once("$srcdir/sql.inc");
5 include_once("$srcdir/encounter.inc");
6 include_once("$srcdir/acl.inc");
8 foreach ($_POST as $k => $var) {
9 if (! is_array($var))
10 $_POST[$k] = mysql_escape_string($var);
11 echo "$var\n";
14 $conn = $GLOBALS['adodb']['db'];
16 // $date = $_POST["year"]."-".$_POST["month"]."-".$_POST["day"];
17 // $onset_date = $_POST["onset_year"]."-".$_POST["onset_month"]."-".$_POST["onset_day"];
19 $date = $_POST['form_date'];
20 $onset_date = $_POST['form_onset_date'];
22 if ($mode == 'new')
24 $encounter = $conn->GenID("sequences");
25 addForm($encounter, "New Patient Encounter",
26 sqlInsert("INSERT INTO form_encounter SET " .
27 "date = '$date', " .
28 "onset_date = '$onset_date', " .
29 "reason = '$reason', " .
30 "facility = '$facility', " .
31 "pid = '$pid', " .
32 "encounter = '$encounter'"),
33 "newpatient", $pid, $userauthorized, $date);
35 else if ($mode == 'update')
37 $id = $_REQUEST['id'];
38 $result = sqlQuery("SELECT encounter FROM form_encounter WHERE id = '$id'");
39 $encounter = $result['encounter'];
40 // See view.php to allow or disallow updates of the encounter date.
41 // $datepart = $_POST["day"] ? "date = '$date', " : "";
42 $datepart = acl_check('encounters', 'date_a') ? "date = '$date', " : "";
43 $id = $_POST["id"];
44 sqlStatement("update form_encounter set " .
45 $datepart .
46 "onset_date = '$onset_date', " .
47 "reason = '$reason', " .
48 "facility = '$facility' " .
49 "where id = '$id'");
52 setencounter($encounter);
54 // Update the list of issues associated with this encounter.
55 sqlStatement("DELETE FROM issue_encounter WHERE " .
56 "pid = '$pid' AND encounter = '$encounter'");
57 if (is_array($_POST['issues'])) {
58 foreach ($_POST['issues'] as $issue) {
59 $query = "INSERT INTO issue_encounter ( " .
60 "pid, list_id, encounter " .
61 ") VALUES ( " .
62 "'$pid', '$issue', '$encounter'" .
63 ")";
64 sqlStatement($query);
68 <html>
69 <body>
70 <script language="Javascript">
71 window.location="<?echo "$rootdir/patient_file/encounter/patient_encounter.php";?>";
72 </script>
74 </body>
75 </html>