• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 18721027590

22 Oct 2025 03:16PM UTC coverage: 65.271% (+0.008%) from 65.263%
18721027590

push

github

web-flow
TRUNK-6449 - Populate provider_role from providermanagement_provider_… (#5421)

23692 of 36298 relevant lines covered (65.27%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.11
/api/src/main/java/org/openmrs/notification/Alert.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.notification;
11

12
import java.io.Serializable;
13
import java.util.Collection;
14
import java.util.Date;
15
import java.util.HashSet;
16
import java.util.Set;
17

18
import org.hibernate.envers.Audited;
19
import org.openmrs.Auditable;
20
import org.openmrs.BaseOpenmrsObject;
21
import org.openmrs.User;
22
import org.openmrs.api.context.Context;
23

24
/**
25
 * Alerts are the simplest form of communication. An Administrator (or script) sets the user or role
26
 * to attribute the alert to. Alerts are not intended to be sent from user to user and a user cannot
27
 * send a "reply alert"
28
 */
29
@Audited
30
public class Alert extends BaseOpenmrsObject implements Auditable, Serializable {
31
        
32
        private static final long serialVersionUID = -507111111109152L;
33
        
34
        public static final int TEXT_MAX_LENGTH = 512;
35
        
36
        private Integer alertId;
37
        
38
        private String text;
39
        
40
        private Boolean satisfiedByAny = Boolean.FALSE;
1✔
41
        
42
        private Boolean alertRead = Boolean.FALSE;
1✔
43
        
44
        private Date dateToExpire;
45
        
46
        private User creator;
47
        
48
        private Date dateCreated;
49
        
50
        private User changedBy;
51
        
52
        private Date dateChanged;
53
        
54
        private Set<AlertRecipient> recipients;
55
        
56
        /**
57
         * Default empty constructor
58
         */
59
        public Alert() {
1✔
60
        }
1✔
61
        
62
        /**
63
         * Initializes an alert with the given alert id
64
         */
65
        public Alert(Integer alertId) {
×
66
                this.alertId = alertId;
×
67
        }
×
68
        
69
        /**
70
         * Convenience constructor to create an alert with the given text and for the given users
71
         *
72
         * @param text String to display for the alert
73
         * @param users Recipients of this alert
74
         */
75
        public Alert(String text, Collection<User> users) {
1✔
76
                setText(text);
1✔
77
                for (User user : users) {
1✔
78
                        addRecipient(user);
1✔
79
                }
1✔
80
        }
1✔
81
        
82
        /**
83
         * Convenience constructor to create an alert with the given text and for the given users
84
         *
85
         * @param text String to display for the alert
86
         * @param user Recipient of the alert
87
         */
88
        public Alert(String text, User user) {
×
89
                setText(text);
×
90
                addRecipient(user);
×
91
        }
×
92
        
93
        /**
94
         * @return Returns the alertId.
95
         */
96
        public Integer getAlertId() {
97
                return alertId;
1✔
98
        }
99
        
100
        /**
101
         * @param alertId The alertId to set.
102
         */
103
        public void setAlertId(Integer alertId) {
104
                this.alertId = alertId;
1✔
105
        }
1✔
106
        
107
        /**
108
         * @return Returns the creator.
109
         */
110
        @Override
111
        public User getCreator() {
112
                return creator;
1✔
113
        }
114
        
115
        /**
116
         * @param creator The creator to set.
117
         */
118
        @Override
119
        public void setCreator(User creator) {
120
                this.creator = creator;
1✔
121
        }
1✔
122
        
123
        /**
124
         * @return Returns the dateCreated.
125
         */
126
        @Override
127
        public Date getDateCreated() {
128
                return dateCreated;
1✔
129
        }
130
        
131
        /**
132
         * @param dateCreated The dateCreated to set.
133
         */
134
        @Override
135
        public void setDateCreated(Date dateCreated) {
136
                this.dateCreated = dateCreated;
1✔
137
        }
1✔
138
        
139
        /**
140
         * @return Returns the date this alert expires
141
         */
142
        public Date getDateToExpire() {
143
                return dateToExpire;
1✔
144
        }
145
        
146
        /**
147
         * @param dateToExpire The date To Expire this alert
148
         */
149
        public void setDateToExpire(Date dateToExpire) {
150
                this.dateToExpire = dateToExpire;
1✔
151
        }
1✔
152
        
153
        /**
154
         * @return Returns the text.
155
         */
156
        public String getText() {
157
                return text;
1✔
158
        }
159
        
160
        /**
161
         * @param text The text to set.
162
         */
163
        public void setText(String text) {
164
                this.text = text;
1✔
165
        }
1✔
166
        
167
        /**
168
         * @see #isSatisfiedByAny()
169
         */
170
        public Boolean getSatisfiedByAny() {
171
                return isSatisfiedByAny();
×
172
        }
173
        
174
        /**
175
         * @return Returns the satisfiedByAny.
176
         */
177
        public Boolean isSatisfiedByAny() {
178
                return satisfiedByAny;
1✔
179
        }
180
        
181
        /**
182
         * @param satisfiedByAny The satisfiedByAny to set.
183
         */
184
        public void setSatisfiedByAny(Boolean satisfiedByAny) {
185
                this.satisfiedByAny = satisfiedByAny;
1✔
186
        }
1✔
187
        
188
        /**
189
         * @see #isAlertRead()
190
         */
191
        public Boolean getAlertRead() {
192
                return isAlertRead();
1✔
193
        }
194
        
195
        /**
196
         * @return Returns the alertRead.
197
         */
198
        public Boolean isAlertRead() {
199
                return alertRead;
1✔
200
        }
201
        
202
        /**
203
         * @param alertRead The alertRead to set.
204
         */
205
        public void setAlertRead(Boolean alertRead) {
206
                this.alertRead = alertRead;
1✔
207
        }
1✔
208
        
209
        /**
210
         * @return Returns the changedBy.
211
         */
212
        @Override
213
        public User getChangedBy() {
214
                return changedBy;
1✔
215
        }
216
        
217
        /**
218
         * @param changedBy The user that changed this alert
219
         */
220
        @Override
221
        public void setChangedBy(User changedBy) {
222
                this.changedBy = changedBy;
1✔
223
        }
1✔
224
        
225
        /**
226
         * @return Returns the date this alert was changed
227
         */
228
        @Override
229
        public Date getDateChanged() {
230
                return dateChanged;
1✔
231
        }
232
        
233
        /**
234
         * @param dateChanged The date this alert was changed
235
         */
236
        @Override
237
        public void setDateChanged(Date dateChanged) {
238
                this.dateChanged = dateChanged;
1✔
239
        }
1✔
240
        
241
        /**
242
         * @return Returns the Recipients of this alert
243
         */
244
        public Set<AlertRecipient> getRecipients() {
245
                return recipients;
1✔
246
        }
247
        
248
        /**
249
         * @param recipients The recipients of this alert
250
         */
251
        public void setRecipients(Set<AlertRecipient> recipients) {
252
                this.recipients = recipients;
1✔
253
        }
1✔
254
        
255
        /**
256
         * Convenience method to add the given AlertRecipient to the list of recipients for this alert
257
         *
258
         * @param r AlertRecipient to add
259
         */
260
        public void addRecipient(AlertRecipient r) {
261
                if (this.recipients == null) {
1✔
262
                        this.recipients = new HashSet<>();
1✔
263
                }
264
                r.setAlert(this);
1✔
265
                // duplicates are avoided by depending on the .equals and .hashcode
266
                //  methods of Alert
267
                recipients.add(r);
1✔
268
        }
1✔
269
        
270
        /**
271
         * Convenience method to add the given user to this list of recipients for this alert
272
         *
273
         * @param u User to add to list of recipients
274
         */
275
        public void addRecipient(User u) {
276
                addRecipient(new AlertRecipient(u, false));
1✔
277
        }
1✔
278
        
279
        /**
280
         * Convenience method to remove the given AlertRecipient from this Alert's list of recipients
281
         *
282
         * @param r user to remove from list of recipients
283
         */
284
        public void removeRecipient(AlertRecipient r) {
285
                if (recipients != null) {
×
286
                        recipients.remove(r);
×
287
                }
288
        }
×
289
        
290
        /**
291
         * Convenience method to find the AlertRecipient object within this alert that corresponds to
292
         * the given <code>recipient</code>
293
         *
294
         * @param recipient
295
         * @return AlertRecipient
296
         */
297
        public AlertRecipient getRecipient(User recipient) {
298
                if (getRecipients() != null) {
×
299
                        for (AlertRecipient ar : recipients) {
×
300
                                if (ar.getRecipient().equals(recipient)) {
×
301
                                        return ar;
×
302
                                }
303
                        }
×
304
                }
305
                return null;
×
306
        }
307
        
308
        /**
309
         * Convenience method to mark this alert as read. In order to persist this change in the
310
         * database, AlertService.saveAlert(Alert) will need to be called after this method is done.
311
         *
312
         * @return This alert (for chaining and one-liner purposes)
313
         * @see org.openmrs.notification.AlertService#saveAlert(Alert)
314
         */
315
        public Alert markAlertRead() {
316
                User authUser = Context.getAuthenticatedUser();
×
317
                
318
                if (authUser != null) {
×
319
                        AlertRecipient ar = getRecipient(authUser);
×
320
                        ar.setAlertRead(true);
×
321
                        if (isSatisfiedByAny()) {
×
322
                                setAlertRead(true);
×
323
                        }
324
                }
325
                
326
                return this;
×
327
        }
328
        
329
        /**
330
         * @see java.lang.Object#toString()
331
         */
332
        @Override
333
        public String toString() {
334
                return "Alert: #" + alertId;
1✔
335
        }
336
        
337
        /**
338
         * @since 1.5
339
         * @see org.openmrs.OpenmrsObject#getId()
340
         */
341
        @Override
342
        public Integer getId() {
343
                return getAlertId();
×
344
        }
345
        
346
        /**
347
         * @since 1.5
348
         * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
349
         */
350
        @Override
351
        public void setId(Integer id) {
352
                setAlertId(id);
1✔
353
        }
1✔
354
        
355
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc