Merge branch 'master' into AE/groupFixes
[openemr.git] / custom / import_xml.php
blob5940bb6b45eefcff40a032345aa7412ec2962b36
1 <?php
2 // Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 /////////////////////////////////////////////////////////////////////
10 // This imports patient demographics from our custom XML format.
11 /////////////////////////////////////////////////////////////////////
13 include_once("../interface/globals.php");
14 include_once("$srcdir/patient.inc");
15 include_once("$srcdir/acl.inc");
17 function setInsurance($pid, $ainsurance, $asubscriber, $seq) {
18 $iwhich = $seq == '2' ? "secondary" : ($seq == '3' ? "tertiary" : "primary");
19 newInsuranceData(
20 $pid,
21 $iwhich,
22 $ainsurance["provider$seq"],
23 $ainsurance["policy$seq"],
24 $ainsurance["group$seq"],
25 $ainsurance["name$seq"],
26 $asubscriber["lname$seq"],
27 $asubscriber["mname$seq"],
28 $asubscriber["fname$seq"],
29 $asubscriber["relationship$seq"],
30 $asubscriber["ss$seq"],
31 fixDate($asubscriber["dob$seq"]),
32 $asubscriber["street$seq"],
33 $asubscriber["zip$seq"],
34 $asubscriber["city$seq"],
35 $asubscriber["state$seq"],
36 $asubscriber["country$seq"],
37 $asubscriber["phone$seq"],
38 $asubscriber["employer$seq"],
39 $asubscriber["employer_street$seq"],
40 $asubscriber["employer_city$seq"],
41 $asubscriber["employer_zip$seq"],
42 $asubscriber["employer_state$seq"],
43 $asubscriber["employer_country$seq"],
44 $ainsurance["copay$seq"],
45 $asubscriber["sex$seq"]
49 // Check authorization.
50 if (!acl_check('patients', 'demo','','write'))
51 die("Updating demographics is not authorized.");
53 if ($_POST['form_import']) {
54 $apatient = array();
55 $apcp = array();
56 $aemployer = array();
57 $ainsurance = array();
58 $asubscriber = array();
60 // $probearr is an array of tag names corresponding to the current
61 // container in the tree structure. $probeix is the current level.
62 $probearr = array('');
63 $probeix = 0;
65 $inspriority = '0'; // 1 = primary, 2 = secondary, 3 = tertiary
67 $parser = xml_parser_create();
68 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
69 $xml = array();
71 if (xml_parse_into_struct($parser, $_POST['form_import_data'], $xml)) {
73 foreach ($xml as $taginfo) {
74 $tag = strtolower($taginfo['tag']);
75 $tagtype = $taginfo['type'];
76 $tagval = addslashes($taginfo['value']);
78 if ($tagtype == 'open') {
79 ++$probeix;
80 $probearr[$probeix] = $tag;
81 continue;
83 if ($tagtype == 'close') {
84 --$probeix;
85 continue;
87 if ($tagtype != 'complete') {
88 die("Invalid tag type '$tagtype'");
91 if ($probeix == 1 && $probearr[$probeix] == 'patient') {
92 $apatient[$tag] = $tagval;
94 else if ($probeix == 2 && $probearr[$probeix] == 'pcp') {
95 $apcp[$tag] = $tagval;
97 else if ($probeix == 2 && $probearr[$probeix] == 'employer') {
98 $aemployer[$tag] = $tagval;
100 else if ($probeix == 2 && $probearr[$probeix] == 'insurance') {
101 if ($tag == 'priority') {
102 $inspriority = $tagval;
103 } else {
104 $ainsurance["$tag$inspriority"] = $tagval;
107 else if ($probeix == 3 && $probearr[$probeix] == 'subscriber') {
108 $asubscriber["$tag$inspriority"] = $tagval;
110 else {
111 $alertmsg = "Invalid tag \"" . $probearr[$probeix] . "\" at level $probeix";
114 } else {
115 $alertmsg = "Invalid import data!";
117 xml_parser_free($parser);
119 $olddata = getPatientData($pid);
121 if ($olddata['squad'] && ! acl_check('squads', $olddata['squad']))
122 die("You are not authorized to access this squad.");
124 newPatientData(
125 $olddata['id'],
126 $apatient['title'],
127 $apatient['fname'],
128 $apatient['lname'],
129 $apatient['mname'],
130 $apatient['sex'],
131 $apatient['dob'],
132 $apatient['street'],
133 $apatient['zip'],
134 $apatient['city'],
135 $apatient['state'],
136 $apatient['country'],
137 $apatient['ss'],
138 $apatient['occupation'],
139 $apatient['phone_home'],
140 $apatient['phone_biz'],
141 $apatient['phone_contact'],
142 $apatient['status'],
143 $apatient['contact_relationship'],
144 $apatient['referrer'],
145 $apatient['referrerID'],
146 $apatient['email'],
147 $apatient['language'],
148 $apatient['ethnoracial'],
149 $apatient['interpreter'],
150 $apatient['migrantseasonal'],
151 $apatient['family_size'],
152 $apatient['monthly_income'],
153 $apatient['homeless'],
154 fixDate($apatient['financial_review']),
155 $apatient['pubpid'],
156 $pid,
157 $olddata['providerID'],
158 $apatient['genericname1'],
159 $apatient['genericval1'],
160 $apatient['genericname2'],
161 $apatient['genericval2'],
162 $apatient['billing_note'],
163 $apatient['phone_cell'],
164 $apatient['hipaa_mail'],
165 $apatient['hipaa_voice'],
166 $olddata['squad']
169 newEmployerData(
170 $pid,
171 $aemployer['name'],
172 $aemployer['street'],
173 $aemployer['zip'],
174 $aemployer['city'],
175 $aemployer['state'],
176 $aemployer['country']
179 setInsurance($pid, $ainsurance, $asubscriber, '1');
180 setInsurance($pid, $ainsurance, $asubscriber, '2');
181 setInsurance($pid, $ainsurance, $asubscriber, '3');
183 echo "<html>\n<body>\n<script language='JavaScript'>\n";
184 if ($alertmsg) echo " alert('$alertmsg');\n";
185 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
186 echo " window.close();\n";
187 echo "</script>\n</body>\n</html>\n";
188 exit();
191 <html>
192 <head>
193 <?php html_header_show();?>
194 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
195 <title><?php xl('Import Patient Demographics','e'); ?></title>
196 </head>
197 <body class="body_top" onload="javascript:document.forms[0].form_import_data.focus()">
199 <p><?php xl('Paste the data to import into the text area below:','e'); ?></p>
201 <center>
202 <form method='post' action="import_xml.php">
204 <textarea name='form_import_data' rows='10' cols='50' style='width:95%'></textarea>
207 <input type='submit' name='form_import' value=<?php xl('Import Patient','e','\'','\''); ?> /> &nbsp;
208 <input type='button' value=<?php xl('Cancel','e','\'','\''); ?> onclick='window.close()' /></p>
209 </form>
210 </center>
212 </body>
213 </html>