Bug fix to add appt with multi provider feature (note Find Available appt is not...
[openemr.git] / library / classes / Note.class.php
blob99e1ed9683a1209f76e5437bf7d322b2f59b0360
1 <?php
3 require_once(dirname(__FILE__) . "/ORDataObject.class.php");
5 /**
6 * class Note
7 * This class offers functionality to store sequential comments/notes about an external object or anything with a unique id.
8 * It is not intended that once a note is save it can be editied or changed.
9 */
11 class Note extends ORDataObject{
14 * Database unique identifier
15 * @var id
17 var $id;
20 * DB unique identifier reference to some other table, this is not unique in the notes table
21 * @var int
23 var $foreign_id;
26 * Narrative comments about whatever object is represented by the foreign id this note is associated with
27 * @var string upto 255 character string
29 var $note;
32 * Foreign key identifier of who initially persisited the note,
33 * potentially ownership could be changed but that would be up to an external non-document object process
34 * @var int
36 var $owner;
39 * Date the note was first persisted
40 * @var date
42 var $date;
45 * Timestamp of the last time the note was changed and persisted, auto maintained by DB, manually change at your own peril
46 * @var int
48 var $revision;
50 /**
51 * Constructor sets all Note attributes to their default value
52 * @param int $id optional existing id of a specific note, if omitted a "blank" note is created
54 function Note($id = "") {
55 //call the parent constructor so we have a _db to work with
56 parent::ORDataObject();
58 //shore up the most basic ORDataObject bits
59 $this->id = $id;
60 $this->_table = "notes";
62 $this->note = "";
63 $this->date = date("Y-m-d H:i:s");
65 if ($id != "") {
66 $this->populate();
70 /**
71 * Convenience function to get an array of many document objects
72 * For really large numbers of documents there is a way more efficient way to do this by overwriting the populate method
73 * @param int $foreign_id optional id use to limit array on to a specific relation, otherwise every document object is returned
75 function notes_factory($foreign_id = "") {
76 $notes = array();
78 if (empty($foreign_id)) {
79 $foreign_id= "like '%'";
81 else {
82 $foreign_id= " = '" . mysql_real_escape_string(strval($foreign_id)) . "'";
85 $d = new note();
86 $sql = "SELECT id FROM " . $d->_table . " WHERE foreign_id " .$foreign_id . " ORDER BY DATE DESC";
87 //echo $sql;
88 $result = $d->_db->Execute($sql);
90 while ($result && !$result->EOF) {
91 $notes[] = new Note($result->fields['id']);
92 $result->MoveNext();
95 return $notes;
98 /**
99 * Convenience function to generate string debug data about the object
101 function toString($html = false) {
102 $string .= "\n"
103 . "ID: " . $this->id."\n"
104 . "FID: " . $this->foreign_id."\n"
105 . "note: " . $this->note . "\n"
106 . "date: " . $this->date . "\n"
107 . "owner: " . $this->owner . "\n"
108 . "revision: " . $this->revision. "\n";
110 if ($html) {
111 return nl2br($string);
113 else {
114 return $string;
118 /**#@+
119 * Getter/Setter methods used by reflection to affect object in persist/poulate operations
120 * @param mixed new value for given attribute
122 function set_id($id) {
123 $this->id = $id;
125 function get_id() {
126 return $this->id;
128 function set_foreign_id($fid) {
129 $this->foreign_id = $fid;
131 function get_foreign_id() {
132 return $this->foreign_id;
134 function set_note($note) {
135 $this->note = $note;
137 function get_note() {
138 return $this->note;
140 function set_date($date) {
141 $this->date = $date;
143 function get_date() {
144 return $this->date;
146 function set_owner($owner) {
147 $this->owner = $owner;
149 function get_owner() {
150 return $this->owner;
153 * No getter for revision because it is updated automatically by the DB.
155 function set_revision($revision) {
156 $this->revision = $revision;
160 * Overridden function to store current object state in the db.
161 * This overide is to allow for a "just in time" foreign id, often this is needed
162 * when the object is never directly exposed and is handled as part of a larger
163 * object hierarchy.
164 * @param int $fid foreign id that should be used so that this note can be related (joined) on it later
167 function persist($fid ="") {
168 if (!empty($fid)) {
169 $this->foreign_id = $fid;
171 parent::persist();
174 } // end of Note