Adapting some reports to the new GUI style.
[openemr.git] / interface / main / ippf_export.php
bloba8ddb783c4ea5cadff1d5700e46afaa39b508eb1
1 <?php
2 // Copyright (C) 2008-2010 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 // This script creates an export file and sends it to the users's
10 // browser for download.
12 require_once("../globals.php");
13 require_once("$srcdir/acl.inc");
14 require_once("$srcdir/patient.inc");
16 if (!acl_check('admin', 'super')) die("Not authorized!");
18 //////////////////////////////////////////////////////////////////////
19 // XML Stuff //
20 //////////////////////////////////////////////////////////////////////
22 $out = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
23 $indent = 0;
25 // Add a string to output with some basic sanitizing.
26 function Add($tag, $text) {
27 global $out, $indent;
28 $text = trim(str_replace(array("\r", "\n", "\t"), " ", $text));
29 $text = substr(htmlspecialchars($text, ENT_NOQUOTES), 0, 50);
30 if (/* $text */ true) {
31 if ($text === 'NULL') $text = '';
32 for ($i = 0; $i < $indent; ++$i) $out .= "\t";
33 $out .= "<$tag>$text</$tag>\n";
37 function AddIfPresent($tag, $text) {
38 if (isset($text) && $text !== '') Add($tag, $text);
41 function OpenTag($tag) {
42 global $out, $indent;
43 for ($i = 0; $i < $indent; ++$i) $out .= "\t";
44 ++$indent;
45 $out .= "<$tag>\n";
48 function CloseTag($tag) {
49 global $out, $indent;
50 --$indent;
51 for ($i = 0; $i < $indent; ++$i) $out .= "\t";
52 $out .= "</$tag>\n";
55 // Remove all non-digits from a string.
56 function Digits($field) {
57 return preg_replace("/\D/", "", $field);
60 // Translate sex.
61 function Sex($field) {
62 /*******************************************************************
63 $sex = strtoupper(substr(trim($field), 0, 1));
64 if ($sex != "M" && $sex != "F") $sex = "U";
65 return $sex;
66 *******************************************************************/
67 return mappedOption('sex', $field);
70 // Translate a date.
71 function LWDate($field) {
72 return fixDate($field);
75 function xmlTime($str, $default='9999-12-31T23:59:59') {
76 if (empty($default)) $default = '1800-01-01T00:00:00';
77 if (strlen($str) < 10 || substr($str, 0, 4) == '0000')
78 $str = $default;
79 else if (strlen($str) > 10)
80 $str = substr($str, 0, 10) . 'T' . substr($str, 11);
81 else
82 $str .= 'T00:00:00';
83 // Per discussion with Daniel 2009-05-12, replace zero day or month with 01.
84 $str = preg_replace('/-00/', '-01', $str);
85 return $str;
88 //////////////////////////////////////////////////////////////////////
90 // Utility function to get the value for a specified key from a string
91 // whose format is key:value|key:value|...
93 function getTextListValue($string, $key) {
94 $tmp = explode('|', $string);
95 foreach ($tmp as $value) {
96 if (preg_match('/^(\w+?):(.*)$/', $value, $matches)) {
97 if ($matches[1] == $key) return $matches[2];
100 return '';
103 // Return the mapped list item ID if there is one, else the option_id.
104 // Or return 9 if the option_id is empty (unspecified).
106 function mappedOption($list_id, $option_id, $default='9') {
107 if ($option_id === '') return $default;
108 $row = sqlQuery("SELECT mapping FROM list_options WHERE " .
109 "list_id = '$list_id' AND option_id = '$option_id' LIMIT 1");
110 if (empty($row)) return $option_id; // should not happen
111 // return ($row['mapping'] === '') ? $option_id : $row['mapping'];
112 $maparr = explode(':', $row['mapping']);
113 return ($maparr[0] === '') ? $option_id : $maparr[0];
116 // Like the above but given a layout item form and field name.
117 // Or return 9 for a list whose id is empty (unspecified).
119 function mappedFieldOption($form_id, $field_id, $option_id) {
120 $row = sqlQuery("SELECT list_id FROM " .
121 "layout_options WHERE " .
122 "form_id = '$form_id' AND " .
123 "field_id = '$field_id' " .
124 "LIMIT 1");
125 if (empty($row)) return $option_id; // should not happen
126 $list_id = $row['list_id'];
127 if ($list_id === '') return $option_id;
128 if ($option_id === '') return '9';
129 $row = sqlQuery("SELECT mapping FROM " .
130 "list_options WHERE " .
131 "list_id = '$list_id' AND " .
132 "option_id = '$option_id' " .
133 "LIMIT 1");
134 if (empty($row)) return $option_id; // should not happen
135 // return ($row['mapping'] === '') ? $option_id : $row['mapping'];
136 $maparr = explode(':', $row['mapping']);
137 return ($maparr[0] === '') ? $option_id : $maparr[0];
140 function exportEncounter($pid, $encounter, $date) {
141 // Starting a new visit (encounter).
142 OpenTag('IMS_eMRUpload_Visit');
143 Add('VisitDate' , xmlTime($date));
144 Add('emrVisitId', $encounter);
146 // Dump IPPF services.
147 $query = "SELECT b.code_type, b.code, b.units, b.fee, c.related_code " .
148 "FROM billing AS b, codes AS c WHERE " .
149 "b.pid = '$pid' AND b.encounter = '$encounter' AND " .
150 "b.activity = 1 AND " .
151 "c.code_type = '12' AND c.code = b.code AND c.modifier = b.modifier ";
152 $bres = sqlStatement($query);
153 while ($brow = sqlFetchArray($bres)) {
154 if (!empty($brow['related_code'])) {
155 $relcodes = explode(';', $brow['related_code']);
156 foreach ($relcodes as $codestring) {
157 if ($codestring === '') continue;
158 list($codetype, $code) = explode(':', $codestring);
159 if ($codetype !== 'IPPF') continue;
160 // Starting a new service (IPPF code).
161 OpenTag('IMS_eMRUpload_Service');
162 Add('IppfServiceProductId', $code);
163 Add('Type' , '0'); // 0=service, 1=product, 2=diagnosis, 3=referral
164 Add('IppfQuantity' , $brow['units']);
165 Add('CurrID' , "TBD"); // TBD: Currency e.g. USD
166 Add('Amount' , $brow['fee']);
167 CloseTag('IMS_eMRUpload_Service');
168 } // end foreach
169 } // end if related code
170 } // end while billing row found
172 // Dump products.
173 $query = "SELECT drug_id, quantity, fee FROM drug_sales WHERE " .
174 "pid = '$pid' AND encounter = '$encounter' " .
175 "ORDER BY drug_id, sale_id";
176 $pres = sqlStatement($query);
177 while ($prow = sqlFetchArray($pres)) {
178 OpenTag('IMS_eMRUpload_Service');
179 Add('IppfServiceProductId', $prow['drug_id']);
180 Add('Type' , '1'); // 0=service, 1=product, 2=diagnosis, 3=referral
181 Add('IppfQuantity' , $prow['quantity']);
182 Add('CurrID' , "TBD"); // TBD: Currency e.g. USD
183 Add('Amount' , $prow['fee']);
184 CloseTag('IMS_eMRUpload_Service');
185 } // end while drug_sales row found
187 // Dump diagnoses.
188 $query = "SELECT code FROM billing WHERE " .
189 "pid = '$pid' AND encounter = '$encounter' AND " .
190 "code_type = 'ICD9' AND activity = 1 ORDER BY code, id";
191 $dres = sqlStatement($query);
192 while ($drow = sqlFetchArray($dres)) {
193 OpenTag('IMS_eMRUpload_Service');
194 Add('IppfServiceProductId', $drow['code']);
195 Add('Type' , '2'); // 0=service, 1=product, 2=diagnosis, 3=referral
196 Add('IppfQuantity' , '1');
197 Add('CurrID' , "TBD"); // TBD: Currency e.g. USD
198 Add('Amount' , '0');
199 CloseTag('IMS_eMRUpload_Service');
200 } // end while billing row found
202 // Export referrals. Match by date. Export code type 3 and
203 // the Requested Service which should be an IPPF code.
204 $query = "SELECT refer_related_code FROM transactions WHERE " .
205 "pid = '$pid' AND refer_date = '$date' AND " .
206 "refer_related_code != '' " .
207 "ORDER BY id";
208 $tres = sqlStatement($query);
209 while ($trow = sqlFetchArray($tres)) {
210 $relcodes = explode(';', $trow['refer_related_code']);
211 foreach ($relcodes as $codestring) {
212 if ($codestring === '') continue;
213 list($codetype, $code) = explode(':', $codestring);
214 if ($codetype !== 'IPPF') continue;
215 OpenTag('IMS_eMRUpload_Service');
216 Add('IppfServiceProductId', $code);
217 Add('Type' , '3'); // 0=service, 1=product, 2=diagnosis, 3=referral
218 Add('IppfQuantity' , '1');
219 Add('CurrID' , "TBD"); // TBD: Currency e.g. USD
220 Add('Amount' , '0');
221 CloseTag('IMS_eMRUpload_Service');
222 } // end foreach
223 } // end referral
225 CloseTag('IMS_eMRUpload_Visit');
228 function endClient($pid, &$encarray) {
229 // Output issues.
230 $ires = sqlStatement("SELECT " .
231 "l.id, l.type, l.begdate, l.enddate, l.title, l.diagnosis, " .
232 "c.prev_method, c.new_method, c.reason_chg, c.reason_term, " .
233 "c.hor_history, c.hor_lmp, c.hor_flow, c.hor_bleeding, c.hor_contra, " .
234 "c.iud_history, c.iud_lmp, c.iud_pain, c.iud_upos, c.iud_contra, " .
235 "c.sur_screen, c.sur_anes, c.sur_type, c.sur_post_ins, c.sur_contra, " .
236 "c.nat_reason, c.nat_method, c.emg_reason, c.emg_method, " .
237 "g.client_status, g.in_ab_proc, g.ab_types, g.ab_location, g.pr_status, " .
238 "g.gest_age_by, g.sti, g.prep_procs, g.reason, g.exp_p_i, g.ab_contraind, " .
239 "g.screening, g.pre_op, g.anesthesia, g.side_eff, g.rec_compl, g.post_op, " .
240 "g.qc_ind, g.contrameth, g.fol_compl " .
241 "FROM lists AS l " .
242 "LEFT JOIN lists_ippf_con AS c ON l.type = 'contraceptive' AND c.id = l.id " .
243 "LEFT JOIN lists_ippf_gcac AS g ON l.type = 'ippf_gcac' AND g.id = l.id " .
244 "WHERE l.pid = '$pid' " .
245 "ORDER BY l.begdate");
247 while ($irow = sqlFetchArray($ires)) {
248 OpenTag('IMS_eMRUpload_Issue');
249 Add('IssueType' , substr($irow['type'], 0, 15)); // per email 2009-03-20
250 Add('emrIssueId' , $irow['id']);
251 Add('IssueStartDate', xmlTime($irow['begdate'], 0));
252 Add('IssueEndDate' , xmlTime($irow['enddate']));
253 Add('IssueTitle' , $irow['title']);
254 Add('IssueDiagnosis', $irow['diagnosis']);
255 $form_id = ($irow['type'] == 'ippf_gcac') ? 'GCA' : 'CON';
256 foreach ($irow AS $key => $value) {
257 if (empty($value)) continue;
258 if ($key == 'id' || $key == 'type' || $key == 'begdate' ||
259 $key == 'enddate' || $key == 'title' || $key == 'diagnosis')
260 continue;
261 $avalues = explode('|', $value);
262 foreach ($avalues as $tmp) {
263 OpenTag('IMS_eMRUpload_IssueData');
264 // TBD: Add IssueCodeGroup to identify the list, if any???
265 Add('IssueCodeGroup', '?');
266 Add('IssueCode', $key);
267 Add('IssueCodeValue', mappedFieldOption($form_id, $key, $tmp));
268 CloseTag('IMS_eMRUpload_IssueData');
271 // List the encounters linked to this issue. We include pid
272 // to speed up the search, as it begins the primary key.
273 $ieres = sqlStatement("SELECT encounter FROM issue_encounter " .
274 "WHERE pid = '$pid' AND list_id = '" . $irow['id'] . "' " .
275 "ORDER BY encounter");
276 while ($ierow = sqlFetchArray($ieres)) {
277 OpenTag('IMS_eMRUpload_VisitIssue');
278 Add('emrIssueId', $irow['id']);
279 Add('emrVisitId', $ierow['encounter']);
280 CloseTag('IMS_eMRUpload_VisitIssue');
282 CloseTag('IMS_eMRUpload_Issue');
285 // Loop on $encarray and generate an "issue" for each GCAC visit form,
286 // similarly to the above.
287 foreach ($encarray as $erow) {
288 $fres = sqlStatement("SELECT form_id FROM forms WHERE " .
289 "pid = '$pid' AND " .
290 "encounter = '" . $erow['encounter'] . "' AND " .
291 "formdir = 'LBFgcac' AND " .
292 "deleted = 0 " .
293 "ORDER BY id");
294 // For each GCAC form in this encounter...
295 while ($frow = sqlFetchArray($fres)) {
296 $form_id = $frow['form_id'];
297 OpenTag('IMS_eMRUpload_Issue');
298 Add('IssueType' , 'ippf_gcac');
299 Add('emrIssueId' , 10000000 + $form_id);
300 Add('IssueStartDate', xmlTime($erow['date'], 0));
301 Add('IssueEndDate' , xmlTime(''));
302 Add('IssueTitle' , 'GCAC Visit Form');
303 Add('IssueDiagnosis', '');
304 $gres = sqlStatement("SELECT field_id, field_value FROM lbf_data WHERE " .
305 "form_id = '$form_id' ORDER BY field_id");
306 // For each data item in the form...
307 while ($grow = sqlFetchArray($gres)) {
308 $key = $grow['field_id'];
309 $value = $grow['field_value'];
310 if (empty($value)) continue;
311 $avalues = explode('|', $value);
312 foreach ($avalues as $tmp) {
313 OpenTag('IMS_eMRUpload_IssueData');
314 Add('IssueCodeGroup', '?');
315 Add('IssueCode', $key);
316 Add('IssueCodeValue', mappedFieldOption('LBFgcac', $key, $tmp));
317 CloseTag('IMS_eMRUpload_IssueData');
320 OpenTag('IMS_eMRUpload_VisitIssue');
321 Add('emrIssueId', 10000000 + $form_id);
322 Add('emrVisitId', $erow['encounter']);
323 CloseTag('IMS_eMRUpload_VisitIssue');
324 CloseTag('IMS_eMRUpload_Issue');
328 CloseTag('IMS_eMRUpload_Client');
331 function endFacility() {
332 global $beg_year, $beg_month;
333 OpenTag('IMS_eMRUpload_Version');
334 Add('XMLversionNumber', '1');
335 Add('Period', sprintf('%04u-%02u-01T00:00:00', $beg_year, $beg_month));
336 CloseTag('IMS_eMRUpload_Version');
337 CloseTag('IMS_eMRUpload_Point');
340 if (!empty($form_submit)) {
342 $beg_year = $_POST['form_year'];
343 $beg_month = $_POST['form_month'];
344 $end_year = $beg_year;
345 $end_month = $beg_month + 1;
346 if ($end_month > 12) {
347 $end_month = 1;
348 ++$end_year;
351 /*******************************************************************
352 $query = "SELECT " .
353 "fe.facility_id, fe.pid, fe.encounter, fe.date, " .
354 "f.name, f.street, f.city, f.state, f.postal_code, f.country_code, " .
355 "f.federal_ein, " .
356 "p.regdate, p.date AS last_update, p.contrastart, p.DOB, " .
357 "p.userlist2 AS education " .
358 "FROM form_encounter AS fe " .
359 "LEFT OUTER JOIN facility AS f ON f.id = fe.facility_id " .
360 "LEFT OUTER JOIN patient_data AS p ON p.pid = fe.pid WHERE " .
361 sprintf("fe.date >= '%04u-%02u-01 00:00:00' AND ", $beg_year, $beg_month) .
362 sprintf("fe.date < '%04u-%02u-01 00:00:00' ", $end_year, $end_month) .
363 "ORDER BY fe.facility_id, fe.pid, fe.encounter";
365 $query = "SELECT DISTINCT " .
366 "fe.facility_id, fe.pid, " .
367 "f.name, f.street, f.city, f.state, f.postal_code, f.country_code, " .
368 "f.federal_ein, " .
369 "p.regdate, p.date AS last_update, p.contrastart, p.DOB, " .
370 "p.userlist2 AS education " .
371 "FROM form_encounter AS fe " .
372 "LEFT OUTER JOIN facility AS f ON f.id = fe.facility_id " .
373 "LEFT OUTER JOIN patient_data AS p ON p.pid = fe.pid WHERE " .
374 sprintf("fe.date >= '%04u-%02u-01 00:00:00' AND ", $beg_year, $beg_month) .
375 sprintf("fe.date < '%04u-%02u-01 00:00:00' ", $end_year, $end_month) .
376 "ORDER BY fe.facility_id, fe.pid";
377 *******************************************************************/
379 // $last_pid = -1;
380 // $last_facility = -1;
382 // Dump info for the main facility.
383 $facrow = sqlQuery("SELECT * FROM facility ORDER BY " .
384 "billing_location DESC, id ASC LIMIT 1");
385 OpenTag('IMS_eMRUpload_Point');
386 Add('ServiceDeliveryPointName' , $facrow['name']);
387 // Add('EmrServiceDeliveryPointId', $facrow['id']);
388 Add('EmrServiceDeliveryPointId', $facrow['facility_npi']);
389 Add('Channel' , '01');
390 Add('Latitude' , '222222'); // TBD: Add this to facility attributes
391 Add('Longitude' , '433333'); // TBD: Add this to facility attributes
392 Add('Address' , $facrow['street']);
393 Add('Address2' , '');
394 Add('City' , $facrow['city']);
395 Add('PostCode' , $facrow['postal_code']);
397 $query = "SELECT DISTINCT " .
398 "fe.pid, " .
399 "p.regdate, p.date AS last_update, p.contrastart, p.DOB, p.sex, " .
400 "p.city, p.state, p.occupation, p.status, p.ethnoracial, " .
401 "p.interpretter, p.monthly_income, p.referral_source, p.pricelevel, " .
402 "p.userlist1, p.userlist3, p.userlist4, p.userlist5, " .
403 "p.usertext11, p.usertext12, p.usertext13, p.usertext14, p.usertext15, " .
404 "p.usertext16, p.usertext17, p.usertext18, p.usertext19, p.usertext20, " .
405 "p.userlist2 AS education " .
406 "FROM form_encounter AS fe " .
407 "LEFT OUTER JOIN patient_data AS p ON p.pid = fe.pid WHERE " .
408 sprintf("fe.date >= '%04u-%02u-01 00:00:00' AND ", $beg_year, $beg_month) .
409 sprintf("fe.date < '%04u-%02u-01 00:00:00' ", $end_year, $end_month) .
410 "ORDER BY fe.pid";
411 $res = sqlStatement($query);
413 while ($row = sqlFetchArray($res)) {
415 /*****************************************************************
416 if ($row['facility_id'] != $last_facility) {
417 if ($last_facility >= 0) {
418 endFacility();
420 $last_facility = $row['facility_id'];
421 // Starting a new facility.
422 OpenTag('IMS_eMRUpload_Point');
423 Add('ServiceDeliveryPointName' , $row['name']);
424 Add('EmrServiceDeliveryPointId', $row['facility_id']);
425 // Add('EntityId' , $row['federal_ein']);
426 Add('Channel' , '01');
427 Add('Latitude' , '222222'); // TBD: Add this to facility attributes
428 Add('Longitude' , '433333'); // TBD: Add this to facility attributes
429 Add('Address' , $row['street']);
430 Add('Address2' , '');
431 Add('City' , $row['city']);
432 Add('PostCode' , $row['postal_code']);
434 *****************************************************************/
436 $last_pid = $row['pid'];
438 /*****************************************************************
439 // Compute education: 0 = none, 1 = some, 9 = unassigned.
440 // The MAs should be told to use "none" for no education.
441 $education = 9;
442 if (!empty($row['education'])) {
443 if (preg_match('/^il/i', $row['education']) ||
444 preg_match('/^no/i', $row['education']))
445 $education = 0;
446 else
447 $education = 1;
449 *****************************************************************/
450 $education = mappedOption('userlist2', $row['education']);
452 // Get most recent contraceptive issue.
453 $crow = sqlQuery("SELECT l.begdate, c.new_method " .
454 "FROM lists AS l, lists_ippf_con AS c WHERE " .
455 "l.pid = '$last_pid' AND c.id = l.id " .
456 "ORDER BY l.begdate DESC LIMIT 1");
458 // Get obstetric and abortion data from most recent static history.
459 $hrow = sqlQuery("SELECT date, " .
460 "usertext16 AS genobshist, " .
461 "usertext17 AS genabohist " .
462 "FROM history_data WHERE pid = '$last_pid' " .
463 "ORDER BY date DESC LIMIT 1");
465 // Starting a new client (patient).
466 OpenTag('IMS_eMRUpload_Client');
467 Add('emrClientId' , $row['pid']);
468 Add('RegisteredOn' , xmlTime($row['regdate']));
469 Add('LastUpdated' , xmlTime($row['last_update']));
470 Add('NewAcceptorDate' , xmlTime($row['contrastart']));
472 // Get the current contraceptive method with greatest effectiveness.
473 $methodid = '';
474 $methodvalue = -999;
475 if (!empty($crow['new_method'])) {
476 $methods = explode('|', $crow['new_method']);
477 /***************************************************************
478 foreach ($methods as $method) {
479 $lorow = sqlQuery("SELECT option_value FROM list_options WHERE " .
480 "list_id = 'contrameth' AND option_id = '$method' LIMIT 1");
481 $value = empty($lorow) ? 0 : (0 + $lorow['option_value']);
482 if ($value > $methodvalue) {
483 $methodid = $method;
484 $methodvalue = $value;
487 ***************************************************************/
488 $methodid = mappedOption('contrameth', $methods[0]);
490 Add('CurrentMethod', $methodid);
492 Add('Dob' , xmlTime($row['DOB']));
493 Add('DobType' , "rel"); // rel=real, est=estimated
494 Add('Pregnancies', 0 + getTextListValue($hrow['genobshist'],'npreg')); // number of pregnancies
495 Add('Children' , 0 + getTextListValue($hrow['genobshist'],'nlc')); // number of living children
496 Add('Abortions' , 0 + getTextListValue($hrow['genabohist'],'nia')); // number of induced abortions
497 Add('Education' , $education);
498 Add('Demo5' , Sex($row['sex']));
500 // Things included if they are present (July 2010)
501 AddIfPresent('City', $row['city']);
502 AddIfPresent('State', mappedOption('state', $row['state'], ''));
503 AddIfPresent('Occupation', mappedOption('occupations', $row['occupation'], ''));
504 AddIfPresent('MaritalStatus', mappedOption('marital', $row['status'], ''));
505 AddIfPresent('Ethnoracial', mappedOption('ethrace', $row['ethnoracial'], ''));
506 AddIfPresent('Interpreter', $row['interpretter']);
507 AddIfPresent('MonthlyIncome', $row['monthly_income']);
508 AddIfPresent('ReferralSource', mappedOption('refsource', $row['referral_source'], ''));
509 AddIfPresent('PriceLevel', mappedOption('pricelevel', $row['pricelevel'], ''));
510 AddIfPresent('UserList1', mappedOption('userlist1', $row['userlist1'], ''));
511 AddIfPresent('UserList3', mappedOption('userlist3', $row['userlist3'], ''));
512 AddIfPresent('UserList4', mappedOption('userlist4', $row['userlist4'], ''));
513 AddIfPresent('UserList5', mappedOption('userlist5', $row['userlist5'], ''));
514 AddIfPresent('UserText11', $row['usertext11']);
515 AddIfPresent('UserText12', $row['usertext12']);
516 AddIfPresent('UserText13', $row['usertext13']);
517 AddIfPresent('UserText14', $row['usertext14']);
518 AddIfPresent('UserText15', $row['usertext15']);
519 AddIfPresent('UserText16', $row['usertext16']);
520 AddIfPresent('UserText17', $row['usertext17']);
521 AddIfPresent('UserText18', $row['usertext18']);
522 AddIfPresent('UserText19', $row['usertext19']);
523 AddIfPresent('UserText20', $row['usertext20']);
525 // Dump all visits for this patient at this facility.
526 $query = "SELECT " .
527 "encounter, date " .
528 "FROM form_encounter WHERE " .
529 // "pid = '$last_pid' AND facility_id = '$last_facility' " .
530 "pid = '$last_pid' " .
531 "ORDER BY encounter";
533 // Add('Debug', $query); // debugging
535 $eres = sqlStatement($query);
536 $encarray = array();
537 while ($erow = sqlFetchArray($eres)) {
538 exportEncounter($last_pid, $erow['encounter'], $erow['date']);
539 $encarray[] = $erow;
542 endClient($last_pid, $encarray);
545 // if ($last_facility >= 0) endFacility();
546 endFacility();
548 header("Pragma: public");
549 header("Expires: 0");
550 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
551 header("Content-Type: application/force-download");
552 header("Content-Length: " . strlen($out));
553 header("Content-Disposition: attachment; filename=export.xml");
554 header("Content-Description: File Transfer");
555 echo $out;
557 exit(0);
560 $months = array(1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April',
561 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September',
562 10 => 'October', 11 => 'November', 12 => 'December');
564 $selmonth = date('m') - 1;
565 $selyear = date('Y') + 0;
566 if ($selmonth < 1) {
567 $selmonth = 12;
568 --$selyear;
571 <html>
573 <head>
574 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
575 <title><?php xl('Backup','e'); ?></title>
576 </head>
578 <body class="body_top">
579 <center>
580 &nbsp;<br />
581 <form method='post' action='ippf_export.php'>
583 <table style='width:30em'>
584 <tr>
585 <td align='center'>
586 <?php echo xl('Month'); ?>:
587 <select name='form_month'>
588 <?php
589 foreach ($months as $key => $value) {
590 echo " <option value='$key'";
591 if ($key == $selmonth) echo " selected";
592 echo ">" . xl($value) . "</option>\n";
595 </select>
596 <input type='text' name='form_year' size='4' value='<?php echo $selyear; ?>' />
597 &nbsp;
598 <input type='submit' name='form_submit' value='Generate XML' />
599 </td>
600 </tr>
601 </table>
603 </form>
605 </center>
607 </body>
608 </html>