more organization of autoloaded files (#424)
[openemr.git] / interface / new / new_patient_save.php
blobd88d98cd307ec10b3dd6aa7566c39f0ae44dd08a
1 <?php
2 require_once("../globals.php");
4 // Validation for non-unique external patient identifier.
5 if (!empty($_POST["pubpid"])) {
6 $form_pubpid = trim($_POST["pubpid"]);
7 $result = sqlQuery("SELECT count(*) AS count FROM patient_data WHERE " .
8 "pubpid = '$form_pubpid'");
9 if ($result['count']) {
10 // Error, not unique.
11 require_once("new.php");
12 exit();
16 require_once("$srcdir/pid.inc");
17 require_once("$srcdir/patient.inc");
19 //here, we lock the patient data table while we find the most recent max PID
20 //other interfaces can still read the data during this lock, however
21 sqlStatement("lock tables patient_data read");
23 $result = sqlQuery("select max(pid)+1 as pid from patient_data");
25 // TBD: This looks wrong to unlock the table before we have added our
26 // patient with its newly allocated pid!
28 sqlStatement("unlock tables");
29 //end table lock
30 $newpid = 1;
32 if ($result['pid'] > 1)
33 $newpid = $result['pid'];
35 setpid($newpid);
37 if($pid == NULL) {
38 $pid = 0;
41 // what do we set for the public pid?
42 if (isset($_POST["pubpid"]) && ($_POST["pubpid"] != "")) {
43 $mypubpid = $_POST["pubpid"];
44 } else {
45 $mypubpid = $pid;
48 if ($_POST['form_create']) {
50 $form_fname = ucwords(trim($_POST["fname"]));
51 $form_lname = ucwords(trim($_POST["lname"]));
52 $form_mname = ucwords(trim($_POST["mname"]));
54 // ===================
55 // DBC SYSTEM WAS REMOVED
56 $form_sex = trim($_POST["sex"]) ;
57 $form_dob = trim($_POST["DOB"]) ;
58 $form_street = '' ;
59 $form_city = '' ;
60 $form_postcode = '' ;
61 $form_countrycode = '' ;
62 // EOS DBC
63 // ===================
65 newPatientData(
66 $_POST["db_id"],
67 $_POST["title"],
68 $form_fname,
69 $form_lname,
70 $form_mname,
71 $form_sex, // sex
72 $form_dob, // dob
73 $form_street, // street
74 $form_postcode, // postal_code
75 $form_city, // city
76 "", // state
77 $form_countrycode, // country_code
78 "", // ss
79 "", // occupation
80 "", // phone_home
81 "", // phone_biz
82 "", // phone_contact
83 "", // status
84 "", // contact_relationship
85 "", // referrer
86 "", // referrerID
87 "", // email
88 "", // language
89 "", // ethnoracial
90 "", // interpreter
91 "", // migrantseasonal
92 "", // family_size
93 "", // monthly_income
94 "", // homeless
95 "", // financial_review
96 "$mypubpid",
97 $pid,
98 "", // providerID
99 "", // genericname1
100 "", // genericval1
101 "", // genericname2
102 "", // genericval2
103 "", //billing_note
104 "", // phone_cell
105 "", // hipaa_mail
106 "", // hipaa_voice
107 0, // squad
108 0, // $pharmacy_id = 0,
109 "", // $drivers_license = "",
110 "", // $hipaa_notice = "",
111 "", // $hipaa_message = "",
112 $_POST['regdate']
115 newEmployerData($pid);
116 newHistoryData($pid);
117 newInsuranceData($pid, "primary");
118 newInsuranceData($pid, "secondary");
119 newInsuranceData($pid, "tertiary");
121 // Set referral source separately because we don't want it messed
122 // with later by newPatientData().
123 if ($refsource = trim($_POST["refsource"])) {
124 sqlQuery("UPDATE patient_data SET referral_source = '$refsource' " .
125 "WHERE pid = '$pid'");
130 <html>
131 <body>
132 <script language="Javascript">
133 <?php
134 if ($alertmsg) {
135 echo "alert('$alertmsg');\n";
137 echo "window.location='$rootdir/patient_file/summary/demographics.php?" .
138 "set_pid=$pid&is_new=1';\n";
140 </script>
142 </body>
143 </html>