3 * Office note repository.
5 * Copyright (C) 2017 Matthew Vita <matthewvita48@gmail.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @author Matthew Vita <matthewvita48@gmail.com>
20 * @link http://www.open-emr.org
23 namespace repositories
;
25 use Doctrine\ORM\EntityRepository
;
27 class ONoteRepository
extends EntityRepository
30 * Add new office note.
32 * @param $note The new office note.
35 public function save(\entities\ONote
$note)
37 $this->_em
->persist($note);
39 return $note->getId();
43 * @param $id The office note id.
44 * @return The single note.
46 public function findNoteById($id)
48 $result = $this->_em
->getRepository($this->_entityName
)->findOneBy(array("id" => $id));
53 * Toggles a office note to be enabled.
55 * @param $id The office note id.
56 * @return true/false if the update was successful.
58 public function enableNoteById($id)
63 $note = $this->findNoteById($id);
66 $note->setActivity(1);
67 $this->_em
->persist($note);
71 } catch (Exception
$e) {
78 * Toggles a office note to be enabled.
80 * @param $id The office note id.
81 * @return true/false if the update was successful.
83 public function disableNoteById($id)
88 $note = $this->findNoteById($id);
91 $note->setActivity(0);
92 $this->_em
->persist($note);
96 } catch (Exception
$e) {
103 * Get office notes with filters, Sorted by DESC. Note
104 * that -1 indicates that all activity types should be
107 * @param $activity -1/0/1 to indicate filtered notes.
108 * @param $offset The start index for pagination.
109 * @param $limit The limit for pagination.
110 * @return list of office notes.
112 public function getNotes($activity, $offset, $limit)
114 if (!is_numeric($offset) ||
!is_numeric($limit)) {
120 if ($activity == 1) {
121 $criteria["activity"] = 1;
122 } else if ($activity == 0) {
123 $criteria["activity"] = 0;
126 $result = $this->_em
->getRepository($this->_entityName
)->findBy(
128 array("date" => "DESC"),
137 * An example of how to use HQL with JOINs. Only use
138 * HQL when the methods that EntityRepository provides
139 * cannot sufficiently meet the complexity of your query.
141 public function findAllHqlExample()
143 // $sql = "SELECT o ";
144 // $sql .= "FROM entities\\ONote o ";
145 // $sql .= "JOIN entities\\User u ";
146 // $sql .= "WITH o.user = u.username";
148 // return $this->_em->createQuery($sql)->getResult();