couple more changes related to prior commit
[openemr.git] / repositories / ONoteRepository.php
blobc89a2a53989ce0ec1eaa133df106a0d50ba275a6
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 {
28 /**
29 * Add new office note.
31 * @param $note The new office note.
32 * @return the new id.
34 public function save(\entities\ONote $note) {
35 $this->_em->persist($note);
36 $this->_em->flush();
37 return $note->getId();
40 /**
41 * @param $id The office note id.
42 * @return The single note.
44 public function findNoteById($id) {
45 $result = $this->_em->getRepository($this->_entityName)->findOneBy(array("id" => $id));
46 return $result;
49 /**
50 * Toggles a office note to be enabled.
52 * @param $id The office note id.
53 * @return true/false if the update was successful.
55 public function enableNoteById($id) {
56 $result = false;
58 try {
59 $note = $this->findNoteById($id);
61 if ($note) {
62 $note->setActivity(1);
63 $this->_em->persist($note);
64 $this->_em->flush();
65 $result = true;
67 } catch (Exception $e) {}
69 return $result;
72 /**
73 * Toggles a office note to be enabled.
75 * @param $id The office note id.
76 * @return true/false if the update was successful.
78 public function disableNoteById($id) {
79 $result = false;
81 try {
82 $note = $this->findNoteById($id);
84 if ($note) {
85 $note->setActivity(0);
86 $this->_em->persist($note);
87 $this->_em->flush();
88 $result = true;
90 } catch (Exception $e) {}
92 return $result;
95 /**
96 * Get office notes with filters, Sorted by DESC. Note
97 * that -1 indicates that all activity types should be
98 * returned.
100 * @param $activity -1/0/1 to indicate filtered notes.
101 * @param $offset The start index for pagination.
102 * @param $limit The limit for pagination.
103 * @return list of office notes.
105 public function getNotes($activity, $offset, $limit) {
106 if (!is_numeric($offset) || !is_numeric($limit)) {
107 return null;
110 $criteria = array();
112 if ($activity == 1) {
113 $criteria["activity"] = 1;
114 } else if ($activity == 0) {
115 $criteria["activity"] = 0;
118 $result = $this->_em->getRepository($this->_entityName)->findBy(
119 $criteria,
120 array("date" => "DESC"),
121 $limit,
122 $offset
125 return $result;
129 * An example of how to use HQL with JOINs. Only use
130 * HQL when the methods that EntityRepository provides
131 * cannot sufficiently meet the complexity of your query.
133 public function findAllHqlExample() {
134 // $sql = "SELECT o ";
135 // $sql .= "FROM entities\\ONote o ";
136 // $sql .= "JOIN entities\\User u ";
137 // $sql .= "WITH o.user = u.username";
139 // return $this->_em->createQuery($sql)->getResult();