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/sql.inc');
16 require_once('library/forms.inc');
22 // Create a visit form from an abortion issue. This may be called
23 // multiple times for a given issue.
25 function do_visit_form($irow, $encounter, $first) {
26 global $insert_count, $debug, $verbose;
30 // If a gcac form already exists for this visit, get out.
31 $row = sqlQuery("SELECT COUNT(*) AS count FROM forms WHERE " .
32 "pid = '$pid' AND encounter = '$encounter' AND " .
33 "formdir = 'LBFgcac' AND deleted = 0");
35 echo "<br />*** Visit $pid.$encounter skipped, already has a GCAC visit form ***\n";
40 'client_status' => $irow['client_status'],
41 'in_ab_proc' => $irow['in_ab_proc'],
42 'ab_location' => $irow['ab_location'],
43 'complications' => $irow['fol_compl'],
44 'contrameth' => $irow['contrameth'],
47 // logic that applies only to the first related visit
49 if ($a['ab_location'] == 'ma') $a['ab_location'] = 'proc';
50 $a['complications'] = $irow['rec_compl'];
51 $a['contrameth'] = '';
56 foreach ($a as $field_id => $value) {
59 $query = "INSERT INTO lbf_data " .
60 "( form_id, field_id, field_value ) " .
61 " VALUES ( '$newid', '$field_id', '$value' )";
62 if ($verbose) echo "<br />$query\n";
63 if (!$debug) sqlStatement($query);
66 $query = "INSERT INTO lbf_data " .
67 "( field_id, field_value ) " .
68 " VALUES ( '$field_id', '$value' )";
69 if ($verbose) echo "<br />$query\n";
70 if (!$debug) $newid = sqlInsert($query);
76 if ($newid && !$debug) {
77 addForm($encounter, 'IPPF GCAC', $newid, 'LBFgcac', $pid, 1);
81 if (!$didone) echo "<br />*** Empty issue skipped for visit $pid.$encounter ***\n";
86 <title
>OpenEMR IPPF Upgrade
</title
>
87 <link rel
='STYLESHEET' href
='interface/themes/style_blue.css'>
91 <span
class='title'>OpenEMR IPPF Upgrade
</span
>
95 if (!empty($_POST['form_submit'])) {
97 // If database is not utf8, convert it.
98 $trow = sqlQuery("SHOW CREATE DATABASE $dbase");
100 $value = array_shift($trow);
101 if (!preg_match('/SET utf8/', $value)) {
102 echo "<br />Converting database to UTF-8 encoding...";
103 $tres = sqlStatement("SHOW TABLES");
104 while ($trow = sqlFetchArray($tres)) {
105 $value = array_shift($trow);
106 $query = "ALTER TABLE $value CONVERT TO CHARACTER SET utf8";
107 if ($verbose) echo "<br />$query\n";
108 sqlStatement($query);
110 $query = "ALTER DATABASE $dbase CHARACTER SET utf8";
111 if ($verbose) echo "<br />$query\n";
112 sqlStatement($query);
113 echo "<br /> \n";
116 $ires = sqlStatement("SELECT " .
117 "l.pid, l.id, l.type, l.begdate, l.title, " .
118 "g.client_status, g.in_ab_proc, g.ab_location, " .
119 "g.rec_compl, g.contrameth, g.fol_compl " .
121 "JOIN lists_ippf_gcac AS g ON l.type = 'ippf_gcac' AND g.id = l.id " .
122 "ORDER BY l.pid, l.begdate");
124 while ($irow = sqlFetchArray($ires)) {
125 $patient_id = $irow['pid'];
126 $list_id = $irow['id'];
129 $ieres = sqlStatement("SELECT encounter " .
130 "FROM issue_encounter " .
131 "WHERE pid = '$patient_id' AND list_id = '$list_id' " .
132 "ORDER BY encounter");
134 if (sqlNumRows($ieres)) {
135 while ($ierow = sqlFetchArray($ieres)) {
136 do_visit_form($irow, $ierow['encounter'], $first);
141 echo "<br />*** Issue $list_id for pid $patient_id has no linked visits, skipped ***\n";
145 echo "<p><font color='green'>Done. Inserted $insert_count visit forms.</font></p>\n";
146 echo "</body></html>\n";
151 <p
>This converts your OpenEMR database to UTF
-8 encoding
if it is not already
,
152 and also converts GCAC issues to the corresponding visit forms
. Both of these
153 steps are needed
for IPPF sites upgrading from releases prior to
2009-08-27.</p
>
155 <form method
='post' action
='ippf_upgrade.php'>
156 <p
><input type
='submit' name
='form_submit' value
='Convert Database' /></p
>