dump db version
[openemr.git] / custom / import_xml.php
blob521486ee9b72615d9be74b98d5c8ca432a4c0ce0
1 <?php
2 /**
3 * Imports patient demographics from our custom XML format.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Roberto Vasquez <robertogagliotta@gmail.com>
9 * @copyright Copyright (c) 2005 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2017 Roberto Vasquez <robertogagliotta@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 require_once("../interface/globals.php");
15 require_once("$srcdir/patient.inc");
16 require_once("$srcdir/acl.inc");
18 use OpenEMR\Core\Header;
20 function setInsurance($pid, $ainsurance, $asubscriber, $seq)
22 $iwhich = $seq == '2' ? "secondary" : ($seq == '3' ? "tertiary" : "primary");
23 newInsuranceData(
24 $pid,
25 $iwhich,
26 $ainsurance["provider$seq"],
27 $ainsurance["policy$seq"],
28 $ainsurance["group$seq"],
29 $ainsurance["name$seq"],
30 $asubscriber["lname$seq"],
31 $asubscriber["mname$seq"],
32 $asubscriber["fname$seq"],
33 $asubscriber["relationship$seq"],
34 $asubscriber["ss$seq"],
35 fixDate($asubscriber["dob$seq"]),
36 $asubscriber["street$seq"],
37 $asubscriber["zip$seq"],
38 $asubscriber["city$seq"],
39 $asubscriber["state$seq"],
40 $asubscriber["country$seq"],
41 $asubscriber["phone$seq"],
42 $asubscriber["employer$seq"],
43 $asubscriber["employer_street$seq"],
44 $asubscriber["employer_city$seq"],
45 $asubscriber["employer_zip$seq"],
46 $asubscriber["employer_state$seq"],
47 $asubscriber["employer_country$seq"],
48 $ainsurance["copay$seq"],
49 $asubscriber["sex$seq"]
53 // Check authorization.
54 if (!acl_check('patients', 'demo', '', 'write')) {
55 die("Updating demographics is not authorized.");
58 if ($_POST['form_import']) {
59 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
60 csrfNotVerified();
63 $apatient = array();
64 $apcp = array();
65 $aemployer = array();
66 $ainsurance = array();
67 $asubscriber = array();
69 // $probearr is an array of tag names corresponding to the current
70 // container in the tree structure. $probeix is the current level.
71 $probearr = array('');
72 $probeix = 0;
74 $inspriority = '0'; // 1 = primary, 2 = secondary, 3 = tertiary
76 $parser = xml_parser_create();
77 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
78 $xml = array();
80 if (xml_parse_into_struct($parser, $_POST['form_import_data'], $xml)) {
81 foreach ($xml as $taginfo) {
82 $tag = strtolower($taginfo['tag']);
83 $tagtype = $taginfo['type'];
84 $tagval = addslashes($taginfo['value']);
86 if ($tagtype == 'open') {
87 ++$probeix;
88 $probearr[$probeix] = $tag;
89 continue;
92 if ($tagtype == 'close') {
93 --$probeix;
94 continue;
97 if ($tagtype != 'complete') {
98 die("Invalid tag type '$tagtype'");
101 if ($probeix == 1 && $probearr[$probeix] == 'patient') {
102 $apatient[$tag] = $tagval;
103 } else if ($probeix == 2 && $probearr[$probeix] == 'pcp') {
104 $apcp[$tag] = $tagval;
105 } else if ($probeix == 2 && $probearr[$probeix] == 'employer') {
106 $aemployer[$tag] = $tagval;
107 } else if ($probeix == 2 && $probearr[$probeix] == 'insurance') {
108 if ($tag == 'priority') {
109 $inspriority = $tagval;
110 } else {
111 $ainsurance["$tag$inspriority"] = $tagval;
113 } else if ($probeix == 3 && $probearr[$probeix] == 'subscriber') {
114 $asubscriber["$tag$inspriority"] = $tagval;
115 } else {
116 $alertmsg = "Invalid tag \"" . $probearr[$probeix] . "\" at level $probeix";
119 } else {
120 $alertmsg = "Invalid import data!";
123 xml_parser_free($parser);
125 $olddata = getPatientData($pid);
127 if ($olddata['squad'] && ! acl_check('squads', $olddata['squad'])) {
128 die("You are not authorized to access this squad.");
131 newPatientData(
132 $olddata['id'],
133 $apatient['title'],
134 $apatient['fname'],
135 $apatient['lname'],
136 $apatient['mname'],
137 $apatient['sex'],
138 fixDate($apatient['dob']),
139 $apatient['street'],
140 $apatient['zip'],
141 $apatient['city'],
142 $apatient['state'],
143 $apatient['country'],
144 $apatient['ss'],
145 $apatient['occupation'],
146 $apatient['phone_home'],
147 $apatient['phone_biz'],
148 $apatient['phone_contact'],
149 $apatient['status'],
150 $apatient['contact_relationship'],
151 $apatient['referrer'],
152 $apatient['referrerID'],
153 $apatient['email'],
154 $apatient['language'],
155 $apatient['ethnoracial'],
156 $apatient['interpreter'],
157 $apatient['migrantseasonal'],
158 $apatient['family_size'],
159 $apatient['monthly_income'],
160 $apatient['homeless'],
161 fixDate($apatient['financial_review']),
162 $apatient['pubpid'],
163 $pid,
164 $olddata['providerID'],
165 $apatient['genericname1'],
166 $apatient['genericval1'],
167 $apatient['genericname2'],
168 $apatient['genericval2'],
169 $apatient['billing_note'],
170 $apatient['phone_cell'],
171 $apatient['hipaa_mail'],
172 $apatient['hipaa_voice'],
173 $olddata['squad']
176 newEmployerData(
177 $pid,
178 $aemployer['name'],
179 $aemployer['street'],
180 $aemployer['zip'],
181 $aemployer['city'],
182 $aemployer['state'],
183 $aemployer['country']
186 setInsurance($pid, $ainsurance, $asubscriber, '1');
187 setInsurance($pid, $ainsurance, $asubscriber, '2');
188 setInsurance($pid, $ainsurance, $asubscriber, '3');
190 echo "<html>\n<body>\n<script language='JavaScript'>\n";
191 if ($alertmsg) {
192 echo " alert('" . addslashes($alertmsg) . "');\n";
195 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
196 echo " window.close();\n";
197 echo "</script>\n</body>\n</html>\n";
198 exit();
201 <html>
202 <head>
203 <?php Header::setupHeader(); ?>
204 <title><?php echo xlt('Import Patient Demographics XML'); ?></title>
205 </head>
206 <body class="body_top" onload="javascript:document.forms[0].form_import_data.focus()">
207 <form method='post' action="import_xml.php" onsubmit="return top.restoreSession()">
208 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
209 <div class="container">
210 <div class="row">
211 <div class="col-xs-12">
212 <div class="form-group"></div>
213 <div class="form-group">
214 <textarea name='form_import_data' class='form-control' rows='10'></textarea>
215 </div>
216 <div class="form-group text-right">
217 <div class="btn-group" role="group">
218 <button type='submit' class='btn btn-default btn-save' name='form_import' value='bn_import'>
219 <?php echo xlt('Import'); ?>
220 </button>
221 <button type="button" class="btn btn-link btn-cancel" onclick="window.close()">
222 <?php echo xlt("Cancel"); ?>
223 </button>
224 </div>
225 </div>
226 </div>
227 </div>
228 </div>
229 </form>
230 </body>
231 </html>