-
Notifications
You must be signed in to change notification settings - Fork 1
/
PatientMed.php
91 lines (74 loc) · 2.53 KB
/
PatientMed.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
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class PatientMedList { //extends SugarBean {
var $patid;
var $medid;
var $medlist = Array();
var $db;
var $medctr = 0;
/**
* Sole constructor
*/
function PatientMedList($id) {
$this->db = DBManagerFactory::getInstance();
$this->patid = $id;
//parent::SugarBean();
}
function GetMedsDB(){
$sql = "SELECT * FROM reg_patient_med where patid = '" . $this->patid . "'";
$sql = $this->db->query($sql);
while ( ($a = $this->db->fetchByAssoc($sql)) != null) {
$this->medlist[] = Array("crud"=> "U", "medid" => $a["medid"],
"name"=>$a["name"],
"dose"=>$a["TabDose"],
"freq"=>$a["Frequency"],
"qty"=>$a["Qty"],
"desc"=>$a["description"]);
if ($a["medid"] > $this->medctr) $this->medctr = $a["medid"];
}
}
function SaveMeds() {
//foreach ($this->medlist as $a) {
// if (($a["medid"] != null) && ($a["medid"] > $this->medctr)) $this->medctr = $a["medid"];
//}
//echo "Saving...";
$this->db->query("DELETE FROM reg_patient_med WHERE patid = '$this->patid'", true);
$this->medctr = 0;
//echo "deleted";
foreach ($this->medlist as $med) {
/*if ($med["crud"] == "U") {
$sql = "UPDATE reg_patient_med SET patid='". $this->patid ."', medid='". $med["medid"] ."', name='".$med["name"]."', description='".$med["desc"]."' WHERE patid = '" .$this->patid . "' AND medid = '". $med["medid"]. "'" ;
echo $sql . "\n";
$this->db->query($sql, true);
}
if ($med["crud"] == "C") {
$this->AddMed($med["name"], $med["desc"]);
}
if ($med["crud"] == "D") {
$this->DeleteMed($med["medid"]);
}
*/
//echo "adding";
$this->AddMed($med["name"], $med["desc"], $med["dose"], $med["freq"], $med["qty"]);
}
}
function BuildList($crud, $medid, $name, $description, $dose, $qty, $freq)
{
$this->medlist[] = Array("crud"=>$crud, "medid" => $medid, "name"=>$name, "desc"=>$description, "dose"=>$dose, "qty"=>$qty, "freq"=>$freq);
}
function AddMed($name, $description, $dose, $qty, $freq)
{
$this->medctr++;
$sql = "INSERT INTO reg_patient_med(patid, medid,name, description, TabDose, Qty, Frequency)
VALUES('$this->patid', '$this->medctr', '$name', '$description', '$dose', '$qty', '$freq')";
echo $sql . "\n";
$this->db->query($sql, true);
}
function DeleteMed($medid) {
//delete
$sql = "DELETE FROM reg_patient_med WHERE patid = '$this->patid' AND medid = '$medid'";
echo $sql . "\n";
$this->db->query($sql, true);
}
}
?>