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

openmrs / openmrs-core / 22629535597

03 Mar 2026 03:16PM UTC coverage: 65.387% (-0.007%) from 65.394%
22629535597

push

github

ibacher
TRUNK-6512: Introduce ConceptReferenceRangeContext API (#5880)

Co-authored-by: Binayak490-cyber <binayak490@gmail.com>

104 of 129 new or added lines in 4 files covered. (80.62%)

4 existing lines in 4 files now uncovered.

23838 of 36457 relevant lines covered (65.39%)

0.65 hits per line

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

57.14
/api/src/main/java/org/openmrs/ConceptReferenceRangeContext.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.Date;
13

14
/**
15
 * Holds the context needed to resolve a concept reference range for a given person and concept. The
16
 * optional date field supports retrospective entry scenarios where date-relative criteria (e.g. age
17
 * at encounter time) should be evaluated at a point in time other than today.
18
 * 
19
 * @since 3.0.0, 2.9.0, 2.8.5, 2.7.9
20
 */
21
public class ConceptReferenceRangeContext {
22
        
23
        private final Person person;
24
        
25
        private final Concept concept;
26
        
27
        private final Date date;
28
        
29
        private final Encounter encounter;
30
        
31
        private final Obs obs;
32
        
33
        /**
34
         * @param person the person to evaluate criteria against (required)
35
         * @param concept the concept whose reference ranges to resolve (required)
36
         * @param date the date at which to evaluate criteria, or null for today
37
         */
38
        public ConceptReferenceRangeContext(Person person, Concept concept, Date date) {
1✔
39
                if (person == null) {
1✔
NEW
40
                        throw new IllegalArgumentException("person is required");
×
41
                }
42
                if (concept == null) {
1✔
NEW
43
                        throw new IllegalArgumentException("concept is required");
×
44
                }
45
                this.person = person;
1✔
46
                this.concept = concept;
1✔
47
                this.date = date;
1✔
48
                this.encounter = null;
1✔
49
                this.obs = null;
1✔
50
        }
1✔
51
        
52
        /**
53
         * Convenience constructor that extracts person, concept, and obsDatetime from an existing Obs.
54
         * The Obs is retained so that criteria expressions referencing {@code $obs} (e.g.
55
         * {@code $obs.obsDatetime}) continue to work.
56
         * 
57
         * @param obs the observation to extract context from
58
         */
59
        public ConceptReferenceRangeContext(Obs obs) {
1✔
60
                if (obs == null) {
1✔
NEW
61
                        throw new IllegalArgumentException("obs is required");
×
62
                }
63
                if (obs.getPerson() == null) {
1✔
NEW
64
                        throw new IllegalArgumentException("person is required");
×
65
                }
66
                if (obs.getConcept() == null) {
1✔
NEW
67
                        throw new IllegalArgumentException("concept is required");
×
68
                }
69
                this.person = obs.getPerson();
1✔
70
                this.concept = obs.getConcept();
1✔
71
                this.date = obs.getObsDatetime();
1✔
72
                this.encounter = obs.getEncounter();
1✔
73
                this.obs = obs;
1✔
74
        }
1✔
75
        
76
        /**
77
         * Construct a context from an encounter and concept. The patient and encounter datetime are
78
         * extracted from the encounter.
79
         * 
80
         * @param encounter the encounter to extract context from (required)
81
         * @param concept the concept whose reference ranges to resolve (required)
82
         * @since 3.0.0, 2.9.0, 2.8.5, 2.7.9
83
         */
NEW
84
        public ConceptReferenceRangeContext(Encounter encounter, Concept concept) {
×
NEW
85
                if (encounter == null) {
×
NEW
86
                        throw new IllegalArgumentException("encounter is required");
×
87
                }
NEW
88
                if (encounter.getPatient() == null) {
×
NEW
89
                        throw new IllegalArgumentException("person is required");
×
90
                }
NEW
91
                if (concept == null) {
×
NEW
92
                        throw new IllegalArgumentException("concept is required");
×
93
                }
NEW
94
                this.person = encounter.getPatient();
×
NEW
95
                this.concept = concept;
×
NEW
96
                this.date = encounter.getEncounterDatetime();
×
NEW
97
                this.encounter = encounter;
×
NEW
98
                this.obs = null;
×
NEW
99
        }
×
100
        
101
        public Person getPerson() {
102
                return person;
1✔
103
        }
104
        
105
        public Concept getConcept() {
106
                return concept;
1✔
107
        }
108
        
109
        /**
110
         * @return the date at which to evaluate criteria, or null meaning "today"
111
         */
112
        public Date getDate() {
113
                return date;
1✔
114
        }
115
        
116
        /**
117
         * @return the encounter if this context was constructed from one or from an Obs with an
118
         *         encounter, or null
119
         * @since 3.0.0, 2.9.0, 2.8.5, 2.7.9
120
         */
121
        public Encounter getEncounter() {
122
                return encounter;
1✔
123
        }
124
        
125
        /**
126
         * @return the original Obs if this context was constructed from one, or null
127
         */
128
        public Obs getObs() {
129
                return obs;
1✔
130
        }
131
}
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