3 // Copyright (C) 2009 Rod Roark <rod@sunsetsystems.com>
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // Disable PHP timeout. This will not work in safe mode.
11 ini_set('max_execution_time', '0');
13 $ignoreAuth = true; // no login required
15 require_once('interface/globals.php');
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)
27 global $insert_count, $debug, $verbose;
31 // If a gcac form already exists for this visit, get out.
32 $row = sqlQuery("SELECT COUNT(*) AS count FROM forms WHERE " .
33 "pid = '$pid' AND encounter = '$encounter' AND " .
34 "formdir = 'LBFgcac' AND deleted = 0");
36 echo "<br />*** Visit $pid.$encounter skipped, already has a GCAC visit form ***\n";
41 'client_status' => $irow['client_status'],
42 'in_ab_proc' => $irow['in_ab_proc'],
43 'ab_location' => $irow['ab_location'],
44 'complications' => $irow['fol_compl'],
45 'contrameth' => $irow['contrameth'],
48 // logic that applies only to the first related visit
50 if ($a['ab_location'] == 'ma') {
51 $a['ab_location'] = 'proc';
54 $a['complications'] = $irow['rec_compl'];
55 $a['contrameth'] = '';
60 foreach ($a as $field_id => $value) {
63 $query = "INSERT INTO lbf_data " .
64 "( form_id, field_id, field_value ) " .
65 " VALUES ( '$newid', '$field_id', '$value' )";
67 echo "<br />$query\n";
74 $query = "INSERT INTO lbf_data " .
75 "( field_id, field_value ) " .
76 " VALUES ( '$field_id', '$value' )";
78 echo "<br />$query\n";
82 $newid = sqlInsert($query);
90 if ($newid && !$debug) {
91 addForm($encounter, 'IPPF GCAC', $newid, 'LBFgcac', $pid, 1);
96 echo "<br />*** Empty issue skipped for visit $pid.$encounter ***\n";
102 <title
>OpenEMR IPPF Upgrade
</title
>
103 <link rel
='STYLESHEET' href
='interface/themes/style_blue.css'>
107 <span
class='title'>OpenEMR IPPF Upgrade
</span
>
111 if (!empty($_POST['form_submit'])) {
112 // If database is not utf8, convert it.
113 $trow = sqlQuery("SHOW CREATE DATABASE $dbase");
115 $value = array_shift($trow);
116 if (!preg_match('/SET utf8/', $value)) {
117 echo "<br />Converting database to UTF-8 encoding...";
118 $tres = sqlStatement("SHOW TABLES");
119 while ($trow = sqlFetchArray($tres)) {
120 $value = array_shift($trow);
121 $query = "ALTER TABLE $value CONVERT TO CHARACTER SET utf8";
123 echo "<br />$query\n";
126 sqlStatement($query);
129 $query = "ALTER DATABASE $dbase CHARACTER SET utf8";
131 echo "<br />$query\n";
134 sqlStatement($query);
135 echo "<br /> \n";
138 $ires = sqlStatement("SELECT " .
139 "l.pid, l.id, l.type, l.begdate, l.title, " .
140 "g.client_status, g.in_ab_proc, g.ab_location, " .
141 "g.rec_compl, g.contrameth, g.fol_compl " .
143 "JOIN lists_ippf_gcac AS g ON l.type = 'ippf_gcac' AND g.id = l.id " .
144 "ORDER BY l.pid, l.begdate");
146 while ($irow = sqlFetchArray($ires)) {
147 $patient_id = $irow['pid'];
148 $list_id = $irow['id'];
151 $ieres = sqlStatement("SELECT encounter " .
152 "FROM issue_encounter " .
153 "WHERE pid = '$patient_id' AND list_id = '$list_id' " .
154 "ORDER BY encounter");
156 if (sqlNumRows($ieres)) {
157 while ($ierow = sqlFetchArray($ieres)) {
158 do_visit_form($irow, $ierow['encounter'], $first);
162 echo "<br />*** Issue $list_id for pid $patient_id has no linked visits, skipped ***\n";
166 echo "<p><font color='green'>Done. Inserted $insert_count visit forms.</font></p>\n";
167 echo "</body></html>\n";
172 <p
>This converts your OpenEMR database to UTF
-8 encoding
if it is not already
,
173 and also converts GCAC issues to the corresponding visit forms
. Both of these
174 steps are needed
for IPPF sites upgrading from releases prior to
2009-08-27.</p
>
176 <form method
='post' action
='ippf_upgrade.php'>
177 <p
><input type
='submit' name
='form_submit' value
='Convert Database' /></p
>