Smart fhir admin enable / disable management (#4142)
[openemr.git] / ippf_upgrade.php
blobbb82ceafd1871168214d9fdedbd2317fa7ca5993
1 <?php
3 // Copyright (C) 2009 Rod Roark <rod@sunsetsystems.com>
4 //
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');
18 use OpenEMR\Core\Header;
20 $verbose = 0;
21 $debug = 0;
22 $insert_count = 0;
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;
31 $pid = $irow['pid'];
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");
37 if ($row['count']) {
38 echo "<br />*** Visit $pid.$encounter skipped, already has a GCAC visit form ***\n";
39 return;
42 $a = array(
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
51 if ($first) {
52 if ($a['ab_location'] == 'ma') {
53 $a['ab_location'] = 'proc';
56 $a['complications'] = $irow['rec_compl'];
57 $a['contrameth'] = '';
60 $newid = 0;
61 $didone = false;
62 foreach ($a as $field_id => $value) {
63 if ($value !== '') {
64 if ($newid) {
65 $query = "INSERT INTO lbf_data " .
66 "( form_id, field_id, field_value ) " .
67 " VALUES ( '$newid', '$field_id', '$value' )";
68 if ($verbose) {
69 echo "<br />$query\n";
72 if (!$debug) {
73 sqlStatement($query);
75 } else {
76 $query = "INSERT INTO lbf_data " .
77 "( field_id, field_value ) " .
78 " VALUES ( '$field_id', '$value' )";
79 if ($verbose) {
80 echo "<br />$query\n";
83 if (!$debug) {
84 $newid = sqlInsert($query);
88 $didone = true;
92 if ($newid && !$debug) {
93 addForm($encounter, 'IPPF GCAC', $newid, 'LBFgcac', $pid, 1);
94 ++$insert_count;
97 if (!$didone) {
98 echo "<br />*** Empty issue skipped for visit $pid.$encounter ***\n";
102 <html>
103 <head>
104 <title>OpenEMR IPPF Upgrade</title>
105 <?php Header::setupHeader(); ?>
106 </head>
107 <body>
108 <div class="container mt-3">
109 <div class="row">
110 <div class="col-12">
111 <h2>OpenEMR IPPF Upgrade</h2>
112 </div>
113 </div>
114 <div class="jumbotron p-4">
115 <?php
116 if (!empty($_POST['form_submit'])) {
117 // If database is not utf8, convert it.
118 $trow = sqlQuery("SHOW CREATE DATABASE $dbase");
119 array_shift($trow);
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";
127 if ($verbose) {
128 echo "<br />$query\n";
131 sqlStatement($query);
134 $query = "ALTER DATABASE $dbase CHARACTER SET utf8";
135 if ($verbose) {
136 echo "<br />$query\n";
139 sqlStatement($query);
140 echo "<br />&nbsp;\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 " .
147 "FROM lists AS l " .
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'];
154 $first = true;
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);
164 $first = false;
166 } else {
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";
173 exit();
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.
180 </p>
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>
183 </form>
184 </div>
185 </div>
186 </body>
187 </html>