reworked logic for auto-display of the football injury audit form
[openemr.git] / interface / forms / newpatient / save.php
blob680807d41febd238268da7781cd39f6336b41f1c
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)) $_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 $facility = $_POST['facility'];
22 $reason = $_POST['reason'];
23 $mode = $_POST['mode'];
25 $normalurl = "$rootdir/patient_file/encounter/patient_encounter.php";
26 $nexturl = $normalurl;
28 if ($mode == 'new')
30 $encounter = $conn->GenID("sequences");
31 addForm($encounter, "New Patient Encounter",
32 sqlInsert("INSERT INTO form_encounter SET " .
33 "date = '$date', " .
34 "onset_date = '$onset_date', " .
35 "reason = '$reason', " .
36 "facility = '$facility', " .
37 "sensitivity = '$sensitivity', " .
38 "pid = '$pid', " .
39 "encounter = '$encounter'"),
40 "newpatient", $pid, $userauthorized, $date);
42 else if ($mode == 'update')
44 $id = $_POST["id"];
45 $result = sqlQuery("SELECT encounter, sensitivity FROM form_encounter WHERE id = '$id'");
46 if ($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) {
47 die("You are not authorized to see this encounter.");
49 $encounter = $result['encounter'];
50 // See view.php to allow or disallow updates of the encounter date.
51 // $datepart = $_POST["day"] ? "date = '$date', " : "";
52 $datepart = acl_check('encounters', 'date_a') ? "date = '$date', " : "";
53 sqlStatement("UPDATE form_encounter SET " .
54 $datepart .
55 "onset_date = '$onset_date', " .
56 "reason = '$reason', " .
57 "facility = '$facility', " .
58 "sensitivity = '$sensitivity' " .
59 "WHERE id = '$id'");
61 else {
62 die("Unknown mode '$mode'");
65 setencounter($encounter);
67 // Update the list of issues associated with this encounter.
68 sqlStatement("DELETE FROM issue_encounter WHERE " .
69 "pid = '$pid' AND encounter = '$encounter'");
70 if (is_array($_POST['issues'])) {
71 foreach ($_POST['issues'] as $issue) {
72 $query = "INSERT INTO issue_encounter ( " .
73 "pid, list_id, encounter " .
74 ") VALUES ( " .
75 "'$pid', '$issue', '$encounter'" .
76 ")";
77 sqlStatement($query);
81 // Custom for Chelsea FC.
83 if ($mode == 'new' && $GLOBALS['default_new_encounter_form'] == 'football_injury_audit') {
85 // If there are any "football injury" issues (medical problems without
86 // "illness" in the title) linked to this encounter, but no encounter linked
87 // to such an issue has the injury form in it, then present that form.
89 $lres = sqlStatement("SELECT list_id " .
90 "FROM issue_encounter, lists WHERE " .
91 "issue_encounter.pid = '$pid' AND " .
92 "issue_encounter.encounter = '$encounter' AND " .
93 "lists.id = issue_encounter.list_id AND " .
94 "lists.type = 'medical_problem' AND " .
95 "lists.title NOT LIKE '%Illness%'");
97 if (mysql_num_rows($lres)) {
98 $nexturl = "$rootdir/patient_file/encounter/load_form.php?formname=" .
99 $GLOBALS['default_new_encounter_form'];
100 while ($lrow = sqlFetchArray($lres)) {
101 $frow = sqlQuery("SELECT count(*) AS count " .
102 "FROM issue_encounter, forms WHERE " .
103 "issue_encounter.list_id = '" . $lrow['list_id'] . "' AND " .
104 "forms.pid = issue_encounter.pid AND " .
105 "forms.encounter = issue_encounter.encounter AND " .
106 "forms.formdir = '" . $GLOBALS['default_new_encounter_form'] . "'");
107 if ($frow['count']) $nexturl = $normalurl;
112 <html>
113 <body>
114 <script language="Javascript">
115 window.location="<?php echo $nexturl; ?>";
116 </script>
118 </body>
119 </html>