3 * Exports patient demographics to a custom XML format
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
15 require_once("../interface/globals.php");
16 require_once("../library/patient.inc");
18 use OpenEMR\Core\Header
;
23 // Add a string to output with some basic sanitizing.
24 function Add($tag, $text)
27 $text = trim(str_replace(array("\r", "\n", "\t"), " ", $text));
29 for ($i = 0; $i < $indent;
34 $out .= "<$tag>$text</$tag>\n";
38 function OpenTag($tag)
41 for ($i = 0; $i < $indent;
50 function CloseTag($tag)
54 for ($i = 0; $i < $indent;
62 // Remove all non-digits from a string.
63 function Digits($field)
65 return preg_replace("/\D/", "", $field);
71 $sex = strtoupper(substr(trim($field), 0, 1));
72 if ($sex != "M" && $sex != "F") {
80 function LWDate($field)
82 return fixDate($field);
85 // Add an insurance section.
86 function addInsurance($row, $seq)
88 if ($row["name$seq"]) {
90 Add("priority", $seq);
91 Add("group", $row["group$seq"]);
92 Add("policy", $row["policy$seq"]);
93 Add("provider", $row["provider$seq"]);
94 Add("name", $row["name$seq"]);
95 Add("street1", $row["street1$seq"]);
96 Add("street2", $row["street2$seq"]);
97 Add("city", $row["city$seq"]);
98 Add("state", $row["state$seq"]);
99 Add("zip", $row["zip$seq"]);
100 Add("country", $row["country$seq"]);
101 Add("type", $row["instype$seq"]);
102 Add("copay", $row["copay$seq"]);
103 OpenTag("subscriber");
104 Add("relationship", $row["relationship$seq"]);
105 Add("lname", $row["lname$seq"]);
106 Add("fname", $row["fname$seq"]);
107 Add("mname", $row["mname$seq"]);
108 Add("street", $row["sstreet$seq"]);
109 Add("city", $row["scity$seq"]);
110 Add("state", $row["sstate$seq"]);
111 Add("zip", $row["szip$seq"]);
112 Add("country", $row["scountry$seq"]);
113 Add("dob", $row["sdob$seq"]);
114 Add("ss", $row["sss$seq"]);
115 Add("phone", $row["sphone$seq"]);
116 Add("employer", $row["semployer$seq"]);
117 Add("sex", $row["ssex$seq"]);
118 Add("employer_street", $row["semployer_street$seq"]);
119 Add("employer_city", $row["semployer_city$seq"]);
120 Add("employer_state", $row["semployer_state$seq"]);
121 Add("employer_zip", $row["semployer_zip$seq"]);
122 Add("employer_country", $row["semployer_country$seq"]);
123 CloseTag("subscriber");
124 CloseTag("insurance");
128 // This mess gets all the info for the patient.
129 //~Well, now it does...-Art
131 foreach (array('primary','secondary','tertiary') as $value) {
132 $insrow[] = sqlQuery("SELECT id FROM insurance_data WHERE " .
133 "pid = ? AND type = ? ORDER BY date DESC LIMIT 1", array($pid, $value));
138 "i1.policy_number AS policy1, i1.group_number AS group1, i1.provider as provider1, " .
139 "i1.subscriber_fname AS fname1, i1.subscriber_mname AS mname1, i1.subscriber_lname AS lname1, " .
140 "i1.subscriber_street AS sstreet1, i1.subscriber_city AS scity1, i1.subscriber_state AS sstate1, " .
141 "i1.subscriber_postal_code AS szip1, i1.subscriber_relationship AS relationship1, " .
142 "i1.subscriber_DOB AS sdob1, i1.subscriber_ss AS sss1, i1.subscriber_phone AS sphone1, " .
143 "i1.subscriber_sex AS ssex1, i1.subscriber_country AS scountry1, " .
144 "i1.subscriber_employer AS semployer1, i1.subscriber_employer_street AS semployer_street1, " .
145 "i1.subscriber_employer_city AS semployer_city1, i1.subscriber_employer_state AS semployer_state1, " .
146 "i1.subscriber_employer_postal_code AS semployer_zip1, " .
147 "i1.subscriber_employer_country AS semployer_country1, i1.copay AS copay1, " .
148 "c1.name AS name1, c1.ins_type_code AS instype1, " .
149 "a1.line1 AS street11, a1.line2 AS street21, a1.city AS city1, a1.state AS state1, " .
150 "a1.zip AS zip1, a1.plus_four AS zip41, a1.country AS country1, " .
151 "i2.policy_number AS policy2, i2.group_number AS group2, i2.provider as provider2, " .
152 "i2.subscriber_fname AS fname2, i2.subscriber_mname AS mname2, i2.subscriber_lname AS lname2, " .
153 "i2.subscriber_postal_code AS szip2, i2.subscriber_relationship AS relationship2, " .
154 "i2.subscriber_DOB AS sdob2, i2.subscriber_ss AS sss2, i2.subscriber_phone AS sphone2, " .
155 "i2.subscriber_sex AS ssex2, i2.subscriber_country AS scountry2, " .
156 "i2.subscriber_employer AS semployer2, i2.subscriber_employer_street AS semployer_street2, " .
157 "i2.subscriber_employer_city AS semployer_city2, i2.subscriber_employer_state AS semployer_state2, " .
158 "i2.subscriber_employer_postal_code AS semployer_zip2, " .
159 "i2.subscriber_employer_country AS semployer_country2, i2.copay AS copay2, " .
160 "c2.name AS name2, c2.ins_type_code AS instype2, " .
161 "a2.line1 AS street12, a2.line2 AS street22, a2.city AS city2, a2.state AS state2, " .
162 "a2.zip AS zip2, a2.plus_four AS zip42, a2.country AS country2, " .
163 "i3.policy_number AS policy3, i3.group_number AS group3, i3.provider as provider3, " .
164 "i3.subscriber_fname AS fname3, i3.subscriber_mname AS mname3, i3.subscriber_lname AS lname3, " .
165 "i3.subscriber_postal_code AS szip3, i3.subscriber_relationship AS relationship3, " .
166 "i3.subscriber_DOB AS sdob3, i3.subscriber_ss AS sss3, i3.subscriber_phone AS sphone3, " .
167 "i3.subscriber_sex AS ssex3, i3.subscriber_country AS scountry3, " .
168 "i3.subscriber_employer AS semployer3, i3.subscriber_employer_street AS semployer_street3, " .
169 "i3.subscriber_employer_city AS semployer_city3, i3.subscriber_employer_state AS semployer_state3, " .
170 "i3.subscriber_employer_postal_code AS semployer_zip3, " .
171 "i3.subscriber_employer_country AS semployer_country3, i3.copay AS copay3, " .
172 "c3.name AS name3, c3.ins_type_code AS instype3, " .
173 "a3.line1 AS street13, a3.line2 AS street23, a3.city AS city3, a3.state AS state3, " .
174 "a3.zip AS zip3, a3.plus_four AS zip43, a3.country AS country3 " .
175 "FROM patient_data AS p " .
176 // "LEFT OUTER JOIN insurance_data AS i1 ON i1.pid = p.pid AND i1.type = 'primary' " .
177 // "LEFT OUTER JOIN insurance_data AS i2 ON i2.pid = p.pid AND i2.type = 'secondary' " .
178 // "LEFT OUTER JOIN insurance_data AS i3 ON i3.pid = p.pid AND i3.type = 'tertiary' " .
179 "LEFT OUTER JOIN insurance_data AS i1 ON i1.id = ? " .
180 "LEFT OUTER JOIN insurance_data AS i2 ON i2.id = ? " .
181 "LEFT OUTER JOIN insurance_data AS i3 ON i3.id = ? " .
183 "LEFT OUTER JOIN insurance_companies AS c1 ON c1.id = i1.provider " .
184 "LEFT OUTER JOIN insurance_companies AS c2 ON c2.id = i2.provider " .
185 "LEFT OUTER JOIN insurance_companies AS c3 ON c3.id = i3.provider " .
186 "LEFT OUTER JOIN addresses AS a1 ON a1.foreign_id = c1.id " .
187 "LEFT OUTER JOIN addresses AS a2 ON a2.foreign_id = c2.id " .
188 "LEFT OUTER JOIN addresses AS a3 ON a3.foreign_id = c3.id " .
189 "WHERE p.pid = ? LIMIT 1";
191 $row = sqlFetchArray(sqlStatement($query, array($insrow[0]['id'], $insrow[1]['id'], $insrow[2]['id'], $pid)));
193 $rowed = getEmployerData($pid);
200 Add("pubpid", $row['pubpid']);
201 Add("lname", $row['lname']);
202 Add("fname", $row['fname']);
203 Add("mname", $row['mname']);
204 Add("title", $row['title']);
205 Add("ss", Digits($row['ss']));
206 Add("dob", LWDate($row['DOB']));
207 Add("sex", Sex($row['sex']));
208 Add("street", $row['street']);
209 Add("city", $row['city']);
210 Add("state", $row['state']);
211 Add("zip", $row['postal_code']);
212 Add("country", $row['country_code']);
213 Add("phone_home", Digits($row['phone_home']));
214 Add("phone_biz", Digits($row['phone_biz']));
215 Add("phone_contact", Digits($row['phone_contact']));
216 Add("phone_cell", Digits($row['phone_cell']));
217 Add("occupation", $row['occupation']);
218 Add("status", $row['status']);
219 Add("contact_relationship", $row['contact_relationship']);
220 Add("referrer", $row['referrer']);
221 Add("referrerID", $row['referrerID']);
222 Add("email", $row['email']);
223 Add("language", $row['language']);
224 Add("ethnoracial", $row['ethnoracial']);
225 Add("interpreter", $row['interpretter']);
226 Add("migrantseasonal", $row['migrantseasonal']);
227 Add("family_size", $row['family_size']);
228 Add("monthly_income", $row['monthly_income']);
229 Add("homeless", $row['homeless']);
230 Add("financial_review", LWDate(substr($row['financial_review'], 0, 10)));
231 Add("genericname1", $row['genericname1']);
232 Add("genericval1", $row['genericval1']);
233 Add("genericname2", $row['genericname2']);
234 Add("genericval2", $row['genericval2']);
235 Add("billing_note", $row['billing_note']);
236 Add("hipaa_mail", $row['hipaa_mail']);
237 Add("hipaa_voice", $row['hipaa_voice']);
239 // Insurance Sections.
241 addInsurance($row, '1');
242 addInsurance($row, '2');
243 addInsurance($row, '3');
245 // Primary Care Physician Section.
247 if ($row['providerID']) {
248 $query = "select id, fname, mname, lname from users where authorized = 1";
249 $query .= " AND id = ?";
250 $prow = sqlFetchArray(sqlStatement($query, array($row['providerID'])));
252 Add("id", $prow['id']);
253 Add("lname", $prow['lname']);
254 Add("fname", $prow['fname']);
255 Add("mname", $prow['mname']);
263 Add("name", $rowed['name']);
264 Add("street", $rowed['street']);
265 Add("zip", $rowed['postal_code']);
266 Add("city", $rowed['city']);
267 Add("state", $rowed['state']);
268 Add("country", $rowed['country']);
269 CloseTag("employer");
275 // header('Content-type: text/xml');
276 // header('Content-Disposition: attachment; filename="pid' . $pid . '.xml"');
281 <?php Header
::setupHeader(); ?
>
282 <title
><?php
echo xlt('Export Patient Demographics XML'); ?
></title
>
284 <body
class="body_top">
285 <div
class="container">
287 <div
class="col-xs-12">
288 <div
class="form-group"></div
>
289 <div
class="form-group">
290 <textarea name
="export_data" class="form-control" rows
="18" readonly
><?php
echo text($out) ?
></textarea
>
292 <div
class="form-group">
293 <div
class="col-xs-12 text-right">
294 <div
class="btn-group" role
="group">
295 <button type
="button" class="btn btn-default btn-cancel" onclick
="window.close()"><?php
echo xlt("Close"); ?
></button
>