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.php');
18 use OpenEMR\Core\Header
;
24 // Create a visit form from an abortion issue. This may be called
25 // multiple times for a given issue.
27 function do_visit_form($irow, $encounter, $first)
29 global $insert_count, $debug, $verbose;
33 // If a gcac form already exists for this visit, get out.
34 $row = sqlQuery("SELECT COUNT(*) AS count FROM forms WHERE " .
35 "pid = '$pid' AND encounter = '$encounter' AND " .
36 "formdir = 'LBFgcac' AND deleted = 0");
38 echo "<br />*** Visit $pid.$encounter skipped, already has a GCAC visit form ***\n";
43 'client_status' => $irow['client_status'],
44 'in_ab_proc' => $irow['in_ab_proc'],
45 'ab_location' => $irow['ab_location'],
46 'complications' => $irow['fol_compl'],
47 'contrameth' => $irow['contrameth'],
50 // logic that applies only to the first related visit
52 if ($a['ab_location'] == 'ma') {
53 $a['ab_location'] = 'proc';
56 $a['complications'] = $irow['rec_compl'];
57 $a['contrameth'] = '';
62 foreach ($a as $field_id => $value) {
65 $query = "INSERT INTO lbf_data " .
66 "( form_id, field_id, field_value ) " .
67 " VALUES ( '$newid', '$field_id', '$value' )";
69 echo "<br />$query\n";
76 $query = "INSERT INTO lbf_data " .
77 "( field_id, field_value ) " .
78 " VALUES ( '$field_id', '$value' )";
80 echo "<br />$query\n";
84 $newid = sqlInsert($query);
92 if ($newid && !$debug) {
93 addForm($encounter, 'IPPF GCAC', $newid, 'LBFgcac', $pid, 1);
98 echo "<br />*** Empty issue skipped for visit $pid.$encounter ***\n";
104 <title
>OpenEMR IPPF Upgrade
</title
>
105 <?php Header
::setupHeader(); ?
>
108 <div
class="container mt-3">
111 <h2
>OpenEMR IPPF Upgrade
</h2
>
114 <div
class="jumbotron p-4">
116 if (!empty($_POST['form_submit'])) {
117 // If database is not utf8, convert it.
118 $trow = sqlQuery("SHOW CREATE DATABASE $dbase");
120 $value = array_shift($trow);
121 if (!preg_match('/SET utf8/', $value)) {
122 echo "<br />Converting database to UTF-8 encoding...";
123 $tres = sqlStatement("SHOW TABLES");
124 while ($trow = sqlFetchArray($tres)) {
125 $value = array_shift($trow);
126 $query = "ALTER TABLE $value CONVERT TO CHARACTER SET utf8";
128 echo "<br />$query\n";
131 sqlStatement($query);
134 $query = "ALTER DATABASE $dbase CHARACTER SET utf8";
136 echo "<br />$query\n";
139 sqlStatement($query);
140 echo "<br /> \n";
143 $ires = sqlStatement("SELECT " .
144 "l.pid, l.id, l.type, l.begdate, l.title, " .
145 "g.client_status, g.in_ab_proc, g.ab_location, " .
146 "g.rec_compl, g.contrameth, g.fol_compl " .
148 "JOIN lists_ippf_gcac AS g ON l.type = 'ippf_gcac' AND g.id = l.id " .
149 "ORDER BY l.pid, l.begdate");
151 while ($irow = sqlFetchArray($ires)) {
152 $patient_id = $irow['pid'];
153 $list_id = $irow['id'];
156 $ieres = sqlStatement("SELECT encounter " .
157 "FROM issue_encounter " .
158 "WHERE pid = '$patient_id' AND list_id = '$list_id' " .
159 "ORDER BY encounter");
161 if (sqlNumRows($ieres)) {
162 while ($ierow = sqlFetchArray($ieres)) {
163 do_visit_form($irow, $ierow['encounter'], $first);
167 echo "<br />*** Issue $list_id for pid $patient_id has no linked visits, skipped ***\n";
171 echo "<p class='text-success'>Done. Inserted $insert_count visit forms.</p>\n";
172 echo "</body></html>\n";
177 This converts your OpenEMR database to UTF
-8 encoding
if it is not already
,
178 and also converts GCAC issues to the corresponding visit forms
. Both of these
179 steps are needed
for IPPF sites upgrading from releases prior to
2009-08-27.
181 <form method
='post' action
='ippf_upgrade.php'>
182 <button
class="btn btn-primary btn-transmit" type
='submit' name
='form_submit' value
='Convert Database'>Convert Database
</button
>