added date to oldEvt call
[openemr.git] / interface / forms / newpatient / save.php
blob5bbcf4b3ab8db6da1901c33722d3eef0fc3059a5
1 <?php
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)) $_POST[$k] = mysql_escape_string($var);
10 echo "$var\n";
13 $conn = $GLOBALS['adodb']['db'];
15 // $date = $_POST["year"]."-".$_POST["month"]."-".$_POST["day"];
16 // $onset_date = $_POST["onset_year"]."-".$_POST["onset_month"]."-".$_POST["onset_day"];
18 $date = $_POST['form_date'];
19 $onset_date = $_POST['form_onset_date'];
20 $sensitivity = $_POST['form_sensitivity'];
21 $pc_catid = $_POST['pc_catid'];
22 $facility_id = $_POST['facility_id'];
23 $reason = $_POST['reason'];
24 $mode = $_POST['mode'];
26 if ($GLOBALS['concurrent_layout'])
27 $normalurl = "$rootdir/patient_file/encounter/encounter_top.php";
28 else
29 $normalurl = "$rootdir/patient_file/encounter/patient_encounter.php";
31 $nexturl = $normalurl;
33 if ($mode == 'new')
35 $encounter = $conn->GenID("sequences");
36 addForm($encounter, "New Patient Encounter",
37 sqlInsert("INSERT INTO form_encounter SET " .
38 "date = '$date', " .
39 "onset_date = '$onset_date', " .
40 "reason = '$reason', " .
41 "pc_catid = '$pc_catid', " .
42 "facility_id = '$facility_id', " .
43 "sensitivity = '$sensitivity', " .
44 "pid = '$pid', " .
45 "encounter = '$encounter'"),
46 "newpatient", $pid, $userauthorized, $date);
48 else if ($mode == 'update')
50 $id = $_POST["id"];
51 $result = sqlQuery("SELECT encounter, sensitivity FROM form_encounter WHERE id = '$id'");
52 if ($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) {
53 die("You are not authorized to see this encounter.");
55 $encounter = $result['encounter'];
56 // See view.php to allow or disallow updates of the encounter date.
57 // $datepart = $_POST["day"] ? "date = '$date', " : "";
58 $datepart = acl_check('encounters', 'date_a') ? "date = '$date', " : "";
59 sqlStatement("UPDATE form_encounter SET " .
60 $datepart .
61 "onset_date = '$onset_date', " .
62 "reason = '$reason', " .
63 "pc_catid = '$pc_catid', " .
64 "facility_id = '$facility_id', " .
65 "sensitivity = '$sensitivity' " .
66 "WHERE id = '$id'");
68 else {
69 die("Unknown mode '$mode'");
72 setencounter($encounter);
74 // Update the list of issues associated with this encounter.
75 sqlStatement("DELETE FROM issue_encounter WHERE " .
76 "pid = '$pid' AND encounter = '$encounter'");
77 if (is_array($_POST['issues'])) {
78 foreach ($_POST['issues'] as $issue) {
79 $query = "INSERT INTO issue_encounter ( " .
80 "pid, list_id, encounter " .
81 ") VALUES ( " .
82 "'$pid', '$issue', '$encounter'" .
83 ")";
84 sqlStatement($query);
88 // Custom for Chelsea FC.
90 if ($mode == 'new' && $GLOBALS['default_new_encounter_form'] == 'football_injury_audit') {
92 // If there are any "football injury" issues (medical problems without
93 // "illness" in the title) linked to this encounter, but no encounter linked
94 // to such an issue has the injury form in it, then present that form.
96 $lres = sqlStatement("SELECT list_id " .
97 "FROM issue_encounter, lists WHERE " .
98 "issue_encounter.pid = '$pid' AND " .
99 "issue_encounter.encounter = '$encounter' AND " .
100 "lists.id = issue_encounter.list_id AND " .
101 "lists.type = 'medical_problem' AND " .
102 "lists.title NOT LIKE '%Illness%'");
104 if (mysql_num_rows($lres)) {
105 $nexturl = "$rootdir/patient_file/encounter/load_form.php?formname=" .
106 $GLOBALS['default_new_encounter_form'];
107 while ($lrow = sqlFetchArray($lres)) {
108 $frow = sqlQuery("SELECT count(*) AS count " .
109 "FROM issue_encounter, forms WHERE " .
110 "issue_encounter.list_id = '" . $lrow['list_id'] . "' AND " .
111 "forms.pid = issue_encounter.pid AND " .
112 "forms.encounter = issue_encounter.encounter AND " .
113 "forms.formdir = '" . $GLOBALS['default_new_encounter_form'] . "'");
114 if ($frow['count']) $nexturl = $normalurl;
119 <html>
120 <body>
121 <script language="Javascript">
122 <?php if ($GLOBALS['concurrent_layout'] && $mode == 'new') { ?>
123 parent.left_nav.setEncounter(<?php echo "'$date', $encounter, window.name"; ?>);
124 parent.left_nav.setRadio(window.name, 'enc');
125 <?php } ?>
126 top.restoreSession();
127 window.location="<?php echo $nexturl; ?>";
128 </script>
130 </body>
131 </html>