Eye Form - Vitreous
[openemr.git] / services / ONoteService.php
blobfb5bd1b5e9f6f64b93562f09985d5a839f6cf6d1
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\Common\Database\Connector;
26 use OpenEMR\Common\Logging\Logger;
27 use OpenEMR\Entities\ONote;
28 use OpenEMR\Services\UserService;
30 class ONoteService
32 /**
33 * Logger used primarily for logging events that are of interest to
34 * developers.
36 private $logger;
38 /**
39 * The onote repository to be used for db CRUD operations.
41 private $repository;
43 /**
44 * Service used for correlating a user with a new onote.
46 private $userService;
48 /**
49 * Default constructor.
51 public function __construct()
53 $this->logger = new Logger("\OpenEMR\Services\ONoteService");
54 $database = Connector::Instance();
55 $entityManager = $database->entityManager;
56 $this->repository = $entityManager->getRepository('\OpenEMR\Entities\ONote');
57 $this->userService = new UserService();
60 /**
61 * Creates a new office note.
63 * @param The text of the office note.
64 * @return $body New id.
66 public function add($body)
68 $newNote = new ONote();
69 $newNote->setBody($body);
70 $newNote->setGroupName($this->userService->getCurrentlyLoggedInUserGroup());
71 $newNote->setUser($this->userService->getCurrentlyLoggedInUser());
72 $newNote->setActivity(1);
73 $newNote->setDate(new \DateTime());
75 $this->logger->debug("Adding new office note");
76 $result = $this->repository->save($newNote);
78 if (empty($result)) {
79 $this->logger->error("Failed adding new office note");
82 $this->logger->debug("Added new office note " . $result);
84 return $result;
87 /**
88 * Toggles a office note to be enabled.
90 * @param $id The office note id.
91 * @return true/false if the update was successful.
93 public function enableNoteById($id)
95 $this->logger->debug("Enabling office note with id " . $id);
96 $result = $this->repository->enableNoteById($id);
98 if (empty($result)) {
99 $this->logger->error("Failed updating office note " . $id);
102 return $result;
106 * Toggles a office note to be disabled.
108 * @param $id The office note id.
109 * @return true/false if the update was successful.
111 public function disableNoteById($id)
113 $this->logger->debug("Disabling office note with id " . $id);
114 $result = $this->repository->disableNoteById($id);
116 if (empty($result)) {
117 $this->logger->error("Failed updating office note " . $id);
120 return $result;
124 * Get office notes with filters.
126 * @param $activity -1/0/1 to indicate filtered notes.
127 * @param $offset The start index for pagination.
128 * @param $limit The limit for pagination.
129 * @return list of office notes.
131 public function getNotes($activity, $offset, $limit)
133 $this->logger->debug("Getting " . $activity . " onotes with filters: " . $offset . " " . $limit);
134 return $this->repository->getNotes($activity, $offset, $limit);