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

openmrs / openmrs-core / 13042462934

29 Jan 2025 11:31PM UTC coverage: 63.705% (-0.003%) from 63.708%
13042462934

push

github

openmrs-bot
Setting new SNAPSHOT version

21982 of 34506 relevant lines covered (63.7%)

0.64 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.search.annotations.DocumentId;
20
import org.hibernate.search.annotations.Indexed;
21
import org.hibernate.search.annotations.IndexedEmbedded;
22
import org.openmrs.api.context.Context;
23

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