Highway to PSR2
[openemr.git] / services / ONoteService.php
blobe3b4b3a48969d24bfd43cb75b6c6a5ef819a6df5
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 services;
25 class ONoteService
27 /**
28 * Logger used primarily for logging events that are of interest to
29 * developers.
31 private $logger;
33 /**
34 * The onote repository to be used for db CRUD operations.
36 private $repository;
38 /**
39 * Service used for correlating a user with a new onote.
41 private $userService;
43 /**
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();
55 /**
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);
73 if (empty($result)) {
74 $this->logger->error("Failed adding new office note");
77 $this->logger->debug("Added new office note " . $result);
79 return $result;
82 /**
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);
93 if (empty($result)) {
94 $this->logger->error("Failed updating office note " . $id);
97 return $result;
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);
115 return $result;
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);