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 OpenEMR\Repositories
;
25 use Doctrine\ORM\EntityRepository
;
26 use OpenEMR\Entities\ONote
;
28 class ONoteRepository
extends EntityRepository
31 * Add new office note.
33 * @param $note The new office note.
36 public function save(ONote
$note)
38 $this->_em
->persist($note);
40 return $note->getId();
44 * @param $id The office note id.
45 * @return The single note.
47 public function findNoteById($id)
49 $result = $this->_em
->getRepository($this->_entityName
)->findOneBy(array("id" => $id));
54 * Toggles a office note to be enabled.
56 * @param $id The office note id.
57 * @return true/false if the update was successful.
59 public function enableNoteById($id)
64 $note = $this->findNoteById($id);
67 $note->setActivity(1);
68 $this->_em
->persist($note);
72 } catch (Exception
$e) {
79 * Toggles a office note to be enabled.
81 * @param $id The office note id.
82 * @return true/false if the update was successful.
84 public function disableNoteById($id)
89 $note = $this->findNoteById($id);
92 $note->setActivity(0);
93 $this->_em
->persist($note);
97 } catch (Exception
$e) {
104 * Get office notes with filters, Sorted by DESC. Note
105 * that -1 indicates that all activity types should be
108 * @param $activity -1/0/1 to indicate filtered notes.
109 * @param $offset The start index for pagination.
110 * @param $limit The limit for pagination.
111 * @return list of office notes.
113 public function getNotes($activity, $offset, $limit)
115 if (!is_numeric($offset) ||
!is_numeric($limit)) {
121 if ($activity == 1) {
122 $criteria["activity"] = 1;
123 } else if ($activity == 0) {
124 $criteria["activity"] = 0;
127 $result = $this->_em
->getRepository($this->_entityName
)->findBy(
129 array("date" => "DESC"),
138 * An example of how to use HQL with JOINs. Only use
139 * HQL when the methods that EntityRepository provides
140 * cannot sufficiently meet the complexity of your query.
142 public function findAllHqlExample()
144 // $sql = "SELECT o ";
145 // $sql .= "FROM ONote o ";
146 // $sql .= "JOIN User u ";
147 // $sql .= "WITH o.user = u.username";
149 // return $this->_em->createQuery($sql)->getResult();