simple fix for hylafax
[openemr.git] / custom / import_xml.php
blob91d4826fd597b41f46ac8dbc048609e2a3ce7ef3
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) {
21 $iwhich = $seq == '2' ? "secondary" : ($seq == '3' ? "tertiary" : "primary");
22 newInsuranceData(
23 $pid,
24 $iwhich,
25 $ainsurance["provider$seq"],
26 $ainsurance["policy$seq"],
27 $ainsurance["group$seq"],
28 $ainsurance["name$seq"],
29 $asubscriber["lname$seq"],
30 $asubscriber["mname$seq"],
31 $asubscriber["fname$seq"],
32 $asubscriber["relationship$seq"],
33 $asubscriber["ss$seq"],
34 fixDate($asubscriber["dob$seq"]),
35 $asubscriber["street$seq"],
36 $asubscriber["zip$seq"],
37 $asubscriber["city$seq"],
38 $asubscriber["state$seq"],
39 $asubscriber["country$seq"],
40 $asubscriber["phone$seq"],
41 $asubscriber["employer$seq"],
42 $asubscriber["employer_street$seq"],
43 $asubscriber["employer_city$seq"],
44 $asubscriber["employer_zip$seq"],
45 $asubscriber["employer_state$seq"],
46 $asubscriber["employer_country$seq"],
47 $ainsurance["copay$seq"],
48 $asubscriber["sex$seq"]
52 // Check authorization.
53 if (!acl_check('patients', 'demo','','write'))
54 die("Updating demographics is not authorized.");
56 if ($_POST['form_import']) {
57 $apatient = array();
58 $apcp = array();
59 $aemployer = array();
60 $ainsurance = array();
61 $asubscriber = array();
63 // $probearr is an array of tag names corresponding to the current
64 // container in the tree structure. $probeix is the current level.
65 $probearr = array('');
66 $probeix = 0;
68 $inspriority = '0'; // 1 = primary, 2 = secondary, 3 = tertiary
70 $parser = xml_parser_create();
71 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
72 $xml = array();
74 if (xml_parse_into_struct($parser, $_POST['form_import_data'], $xml)) {
76 foreach ($xml as $taginfo) {
77 $tag = strtolower($taginfo['tag']);
78 $tagtype = $taginfo['type'];
79 $tagval = addslashes($taginfo['value']);
81 if ($tagtype == 'open') {
82 ++$probeix;
83 $probearr[$probeix] = $tag;
84 continue;
86 if ($tagtype == 'close') {
87 --$probeix;
88 continue;
90 if ($tagtype != 'complete') {
91 die("Invalid tag type '$tagtype'");
94 if ($probeix == 1 && $probearr[$probeix] == 'patient') {
95 $apatient[$tag] = $tagval;
97 else if ($probeix == 2 && $probearr[$probeix] == 'pcp') {
98 $apcp[$tag] = $tagval;
100 else if ($probeix == 2 && $probearr[$probeix] == 'employer') {
101 $aemployer[$tag] = $tagval;
103 else if ($probeix == 2 && $probearr[$probeix] == 'insurance') {
104 if ($tag == 'priority') {
105 $inspriority = $tagval;
106 } else {
107 $ainsurance["$tag$inspriority"] = $tagval;
110 else if ($probeix == 3 && $probearr[$probeix] == 'subscriber') {
111 $asubscriber["$tag$inspriority"] = $tagval;
113 else {
114 $alertmsg = "Invalid tag \"" . $probearr[$probeix] . "\" at level $probeix";
117 } else {
118 $alertmsg = "Invalid import data!";
120 xml_parser_free($parser);
122 $olddata = getPatientData($pid);
124 if ($olddata['squad'] && ! acl_check('squads', $olddata['squad']))
125 die("You are not authorized to access this squad.");
127 newPatientData(
128 $olddata['id'],
129 $apatient['title'],
130 $apatient['fname'],
131 $apatient['lname'],
132 $apatient['mname'],
133 $apatient['sex'],
134 $apatient['dob'],
135 $apatient['street'],
136 $apatient['zip'],
137 $apatient['city'],
138 $apatient['state'],
139 $apatient['country'],
140 $apatient['ss'],
141 $apatient['occupation'],
142 $apatient['phone_home'],
143 $apatient['phone_biz'],
144 $apatient['phone_contact'],
145 $apatient['status'],
146 $apatient['contact_relationship'],
147 $apatient['referrer'],
148 $apatient['referrerID'],
149 $apatient['email'],
150 $apatient['language'],
151 $apatient['ethnoracial'],
152 $apatient['interpreter'],
153 $apatient['migrantseasonal'],
154 $apatient['family_size'],
155 $apatient['monthly_income'],
156 $apatient['homeless'],
157 fixDate($apatient['financial_review']),
158 $apatient['pubpid'],
159 $pid,
160 $olddata['providerID'],
161 $apatient['genericname1'],
162 $apatient['genericval1'],
163 $apatient['genericname2'],
164 $apatient['genericval2'],
165 $apatient['billing_note'],
166 $apatient['phone_cell'],
167 $apatient['hipaa_mail'],
168 $apatient['hipaa_voice'],
169 $olddata['squad']
172 newEmployerData(
173 $pid,
174 $aemployer['name'],
175 $aemployer['street'],
176 $aemployer['zip'],
177 $aemployer['city'],
178 $aemployer['state'],
179 $aemployer['country']
182 setInsurance($pid, $ainsurance, $asubscriber, '1');
183 setInsurance($pid, $ainsurance, $asubscriber, '2');
184 setInsurance($pid, $ainsurance, $asubscriber, '3');
186 echo "<html>\n<body>\n<script language='JavaScript'>\n";
187 if ($alertmsg) echo " alert('$alertmsg');\n";
188 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
189 echo " window.close();\n";
190 echo "</script>\n</body>\n</html>\n";
191 exit();
194 <html>
195 <head>
196 <?php Header::setupHeader(); ?>
197 <title><?php echo xlt('Import Patient Demographics XML'); ?></title>
198 </head>
199 <body class="body_top" onload="javascript:document.forms[0].form_import_data.focus()">
200 <form method='post' action="import_xml.php" onsubmit="return top.restoreSession()">
201 <div class="container">
202 <div class="row">
203 <div class="col-xs-12">
204 <div class="form-group"></div>
205 <div class="form-group">
206 <textarea name='form_import_data' class='form-control' rows='10'></textarea>
207 </div>
208 <div class="form-group text-right">
209 <div class="btn-group" role="group">
210 <button type='submit' class='btn btn-default btn-save' name='form_import' value='bn_import'>
211 <?php echo xlt('Import'); ?>
212 </button>
213 <button type="button" class="btn btn-link btn-cancel" onclick="window.close()">
214 <?php echo xlt("Cancel"); ?>
215 </button>
216 </div>
217 </div>
218 </div>
219 </div>
220 </div>
221 </form>
222 </body>
223 </html>