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 program exports patient demographics to a custom XML format.
11 /////////////////////////////////////////////////////////////////////
13 include_once("../interface/globals.php");
14 include_once("../library/patient.inc");
19 // Add a string to output with some basic sanitizing.
20 function Add($tag, $text) {
22 $text = trim(str_replace(array("\r", "\n", "\t"), " ", $text));
24 for ($i = 0; $i < $indent; ++
$i) $out .= "\t";
25 $out .= "<$tag>$text</$tag>\n";
29 function OpenTag($tag) {
31 for ($i = 0; $i < $indent; ++
$i) $out .= "\t";
36 function CloseTag($tag) {
39 for ($i = 0; $i < $indent; ++
$i) $out .= "\t";
43 // Remove all non-digits from a string.
44 function Digits($field) {
45 return preg_replace("/\D/", "", $field);
49 function Sex($field) {
50 $sex = strtoupper(substr(trim($field), 0, 1));
51 if ($sex != "M" && $sex != "F") $sex = "U";
56 function LWDate($field) {
57 return fixDate($field);
60 // Add an insurance section.
61 function addInsurance($row, $seq) {
62 if ($row["name$seq"]) {
64 Add("priority" , $seq);
65 Add("group" , $row["group$seq"]);
66 Add("policy" , $row["policy$seq"]);
67 Add("provider" , $row["provider$seq"]);
68 Add("name" , $row["name$seq"]);
69 Add("street1" , $row["street1$seq"]);
70 Add("street2" , $row["street2$seq"]);
71 Add("city" , $row["city$seq"]);
72 Add("state" , $row["state$seq"]);
73 Add("zip" , $row["zip$seq"]);
74 Add("country" , $row["country$seq"]);
75 Add("type" , $row["instype$seq"]);
76 Add("copay" , $row["copay$seq"]);
77 OpenTag("subscriber");
78 Add("relationship" , $row["relationship$seq"]);
79 Add("lname" , $row["lname$seq"]);
80 Add("fname" , $row["fname$seq"]);
81 Add("mname" , $row["mname$seq"]);
82 Add("street" , $row["sstreet$seq"]);
83 Add("city" , $row["scity$seq"]);
84 Add("state" , $row["sstate$seq"]);
85 Add("zip" , $row["szip$seq"]);
86 Add("country" , $row["scountry$seq"]);
87 Add("dob" , $row["sdob$seq"]);
88 Add("ss" , $row["sss$seq"]);
89 Add("phone" , $row["sphone$seq"]);
90 Add("employer" , $row["semployer$seq"]);
91 Add("sex" , $row["ssex$seq"]);
92 Add("employer_street" , $row["semployer_street$seq"]);
93 Add("employer_city" , $row["semployer_city$seq"]);
94 Add("employer_state" , $row["semployer_state$seq"]);
95 Add("employer_zip" , $row["semployer_zip$seq"]);
96 Add("employer_country" , $row["semployer_country$seq"]);
97 CloseTag("subscriber");
98 CloseTag("insurance");
102 // This mess gets all the info for the patient.
105 foreach (array('primary','secondary','tertiary') as $value) {
106 $insrow[] = sqlQuery("SELECT id FROM insurance_data WHERE " .
107 "pid = '$pid' AND type = '$value' ORDER BY date DESC LIMIT 1");
110 "p.pubpid, p.fname, p.mname, p.lname, p.DOB, p.providerID, " .
111 "p.ss, p.street, p.city, p.state, p.postal_code, p.phone_home, p.sex, " .
112 "p.title, p.country_code, p.occupation, p.phone_biz, p.phone_contact, p.phone_cell, " .
113 "p.status, p.contact_relationship, p.referrer, p.referrerID, p.email, " .
114 "p.language, p.ethnoracial, p.interpretter, p.migrantseasonal, p.family_size, " .
115 "p.monthly_income, p.homeless, p.financial_review, p.hipaa_mail, p.hipaa_voice, " .
116 "p.genericname1, p.genericval1, p.genericname2, p.genericval2, " .
117 "i1.policy_number AS policy1, i1.group_number AS group1, i1.provider as provider1, " .
118 "i1.subscriber_fname AS fname1, i1.subscriber_mname AS mname1, i1.subscriber_lname AS lname1, " .
119 "i1.subscriber_street AS sstreet1, i1.subscriber_city AS scity1, i1.subscriber_state AS sstate1, " .
120 "i1.subscriber_postal_code AS szip1, i1.subscriber_relationship AS relationship1, " .
121 "i1.subscriber_DOB AS sdob1, i1.subscriber_ss AS sss1, i1.subscriber_phone AS sphone1, " .
122 "i1.subscriber_sex AS ssex1, i1.subscriber_country AS scountry1, " .
123 "i1.subscriber_employer AS semployer1, i1.subscriber_employer_street AS semployer_street1, " .
124 "i1.subscriber_employer_city AS semployer_city1, i1.subscriber_employer_state AS semployer_state1, " .
125 "i1.subscriber_employer_postal_code AS semployer_zip1, " .
126 "i1.subscriber_employer_country AS semployer_country1, i1.copay AS copay1, " .
127 "c1.name AS name1, c1.freeb_type AS instype1, " .
128 "a1.line1 AS street11, a1.line2 AS street21, a1.city AS city1, a1.state AS state1, " .
129 "a1.zip AS zip1, a1.plus_four AS zip41, a1.country AS country1, " .
130 "i2.policy_number AS policy2, i2.group_number AS group2, i2.provider as provider2, " .
131 "i2.subscriber_fname AS fname2, i2.subscriber_mname AS mname2, i2.subscriber_lname AS lname2, " .
132 "i2.subscriber_postal_code AS szip2, i2.subscriber_relationship AS relationship2, " .
133 "i2.subscriber_DOB AS sdob2, i2.subscriber_ss AS sss2, i2.subscriber_phone AS sphone2, " .
134 "i2.subscriber_sex AS ssex2, i2.subscriber_country AS scountry2, " .
135 "i2.subscriber_employer AS semployer2, i2.subscriber_employer_street AS semployer_street2, " .
136 "i2.subscriber_employer_city AS semployer_city2, i2.subscriber_employer_state AS semployer_state2, " .
137 "i2.subscriber_employer_postal_code AS semployer_zip2, " .
138 "i2.subscriber_employer_country AS semployer_country2, i2.copay AS copay2, " .
139 "c2.name AS name2, c2.freeb_type AS instype2, " .
140 "a2.line1 AS street12, a2.line2 AS street22, a2.city AS city2, a2.state AS state2, " .
141 "a2.zip AS zip2, a2.plus_four AS zip42, a2.country AS country2, " .
142 "i3.policy_number AS policy3, i3.group_number AS group3, i3.provider as provider3, " .
143 "i3.subscriber_fname AS fname3, i3.subscriber_mname AS mname3, i3.subscriber_lname AS lname3, " .
144 "i3.subscriber_postal_code AS szip3, i3.subscriber_relationship AS relationship3, " .
145 "i3.subscriber_DOB AS sdob3, i3.subscriber_ss AS sss3, i3.subscriber_phone AS sphone3, " .
146 "i3.subscriber_sex AS ssex3, i3.subscriber_country AS scountry3, " .
147 "i3.subscriber_employer AS semployer3, i3.subscriber_employer_street AS semployer_street3, " .
148 "i3.subscriber_employer_city AS semployer_city3, i3.subscriber_employer_state AS semployer_state3, " .
149 "i3.subscriber_employer_postal_code AS semployer_zip3, " .
150 "i3.subscriber_employer_country AS semployer_country3, i3.copay AS copay3, " .
151 "c3.name AS name3, c3.freeb_type AS instype3, " .
152 "a3.line1 AS street13, a3.line2 AS street23, a3.city AS city3, a3.state AS state3, " .
153 "a3.zip AS zip3, a3.plus_four AS zip43, a3.country AS country3 " .
154 "FROM patient_data AS p " .
155 // "LEFT OUTER JOIN insurance_data AS i1 ON i1.pid = p.pid AND i1.type = 'primary' " .
156 // "LEFT OUTER JOIN insurance_data AS i2 ON i2.pid = p.pid AND i2.type = 'secondary' " .
157 // "LEFT OUTER JOIN insurance_data AS i3 ON i3.pid = p.pid AND i3.type = 'tertiary' " .
158 "LEFT OUTER JOIN insurance_data AS i1 ON i1.id = '" . $insrow[0]['id'] . "' " .
159 "LEFT OUTER JOIN insurance_data AS i2 ON i2.id = '" . $insrow[1]['id'] . "' " .
160 "LEFT OUTER JOIN insurance_data AS i3 ON i3.id = '" . $insrow[2]['id'] . "' " .
162 "LEFT OUTER JOIN insurance_companies AS c1 ON c1.id = i1.provider " .
163 "LEFT OUTER JOIN insurance_companies AS c2 ON c2.id = i2.provider " .
164 "LEFT OUTER JOIN insurance_companies AS c3 ON c3.id = i3.provider " .
165 "LEFT OUTER JOIN addresses AS a1 ON a1.foreign_id = c1.id " .
166 "LEFT OUTER JOIN addresses AS a2 ON a2.foreign_id = c2.id " .
167 "LEFT OUTER JOIN addresses AS a3 ON a3.foreign_id = c3.id " .
168 "WHERE p.pid = '$pid' LIMIT 1";
170 $row = sqlFetchArray(sqlStatement($query));
172 $rowed = getEmployerData($pid);
179 Add("pubpid" , $row['pubpid']);
180 Add("lname" , $row['lname']);
181 Add("fname" , $row['fname']);
182 Add("mname" , $row['mname']);
183 Add("title" , $row['title']);
184 Add("ss" , Digits($row['ss']));
185 Add("dob" , LWDate($row['DOB']));
186 Add("sex" , Sex($row['sex']));
187 Add("street" , $row['street']);
188 Add("city" , $row['city']);
189 Add("state" , $row['state']);
190 Add("zip" , $row['postal_code']);
191 Add("country" , $row['country_code']);
192 Add("phone_home" , Digits($row['phone_home']));
193 Add("phone_biz" , Digits($row['phone_biz']));
194 Add("phone_contact" , Digits($row['phone_contact']));
195 Add("phone_cell" , Digits($row['phone_cell']));
196 Add("occupation" , $row['occupation']);
197 Add("status" , $row['status']);
198 Add("contact_relationship", $row['contact_relationship']);
199 Add("referrer" , $row['referrer']);
200 Add("referrerID" , $row['referrerID']);
201 Add("email" , $row['email']);
202 Add("language" , $row['language']);
203 Add("ethnoracial" , $row['ethnoracial']);
204 Add("interpreter" , $row['interpretter']);
205 Add("migrantseasonal" , $row['migrantseasonal']);
206 Add("family_size" , $row['family_size']);
207 Add("monthly_income" , $row['monthly_income']);
208 Add("homeless" , $row['homeless']);
209 Add("financial_review" , LWDate(substr($row['financial_review'], 0, 10)));
210 Add("genericname1" , $row['genericname1']);
211 Add("genericval1" , $row['genericval1']);
212 Add("genericname2" , $row['genericname2']);
213 Add("genericval2" , $row['genericval2']);
214 Add("hipaa_mail" , $row['hipaa_mail']);
215 Add("hipaa_voice" , $row['hipaa_voice']);
217 // Insurance Sections.
219 addInsurance($row, '1');
220 addInsurance($row, '2');
221 addInsurance($row, '3');
223 // Primary Care Physician Section.
225 if ($row['providerID']) {
226 $query = "select id, fname, mname, lname from users where authorized = 1";
227 $query .= " AND id = " . $row['providerID'];
228 $prow = sqlFetchArray(sqlStatement($query));
230 Add("id", $prow['id']);
231 Add("lname", $prow['lname']);
232 Add("fname", $prow['fname']);
233 Add("mname", $prow['mname']);
241 Add("name" , $rowed['name']);
242 Add("street" , $rowed['street']);
243 Add("zip" , $rowed['postal_code']);
244 Add("city" , $rowed['city']);
245 Add("state" , $rowed['state']);
246 Add("country", $rowed['country']);
247 CloseTag("employer");
253 // header('Content-type: text/xml');
254 // header('Content-Disposition: attachment; filename="pid' . $pid . '.xml"');
259 <?
html_header_show();?
>
260 <link rel
=stylesheet href
="<?echo $css_header;?>" type
="text/css">
261 <title
><?php
xl('Export Patient Demographics','e'); ?
></title
>
265 <p
><?php
xl('The exported data appears in the text area below. You can copy and
266 paste this into an email or to any other desired destination.','e'); ?
></p
>
271 <textarea rows
='10' cols
='50' style
='width:95%' readonly
>
275 <p
><input type
='button' value
=<?php
xl('OK','e','\'','\''); ?
> onclick
='window.close()' /></p
>