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
28 * Logger used primarily for logging events that are of interest to
34 * The onote repository to be used for db CRUD operations.
39 * Service used for correlating a user with a new onote.
44 * Default constructor.
46 public function __construct()
48 $this->logger
= new \common\logging\
Logger("\services\ONoteService");
49 $database = \common\database\Connector
::Instance();
50 $entityManager = $database->entityManager
;
51 $this->repository
= $entityManager->getRepository('\entities\ONote');
52 $this->userService
= new \services\
UserService();
56 * Creates a new office note.
58 * @param The text of the office note.
59 * @return $body New id.
61 public function add($body)
63 $newNote = new \entities\
ONote();
64 $newNote->setBody($body);
65 $newNote->setGroupName($this->userService
->getCurrentlyLoggedInUserGroup());
66 $newNote->setUser($this->userService
->getCurrentlyLoggedInUser());
67 $newNote->setActivity(1);
68 $newNote->setDate(new \
DateTime());
70 $this->logger
->debug("Adding new office note");
71 $result = $this->repository
->save($newNote);
74 $this->logger
->error("Failed adding new office note");
77 $this->logger
->debug("Added new office note " . $result);
83 * Toggles a office note to be enabled.
85 * @param $id The office note id.
86 * @return true/false if the update was successful.
88 public function enableNoteById($id)
90 $this->logger
->debug("Enabling office note with id " . $id);
91 $result = $this->repository
->enableNoteById($id);
94 $this->logger
->error("Failed updating office note " . $id);
101 * Toggles a office note to be disabled.
103 * @param $id The office note id.
104 * @return true/false if the update was successful.
106 public function disableNoteById($id)
108 $this->logger
->debug("Disabling office note with id " . $id);
109 $result = $this->repository
->disableNoteById($id);
111 if (empty($result)) {
112 $this->logger
->error("Failed updating office note " . $id);
119 * Get office notes with filters.
121 * @param $activity -1/0/1 to indicate filtered notes.
122 * @param $offset The start index for pagination.
123 * @param $limit The limit for pagination.
124 * @return list of office notes.
126 public function getNotes($activity, $offset, $limit)
128 $this->logger
->debug("Getting " . $activity . " onotes with filters: " . $offset . " " . $limit);
129 return $this->repository
->getNotes($activity, $offset, $limit);