2 // Copyright (C) 2009 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 // Disable PHP timeout. This will not work in safe mode.
10 ini_set('max_execution_time', '0');
12 $ignoreAuth = true; // no login required
14 require_once('interface/globals.php');
15 require_once('library/forms.inc');
21 // Create a visit form from an abortion issue. This may be called
22 // multiple times for a given issue.
24 function do_visit_form($irow, $encounter, $first) {
25 global $insert_count, $debug, $verbose;
29 // If a gcac form already exists for this visit, get out.
30 $row = sqlQuery("SELECT COUNT(*) AS count FROM forms WHERE " .
31 "pid = '$pid' AND encounter = '$encounter' AND " .
32 "formdir = 'LBFgcac' AND deleted = 0");
34 echo "<br />*** Visit $pid.$encounter skipped, already has a GCAC visit form ***\n";
39 'client_status' => $irow['client_status'],
40 'in_ab_proc' => $irow['in_ab_proc'],
41 'ab_location' => $irow['ab_location'],
42 'complications' => $irow['fol_compl'],
43 'contrameth' => $irow['contrameth'],
46 // logic that applies only to the first related visit
48 if ($a['ab_location'] == 'ma') $a['ab_location'] = 'proc';
49 $a['complications'] = $irow['rec_compl'];
50 $a['contrameth'] = '';
55 foreach ($a as $field_id => $value) {
58 $query = "INSERT INTO lbf_data " .
59 "( form_id, field_id, field_value ) " .
60 " VALUES ( '$newid', '$field_id', '$value' )";
61 if ($verbose) echo "<br />$query\n";
62 if (!$debug) sqlStatement($query);
65 $query = "INSERT INTO lbf_data " .
66 "( field_id, field_value ) " .
67 " VALUES ( '$field_id', '$value' )";
68 if ($verbose) echo "<br />$query\n";
69 if (!$debug) $newid = sqlInsert($query);
75 if ($newid && !$debug) {
76 addForm($encounter, 'IPPF GCAC', $newid, 'LBFgcac', $pid, 1);
80 if (!$didone) echo "<br />*** Empty issue skipped for visit $pid.$encounter ***\n";
85 <title
>OpenEMR IPPF Upgrade
</title
>
86 <link rel
='STYLESHEET' href
='interface/themes/style_blue.css'>
90 <span
class='title'>OpenEMR IPPF Upgrade
</span
>
94 if (!empty($_POST['form_submit'])) {
96 // If database is not utf8, convert it.
97 $trow = sqlQuery("SHOW CREATE DATABASE $dbase");
99 $value = array_shift($trow);
100 if (!preg_match('/SET utf8/', $value)) {
101 echo "<br />Converting database to UTF-8 encoding...";
102 $tres = sqlStatement("SHOW TABLES");
103 while ($trow = sqlFetchArray($tres)) {
104 $value = array_shift($trow);
105 $query = "ALTER TABLE $value CONVERT TO CHARACTER SET utf8";
106 if ($verbose) echo "<br />$query\n";
107 sqlStatement($query);
109 $query = "ALTER DATABASE $dbase CHARACTER SET utf8";
110 if ($verbose) echo "<br />$query\n";
111 sqlStatement($query);
112 echo "<br /> \n";
115 $ires = sqlStatement("SELECT " .
116 "l.pid, l.id, l.type, l.begdate, l.title, " .
117 "g.client_status, g.in_ab_proc, g.ab_location, " .
118 "g.rec_compl, g.contrameth, g.fol_compl " .
120 "JOIN lists_ippf_gcac AS g ON l.type = 'ippf_gcac' AND g.id = l.id " .
121 "ORDER BY l.pid, l.begdate");
123 while ($irow = sqlFetchArray($ires)) {
124 $patient_id = $irow['pid'];
125 $list_id = $irow['id'];
128 $ieres = sqlStatement("SELECT encounter " .
129 "FROM issue_encounter " .
130 "WHERE pid = '$patient_id' AND list_id = '$list_id' " .
131 "ORDER BY encounter");
133 if (sqlNumRows($ieres)) {
134 while ($ierow = sqlFetchArray($ieres)) {
135 do_visit_form($irow, $ierow['encounter'], $first);
140 echo "<br />*** Issue $list_id for pid $patient_id has no linked visits, skipped ***\n";
144 echo "<p><font color='green'>Done. Inserted $insert_count visit forms.</font></p>\n";
145 echo "</body></html>\n";
150 <p
>This converts your OpenEMR database to UTF
-8 encoding
if it is not already
,
151 and also converts GCAC issues to the corresponding visit forms
. Both of these
152 steps are needed
for IPPF sites upgrading from releases prior to
2009-08-27.</p
>
154 <form method
='post' action
='ippf_upgrade.php'>
155 <p
><input type
='submit' name
='form_submit' value
='Convert Database' /></p
>