-
Notifications
You must be signed in to change notification settings - Fork 0
/
prescriptionrecord.php
309 lines (292 loc) · 9.15 KB
/
prescriptionrecord.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
include("adheader.php");
include("dbconnection.php");
if(isset($_GET['delid']))
{
$sql ="DELETE FROM prescription_records WHERE prescription_record_id='$_GET[delid]'";
$qsql=mysqli_query($con,$sql);
if(mysqli_affected_rows($con) == 1)
{
echo "<script>window.location='prescriptionrecord.php?prescriptionid=$_GET[prescriptionid]';</script>";
echo "<script>alert('prescription deleted successfully..');</script>";
}
}
if(isset($_POST['submit']))
{
if(isset($_GET['editid']))
{
$sql ="UPDATE prescription_records SET prescription_id='$_POST[prescriptionid]',medicine_name='$_POST[medicine]',cost='$_POST[cost]',unit='$_POST[unit]',dosage='$_POST[select2]',status=' $_POST[select]' WHERE prescription_record_id='$_GET[editid]'";
if($qsql = mysqli_query($con,$sql))
{
echo "<script>alert('prescription record updated successfully...');</script>";
}
else
{
echo mysqli_error($con);
}
}
else
{
$sql ="INSERT INTO prescription_records(prescription_id,medicine_name,cost,unit,dosage,status) values('$_POST[prescriptionid]','$_POST[medicineid]','$_POST[cost]','$_POST[unit]','$_POST[select2]','Active')";
if($qsql = mysqli_query($con,$sql))
{
$presamt=$_POST['cost']*$_POST['unit'];
$billtype = "Prescription update";
$prescriptionid= $_POST['prescriptionid'];
include("insertbillingrecord.php");
echo "<script>alert('prescription record inserted successfully...');</script>";
echo "<script>window.location='prescriptionrecord.php?prescriptionid=$_GET[prescriptionid]&patientid=$_GET[patientid]&appid=$_GET[appid]';</script>";
}
else
{
echo mysqli_error($con);
}
}
}
if(isset($_GET['editid']))
{
$sql="SELECT * FROM prescription_records WHERE prescription_record_id='$_GET[editid]' ";
$qsql = mysqli_query($con,$sql);
$rsedit = mysqli_fetch_array($qsql);
}
?>
<div class="container-fluid">
<div class="block-header"><h2>Add New Prescription Record</h2></div>
<div class="card" style="padding:10px">
<table class="table table-bordered table-striped">
<tbody>
<tr>
<td><strong>Doctor</strong></td>
<td><strong>Patient</strong></td>
<td><strong>Prescription Date</strong></td>
<td><strong>Status</strong></td>
</tr>
<?php
$sql ="SELECT * FROM prescription WHERE prescriptionid='$_GET[prescriptionid]'";
$qsql = mysqli_query($con,$sql);
while($rs = mysqli_fetch_array($qsql))
{
$sqlpatient = "SELECT * FROM patient WHERE patientid='$rs[patientid]'";
$qsqlpatient = mysqli_query($con,$sqlpatient);
$rspatient = mysqli_fetch_array($qsqlpatient);
$sqldoctor = "SELECT * FROM doctor WHERE doctorid='$rs[doctorid]'";
$qsqldoctor = mysqli_query($con,$sqldoctor);
$rsdoctor = mysqli_fetch_array($qsqldoctor);
echo "<tr>
<td> $rsdoctor[doctorname]</td>
<td> $rspatient[patientname]</td>
<td> $rs[prescriptiondate]</td>
<td> $rs[status]</td>
</tr>";
}
?>
</tbody>
</table>
</div>
<div class="card" style="padding:10px">
<?php
if(!isset($_SESSION['patientid']))
{
?>
<form method="post" action="" name="frmpresrecord" onSubmit="return validateform()">
<input type="hidden" name="prescriptionid" value="<?php echo $_GET['prescriptionid']; ?>" />
<table class="table table-striped">
<tbody>
<tr>
<td width="34%">Medicine</td>
<td width="66%">
<select class="form-control show-tick" name="medicineid" id="medicineid" onchange="loadmedicine(this.value)">
<option value="">Select Medicine</option>
<?php
$sqlmedicine ="SELECT * FROM medicine WHERE status='Active'";
$qsqlmedicine = mysqli_query($con,$sqlmedicine);
while($rsmedicine = mysqli_fetch_array($qsqlmedicine))
{
echo "<option value='$rsmedicine[medicineid]'>$rsmedicine[medicinename] ( ₹ $rsmedicine[medicinecost] )</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Cost</td>
<td><input class="form-control" type="text" name="cost" id="cost" value="<?php echo $rsmedicine['medicinecost']; ?>" readonly style="background-color:pink;" /></td>
</tr>
<tr>
<td>Unit</td>
<td><input class="form-control" type="number" min="1" name="unit" id="unit" value="<?php echo $rsedit['unit']; ?>" onkeyup="calctotalcost(cost.value,this.value)" onchange="" /></td>
</tr>
<tr>
<td>Total Cost</td>
<td><input class="form-control" type="text" name="totcost" id="totcost" value="<?php echo $rsedit['cost']; ?>" readonly style="background-color:pink;" /></td>
</tr>
<tr>
<td>Dosage</td>
<td><select class="form-control show-tick" name="select2" id="select2">
<option value="">Select</option>
<?php
$arr = array("0-0-1","0-1-1","1-0-1","1-1-1","1-1-0","0-1-0","1-0-0");
foreach($arr as $val)
{
if($val == $rsedit['dosage'])
{
echo "<option value='$val' selected>$val</option>";
}
else
{
echo "<option value='$val'>$val</option>";
}
}
?>
</select></td>
</tr>
<tr>
<td colspan="2" align="center"><input class="btn btn-default" type="submit" name="submit" id="submit" value="Submit" /> </td>
</tr>
</tbody>
</table>
</form>
<?php
}
?>
</div>
<div class="block-header"><h2>View Prescription record</h2></div>
<div class="card" style="padding:10px">
<table class="table table-hover table-striped">
<tbody>
<tr>
<td><strong>Medicine</strong></td>
<td><strong>Dosage</strong></td>
<td><strong>Cost</strong></td>
<td><strong>Unit</strong></td>
<td><strong>Total</strong></td>
<?php
if(!isset($_SESSION['patientid']))
{
?>
<td><strong>Action</strong></td>
<?php
}
?>
</tr>
<?php
$gtotal=0;
$sql ="SELECT * FROM prescription_records LEFT JOIN medicine on prescription_records.medicine_name=medicine.medicineid WHERE prescription_id='$_GET[prescriptionid]'";
$qsql = mysqli_query($con,$sql);
while($rs = mysqli_fetch_array($qsql))
{
echo "<tr>
<td> $rs[medicinename]</td>
<td> $rs[dosage]</td>
<td> ₹$rs[cost]</td>
<td> $rs[unit]</td>
<td >₹" . $rs['cost'] * $rs['unit'] . "</td>";
if(!isset($_SESSION['patientid']))
{
echo " <td> <a href='prescriptionrecord.php?delid=$rs[prescription_record_id]&prescriptionid=$_GET[prescriptionid]'>Delete</a> </td>";
}
echo "</tr>";
$gtotal = $gtotal+($rs['cost'] * $rs['unit']);
}
?>
<tr>
<th colspan="4" align="right">Grand Total </th>
<th align="right">₹<?php echo $gtotal; ?></th>
<td></td>
</tr>
<tr>
<td colspan="6"><div align="center">
<input Class="btn btn-default" type="submit" name="print" id="print" value="Print" onclick="myFunction()"/>
</div></td>
</tr>
</tbody>
</table>
<table>
<tr><td>
<center><a href='patientreport.php?patientid=<?php echo $_GET['patientid']; ?>&appointmentid=<?php echo $_GET['appid']; ?>'><strong>View Patient Report>></strong></a></center>
</td></tr>
</table>
<script>
function myFunction() {
window.print();
}
</script>
<p> </p>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
<?php
include("adfooter.php");
?>
<script type="application/javascript">
function loadmedicine(medicineid)
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("totcost").value = this.responseText;
document.getElementById("cost").value = this.responseText;
document.getElementById("unit").value = 1;
}
};
xmlhttp.open("GET","ajaxmedicine.php?medicineid="+medicineid,true);
xmlhttp.send();
}
function calctotalcost(cost,qty)
{
document.getElementById("totcost").value = parseFloat(cost) * parseFloat(qty);
}
function validateform()
{
if(document.frmpresrecord.prescriptionid.value == "")
{
alert("Prescription id should not be empty..");
document.frmpresrecord.prescriptionid.focus();
return false;
}
else if(document.frmpresrecord.medicine.value == "")
{
alert("Medicine field should not be empty..");
document.frmpresrecord.medicine.focus();
return false;
}
else if(document.frmpresrecord.cost.value == "")
{
alert("Cost should not be empty..");
document.frmpresrecord.cost.focus();
return false;
}
else if(document.frmpresrecord.unit.value == "")
{
alert("Unit should not be empty..");
document.frmpresrecord.unit.focus();
return false;
}
else if(document.frmpresrecord.select2.value == "")
{
alert("Dosage should not be empty..");
document.frmpresrecord.select2.focus();
return false;
}
else if(document.frmpresrecord.select.value == "" )
{
alert("Kindly select the status..");
document.frmpresrecord.select.focus();
return false;
}
else
{
return true;
}
}
</script>