CDR Module CMQ PQRI database addition.
[openemr.git] / interface / new / new_comprehensive_save.php
bloba7569a4cd73cfcc7cf9d0166ac97d2513db9d749
1 <?php
2 // Copyright (C) 2009 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("$srcdir/sql.inc");
12 // Validation for non-unique external patient identifier.
13 $alertmsg = '';
14 if (!empty($_POST["form_pubpid"])) {
15 $form_pubpid = trim($_POST["form_pubpid"]);
16 $result = sqlQuery("SELECT count(*) AS count FROM patient_data WHERE " .
17 "pubpid = '$form_pubpid'");
18 if ($result['count']) {
19 // Error, not unique.
20 $alertmsg = xl('Warning: Patient ID is not unique!');
24 require_once("$srcdir/pid.inc");
25 require_once("$srcdir/patient.inc");
26 require_once("$srcdir/options.inc.php");
28 // here, we lock the patient data table while we find the most recent max PID
29 // other interfaces can still read the data during this lock, however
30 // sqlStatement("lock tables patient_data read");
32 $result = sqlQuery("SELECT MAX(pid)+1 AS pid FROM patient_data");
34 $newpid = 1;
36 if ($result['pid'] > 1) $newpid = $result['pid'];
38 setpid($newpid);
40 if (empty($pid)) {
41 // sqlStatement("unlock tables");
42 die("Internal error: setpid($newpid) failed!");
45 // Update patient_data and employer_data:
47 $newdata = array();
48 $newdata['patient_data' ] = array();
49 $newdata['employer_data'] = array();
50 $fres = sqlStatement("SELECT * FROM layout_options " .
51 "WHERE form_id = 'DEM' AND uor > 0 AND field_id != '' " .
52 "ORDER BY group_name, seq");
53 while ($frow = sqlFetchArray($fres)) {
54 $data_type = $frow['data_type'];
55 $field_id = $frow['field_id'];
56 // $value = '';
57 $colname = $field_id;
58 $tblname = 'patient_data';
59 if (strpos($field_id, 'em_') === 0) {
60 $colname = substr($field_id, 3);
61 $tblname = 'employer_data';
64 // if (isset($_POST["form_$field_id"])) $value = $_POST["form_$field_id"];
65 // if (!get_magic_quotes_gpc()) $value = addslashes($value);
66 $value = get_layout_form_value($frow);
68 if ($field_id == 'pubpid' && empty($value)) $value = $pid;
69 $newdata[$tblname][$colname] = $value;
71 updatePatientData($pid, $newdata['patient_data'], true);
72 updateEmployerData($pid, $newdata['employer_data'], true);
74 $i1dob = fixDate(formData("i1subscriber_DOB"));
75 $i1date = fixDate(formData("i1effective_date"));
77 // sqlStatement("unlock tables");
78 // end table lock
80 newHistoryData($pid);
81 newInsuranceData(
82 $pid,
83 "primary",
84 formData("i1provider"),
85 formData("i1policy_number"),
86 formData("i1group_number"),
87 formData("i1plan_name"),
88 formData("i1subscriber_lname"),
89 formData("i1subscriber_mname"),
90 formData("i1subscriber_fname"),
91 formData("form_i1subscriber_relationship"),
92 formData("i1subscriber_ss"),
93 $i1dob,
94 formData("i1subscriber_street"),
95 formData("i1subscriber_postal_code"),
96 formData("i1subscriber_city"),
97 formData("form_i1subscriber_state"),
98 formData("form_i1subscriber_country"),
99 formData("i1subscriber_phone"),
100 formData("i1subscriber_employer"),
101 formData("i1subscriber_employer_street"),
102 formData("i1subscriber_employer_city"),
103 formData("i1subscriber_employer_postal_code"),
104 formData("form_i1subscriber_employer_state"),
105 formData("form_i1subscriber_employer_country"),
106 formData('i1copay'),
107 formData('form_i1subscriber_sex'),
108 $i1date,
109 formData('i1accept_assignment')
113 $i2dob = fixDate(formData("i2subscriber_DOB"));
114 $i2date = fixDate(formData("i2effective_date"));
118 newInsuranceData(
119 $pid,
120 "secondary",
121 formData("i2provider"),
122 formData("i2policy_number"),
123 formData("i2group_number"),
124 formData("i2plan_name"),
125 formData("i2subscriber_lname"),
126 formData("i2subscriber_mname"),
127 formData("i2subscriber_fname"),
128 formData("form_i2subscriber_relationship"),
129 formData("i2subscriber_ss"),
130 $i2dob,
131 formData("i2subscriber_street"),
132 formData("i2subscriber_postal_code"),
133 formData("i2subscriber_city"),
134 formData("form_i2subscriber_state"),
135 formData("form_i2subscriber_country"),
136 formData("i2subscriber_phone"),
137 formData("i2subscriber_employer"),
138 formData("i2subscriber_employer_street"),
139 formData("i2subscriber_employer_city"),
140 formData("i2subscriber_employer_postal_code"),
141 formData("form_i2subscriber_employer_state"),
142 formData("form_i2subscriber_employer_country"),
143 formData('i2copay'),
144 formData('form_i2subscriber_sex'),
145 $i2date,
146 formData('i2accept_assignment')
149 $i3dob = fixDate(formData("i3subscriber_DOB"));
150 $i3date = fixDate(formData("i3effective_date"));
152 newInsuranceData(
153 $pid,
154 "tertiary",
155 formData("i3provider"),
156 formData("i3policy_number"),
157 formData("i3group_number"),
158 formData("i3plan_name"),
159 formData("i3subscriber_lname"),
160 formData("i3subscriber_mname"),
161 formData("i3subscriber_fname"),
162 formData("form_i3subscriber_relationship"),
163 formData("i3subscriber_ss"),
164 $i3dob,
165 formData("i3subscriber_street"),
166 formData("i3subscriber_postal_code"),
167 formData("i3subscriber_city"),
168 formData("form_i3subscriber_state"),
169 formData("form_i3subscriber_country"),
170 formData("i3subscriber_phone"),
171 formData("i3subscriber_employer"),
172 formData("i3subscriber_employer_street"),
173 formData("i3subscriber_employer_city"),
174 formData("i3subscriber_employer_postal_code"),
175 formData("form_i3subscriber_employer_state"),
176 formData("form_i3subscriber_employer_country"),
177 formData('i3copay'),
178 formData('form_i3subscriber_sex'),
179 $i3date,
180 formData('i3accept_assignment')
183 <html>
184 <body>
185 <script language="Javascript">
186 <?php
187 if ($alertmsg) {
188 echo "alert('$alertmsg');\n";
190 if ($GLOBALS['concurrent_layout']) {
191 echo "window.location='$rootdir/patient_file/summary/demographics.php?" .
192 "set_pid=$pid&is_new=1';\n";
193 } else {
194 echo "window.location='$rootdir/patient_file/patient_file.php?set_pid=$pid';\n";
197 </script>
199 </body>
200 </html>