Added a provider filter to Procedures / Electronic Reports.
[openemr.git] / ippf_upgrade.php
blob5445ba10a4c5acd3742a7be6a5dd1f58b10ab49e
1 <?php
2 // Copyright (C) 2009 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 // 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');
18 $verbose = 0;
19 $debug = 0;
20 $insert_count = 0;
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;
28 $pid = $irow['pid'];
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");
34 if ($row['count']) {
35 echo "<br />*** Visit $pid.$encounter skipped, already has a GCAC visit form ***\n";
36 return;
39 $a = array(
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
48 if ($first) {
49 if ($a['ab_location'] == 'ma') $a['ab_location'] = 'proc';
50 $a['complications'] = $irow['rec_compl'];
51 $a['contrameth'] = '';
54 $newid = 0;
55 $didone = false;
56 foreach ($a as $field_id => $value) {
57 if ($value !== '') {
58 if ($newid) {
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);
65 else {
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);
72 $didone = true;
76 if ($newid && !$debug) {
77 addForm($encounter, 'IPPF GCAC', $newid, 'LBFgcac', $pid, 1);
78 ++$insert_count;
81 if (!$didone) echo "<br />*** Empty issue skipped for visit $pid.$encounter ***\n";
84 <html>
85 <head>
86 <title>OpenEMR IPPF Upgrade</title>
87 <link rel='STYLESHEET' href='interface/themes/style_blue.css'>
88 </head>
89 <body>
90 <center>
91 <span class='title'>OpenEMR IPPF Upgrade</span>
92 <br>
93 </center>
94 <?php
95 if (!empty($_POST['form_submit'])) {
97 // If database is not utf8, convert it.
98 $trow = sqlQuery("SHOW CREATE DATABASE $dbase");
99 array_shift($trow);
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 />&nbsp;\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 " .
120 "FROM lists AS l " .
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'];
127 $first = true;
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);
137 $first = false;
140 else {
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";
147 exit();
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>
154 <center>
155 <form method='post' action='ippf_upgrade.php'>
156 <p><input type='submit' name='form_submit' value='Convert Database' /></p>
157 </form>
158 </center>
159 </body>
160 </html>