some optimization for IPPF forms
[openemr.git] / interface / new / new_patient_save.php
blob66ae2c4a7cb84fedb0bc4341d95915a90bf5c8d4
1 <?php
2 require_once("../globals.php");
3 require_once("$srcdir/sql.inc");
5 // Validation for non-unique external patient identifier.
6 if (!empty($_POST["pubpid"])) {
7 $form_pubpid = trim($_POST["pubpid"]);
8 $result = sqlQuery("SELECT count(*) AS count FROM patient_data WHERE " .
9 "pubpid = '$form_pubpid'");
10 if ($result['count']) {
11 // Error, not unique.
12 require_once("new.php");
13 exit();
17 require_once("$srcdir/pid.inc");
18 require_once("$srcdir/patient.inc");
20 //here, we lock the patient data table while we find the most recent max PID
21 //other interfaces can still read the data during this lock, however
22 sqlStatement("lock tables patient_data read");
24 $result = sqlQuery("select max(pid)+1 as pid from patient_data");
26 // TBD: This looks wrong to unlock the table before we have added our
27 // patient with its newly allocated pid!
29 sqlStatement("unlock tables");
30 //end table lock
31 $newpid = 1;
33 if ($result['pid'] > 1)
34 $newpid = $result['pid'];
36 setpid($newpid);
38 if($pid == NULL) {
39 $pid = 0;
42 //what do we set for the public pid?
43 if (isset($_POST["pubpid"]) && ($_POST["pubpid"] != "")) {
44 $mypubpid = $_POST["pubpid"];
45 } else {
46 $mypubpid = $pid;
49 if ($_POST['form_create']) {
51 $form_fname = ucwords(trim($_POST["fname"]));
52 $form_lname = ucwords(trim($_POST["lname"]));
53 $form_mname = ucwords(trim($_POST["mname"]));
55 // ===================
56 // DBC SYSTEM
57 $form_dbcprefix = ( $GLOBALS['dutchpc'] ) ? ucwords(trim($_POST["dbc_prefix"])) : '' ;
58 $form_dbcprefixpartner = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_prefix_partner"]) : '' ;
59 $form_dbclastpartner = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_lastname_partner"]) : '' ;
60 $form_sex = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_sex"]) : '' ;
61 // in db the value for sex is a word! so we must translate it
62 switch ( $form_sex ) {
63 case 1 : $form_sex = 'Male'; break;
64 case 2: $form_sex = 'Female'; break;
65 default: $form_sex = 'Male';
67 $form_voorletters = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_voorletters"]) : '' ;
68 $form_dob = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_geboort"]) : '' ;
69 $form_street = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_straat"]) : '' ;
70 $form_number = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_nummer"]) : '' ;
71 $form_addition = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_toevoe"]) : '' ;
72 $form_city = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_plaats"]) : '' ;
73 $form_postcode = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_postal"]) : '' ;
74 $form_countrycode = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_land"]) : '' ;
75 $form_provider = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_insurance"]) : '' ;
76 $form_insdate = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_insdatum"]) : '' ;
77 $form_policy = ( $GLOBALS['dutchpc'] ) ? trim($_POST["dbc_policy"]) : '' ;
78 // EOS DBC
79 // ===================
81 newPatientData(
82 $_POST["db_id"],
83 $_POST["title"],
84 $form_fname,
85 $form_lname,
86 $form_mname,
87 $form_sex, // sex
88 $form_dob, // dob
89 $form_street, // street
90 $form_street, // DBC use ---- $nstreet
91 $form_number, // DBC use ---- $nnr
92 $form_addition, // DBC use ---- $nadd
93 $form_postcode, // postal_code
94 $form_city, // city
95 "", // state
96 $form_countrycode, // country_code
97 "", // ss
98 "", // occupation
99 "", // phone_home
100 "", // phone_biz
101 "", // phone_contact
102 "", // status
103 "", // contact_relationship
104 "", // referrer
105 "", // referrerID
106 "", // email
107 "", // language
108 "", // ethnoracial
109 "", // interpreter
110 "", // migrantseasonal
111 "", // family_size
112 "", // monthly_income
113 "", // homeless
114 "", // financial_review
115 "$mypubpid",
116 $pid,
117 "", // providerID
118 "", // genericname1
119 "", // genericval1
120 "", // genericname2
121 "", // genericval2
122 "", // phone_cell
123 "", // hipaa_mail
124 "", // hipaa_voice
125 0, // squad
126 0, // $pharmacy_id = 0,
127 "", // $drivers_license = "",
128 "", // $hipaa_notice = "",
129 "", // $hipaa_message = "",
130 $_POST['regdate'],
131 // ======== dutch specific
132 $form_dbcprefix, // $prefixlast
133 $form_dbcprefixpartner, // $prefixlastpartner
134 $form_dbclastpartner, // $lastpartner
135 $form_voorletters, // initials
136 "", // $provider_data
137 "" // $referer_data
138 // ======== EOS dutch specific
142 newEmployerData($pid);
143 newHistoryData($pid);
144 newInsuranceData($pid, "primary");
145 newInsuranceData($pid, "secondary");
146 newInsuranceData($pid, "tertiary");
149 // DBC DUTCH INSURANCE DATA
150 if ( $GLOBALS['dutchpc'] ) set_insurer_nl($pid, $form_provider, $form_insdate, $form_policy);
151 // EOS DBC
153 // Set referral source separately because we don't want it messed
154 // with later by newPatientData().
155 if ($refsource = trim($_POST["refsource"])) {
156 sqlQuery("UPDATE patient_data SET referral_source = '$refsource' " .
157 "WHERE pid = '$pid'");
160 // DBC Dutch System
161 if ( $GLOBALS['dutchpc'] ) {
162 generate_id1250($pid); // generate an ID1250 number
167 <html>
168 <body>
169 <script language="Javascript">
171 if ($alertmsg) {
172 echo "alert('$alertmsg');\n";
174 if ($GLOBALS['concurrent_layout']) {
175 echo "window.location='$rootdir/patient_file/summary/demographics.php?" .
176 "set_pid=$pid&is_new=1';\n";
177 } else {
178 echo "window.location='$rootdir/patient_file/patient_file.php?set_pid=$pid';\n";
181 </script>
183 </body>
184 </html>