Implement new security model in LBF forms.
[openemr.git] / custom / import_xml.php
blobb07e343cbd48317170a278910f98b5c4c20ec7a9
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['phone_cell'],
163 $apatient['hipaa_mail'],
164 $apatient['hipaa_voice'],
165 $olddata['squad']
168 newEmployerData(
169 $pid,
170 $aemployer['name'],
171 $aemployer['street'],
172 $aemployer['zip'],
173 $aemployer['city'],
174 $aemployer['state'],
175 $aemployer['country']
178 setInsurance($pid, $ainsurance, $asubscriber, '1');
179 setInsurance($pid, $ainsurance, $asubscriber, '2');
180 setInsurance($pid, $ainsurance, $asubscriber, '3');
182 echo "<html>\n<body>\n<script language='JavaScript'>\n";
183 if ($alertmsg) echo " alert('$alertmsg');\n";
184 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
185 echo " window.close();\n";
186 echo "</script>\n</body>\n</html>\n";
187 exit();
190 <html>
191 <head>
192 <?php html_header_show();?>
193 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
194 <title><?php xl('Import Patient Demographics','e'); ?></title>
195 </head>
196 <body class="body_top" onload="javascript:document.forms[0].form_import_data.focus()">
198 <p><?php xl('Paste the data to import into the text area below:','e'); ?></p>
200 <center>
201 <form method='post' action="import_xml.php">
203 <textarea name='form_import_data' rows='10' cols='50' style='width:95%'></textarea>
206 <input type='submit' name='form_import' value=<?php xl('Import Patient','e','\'','\''); ?> /> &nbsp;
207 <input type='button' value=<?php xl('Cancel','e','\'','\''); ?> onclick='window.close()' /></p>
208 </form>
209 </center>
211 </body>
212 </html>