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

openmrs / openmrs-core / 19175973922

07 Nov 2025 05:22PM UTC coverage: 65.291% (+0.004%) from 65.287%
19175973922

push

github

web-flow
TRUNK-6463: Problem editing existing Complex Obs with the new Local F… (#5458)

* TRUNK-6463: Problem editing existing Complex Obs with the new Local File Storage Service
TRUNK-6464: Test Context should not create new application data directory for each test

2 of 2 new or added lines in 1 file covered. (100.0%)

43 existing lines in 2 files now uncovered.

23722 of 36333 relevant lines covered (65.29%)

0.65 hits per line

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

45.45
/api/src/main/java/org/openmrs/MedicationDispense.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 org.hibernate.envers.Audited;
13

14
import javax.persistence.Column;
15
import javax.persistence.Entity;
16
import javax.persistence.GeneratedValue;
17
import javax.persistence.GenerationType;
18
import javax.persistence.Id;
19
import javax.persistence.JoinColumn;
20
import javax.persistence.Lob;
21
import javax.persistence.ManyToOne;
22
import javax.persistence.Table;
23
import java.util.Date;
24

25
/**
26
 * The MedicationDispense class records detailed information about the provision of a supply of a medication 
27
 * with the intention that it is subsequently consumed by a patient (usually in response to a prescription).
28
 * 
29
 * @see <a href="https://www.hl7.org/fhir/medicationdispense.html">
30
 *                     https://www.hl7.org/fhir/medicationdispense.html
31
 *             </a>
32
 * @since 2.6
33
 */
34
@Entity
35
@Table(name = "medication_dispense")
36
@Audited
37
public class MedicationDispense extends BaseFormRecordableOpenmrsData {
38
        
39
        private static final long serialVersionUID = 1L;
40
        
41
        @Id
42
        @GeneratedValue(strategy = GenerationType.IDENTITY)
43
        @Column(name = "medication_dispense_id")
44
        private Integer medicationDispenseId;
45

46
        /**
47
         * FHIR:subject
48
         * Patient for whom the medication is intended
49
         */
50
        @ManyToOne(optional = false)
51
        @JoinColumn(name = "patient_id")
52
        private Patient patient;
53
        
54
        /**
55
         * FHIR:context
56
         * Encounter when the dispensing event occurred
57
         */
58
        @ManyToOne(optional = true)
59
        @JoinColumn(name = "encounter_id")
60
        private Encounter encounter;
61

62
        /**
63
         * FHIR:medication.medicationCodeableConcept
64
         * Corresponds to drugOrder.concept
65
         */
66
        @ManyToOne(optional = false)
67
        @JoinColumn(name = "concept")
68
        private Concept concept;
69
        
70
        /**
71
         * FHIR:medication.reference(Medication)
72
         * Corresponds to drugOrder.drug
73
         */
74
        @ManyToOne(optional = true)
75
        @JoinColumn(name = "drug_id")
76
        private Drug drug;
77

78
        /**
79
         * FHIR:location
80
         * Where the dispensed event occurred
81
         */
82
        @ManyToOne(optional = true)
83
        @JoinColumn(name = "location_id")
84
        private Location location;
85

86
        /**
87
         * FHIR:performer.actor with null for performer.function.
88
         * Per <a href="https://www.hl7.org/fhir/medicationdispense-definitions.html#MedicationDispense.performer">
89
         *             https://www.hl7.org/fhir/medicationdispense-definitions.html#MedicationDispense.performer
90
         *     </a>specification, It should be assumed that the actor is the dispenser of the medication
91
         */
92
        @ManyToOne(optional = true)
93
        @JoinColumn(name = "dispenser")
94
        private Provider dispenser;
95

96
        /**
97
         * FHIR:authorizingPrescription
98
         * The drug order that led to this dispensing event; 
99
         * note that authorizing prescription maps to a "MedicationRequest" FHIR resource
100
         */
101
        @ManyToOne(optional = true)
102
        @JoinColumn(name = "drug_order_id")
103
        private DrugOrder drugOrder;
104

105
        /**
106
         * FHIR:status
107
         * @see <a href="https://www.hl7.org/fhir/valueset-medicationdispense-status.html">
108
         *                     https://www.hl7.org/fhir/valueset-medicationdispense-status.html
109
         *             </a>
110
         * i.e. preparation, in-progress, cancelled, on-hold, completed, entered-in-error, stopped, declined, unknown
111
         */
112
        @ManyToOne(optional = false)
113
        @JoinColumn(name = "status")
114
        private Concept status;
115

116
        /**
117
         * FHIR:statusReason.statusReasonCodeableConcept
118
         * @see <a href="https://www.hl7.org/fhir/valueset-medicationdispense-status-reason.html">
119
         *                     https://www.hl7.org/fhir/valueset-medicationdispense-status-reason.html
120
         *             </a>
121
         * i.e "Stock Out"
122
         */
123
        @ManyToOne(optional = true)
124
        @JoinColumn(name = "status_reason")
125
        private Concept statusReason;
126

127
        /**
128
         * FHIR:type.codeableConcept
129
         * @see <a href="https://www.hl7.org/fhir/v3/ActPharmacySupplyType/vs.html">
130
         *                     https://www.hl7.org/fhir/v3/ActPharmacySupplyType/vs.html
131
         *             </a> for potential example concepts
132
         * i.e. "Refill" and "Partial Fill"
133
         */
134
        @ManyToOne(optional = true)
135
        @JoinColumn(name = "type")
136
        private Concept type;
137

138
        /**
139
         * FHIR:quantity.value
140
         * Relates to drugOrder.quantity
141
         */
142
        @Column(name = "quantity")
143
        private Double quantity;
144

145
        /**
146
         * FHIR:quantity.unit and/or quanity.code
147
         * Relates to drugOrder.quantityUnits
148
         */
149
        @ManyToOne(optional = true)
150
        @JoinColumn(name = "quantity_units")
151
        private Concept quantityUnits;
152

153
        /**
154
         * FHIR:dosageInstructions.doseAndRate.dose.doseQuantity
155
         * Relates to drugOrder.dose
156
         */
157
        @Column(name = "dose")
158
        private Double dose;
159

160
        /**
161
         * FHIR:dosageInstructions.doseAndRate.dose.quantity.unit and/or code
162
         * Relates to drugOrder.doseUnits
163
         */
164
        @ManyToOne(optional = true)
165
        @JoinColumn(name = "dose_units")
166
        private Concept doseUnits;
167

168
        /**
169
         * FHIR:dosageInstructions.route
170
         * Relates to drugOrder.route
171
         */
172
        @ManyToOne(optional = true)
173
        @JoinColumn(name = "route")
174
        private Concept route;
175

176
        /**
177
         * FHIR:DosageInstructions.timing.repeat.frequency+period+periodUnit
178
         * @see <a href="https://build.fhir.org/datatypes.html#Timing">https://build.fhir.org/datatypes.html#Timing</a>
179
         * Note that we will continue to map this as a single "frequency" concept, although it doesn't map well to FHIR, 
180
         * to make consistent with DrugOrder in OpenMRS
181
         * Relates to drugOrder.frequency
182
         */
183
        @ManyToOne(optional = true)
184
        @JoinColumn(name = "frequency")
185
        private OrderFrequency frequency;
186

187
        /**
188
         * FHIR:DosageInstructions.AsNeeded.asNeededBoolean
189
         * Relates to drugOrder.asNeeded
190
         */
191
        @Column(name = "as_needed")
192
        private Boolean asNeeded;
193

194
        /**
195
         * FHIR:DosageInstructions.patientInstructions
196
         * Relates to drugOrder.dosingInstructions
197
         */
198
        @Column(name = "dosing_instructions", length=65535)
199
        @Lob
200
        private String dosingInstructions;
201

202
        /**
203
         * FHIR:whenPrepared
204
         * From FHIR: "When product was packaged and reviewed"
205
         */
206
        @Column(name = "date_prepared")
207
        private Date datePrepared;
208

209
        /**
210
         * FHIR:whenHandedOver
211
         * From FHIR: "When product was given out"
212
         */
213
        @Column(name = "date_handed_over")
214
        private Date dateHandedOver;
215

216
        /**
217
         * FHIR:substitution.wasSubstituted
218
         * True/false whether a substitution was made during this dispense event
219
         */
220
        @Column(name = "was_substituted")
221
        private Boolean wasSubstituted;
222

223
        /**
224
         * FHIR:substitution.type
225
         * @see <a href="https://www.hl7.org/fhir/v3/ActSubstanceAdminSubstitutionCode/vs.html">
226
         *                     https://www.hl7.org/fhir/v3/ActSubstanceAdminSubstitutionCode/vs.html
227
         *      </a>
228
         */
229
        @ManyToOne(optional = true)
230
        @JoinColumn(name = "substitution_type")
231
        private Concept substitutionType;
232

233
        /**
234
         * FHIR:substitution.reason
235
         * @see <a href="https://www.hl7.org/fhir/v3/SubstanceAdminSubstitutionReason/vs.html">
236
         *                     https://www.hl7.org/fhir/v3/SubstanceAdminSubstitutionReason/vs.html
237
         *      </a>
238
         */
239
        @ManyToOne(optional = true)
240
        @JoinColumn(name = "substitution_reason")
241
        private Concept substitutionReason;
242

243
        
244
        public MedicationDispense() {
1✔
245
        }
1✔
246

247
        /**
248
         * @see BaseOpenmrsObject#getId() 
249
         */
250
        @Override
251
        public Integer getId() {
252
                return getMedicationDispenseId();
1✔
253
        }
254

255
        /**
256
         * @see BaseOpenmrsObject#setId(Integer)
257
         */
258
        @Override
259
        public void setId(Integer id) {
UNCOV
260
                setMedicationDispenseId(id);
×
UNCOV
261
        }
×
262

263
        public Integer getMedicationDispenseId() {
264
                return medicationDispenseId;
1✔
265
        }
266

267
        public void setMedicationDispenseId(Integer medicationDispenseId) {
UNCOV
268
                this.medicationDispenseId = medicationDispenseId;
×
UNCOV
269
        }
×
270

271
        public Patient getPatient() {
272
                return patient;
1✔
273
        }
274

275
        public void setPatient(Patient patient) {
276
                this.patient = patient;
1✔
277
        }
1✔
278

279
        public Encounter getEncounter() {
280
                return encounter;
1✔
281
        }
282

283
        public void setEncounter(Encounter encounter) {
UNCOV
284
                this.encounter = encounter;
×
UNCOV
285
        }
×
286

287
        public Concept getConcept() {
288
                return concept;
1✔
289
        }
290

291
        public void setConcept(Concept concept) {
292
                this.concept = concept;
1✔
293
        }
1✔
294

295
        public Drug getDrug() {
296
                return drug;
1✔
297
        }
298

299
        public void setDrug(Drug drug) {
UNCOV
300
                this.drug = drug;
×
UNCOV
301
        }
×
302

303
        public Location getLocation() {
304
                return location;
1✔
305
        }
306

307
        public void setLocation(Location location) {
UNCOV
308
                this.location = location;
×
UNCOV
309
        }
×
310

311
        public Provider getDispenser() {
312
                return dispenser;
1✔
313
        }
314

315
        public void setDispenser(Provider dispenser) {
UNCOV
316
                this.dispenser = dispenser;
×
UNCOV
317
        }
×
318

319
        public DrugOrder getDrugOrder() {
320
                return drugOrder;
1✔
321
        }
322

323
        public void setDrugOrder(DrugOrder drugOrder) {
UNCOV
324
                this.drugOrder = drugOrder;
×
UNCOV
325
        }
×
326

327
        public Concept getStatus() {
328
                return status;
1✔
329
        }
330

331
        public void setStatus(Concept status) {
332
                this.status = status;
1✔
333
        }
1✔
334

335
        public Concept getStatusReason() {
336
                return statusReason;
1✔
337
        }
338

339
        public void setStatusReason(Concept statusReason) {
340
                this.statusReason = statusReason;
1✔
341
        }
1✔
342

343
        public Concept getType() {
344
                return type;
1✔
345
        }
346

347
        public void setType(Concept type) {
UNCOV
348
                this.type = type;
×
UNCOV
349
        }
×
350

351
        public Double getQuantity() {
352
                return quantity;
1✔
353
        }
354

355
        public void setQuantity(Double quantity) {
UNCOV
356
                this.quantity = quantity;
×
UNCOV
357
        }
×
358

359
        public Concept getQuantityUnits() {
360
                return quantityUnits;
1✔
361
        }
362

363
        public void setQuantityUnits(Concept quantityUnits) {
UNCOV
364
                this.quantityUnits = quantityUnits;
×
UNCOV
365
        }
×
366

367
        public Double getDose() {
368
                return dose;
1✔
369
        }
370

371
        public void setDose(Double dose) {
UNCOV
372
                this.dose = dose;
×
UNCOV
373
        }
×
374

375
        public Concept getDoseUnits() {
376
                return doseUnits;
1✔
377
        }
378

379
        public void setDoseUnits(Concept doseUnits) {
UNCOV
380
                this.doseUnits = doseUnits;
×
UNCOV
381
        }
×
382

383
        public Concept getRoute() {
384
                return route;
1✔
385
        }
386

387
        public void setRoute(Concept route) {
UNCOV
388
                this.route = route;
×
UNCOV
389
        }
×
390

391
        public OrderFrequency getFrequency() {
392
                return frequency;
1✔
393
        }
394

395
        public void setFrequency(OrderFrequency frequency) {
UNCOV
396
                this.frequency = frequency;
×
UNCOV
397
        }
×
398

399
        public Boolean getAsNeeded() {
400
                return asNeeded;
1✔
401
        }
402

403
        public void setAsNeeded(Boolean asNeeded) {
UNCOV
404
                this.asNeeded = asNeeded;
×
UNCOV
405
        }
×
406

407
        public String getDosingInstructions() {
408
                return dosingInstructions;
1✔
409
        }
410

411
        public void setDosingInstructions(String dosingInstructions) {
UNCOV
412
                this.dosingInstructions = dosingInstructions;
×
UNCOV
413
        }
×
414

415
        public Date getDatePrepared() {
416
                return datePrepared;
1✔
417
        }
418

419
        public void setDatePrepared(Date datePrepared) {
UNCOV
420
                this.datePrepared = datePrepared;
×
UNCOV
421
        }
×
422

423
        public Date getDateHandedOver() {
424
                return dateHandedOver;
1✔
425
        }
426

427
        public void setDateHandedOver(Date dateHandedOver) {
UNCOV
428
                this.dateHandedOver = dateHandedOver;
×
UNCOV
429
        }
×
430

431
        public Boolean getWasSubstituted() {
432
                return wasSubstituted;
1✔
433
        }
434

435
        public void setWasSubstituted(Boolean wasSubstituted) {
UNCOV
436
                this.wasSubstituted = wasSubstituted;
×
UNCOV
437
        }
×
438

439
        public Concept getSubstitutionType() {
440
                return substitutionType;
1✔
441
        }
442

443
        public void setSubstitutionType(Concept substitutionType) {
UNCOV
444
                this.substitutionType = substitutionType;
×
UNCOV
445
        }
×
446

447
        public Concept getSubstitutionReason() {
448
                return substitutionReason;
1✔
449
        }
450

451
        public void setSubstitutionReason(Concept substitutionReason) {
UNCOV
452
                this.substitutionReason = substitutionReason;
×
UNCOV
453
        }
×
454
}
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