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

openmrs / openmrs-core / 19233807477

10 Nov 2025 01:48PM UTC coverage: 64.874% (-0.02%) from 64.894%
19233807477

push

github

web-flow
Use the latest supported JDK17 for default docker images in 2.7.x (#5407)

23432 of 36119 relevant lines covered (64.87%)

0.65 hits per line

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

75.44
/api/src/main/java/org/openmrs/Drug.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;
11

12
import java.util.Collection;
13
import java.util.LinkedHashSet;
14
import java.util.Locale;
15
import java.util.Set;
16

17
import org.apache.commons.lang3.StringUtils;
18
import org.codehaus.jackson.annotate.JsonIgnore;
19
import org.hibernate.envers.Audited;
20
import org.hibernate.envers.NotAudited;
21
import org.hibernate.search.annotations.DocumentId;
22
import org.hibernate.search.annotations.Indexed;
23
import org.hibernate.search.annotations.IndexedEmbedded;
24
import org.openmrs.api.context.Context;
25

26
/**
27
 * Drug
28
 */
29
@Indexed
30
@Audited
31
public class Drug extends BaseChangeableOpenmrsMetadata {
32
        
33
        public static final long serialVersionUID = 285L;
34
        
35
        // Fields
36
        @DocumentId
37
        private Integer drugId;
38
        
39
        private Boolean combination = false;
1✔
40
        
41
        private Concept dosageForm;
42
        
43
        private Double maximumDailyDose;
44
        
45
        private Double minimumDailyDose;
46
        
47
        private String strength;
48
        
49
        private Concept doseLimitUnits;
50
        
51
        @IndexedEmbedded(includeEmbeddedObjectId = true)
52
        private Concept concept;
53
        
54
        @IndexedEmbedded(includeEmbeddedObjectId = true)
55
        private Set<DrugReferenceMap> drugReferenceMaps;
56
        
57
        private Collection<DrugIngredient> ingredients;
58
        
59
        // Constructors
60
        
61
        /** default constructor */
62
        public Drug() {
1✔
63
                ingredients = new LinkedHashSet<>();
1✔
64
        }
1✔
65
        
66
        /** constructor with id */
67
        public Drug(Integer drugId) {
×
68
                this.drugId = drugId;
×
69
        }
×
70
        
71
        // Property accessors
72
        
73
        /**
74
         * Gets the internal identification number for this drug
75
         *
76
         * @return Integer
77
         */
78
        public Integer getDrugId() {
79
                return this.drugId;
1✔
80
        }
81
        
82
        /**
83
         * Sets the internal identification number for this drug
84
         *
85
         * @param drugId
86
         */
87
        public void setDrugId(Integer drugId) {
88
                this.drugId = drugId;
1✔
89
        }
1✔
90
        
91
        /**
92
         * Gets the entries concept drug name in the form of CONCEPTNAME (Drug: DRUGNAME)
93
         * 
94
         * @param locale
95
         * @return full drug name (with concept name appended)
96
         */
97
        public String getFullName(Locale locale) {
98
                if (concept == null) {
×
99
                        return getName();
×
100
                } else {
101
                        return getName() + " (" + concept.getName(locale).getName() + ")";
×
102
                }
103
        }
104
        
105
        /**
106
         * Gets whether or not this is a combination drug
107
         *
108
         * @return Boolean
109
         * 
110
         * @deprecated as of 2.0, use {@link #getCombination()}
111
         */
112
        @Deprecated
113
        @JsonIgnore
114
        public Boolean isCombination() {
115
                return getCombination();
×
116
        }
117
        
118
        public Boolean getCombination() {
119
                return combination;
1✔
120
        }
121
        
122
        /**
123
         * Sets whether or not this is a combination drug
124
         *
125
         * @param combination
126
         */
127
        public void setCombination(Boolean combination) {
128
                this.combination = combination;
1✔
129
        }
1✔
130
        
131
        /**
132
         * Gets the strength
133
         *
134
         * @return String
135
         * @since 1.10
136
         */
137
        public String getStrength() {
138
                return strength;
1✔
139
        }
140
        
141
        /**
142
         * Sets the strength
143
         *
144
         * @param strength
145
         * @since 1.10
146
         */
147
        public void setStrength(String strength) {
148
                this.strength = strength;
1✔
149
        }
1✔
150
        
151
        /**
152
         * Gets the concept this drug is tied to
153
         *
154
         * @return Concept
155
         */
156
        public Concept getConcept() {
157
                return this.concept;
1✔
158
        }
159
        
160
        /**
161
         * Sets the concept this drug is tied to
162
         *
163
         * @param concept
164
         */
165
        public void setConcept(Concept concept) {
166
                this.concept = concept;
1✔
167
        }
1✔
168
        
169
        public Concept getDosageForm() {
170
                return dosageForm;
1✔
171
        }
172
        
173
        public void setDosageForm(Concept dosageForm) {
174
                this.dosageForm = dosageForm;
1✔
175
        }
1✔
176
        
177
        public Double getMaximumDailyDose() {
178
                return maximumDailyDose;
1✔
179
        }
180
        
181
        public void setMaximumDailyDose(Double maximumDailyDose) {
182
                this.maximumDailyDose = maximumDailyDose;
1✔
183
        }
1✔
184
        
185
        public Double getMinimumDailyDose() {
186
                return minimumDailyDose;
1✔
187
        }
188
        
189
        public void setMinimumDailyDose(Double minimumDailyDose) {
190
                this.minimumDailyDose = minimumDailyDose;
1✔
191
        }
1✔
192
        
193
        /**
194
         * @return Returns the ingredients
195
         * @since 1.10
196
         */
197
        public Collection<DrugIngredient> getIngredients() {
198
                return ingredients;
1✔
199
        }
200
        
201
        /**
202
         * @param ingredients
203
         *            The ingredients to set
204
         * @since 1.10
205
         */
206
        public void setIngredients(Collection<DrugIngredient> ingredients) {
207
                this.ingredients = ingredients;
1✔
208
        }
1✔
209
        
210
        /**
211
         * @since 1.5
212
         * @see org.openmrs.OpenmrsObject#getId()
213
         */
214
        @Override
215
        public Integer getId() {
216
                
217
                return getDrugId();
1✔
218
        }
219
        
220
        /**
221
         * @since 1.5
222
         * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
223
         */
224
        @Override
225
        public void setId(Integer id) {
226
                setDrugId(id);
×
227
        }
×
228
        
229
        /**
230
         * Convenience method that returns a display name for the drug, defaults to drug.name
231
         *
232
         * @return the display name
233
         * @since 1.8.5, 1.9.4, 1.10
234
         */
235
        public String getDisplayName() {
236
                if (StringUtils.isNotBlank(getName())) {
×
237
                        return getName();
×
238
                }
239
                if (getConcept() != null) {
×
240
                        return getConcept().getName().getName();
×
241
                }
242
                return "";
×
243
        }
244
        
245
        /**
246
         * @return Returns the drugReferenceMaps.
247
         * @since 1.10
248
         */
249
        public Set<DrugReferenceMap> getDrugReferenceMaps() {
250
                if (drugReferenceMaps == null) {
1✔
251
                        drugReferenceMaps = new LinkedHashSet<>();
1✔
252
                }
253
                return drugReferenceMaps;
1✔
254
        }
255
        
256
        /**
257
         * @param drugReferenceMaps The drugReferenceMaps to set.
258
         * @since 1.10
259
         */
260
        public void setDrugReferenceMaps(Set<DrugReferenceMap> drugReferenceMaps) {
261
                this.drugReferenceMaps = drugReferenceMaps;
1✔
262
        }
1✔
263
        
264
        /**
265
         * Add the given DrugReferenceMap object to this drug's list of drug reference mappings. If there is
266
         * already a corresponding DrugReferenceMap object for this concept, this one will not be added.
267
         *
268
         * @param drugReferenceMap
269
         * @since 1.10
270
         *
271
         * <strong>Should</strong> set drug as the drug to which a mapping is being added
272
         *
273
         * <strong>Should</strong> should not add duplicate drug reference maps
274
         */
275
        public void addDrugReferenceMap(DrugReferenceMap drugReferenceMap) {
276
                if (drugReferenceMap != null && !getDrugReferenceMaps().contains(drugReferenceMap)) {
1✔
277
                        drugReferenceMap.setDrug(this);
1✔
278
                        if (drugReferenceMap.getConceptMapType() == null) {
1✔
279
                                drugReferenceMap.setConceptMapType(Context.getConceptService().getDefaultConceptMapType());
1✔
280
                        }
281
                        getDrugReferenceMaps().add(drugReferenceMap);
1✔
282
                }
283
        }
1✔
284
        
285
        /**
286
         * Gets the doseLimitUnits which represents the units of the existing maximumDailyDose and
287
         * minimumDailyDose
288
         * 
289
         * @return the doseLimitUnits.
290
         * @since 2.3.0
291
         */
292
        public Concept getDoseLimitUnits() {
293
                return doseLimitUnits;
1✔
294
        }
295
        
296
        /**
297
         * Sets the doseLimitUnits which represents the units of the existing maximumDailyDose and
298
         * minimumDailyDose
299
         * 
300
         * @param doseLimitUnits The doseLimitUnits to set.
301
         * @since 2.3.0
302
         */
303
        public void setDoseLimitUnits(Concept doseLimitUnits) {
304
                this.doseLimitUnits = doseLimitUnits;
1✔
305
        }
1✔
306
}
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