2 // Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
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");
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 $thisauth = acl_check('patients', 'demo');
51 if ($thisauth != 'write')
52 die("Updating demographics is not authorized.");
54 if ($_POST['form_import']) {
58 $ainsurance = array();
59 $asubscriber = array();
61 // $probearr is an array of tag names corresponding to the current
62 // container in the tree structure. $probeix is the current level.
63 $probearr = array('');
66 $inspriority = '0'; // 1 = primary, 2 = secondary, 3 = tertiary
68 $parser = xml_parser_create();
69 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE
, 1);
72 if (xml_parse_into_struct($parser, $_POST['form_import_data'], $xml)) {
74 foreach ($xml as $taginfo) {
75 $tag = strtolower($taginfo['tag']);
76 $tagtype = $taginfo['type'];
77 $tagval = addslashes($taginfo['value']);
79 if ($tagtype == 'open') {
81 $probearr[$probeix] = $tag;
84 if ($tagtype == 'close') {
88 if ($tagtype != 'complete') {
89 die("Invalid tag type '$tagtype'");
92 if ($probeix == 1 && $probearr[$probeix] == 'patient') {
93 $apatient[$tag] = $tagval;
95 else if ($probeix == 2 && $probearr[$probeix] == 'pcp') {
96 $apcp[$tag] = $tagval;
98 else if ($probeix == 2 && $probearr[$probeix] == 'employer') {
99 $aemployer[$tag] = $tagval;
101 else if ($probeix == 2 && $probearr[$probeix] == 'insurance') {
102 if ($tag == 'priority') {
103 $inspriority = $tagval;
105 $ainsurance["$tag$inspriority"] = $tagval;
108 else if ($probeix == 3 && $probearr[$probeix] == 'subscriber') {
109 $asubscriber["$tag$inspriority"] = $tagval;
112 $alertmsg = "Invalid tag \"" . $probearr[$probeix] . "\" at level $probeix";
116 $alertmsg = "Invalid import data!";
118 xml_parser_free($parser);
120 $olddata = getPatientData($pid);
122 if ($olddata['squad'] && ! acl_check('squads', $olddata['squad']))
123 die("You are not authorized to access this squad.");
137 $apatient['country'],
139 $apatient['occupation'],
140 $apatient['phone_home'],
141 $apatient['phone_biz'],
142 $apatient['phone_contact'],
144 $apatient['contact_relationship'],
145 $apatient['referrer'],
146 $apatient['referrerID'],
148 $apatient['language'],
149 $apatient['ethnoracial'],
150 $apatient['interpreter'],
151 $apatient['migrantseasonal'],
152 $apatient['family_size'],
153 $apatient['monthly_income'],
154 $apatient['homeless'],
155 fixDate($apatient['financial_review']),
158 $olddata['providerID'],
159 $apatient['genericname1'],
160 $apatient['genericval1'],
161 $apatient['genericname2'],
162 $apatient['genericval2'],
163 $apatient['phone_cell'],
164 $apatient['hipaa_mail'],
165 $apatient['hipaa_voice'],
172 $aemployer['street'],
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";
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
>
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
>
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','\'','\''); ?
> />  
;
208 <input type
='button' value
=<?php
xl('Cancel','e','\'','\''); ?
> onclick
='window.close()' /></p
>