4 * Imports patient demographics from our custom XML format.
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Roberto Vasquez <robertogagliotta@gmail.com>
10 * @copyright Copyright (c) 2005 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (c) 2017 Roberto Vasquez <robertogagliotta@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../interface/globals.php");
16 require_once("$srcdir/patient.inc");
18 use OpenEMR\Common\Acl\AclMain
;
19 use OpenEMR\Common\Csrf\CsrfUtils
;
20 use OpenEMR\Core\Header
;
22 function setInsurance($pid, $ainsurance, $asubscriber, $seq)
24 $iwhich = $seq == '2' ?
"secondary" : ($seq == '3' ?
"tertiary" : "primary");
28 $ainsurance["provider$seq"],
29 $ainsurance["policy$seq"],
30 $ainsurance["group$seq"],
31 $ainsurance["name$seq"],
32 $asubscriber["lname$seq"],
33 $asubscriber["mname$seq"],
34 $asubscriber["fname$seq"],
35 $asubscriber["relationship$seq"],
36 $asubscriber["ss$seq"],
37 fixDate($asubscriber["dob$seq"]),
38 $asubscriber["street$seq"],
39 $asubscriber["zip$seq"],
40 $asubscriber["city$seq"],
41 $asubscriber["state$seq"],
42 $asubscriber["country$seq"],
43 $asubscriber["phone$seq"],
44 $asubscriber["employer$seq"],
45 $asubscriber["employer_street$seq"],
46 $asubscriber["employer_city$seq"],
47 $asubscriber["employer_zip$seq"],
48 $asubscriber["employer_state$seq"],
49 $asubscriber["employer_country$seq"],
50 $ainsurance["copay$seq"],
51 $asubscriber["sex$seq"]
55 // Check authorization.
56 if (!AclMain
::aclCheckCore('patients', 'demo', '', 'write')) {
57 die("Updating demographics is not authorized.");
60 if ($_POST['form_import']) {
61 if (!CsrfUtils
::verifyCsrfToken($_POST["csrf_token_form"])) {
62 CsrfUtils
::csrfNotVerified();
68 $ainsurance = array();
69 $asubscriber = array();
71 // $probearr is an array of tag names corresponding to the current
72 // container in the tree structure. $probeix is the current level.
73 $probearr = array('');
76 $inspriority = '0'; // 1 = primary, 2 = secondary, 3 = tertiary
78 $parser = xml_parser_create();
79 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE
, 1);
82 if (xml_parse_into_struct($parser, $_POST['form_import_data'], $xml)) {
83 foreach ($xml as $taginfo) {
84 $tag = strtolower($taginfo['tag']);
85 $tagtype = $taginfo['type'];
86 $tagval = addslashes($taginfo['value']);
88 if ($tagtype == 'open') {
90 $probearr[$probeix] = $tag;
94 if ($tagtype == 'close') {
99 if ($tagtype != 'complete') {
100 die("Invalid tag type '$tagtype'");
103 if ($probeix == 1 && $probearr[$probeix] == 'patient') {
104 $apatient[$tag] = $tagval;
105 } elseif ($probeix == 2 && $probearr[$probeix] == 'pcp') {
106 $apcp[$tag] = $tagval;
107 } elseif ($probeix == 2 && $probearr[$probeix] == 'employer') {
108 $aemployer[$tag] = $tagval;
109 } elseif ($probeix == 2 && $probearr[$probeix] == 'insurance') {
110 if ($tag == 'priority') {
111 $inspriority = $tagval;
113 $ainsurance["$tag$inspriority"] = $tagval;
115 } elseif ($probeix == 3 && $probearr[$probeix] == 'subscriber') {
116 $asubscriber["$tag$inspriority"] = $tagval;
118 $alertmsg = "Invalid tag \"" . $probearr[$probeix] . "\" at level $probeix";
122 $alertmsg = "Invalid import data!";
125 xml_parser_free($parser);
127 $olddata = getPatientData($pid);
129 if ($olddata['squad'] && ! AclMain
::aclCheckCore('squads', $olddata['squad'])) {
130 die("You are not authorized to access this squad.");
140 fixDate($apatient['dob']),
145 $apatient['country'],
147 $apatient['occupation'],
148 $apatient['phone_home'],
149 $apatient['phone_biz'],
150 $apatient['phone_contact'],
152 $apatient['contact_relationship'],
153 $apatient['referrer'],
154 $apatient['referrerID'],
156 $apatient['language'],
157 $apatient['ethnoracial'],
158 $apatient['interpreter'],
159 $apatient['migrantseasonal'],
160 $apatient['family_size'],
161 $apatient['monthly_income'],
162 $apatient['homeless'],
163 fixDate($apatient['financial_review']),
166 $olddata['providerID'],
167 $apatient['genericname1'],
168 $apatient['genericval1'],
169 $apatient['genericname2'],
170 $apatient['genericval2'],
171 $apatient['billing_note'],
172 $apatient['phone_cell'],
173 $apatient['hipaa_mail'],
174 $apatient['hipaa_voice'],
181 $aemployer['street'],
185 $aemployer['country']
188 setInsurance($pid, $ainsurance, $asubscriber, '1');
189 setInsurance($pid, $ainsurance, $asubscriber, '2');
190 setInsurance($pid, $ainsurance, $asubscriber, '3');
192 echo "<html>\n<body>\n<script>\n";
194 echo " alert('" . addslashes($alertmsg) . "');\n";
197 echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
198 echo " window.close();\n";
199 echo "</script>\n</body>\n</html>\n";
205 <?php Header
::setupHeader(); ?
>
206 <title
><?php
echo xlt('Import Patient Demographics XML'); ?
></title
>
208 <body
class="body_top" onload
="javascript:document.forms[0].form_import_data.focus()">
209 <form method
='post' action
="import_xml.php" onsubmit
="return top.restoreSession()">
210 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
211 <div
class="container">
214 <div
class="form-group"></div
>
215 <div
class="form-group">
216 <textarea name
='form_import_data' class='form-control' rows
='10'></textarea
>
218 <div
class="form-group text-right">
219 <div
class="btn-group" role
="group">
220 <button type
='submit' class='btn btn-secondary btn-save' name
='form_import' value
='bn_import'>
221 <?php
echo xlt('Import'); ?
>
223 <button type
="button" class="btn btn-link btn-cancel" onclick
="dlgclose()">
224 <?php
echo xlt("Cancel"); ?
>