Improved Code Sniffing (#928)
[openemr.git] / custom / import_xml.php
blob632328bae369ed5eabe5ac7b3b0ae9adf16fdc74
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 include_once("../interface/globals.php");
15 include_once("$srcdir/patient.inc");
16 include_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.");
57 if ($_POST['form_import']) {
58 $apatient = array();
59 $apcp = array();
60 $aemployer = array();
61 $ainsurance = array();
62 $asubscriber = array();
64 // $probearr is an array of tag names corresponding to the current
65 // container in the tree structure. $probeix is the current level.
66 $probearr = array('');
67 $probeix = 0;
69 $inspriority = '0'; // 1 = primary, 2 = secondary, 3 = tertiary
71 $parser = xml_parser_create();
72 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
73 $xml = array();
75 if (xml_parse_into_struct($parser, $_POST['form_import_data'], $xml)) {
77 foreach ($xml as $taginfo) {
78 $tag = strtolower($taginfo['tag']);
79 $tagtype = $taginfo['type'];
80 $tagval = addslashes($taginfo['value']);
82 if ($tagtype == 'open') {
83 ++$probeix;
84 $probearr[$probeix] = $tag;
85 continue;
87 if ($tagtype == 'close') {
88 --$probeix;
89 continue;
91 if ($tagtype != 'complete') {
92 die("Invalid tag type '$tagtype'");
95 if ($probeix == 1 && $probearr[$probeix] == 'patient') {
96 $apatient[$tag] = $tagval;
98 else if ($probeix == 2 && $probearr[$probeix] == 'pcp') {
99 $apcp[$tag] = $tagval;
101 else if ($probeix == 2 && $probearr[$probeix] == 'employer') {
102 $aemployer[$tag] = $tagval;
104 else if ($probeix == 2 && $probearr[$probeix] == 'insurance') {
105 if ($tag == 'priority') {
106 $inspriority = $tagval;
107 } else {
108 $ainsurance["$tag$inspriority"] = $tagval;
111 else if ($probeix == 3 && $probearr[$probeix] == 'subscriber') {
112 $asubscriber["$tag$inspriority"] = $tagval;
114 else {
115 $alertmsg = "Invalid tag \"" . $probearr[$probeix] . "\" at level $probeix";
118 } else {
119 $alertmsg = "Invalid import data!";
121 xml_parser_free($parser);
123 $olddata = getPatientData($pid);
125 if ($olddata['squad'] && ! acl_check('squads', $olddata['squad']))
126 die("You are not authorized to access this squad.");
128 newPatientData(
129 $olddata['id'],
130 $apatient['title'],
131 $apatient['fname'],
132 $apatient['lname'],
133 $apatient['mname'],
134 $apatient['sex'],
135 $apatient['dob'],
136 $apatient['street'],
137 $apatient['zip'],
138 $apatient['city'],
139 $apatient['state'],
140 $apatient['country'],
141 $apatient['ss'],
142 $apatient['occupation'],
143 $apatient['phone_home'],
144 $apatient['phone_biz'],
145 $apatient['phone_contact'],
146 $apatient['status'],
147 $apatient['contact_relationship'],
148 $apatient['referrer'],
149 $apatient['referrerID'],
150 $apatient['email'],
151 $apatient['language'],
152 $apatient['ethnoracial'],
153 $apatient['interpreter'],
154 $apatient['migrantseasonal'],
155 $apatient['family_size'],
156 $apatient['monthly_income'],
157 $apatient['homeless'],
158 fixDate($apatient['financial_review']),
159 $apatient['pubpid'],
160 $pid,
161 $olddata['providerID'],
162 $apatient['genericname1'],
163 $apatient['genericval1'],
164 $apatient['genericname2'],
165 $apatient['genericval2'],
166 $apatient['billing_note'],
167 $apatient['phone_cell'],
168 $apatient['hipaa_mail'],
169 $apatient['hipaa_voice'],
170 $olddata['squad']
173 newEmployerData(
174 $pid,
175 $aemployer['name'],
176 $aemployer['street'],
177 $aemployer['zip'],
178 $aemployer['city'],
179 $aemployer['state'],
180 $aemployer['country']
183 setInsurance($pid, $ainsurance, $asubscriber, '1');
184 setInsurance($pid, $ainsurance, $asubscriber, '2');
185 setInsurance($pid, $ainsurance, $asubscriber, '3');
187 echo "<html>\n<body>\n<script language='JavaScript'>\n";
188 if ($alertmsg) echo " alert('$alertmsg');\n";
189 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
190 echo " window.close();\n";
191 echo "</script>\n</body>\n</html>\n";
192 exit();
195 <html>
196 <head>
197 <?php Header::setupHeader(); ?>
198 <title><?php echo xlt('Import Patient Demographics XML'); ?></title>
199 </head>
200 <body class="body_top" onload="javascript:document.forms[0].form_import_data.focus()">
201 <form method='post' action="import_xml.php" onsubmit="return top.restoreSession()">
202 <div class="container">
203 <div class="row">
204 <div class="col-xs-12">
205 <div class="form-group"></div>
206 <div class="form-group">
207 <textarea name='form_import_data' class='form-control' rows='10'></textarea>
208 </div>
209 <div class="form-group text-right">
210 <div class="btn-group" role="group">
211 <button type='submit' class='btn btn-default btn-save' name='form_import' value='bn_import'>
212 <?php echo xlt('Import'); ?>
213 </button>
214 <button type="button" class="btn btn-link btn-cancel" onclick="window.close()">
215 <?php echo xlt("Cancel"); ?>
216 </button>
217 </div>
218 </div>
219 </div>
220 </div>
221 </div>
222 </form>
223 </body>
224 </html>