7 * @link http://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once("../globals.php");
15 use OpenEMR\Common\Csrf\CsrfUtils
;
17 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
18 CsrfUtils
::csrfNotVerified();
21 // Validation for non-unique external patient identifier.
22 if (!empty($_POST["pubpid"])) {
23 $form_pubpid = trim($_POST["pubpid"]);
24 $result = sqlQuery("SELECT count(*) AS count FROM patient_data WHERE " .
25 "pubpid = ?", array($form_pubpid));
26 if ($result['count']) {
28 require_once("new.php");
33 require_once("$srcdir/pid.inc.php");
34 require_once("$srcdir/patient.inc.php");
36 //here, we lock the patient data table while we find the most recent max PID
37 //other interfaces can still read the data during this lock, however
38 sqlStatement("lock tables patient_data read");
40 $result = sqlQuery("select max(pid)+1 as pid from patient_data");
42 // TBD: This looks wrong to unlock the table before we have added our
43 // patient with its newly allocated pid!
45 sqlStatement("unlock tables");
49 if ($result['pid'] > 1) {
50 $newpid = $result['pid'];
59 // what do we set for the public pid?
60 if (isset($_POST["pubpid"]) && ($_POST["pubpid"] != "")) {
61 $mypubpid = $_POST["pubpid"];
66 if ($_POST['form_create']) {
67 $form_fname = ucwords(trim($_POST["fname"]));
68 $form_lname = ucwords(trim($_POST["lname"]));
69 $form_mname = ucwords(trim($_POST["mname"]));
71 // ===================
72 // DBC SYSTEM WAS REMOVED
73 $form_sex = trim($_POST["sex"]) ;
74 $form_dob = DateToYYYYMMDD(trim($_POST["DOB"])) ;
78 $form_countrycode = '' ;
79 $form_regdate = DateToYYYYMMDD(trim($_POST['regdate']));
81 // ===================
91 $form_street, // street
92 $form_postcode, // postal_code
95 $form_countrycode, // country_code
102 "", // contact_relationship
109 "", // migrantseasonal
111 "", // monthly_income
113 "", // financial_review
126 0, // $pharmacy_id = 0,
127 "", // $drivers_license = "",
128 "", // $hipaa_notice = "",
129 "", // $hipaa_message = "",
133 newEmployerData($pid);
134 newHistoryData($pid);
135 newInsuranceData($pid, "primary");
136 newInsuranceData($pid, "secondary");
137 newInsuranceData($pid, "tertiary");
139 // Set referral source separately because we don't want it messed
140 // with later by newPatientData().
141 if ($refsource = trim($_POST["refsource"])) {
142 sqlQuery("UPDATE patient_data SET referral_source = ? " .
143 "WHERE pid = ?", array($refsource, $pid));
152 echo "alert(" . js_escape($alertmsg) . ");\n";
155 echo "window.location='$rootdir/patient_file/summary/demographics.php?" .
156 "set_pid=" . attr_url($pid) . "&is_new=1';\n";