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
27 * Logger used primarily for logging events that are of interest to
33 * The onote repository to be used for db CRUD operations.
38 * Service used for correlating a user with a new onote.
43 * Default constructor.
45 public function __construct() {
46 $this->logger
= new \common\logging\
Logger("\services\ONoteService");
47 $database = \common\database\Connector
::Instance();
48 $entityManager = $database->entityManager
;
49 $this->repository
= $entityManager->getRepository('\entities\ONote');
50 $this->userService
= new \services\
UserService();
54 * Creates a new office note.
56 * @param The text of the office note.
57 * @return $body New id.
59 public function add($body) {
60 $newNote = new \entities\
ONote();
61 $newNote->setBody($body);
62 $newNote->setGroupName($this->userService
->getCurrentlyLoggedInUserGroup());
63 $newNote->setUser($this->userService
->getCurrentlyLoggedInUser());
64 $newNote->setActivity(1);
65 $newNote->setDate(new \
DateTime());
67 $this->logger
->debug("Adding new office note");
68 $result = $this->repository
->save($newNote);
71 $this->logger
->error("Failed adding new office note");
74 $this->logger
->debug("Added new office note " . $result);
80 * Toggles a office note to be enabled.
82 * @param $id The office note id.
83 * @return true/false if the update was successful.
85 public function enableNoteById($id) {
86 $this->logger
->debug("Enabling office note with id " . $id);
87 $result = $this->repository
->enableNoteById($id);
90 $this->logger
->error("Failed updating office note " . $id);
97 * Toggles a office note to be disabled.
99 * @param $id The office note id.
100 * @return true/false if the update was successful.
102 public function disableNoteById($id) {
103 $this->logger
->debug("Disabling office note with id " . $id);
104 $result = $this->repository
->disableNoteById($id);
106 if (empty($result)) {
107 $this->logger
->error("Failed updating office note " . $id);
114 * Get office notes with filters.
116 * @param $activity -1/0/1 to indicate filtered notes.
117 * @param $offset The start index for pagination.
118 * @param $limit The limit for pagination.
119 * @return list of office notes.
121 public function getNotes($activity, $offset, $limit) {
122 $this->logger
->debug("Getting " . $activity . " onotes with filters: " . $offset . " " . $limit);
123 return $this->repository
->getNotes($activity, $offset, $limit);