migrate old clinical notes form to clinic note (#4516)
[openemr.git] / contrib / forms / clinic_note / new.php
blob895a9f691443a449873580159e99208d102a661f
1 <?php
3 /**
4 * clinic_note new.php
6 * @package OpenEMR
7 * @link https://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @author Daniel Ehrlich <daniel.ehrlich1@gmail.com>
11 * @copyright Copyright (c) 2005 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2018-2021 Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2018 Daniel Ehrlich <daniel.ehrlich1@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../../globals.php");
18 require_once("$srcdir/api.inc");
19 require_once("$srcdir/forms.inc");
21 use OpenEMR\Common\Csrf\CsrfUtils;
22 use OpenEMR\Core\Header;
24 $row = array();
26 if (! $encounter) { // comes from globals.php
27 die("Internal error: we do not seem to be in an encounter!");
30 function rbvalue($rbname)
32 $tmp = $_POST[$rbname] ?? null;
33 if (! $tmp) {
34 $tmp = '0';
37 return "$tmp";
40 function cbvalue($cbname)
42 return $_POST[$cbname] ? '1' : '0';
45 function rbinput($name, $value, $desc, $colname)
47 global $row;
48 $ret = "<input type='radio' name='" . attr($name) . "' value='" . attr($value) . "'";
49 if (!empty($row) && ($row[$colname] == $value)) {
50 $ret .= " checked";
53 $ret .= " />" . text($desc);
54 return $ret;
57 function rbcell($name, $value, $desc, $colname)
59 return "<td width='25%' nowrap>" . rbinput($name, $value, $desc, $colname) . "</td>\n";
62 function cbinput($name, $colname)
64 global $row;
65 $ret = "<input type='checkbox' name='" . attr($name) . "' value='1'";
66 if ($row[$colname]) {
67 $ret .= " checked";
70 $ret .= " />";
71 return $ret;
74 function cbcell($name, $desc, $colname)
76 return "<td width='25%' nowrap>" . cbinput($name, $colname) . text($desc) . "</td>\n";
79 $formid = $_GET['id'] ?? null;
81 // If Save was clicked, save the info.
83 if (!empty($_POST['bn_save'])) {
84 $fu_timing = $_POST['fu_timing'];
85 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
86 CsrfUtils::csrfNotVerified();
89 // If updating an existing form...
91 if ($formid) {
92 $query = "UPDATE form_clinic_note SET
93 history = ?,
94 examination = ?,
95 plan = ?,
96 followup_required = ?,
97 followup_timing = ?
98 WHERE id = ?";
100 sqlStatement($query, array($_POST['form_history'], $_POST['form_examination'], $_POST['form_plan'], rbvalue('fu_required'), $fu_timing, $formid));
101 } else { // If adding a new form...
102 $query = "INSERT INTO form_clinic_note ( " .
103 "history, examination, plan, followup_required, followup_timing
104 ) VALUES ( ?, ?, ?, ?, ? )";
106 $newid = sqlInsert($query, array($_POST['form_history'], $_POST['form_examination'], $_POST['form_plan'], rbvalue('fu_required'), $fu_timing));
107 addForm($encounter, "Clinic Note", $newid, "clinic_note", $pid, $userauthorized);
110 formHeader("Redirecting....");
111 formJump();
112 formFooter();
113 exit;
116 if ($formid) {
117 $row = sqlQuery("SELECT * FROM form_clinic_note WHERE " .
118 "id = ? AND activity = '1'", array($formid));
121 <html>
122 <head>
123 <?php Header::setupHeader(); ?>
125 </head>
127 <body <?php echo $top_bg_line;?> topmargin="0" rightmargin="0" leftmargin="2"
128 bottommargin="0" marginwidth="2" marginheight="0">
129 <form method="post" action="<?php echo $rootdir ?>/forms/clinic_note/new.php?id=<?php echo attr_url($formid) ?>"
130 onsubmit="return top.restoreSession()">
131 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
133 <center>
136 <table border='1' width='95%'>
138 <tr bgcolor='#dddddd'>
139 <td colspan='2' align='center'><b><?php echo xlt("This Encounter"); ?></b></td>
140 </tr>
142 <tr>
143 <td width='5%' nowrap> <?php echo xlt("History"); ?> </td>
144 <td width='95%' nowrap>
145 <textarea name='form_history' rows='7' style='width:100%'><?php echo text($row['history'] ?? '') ?></textarea>
146 </td>
147 </tr>
149 <tr>
150 <td nowrap> <?php echo xlt("Examination"); ?> </td>
151 <td nowrap>
152 <textarea name='form_examination' rows='7' style='width:100%'><?php echo text($row['examination'] ?? '') ?></textarea>
153 </td>
154 </tr>
156 <tr>
157 <td nowrap> <?php echo xlt("Plan"); ?> </td>
158 <td nowrap>
159 <textarea name='form_plan' rows='7' style='width:100%'><?php echo text($row['plan'] ?? '') ?></textarea>
160 </td>
161 </tr>
163 <tr>
164 <td nowrap><?php echo xlt("Follow Up"); ?></td>
165 <td nowrap>
166 <table width='100%'>
167 <tr>
168 <td width='5%' nowrap>
169 <?php echo rbinput('fu_required', '1', xl('Required in') . ':', 'followup_required') ?>
170 </td>
171 <td nowrap>
172 <input type='text' name='fu_timing' size='10' style='width:100%'
173 title='<?php echo xla("When to follow up"); ?>'
174 value='<?php echo attr($row['followup_timing'] ?? '') ?>' />
175 </td>
176 </tr>
177 <tr>
178 <td colspan='2' nowrap>
179 <?php echo rbinput('fu_required', '2', xl('Pending investigation'), 'followup_required') ?>
180 </td>
181 </tr>
182 <tr>
183 <td colspan='2' nowrap>
184 <?php echo rbinput('fu_required', '0', xl('None required'), 'followup_required') ?>
185 </td>
186 </tr>
187 </table>
188 </td>
189 </tr>
191 </table>
194 <input type='submit' name='bn_save' value='<?php echo xla("Save"); ?>' />
195 &nbsp;
196 <input type='button' value='<?php echo xla("Cancel"); ?>' onclick="parent.closeTab(window.name, false)" />
197 </p>
199 </center>
201 </form>
202 </body>
203 </html>