5 * This class offers functionality to store sequential comments/notes about an external object or anything with a unique id.
6 * It is not intended that once a note is save it can be editied or changed.
9 use OpenEMR\Common\ORDataObject\ORDataObject
;
11 class Note
extends ORDataObject
14 * Database unique identifier
20 * DB unique identifier reference to some other table, this is not unique in the notes table
26 * Narrative comments about whatever object is represented by the foreign id this note is associated with
27 * @var string upto 255 character string
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
39 * Date the note was first persisted
45 * Timestamp of the last time the note was changed and persisted, auto maintained by DB, manually change at your own peril
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 __construct($id = "")
56 //call the parent constructor so we have a _db to work with
57 parent
::__construct();
59 //shore up the most basic ORDataObject bits
61 $this->_table
= "notes";
64 $this->date
= date("Y-m-d H:i:s");
72 * Convenience function to get an array of many document objects
73 * For really large numbers of documents there is a way more efficient way to do this by overwriting the populate method
74 * @param int $foreign_id optional id use to limit array on to a specific relation, otherwise every document object is returned
76 public static function notes_factory($foreign_id = "")
82 if (empty($foreign_id)) {
83 $foreign_id_sql = " like '%'";
85 $foreign_id_sql = " = ?";
86 $sqlArray[] = strval($foreign_id);
90 $sql = "SELECT id FROM " . escape_table_name($d->_table
) . " WHERE foreign_id " . $foreign_id_sql . " ORDER BY DATE DESC";
92 $result = $d->_db
->Execute($sql, $sqlArray);
94 while ($result && !$result->EOF
) {
95 $notes[] = new Note($result->fields
['id']);
102 public function getOwnerName()
104 if (!empty($this->owner
)) {
105 $user_info = sqlQuery("SELECT `fname`, `lname` FROM `users` where `id`=?", [$this->owner
]);
106 if (!empty($user_info)) {
107 return ($user_info['fname'] . " " . $user_info['lname']);
113 * Convenience function to generate string debug data about the object
115 function toString($html = false)
118 . "ID: " . $this->id
. "\n"
119 . "FID: " . $this->foreign_id
. "\n"
120 . "note: " . $this->note
. "\n"
121 . "date: " . $this->date
. "\n"
122 . "owner: " . $this->owner
. "\n"
123 . "revision: " . $this->revision
. "\n";
126 return nl2br($string);
133 * Getter/Setter methods used by reflection to affect object in persist/poulate operations
134 * @param mixed new value for given attribute
144 function set_foreign_id($fid)
146 $this->foreign_id
= $fid;
148 function get_foreign_id()
150 return $this->foreign_id
;
152 function set_note($note)
160 function set_date($date)
168 function set_owner($owner)
170 $this->owner
= $owner;
177 * No getter for revision because it is updated automatically by the DB.
179 function set_revision($revision)
181 $this->revision
= $revision;
185 * Overridden function to store current object state in the db.
186 * This overide is to allow for a "just in time" foreign id, often this is needed
187 * when the object is never directly exposed and is handled as part of a larger
189 * @param int $fid foreign id that should be used so that this note can be related (joined) on it later
192 function persist($fid = "")
195 $this->foreign_id
= $fid;