preparing for 5.0.1 release in several weeks (#1509)
[openemr.git] / interface / forms / eye_mag / new.php
blob52caac0819f5744dce5e2043f439dc955f29ad9b
1 <?php
2 /**
3 * forms/eye_mag/new.php
5 * The page shown when the user requests a new form
7 * Copyright (C) 2016 Raymond Magauran <magauran@MedFetch.com>
9 * LICENSE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * @package OpenEMR
23 * @author Ray Magauran <magauran@MedFetch.com>
24 * @link http://www.open-emr.org
30 include_once("../../globals.php");
31 include_once("$srcdir/api.inc");
33 $form_name = "Eye Exam";
34 $table_name = "form_eye_mag";
35 $form_folder = "eye_mag";
36 include_once("../../forms/".$form_folder."/php/".$form_folder."_functions.php");
37 formHeader("Form: ".$form_name);
38 $returnurl = 'encounter_top.php';
40 $pid = $_REQUEST['pid'];
42 if (!$pid) {
43 $pid = $_SESSION['pid'];
44 } else {
45 $_SESSION['pid'] = $pid;
48 if (!$user) {
49 $user = $_SESSION['authUser'];
52 if (!$group) {
53 $group = $_SESSION['authProvider'];
56 if (!$_SESSION['encounter']) {
57 $encounter = date("Ymd");
58 } else {
59 $encounter=$_SESSION['encounter'];
62 $query = "select * from form_encounter where pid =? and encounter= ?";
63 $encounter_data = sqlQuery($query, array($pid,$encounter));
64 $encounter_date = $encounter_data['date'];
66 $query = "SELECT * " .
67 "FROM form_encounter AS fe, forms AS f WHERE " .
68 "fe.pid = ? AND fe.date = ? AND " .
69 "f.formdir = ? AND f.encounter = fe.encounter AND f.deleted = 0";
70 $erow = sqlQuery($query, array($pid,$encounter_date,$form_folder));
72 if ($erow['form_id'] > '0') {
73 formHeader("Redirecting....");
74 formJump('./view_form.php?formname='.$form_folder.'&id='.attr($erow['form_id']).'&pid='.attr($pid));
75 formFooter();
76 exit;
77 } else {
78 $id = $erow2['count']++;
79 $providerid = findProvider(attr($pid), $encounter);
80 $newid = formSubmit($table_name, $_POST, $id, $providerid);
81 $sql = "insert into forms (date, encounter, form_name, form_id, pid, " .
82 "user, groupname, authorized, formdir) values (NOW(),?,?,?,?,?,?,?,?)";//activity=1, date = NOW()
83 $answer = sqlInsert($sql, array($encounter,$form_name,$newid,$pid,$user,$group,$providerid,$form_folder));
86 formHeader("Redirecting....");
87 formJump('./view_form.php?formname='.$form_folder.'&id='.attr($newid).'&pid='.attr($pid));
88 formFooter();
89 exit;