6 * @link http://www.open-emr.org
7 * @author Matthew Vita <matthewvita48@gmail.com>
8 * @copyright Copyright (c) 2017 Matthew Vita <matthewvita48@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 namespace OpenEMR\Services
;
15 use OpenEMR\Common\Database\Connector
;
16 use OpenEMR\Common\Logging\Logger
;
17 use OpenEMR\Entities\ONote
;
18 use OpenEMR\Services\UserService
;
23 * Logger used primarily for logging events that are of interest to
29 * The onote repository to be used for db CRUD operations.
34 * Service used for correlating a user with a new onote.
39 * Default constructor.
41 public function __construct()
43 $this->logger
= new Logger("\OpenEMR\Services\ONoteService");
44 $database = Connector
::Instance();
45 $entityManager = $database->entityManager
;
46 $this->repository
= $entityManager->getRepository('\OpenEMR\Entities\ONote');
47 $this->userService
= new UserService();
51 * Creates a new office note.
53 * @param The text of the office note.
54 * @return $body New id.
56 public function add($body)
58 $newNote = new ONote();
59 $newNote->setBody($body);
60 $newNote->setGroupName($this->userService
->getCurrentlyLoggedInUserGroup());
61 $newNote->setUser($this->userService
->getCurrentlyLoggedInUser());
62 $newNote->setActivity(1);
63 $newNote->setDate(new \
DateTime());
65 $this->logger
->debug("Adding new office note");
66 $result = $this->repository
->save($newNote);
69 $this->logger
->error("Failed adding new office note");
72 $this->logger
->debug("Added new office note " . $result);
78 * Toggles a office note to be enabled.
80 * @param $id The office note id.
81 * @return true/false if the update was successful.
83 public function enableNoteById($id)
85 $this->logger
->debug("Enabling office note with id " . $id);
86 $result = $this->repository
->enableNoteById($id);
89 $this->logger
->error("Failed updating office note " . $id);
96 * Toggles a office note to be disabled.
98 * @param $id The office note id.
99 * @return true/false if the update was successful.
101 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)
123 $this->logger
->debug("Getting " . $activity . " onotes with filters: " . $offset . " " . $limit);
124 return $this->repository
->getNotes($activity, $offset, $limit);