Minor modification ub04 support scripts.
[openemr.git] / services / ONoteService.php
blobf2e6f92125f5b0bc04a53f01e43376061a90f386
1 <?php
2 /**
3 * ONoteService
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\Services;
25 use OpenEMR\Services\UserService;
27 class ONoteService
29 /**
30 * Logger used primarily for logging events that are of interest to
31 * developers.
33 private $logger;
35 /**
36 * The onote repository to be used for db CRUD operations.
38 private $repository;
40 /**
41 * Service used for correlating a user with a new onote.
43 private $userService;
45 /**
46 * Default constructor.
48 public function __construct()
50 $this->logger = new \common\logging\Logger("\OpenEMR\Services\ONoteService");
51 $database = \common\database\Connector::Instance();
52 $entityManager = $database->entityManager;
53 $this->repository = $entityManager->getRepository('\entities\ONote');
54 $this->userService = new UserService();
57 /**
58 * Creates a new office note.
60 * @param The text of the office note.
61 * @return $body New id.
63 public function add($body)
65 $newNote = new \entities\ONote();
66 $newNote->setBody($body);
67 $newNote->setGroupName($this->userService->getCurrentlyLoggedInUserGroup());
68 $newNote->setUser($this->userService->getCurrentlyLoggedInUser());
69 $newNote->setActivity(1);
70 $newNote->setDate(new \DateTime());
72 $this->logger->debug("Adding new office note");
73 $result = $this->repository->save($newNote);
75 if (empty($result)) {
76 $this->logger->error("Failed adding new office note");
79 $this->logger->debug("Added new office note " . $result);
81 return $result;
84 /**
85 * Toggles a office note to be enabled.
87 * @param $id The office note id.
88 * @return true/false if the update was successful.
90 public function enableNoteById($id)
92 $this->logger->debug("Enabling office note with id " . $id);
93 $result = $this->repository->enableNoteById($id);
95 if (empty($result)) {
96 $this->logger->error("Failed updating office note " . $id);
99 return $result;
103 * Toggles a office note to be disabled.
105 * @param $id The office note id.
106 * @return true/false if the update was successful.
108 public function disableNoteById($id)
110 $this->logger->debug("Disabling office note with id " . $id);
111 $result = $this->repository->disableNoteById($id);
113 if (empty($result)) {
114 $this->logger->error("Failed updating office note " . $id);
117 return $result;
121 * Get office notes with filters.
123 * @param $activity -1/0/1 to indicate filtered notes.
124 * @param $offset The start index for pagination.
125 * @param $limit The limit for pagination.
126 * @return list of office notes.
128 public function getNotes($activity, $offset, $limit)
130 $this->logger->debug("Getting " . $activity . " onotes with filters: " . $offset . " " . $limit);
131 return $this->repository->getNotes($activity, $offset, $limit);