forked from smuwanga/ViralLoad
/
tpl.samples.patients.modify.php
295 lines (279 loc) · 14 KB
/
tpl.samples.patients.modify.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?
//security check
if(!$GLOBALS['vlDC'] || !$_SESSION["VLEMAIL"]) {
die("<font face=arial size=2>You must be logged in to view this page.</font>");
}
//validation
$modify=validate($modify);
$artNumber=validate($artNumber);
//clean art number by removing - . / and spaces
//$artNumber=preg_replace("/\-/s","",$artNumber);
//$artNumber=preg_replace("/\./s","",$artNumber);
//$artNumber=preg_replace("/\//s","",$artNumber);
//$artNumber=preg_replace("/\s/s","",$artNumber);
$otherID=validate($otherID);
$gender=validate($gender);
$dateOfBirthDay=validate($dateOfBirthDay);
$dateOfBirthMonth=validate($dateOfBirthMonth);
$dateOfBirthYear=validate($dateOfBirthYear);
$patientPhone=validate($patientPhone);
if($savePatient) {
//validate data
$error=0;
$error=checkFormFields("Gender::$gender");
//is both ART and Other ID Number are missing
if(!$artNumber && !$otherID) {
$error.="<br /><strong>ART Number is Missing</strong><br />Kindly provide an ART Number<br />";
}
//date of birth missing?
/* 7/Sept/15
* Request from vbigira@clintonhealthaccess.org
* Just got another urgent request from CPHL: They would like the VL database to have an additional entry for patients
* whose date of birth or age is not given by the facility. This was initially a 'must-have' option but with massive
* numbers of forms returning without this information, they would like to have the option of leaving it as a "Left blank".
* This can be put after the age variable.
if(!$dateOfBirthDay || !$dateOfBirthMonth || !$dateOfBirthYear) {
$error.="<br /><strong>Date of Birth Missing</strong><br />Kindly provide the Date of Birth<br />";
}
*/
//is both date of birth and age in years/months missing?
$dateOfBirth=0;
if($dateOfBirthYear && $dateOfBirthMonth && $dateOfBirthDay) {
$dateOfBirth="$dateOfBirthYear-$dateOfBirthMonth-$dateOfBirthDay";
}
//input data
if(!$error) {
//log changes
logTableChange("vl_patients","artNumber",$modify,getDetailedTableInfo2("vl_patients","id='$modify'","artNumber"),$artNumber);
logTableChange("vl_patients","otherID",$modify,getDetailedTableInfo2("vl_patients","id='$modify'","otherID"),$otherID);
logTableChange("vl_patients","gender",$modify,getDetailedTableInfo2("vl_patients","id='$modify'","gender"),$gender);
if(!$noDateOfBirthSupplied) { logTableChange("vl_patients","dateOfBirth",$modify,getDetailedTableInfo2("vl_patients","id='$modify'","dateOfBirth"),$dateOfBirth); }
mysqlquery("update vl_patients set
artNumber='$artNumber',
otherID='$otherID',
".(!$noDateOfBirthSupplied?"dateOfBirth='$dateOfBirth', ":"dateOfBirth='', ")."
gender='$gender'
where
id='$modify'");
//log patient phone number, if unique
if($patientPhone) {
$phoneID=0;
$phoneID=getDetailedTableInfo2("vl_patients_phone","patientID='$modify' and phone='$patientPhone' limit 1","id");
if(!$phoneID) {
mysqlquery("insert into vl_patients_phone
(patientID,phone,created,createdby)
values
('$modify','$patientPhone','$datetime','$trailSessionUser')");
} else {
//log this change
logTableChange("vl_patients_phone","created",$phoneID,getDetailedTableInfo2("vl_patients_phone","id='$phoneID'","created"),$datetime);
mysqlquery("update vl_patients_phone set created='$datetime' where id='$phoneID'");
}
}
//redirect to home with updates on the tracking number
go("/samples/modified/");
}
} else {
//prepopulate
$artNumber=0;
$artNumber=getDetailedTableInfo2("vl_patients","id='$modify' limit 1","artNumber");
$otherID=0;
$otherID=getDetailedTableInfo2("vl_patients","id='$modify' limit 1","otherID");
$gender=0;
$gender=getDetailedTableInfo2("vl_patients","id='$modify' limit 1","gender");
$dateOfBirth=0;
$dateOfBirth=getDetailedTableInfo2("vl_patients","id='$modify' limit 1","dateOfBirth");
if(!isDateAuthentic($dateOfBirth)) {
$noDateOfBirthSupplied=1;
} else {
$noDateOfBirthSupplied=0;
}
$patientPhone=0;
$patientPhone=getDetailedTableInfo2("vl_patients_phone","patientID='$modify' order by created desc limit 1","phone");
}
?>
<script Language="JavaScript" Type="text/javascript">
<!--
function validate(envelopes) {
//check for missing information
if(!document.samples.artNumber.value && !document.samples.otherID.value) {
alert('Missing Mandatory Field: ART Number');
document.samples.artNumber.focus();
return (false);
}
if(!document.samples.gender.value) {
alert('Missing Mandatory Field: Gender');
document.samples.gender.focus();
return (false);
}
/*
if((!document.samples.dateOfBirthDay.value || !document.samples.dateOfBirthMonth.value || !document.samples.dateOfBirthYear.value) && (!document.samples.dateOfBirthAge.value || !document.samples.dateOfBirthIn.value)) {
alert('Missing Mandatory Field: Date of Birth or Patient Age');
document.samples.dateOfBirthDay.focus();
return (false);
}
*/
return (true);
}
function checkMonthDay(theField) {
if(theField.value && !document.samples.dateOfBirthMonth.value && !document.samples.dateOfBirthDay.value) {
//default to first day/month
document.samples.dateOfBirthDay.value="01";
document.samples.dateOfBirthMonth.value="01"
}
}
function disableEnableDateOfBirth(checkedObject) {
if(checkedObject.checked==true) {
//has been checked
document.samples.dateOfBirthYear.disabled=true;
document.samples.dateOfBirthMonth.disabled=true;
document.samples.dateOfBirthDay.disabled=true;
} else if(checkedObject.checked==false) {
//has been unchecked
document.samples.dateOfBirthYear.disabled=false;
document.samples.dateOfBirthMonth.disabled=false;
document.samples.dateOfBirthDay.disabled=false;
}
}
//-->
</script>
<!--<form name="samples" method="post" action="/samples/manage.patients/modify/<?=$modify?>/" onsubmit="return validate(this)">-->
<form name="samples" method="post" action="/samples/manage.patients/modify/<?=$modify?>/">
<table width="100%" border="0" class="vl">
<? if($success) { ?>
<tr>
<td class="vl_success">Data Captured Successfully!</td>
</tr>
<tr>
<td> </td>
</tr>
<? } elseif($error) { ?>
<tr>
<td class="vl_error"><?=$error?></td>
</tr>
<tr>
<td> </td>
</tr>
<? } ?>
<tr>
<td class="toplinks" style="padding:0px 0px 10px 0px"><a class="toplinks" href="/dashboard/">HOME</a> <a class="toplinks" href="/samples/">SAMPLES</a> <a class="toplinks" href="/samples/manage.patients/">Patients</a></td>
</tr>
<tr>
<td><strong>Modify Patient's Information</strong></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<fieldset style="width: 100%">
<legend><strong>PATIENT INFORMATION</strong></legend>
<div style="padding:5px 0px 0px 0px">
<table width="100%" border="0" class="vl">
<tr>
<td width="20%">ART Number <font class="vl_red">*</font></td>
<td width="80%"><input type="text" name="artNumber" id="artNumber" value="<?=$artNumber?>" class="search_pre" size="25" maxlength="20" /></td>
</tr>
<tr>
<td>Other ID</td>
<td><input type="text" name="otherID" id="otherID" value="<?=$otherID?>" class="search_pre" size="25" maxlength="50" /></td>
</tr>
<tr>
<td>Gender <font class="vl_red">*</font></td>
<td>
<select name="gender" id="gender" class="search" onchange="checkGender(this)">
<?
if($gender) {
echo "<option value=\"$gender\" selected=\"selected\">$gender</option>";
} else {
echo "<option value=\"\" selected=\"selected\">Select Gender</option>";
}
?>
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Missing Gender">Missing Gender</option>
</select>
</td>
</tr>
<tr>
<td>Date of Birth</td>
<td>
<table width="10%" border="0" cellspacing="0" cellpadding="0" class="vl">
<tr>
<td><select name="dateOfBirthDay" id="dateOfBirthDay" class="search" <?=($noDateOfBirthSupplied?"disabled=\"disabled\"":"")?>>
<?
if($dateOfBirth) {
echo "<option value=\"".getFormattedDateDay($dateOfBirth)."\" selected=\"selected\">".getFormattedDateDay($dateOfBirth)."</option>";
} else {
echo "<option value=\"\" selected=\"selected\">Select Date</option>";
}
for($j=1;$j<=31;$j++) {
echo "<option value=\"".($j<10?"0$j":$j)."\">$j</option>";
}
?>
</select></td>
<td style="padding:0px 0px 0px 5px"><select name="dateOfBirthMonth" id="dateOfBirthMonth" class="search" <?=($noDateOfBirthSupplied?"disabled=\"disabled\"":"")?>>
<?
if($dateOfBirth) {
echo "<option value=\"".getFormattedDateMonth($dateOfBirth)."\" selected=\"selected\">".getFormattedDateMonthname($dateOfBirth)."</option>";
} else {
echo "<option value=\"\" selected=\"selected\">Select Month</option>";
}
?>
<option value="01">Jan</option>
<option value="02">Feb</option>
<option value="03">Mar</option>
<option value="04">Apr</option>
<option value="05">May</option>
<option value="06">Jun</option>
<option value="07">Jul</option>
<option value="08">Aug</option>
<option value="09">Sept</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select></td>
<td style="padding:0px 0px 0px 5px"><select name="dateOfBirthYear" id="dateOfBirthYear" class="search" onchange="checkMonthDay(this)" <?=($noDateOfBirthSupplied?"disabled=\"disabled\"":"")?>>
<?
if($dateOfBirth) {
echo "<option value=\"".getFormattedDateYear($dateOfBirth)."\" selected=\"selected\">".getFormattedDateYear($dateOfBirth)."</option>";
} else {
echo "<option value=\"\" selected=\"selected\">Select Year</option>";
}
for($j=getFormattedDateYear(getDualInfoWithAlias("last_day(now())","lastmonth"));$j>=(getCurrentYear()-100);$j--) {
echo "<option value=\"$j\">$j</option>";
}
?>
</select></td>
<td style="padding:0px 0px 0px 5px">or</td>
<td style="padding:0px 0px 0px 5px"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="vl">
<tr>
<td width="1%"><input name="noDateOfBirthSupplied" type="checkbox" id="noDateOfBirthSupplied" value="1" onclick="disableEnableDateOfBirth(this);" <?=($noDateOfBirthSupplied?"checked=\"checked\"":"")?> /></td>
<td width="99%" style="padding:0px 0px 0px 5px">No date of birth supplied</td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Patient Phone</td>
<td><table width="10%" border="0" cellspacing="0" cellpadding="0" class="vl">
<tr>
<td><input type="text" name="patientPhone" id="patientPhone" value="<?=$patientPhone?>" class="search_pre" size="15" maxlength="20" /></td>
</tr>
</table></td>
</tr>
</table>
</div>
</fieldset>
</td>
</tr>
<tr>
<td style="padding:10px 0px 0px 0px"><input type="submit" name="savePatient" id="savePatient" class="button" value=" Save Changes to Patient " /></td>
</tr>
<tr>
<td style="padding:20px 0px 0px 0px"><a href="/samples/">Return to Samples</a> :: <a href="/dashboard/">Return to Dashboard</a></td>
</tr>
</table>
</form>