forked from bradymiller/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ippf_upgrade.php
187 lines (161 loc) · 6.18 KB
/
ippf_upgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
// Copyright (C) 2009 Rod Roark <rod@sunsetsystems.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// Disable PHP timeout. This will not work in safe mode.
ini_set('max_execution_time', '0');
$ignoreAuth = true; // no login required
require_once('interface/globals.php');
require_once('library/forms.inc.php');
use OpenEMR\Core\Header;
$verbose = 0;
$debug = 0;
$insert_count = 0;
// Create a visit form from an abortion issue. This may be called
// multiple times for a given issue.
//
function do_visit_form($irow, $encounter, $first)
{
global $insert_count, $debug, $verbose;
$pid = $irow['pid'];
// If a gcac form already exists for this visit, get out.
$row = sqlQuery("SELECT COUNT(*) AS count FROM forms WHERE " .
"pid = '$pid' AND encounter = '$encounter' AND " .
"formdir = 'LBFgcac' AND deleted = 0");
if ($row['count']) {
echo "<br />*** Visit $pid.$encounter skipped, already has a GCAC visit form ***\n";
return;
}
$a = array(
'client_status' => $irow['client_status'],
'in_ab_proc' => $irow['in_ab_proc'],
'ab_location' => $irow['ab_location'],
'complications' => $irow['fol_compl'],
'contrameth' => $irow['contrameth'],
);
// logic that applies only to the first related visit
if ($first) {
if ($a['ab_location'] == 'ma') {
$a['ab_location'] = 'proc';
}
$a['complications'] = $irow['rec_compl'];
$a['contrameth'] = '';
}
$newid = 0;
$didone = false;
foreach ($a as $field_id => $value) {
if ($value !== '') {
if ($newid) {
$query = "INSERT INTO lbf_data " .
"( form_id, field_id, field_value ) " .
" VALUES ( '$newid', '$field_id', '$value' )";
if ($verbose) {
echo "<br />$query\n";
}
if (!$debug) {
sqlStatement($query);
}
} else {
$query = "INSERT INTO lbf_data " .
"( field_id, field_value ) " .
" VALUES ( '$field_id', '$value' )";
if ($verbose) {
echo "<br />$query\n";
}
if (!$debug) {
$newid = sqlInsert($query);
}
}
$didone = true;
}
}
if ($newid && !$debug) {
addForm($encounter, 'IPPF GCAC', $newid, 'LBFgcac', $pid, 1);
++$insert_count;
}
if (!$didone) {
echo "<br />*** Empty issue skipped for visit $pid.$encounter ***\n";
}
}
?>
<html>
<head>
<title>OpenEMR IPPF Upgrade</title>
<?php Header::setupHeader(); ?>
</head>
<body>
<div class="container mt-3">
<div class="row">
<div class="col-12">
<h2>OpenEMR IPPF Upgrade</h2>
</div>
</div>
<div class="jumbotron p-4">
<?php
if (!empty($_POST['form_submit'])) {
// If database is not utf8, convert it.
$trow = sqlQuery("SHOW CREATE DATABASE $dbase");
array_shift($trow);
$value = array_shift($trow);
if (!preg_match('/SET utf8/', $value)) {
echo "<br />Converting database to UTF-8 encoding...";
$tres = sqlStatement("SHOW TABLES");
while ($trow = sqlFetchArray($tres)) {
$value = array_shift($trow);
$query = "ALTER TABLE $value CONVERT TO CHARACTER SET utf8";
if ($verbose) {
echo "<br />$query\n";
}
sqlStatement($query);
}
$query = "ALTER DATABASE $dbase CHARACTER SET utf8";
if ($verbose) {
echo "<br />$query\n";
}
sqlStatement($query);
echo "<br /> \n";
}
$ires = sqlStatement("SELECT " .
"l.pid, l.id, l.type, l.begdate, l.title, " .
"g.client_status, g.in_ab_proc, g.ab_location, " .
"g.rec_compl, g.contrameth, g.fol_compl " .
"FROM lists AS l " .
"JOIN lists_ippf_gcac AS g ON l.type = 'ippf_gcac' AND g.id = l.id " .
"ORDER BY l.pid, l.begdate");
while ($irow = sqlFetchArray($ires)) {
$patient_id = $irow['pid'];
$list_id = $irow['id'];
$first = true;
$ieres = sqlStatement("SELECT encounter " .
"FROM issue_encounter " .
"WHERE pid = '$patient_id' AND list_id = '$list_id' " .
"ORDER BY encounter");
if (sqlNumRows($ieres)) {
while ($ierow = sqlFetchArray($ieres)) {
do_visit_form($irow, $ierow['encounter'], $first);
$first = false;
}
} else {
echo "<br />*** Issue $list_id for pid $patient_id has no linked visits, skipped ***\n";
}
}
echo "<p class='text-success'>Done. Inserted $insert_count visit forms.</p>\n";
echo "</body></html>\n";
exit();
}
?>
<p>
This converts your OpenEMR database to UTF-8 encoding if it is not already,
and also converts GCAC issues to the corresponding visit forms. Both of these
steps are needed for IPPF sites upgrading from releases prior to 2009-08-27.
</p>
<form method='post' action='ippf_upgrade.php'>
<button class="btn btn-primary btn-transmit" type='submit' name='form_submit' value='Convert Database'>Convert Database</button>
</form>
</div>
</div>
</body>
</html>