Highway to PSR2
[openemr.git] / repositories / ONoteRepository.php
blob1afb581c11b199223059d93621c3ca3728afd210
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 repositories;
25 use Doctrine\ORM\EntityRepository;
27 class ONoteRepository extends EntityRepository
29 /**
30 * Add new office note.
32 * @param $note The new office note.
33 * @return the new id.
35 public function save(\entities\ONote $note)
37 $this->_em->persist($note);
38 $this->_em->flush();
39 return $note->getId();
42 /**
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));
49 return $result;
52 /**
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)
60 $result = false;
62 try {
63 $note = $this->findNoteById($id);
65 if ($note) {
66 $note->setActivity(1);
67 $this->_em->persist($note);
68 $this->_em->flush();
69 $result = true;
71 } catch (Exception $e) {
74 return $result;
77 /**
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)
85 $result = false;
87 try {
88 $note = $this->findNoteById($id);
90 if ($note) {
91 $note->setActivity(0);
92 $this->_em->persist($note);
93 $this->_em->flush();
94 $result = true;
96 } catch (Exception $e) {
99 return $result;
103 * Get office notes with filters, Sorted by DESC. Note
104 * that -1 indicates that all activity types should be
105 * returned.
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)) {
115 return null;
118 $criteria = array();
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(
127 $criteria,
128 array("date" => "DESC"),
129 $limit,
130 $offset
133 return $result;
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();