minor documentation fixes
[openemr.git] / repositories / ONoteRepository.php
blobbb29e800e2df49cd0a2b43daa59ea302c2bedd92
1 <?php
2 /**
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>;.
18 * @package OpenEMR
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
30 /**
31 * Add new office note.
33 * @param $note The new office note.
34 * @return the new id.
36 public function save(ONote $note)
38 $this->_em->persist($note);
39 $this->_em->flush();
40 return $note->getId();
43 /**
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));
50 return $result;
53 /**
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)
61 $result = false;
63 try {
64 $note = $this->findNoteById($id);
66 if ($note) {
67 $note->setActivity(1);
68 $this->_em->persist($note);
69 $this->_em->flush();
70 $result = true;
72 } catch (Exception $e) {
75 return $result;
78 /**
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)
86 $result = false;
88 try {
89 $note = $this->findNoteById($id);
91 if ($note) {
92 $note->setActivity(0);
93 $this->_em->persist($note);
94 $this->_em->flush();
95 $result = true;
97 } catch (Exception $e) {
100 return $result;
104 * Get office notes with filters, Sorted by DESC. Note
105 * that -1 indicates that all activity types should be
106 * returned.
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)) {
116 return null;
119 $criteria = array();
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(
128 $criteria,
129 array("date" => "DESC"),
130 $limit,
131 $offset
134 return $result;
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();