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

openmrs / openmrs-core / 14624226260

23 Apr 2025 05:22PM UTC coverage: 63.798% (-0.003%) from 63.801%
14624226260

push

github

ibacher
Revert "TRUNK-6300 Add Storage Service"

This reverts commit 6751872ea.

We need a mechanism to provide a PropertySource and a default value for this property before this is workable.

22014 of 34506 relevant lines covered (63.8%)

0.64 hits per line

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

85.9
/api/src/main/java/org/openmrs/PatientIdentifier.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.io.Serializable;
13
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.Method;
15
import java.util.Comparator;
16

17
import org.codehaus.jackson.annotate.JsonIgnore;
18
import org.hibernate.search.annotations.Analyzer;
19
import org.hibernate.search.annotations.Boost;
20
import org.hibernate.search.annotations.DocumentId;
21
import org.hibernate.search.annotations.Field;
22
import org.hibernate.search.annotations.Fields;
23
import org.hibernate.search.annotations.Indexed;
24
import org.hibernate.search.annotations.IndexedEmbedded;
25
import org.hibernate.search.annotations.SortableField;
26
import org.openmrs.api.db.hibernate.search.LuceneAnalyzers;
27
import org.openmrs.util.OpenmrsUtil;
28
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
30

31
/**
32
 * A <code>Patient</code> can have zero to n identifying PatientIdentifier(s). PatientIdentifiers
33
 * are anything from medical record numbers, to social security numbers, to driver's licenses. The
34
 * type of identifier is defined by the PatientIdentifierType. A PatientIdentifier also contains a
35
 * Location.
36
 *
37
 * @see org.openmrs.PatientIdentifierType
38
 */
39
@Indexed
40
public class PatientIdentifier extends BaseChangeableOpenmrsData implements java.io.Serializable, Cloneable, Comparable<PatientIdentifier> {
41
        
42
        public static final long serialVersionUID = 1123121L;
43
        
44
        private static final Logger log = LoggerFactory.getLogger(PatientIdentifier.class);
1✔
45
        
46
        // Fields
47
        
48
        /**
49
         * @since 1.5
50
         */
51
        @DocumentId
52
        private Integer patientIdentifierId;
53

54
        @IndexedEmbedded(includeEmbeddedObjectId = true)
55
        private Patient patient;
56

57
        @Fields({
58
                        @Field(name = "identifierPhrase", analyzer = @Analyzer(definition = LuceneAnalyzers.PHRASE_ANALYZER), boost = @Boost(8f)),
59
                        @Field(name = "identifierExact", analyzer = @Analyzer(definition = LuceneAnalyzers.EXACT_ANALYZER), boost = @Boost(4f)),
60
                        @Field(name = "identifierStart", analyzer = @Analyzer(definition = LuceneAnalyzers.START_ANALYZER), boost = @Boost(2f)),
61
                        @Field(name = "identifierAnywhere", analyzer = @Analyzer(definition = LuceneAnalyzers.ANYWHERE_ANALYZER))
62
        })
63
        @SortableField(forField = "identifierExact")
64
        private String identifier;
65

66
        @IndexedEmbedded(includeEmbeddedObjectId = true)
67
        private PatientIdentifierType identifierType;
68
        
69
        private Location location;
70

71
        private PatientProgram patientProgram;
72
        
73

74
        @Field
1✔
75
        private Boolean preferred = false;
1✔
76
        
77
        /** default constructor */
78
        public PatientIdentifier() {
1✔
79
        }
1✔
80
        
81
        /**
82
         * Convenience constructor for creating a basic identifier
83
         *
84
         * @param identifier String identifier
85
         * @param type PatientIdentifierType
86
         * @param location Location of the identifier
87
         */
88
        public PatientIdentifier(String identifier, PatientIdentifierType type, Location location) {
1✔
89
                this.identifier = identifier;
1✔
90
                this.identifierType = type;
1✔
91
                this.location = location;
1✔
92
        }
1✔
93
        
94
        /**
95
         * Compares this PatientIdentifier object to the given otherIdentifier. This method differs from
96
         * {@link #equals(Object)} in that this method compares the inner fields of each identifier for
97
         * equality. Note: Null/empty fields on <code>otherIdentifier</code> /will not/ cause a false
98
         * value to be returned
99
         *
100
         * @param otherIdentifier PatientiIdentifier with which to compare
101
         * @return boolean true/false whether or not they are the same names
102
         */
103
        public boolean equalsContent(PatientIdentifier otherIdentifier) {
104
                boolean returnValue = true;
1✔
105
                
106
                // these are the methods to compare.
107
                String[] methods = { "getIdentifier", "getIdentifierType", "getLocation" };
1✔
108
                
109
                Class<? extends PatientIdentifier> identifierClass = this.getClass();
1✔
110
                
111
                // loop over all of the selected methods and compare this and other
112
                for (String methodName : methods) {
1✔
113
                        try {
114
                                Method method = identifierClass.getMethod(methodName);
1✔
115
                                
116
                                Object thisValue = method.invoke(this);
1✔
117
                                Object otherValue = method.invoke(otherIdentifier);
1✔
118
                                
119
                                if (otherValue != null) {
1✔
120
                                        returnValue &= otherValue.equals(thisValue);
1✔
121
                                }
122
                                
123
                        }
124
                        catch (NoSuchMethodException e) {
×
125
                                log.warn("No such method for comparison " + methodName, e);
×
126
                        }
127
                        catch (IllegalAccessException | InvocationTargetException e) {
×
128
                                log.error("Error while comparing identifiers", e);
×
129
                        }
1✔
130

131
                }
132
                
133
                return returnValue;
1✔
134
        }
135
        
136
        //property accessors
137
        
138
        /**
139
         * @return Returns the identifier.
140
         */
141
        public String getIdentifier() {
142
                return identifier;
1✔
143
        }
144
        
145
        /**
146
         * @param identifier The identifier to set.
147
         */
148
        public void setIdentifier(String identifier) {
149
                this.identifier = identifier;
1✔
150
        }
1✔
151
        
152
        /**
153
         * @return Returns the identifierType.
154
         */
155
        public PatientIdentifierType getIdentifierType() {
156
                return identifierType;
1✔
157
        }
158
        
159
        /**
160
         * @param identifierType The identifierType to set.
161
         */
162
        public void setIdentifierType(PatientIdentifierType identifierType) {
163
                this.identifierType = identifierType;
1✔
164
        }
1✔
165
        
166
        /**
167
         * @return Returns the location.
168
         */
169
        public Location getLocation() {
170
                return location;
1✔
171
        }
172
        
173
        /**
174
         * @param location The location to set.
175
         */
176
        public void setLocation(Location location) {
177
                this.location = location;
1✔
178
        }
1✔
179
        
180
        /**
181
         * @return Returns the patient.
182
         */
183
        public Patient getPatient() {
184
                return patient;
1✔
185
        }
186
        
187
        /**
188
         * @param patient The patient to set.
189
         */
190
        public void setPatient(Patient patient) {
191
                this.patient = patient;
1✔
192
        }
1✔
193
        
194
        @Override
195
        public String toString() {
196
                return this.identifier;
1✔
197
        }
198
        
199
        /**
200
         * @return Returns the preferred.
201
         */
202
        public Boolean getPreferred() {
203
                return preferred;
1✔
204
        }
205
        
206
        /**
207
         * @param preferred The preferred to set.
208
         */
209
        public void setPreferred(Boolean preferred) {
210
                this.preferred = preferred;
1✔
211
        }
1✔
212
        
213
        /**
214
         * @return the preferred status
215
         * 
216
         * @deprecated as of 2.0, use {@link #getPreferred()}
217
         */
218
        @Deprecated
219
        @JsonIgnore
220
        public Boolean isPreferred() {
221
                return getPreferred();
×
222
        }
223
        
224
        /**
225
         * @see java.lang.Comparable#compareTo(java.lang.Object)
226
         * @deprecated since 1.12. Use DefaultComparator instead.
227
         * Note: this comparator imposes orderings that are inconsistent with equals.
228
         */
229
        @Deprecated
230
        @Override
231
        @SuppressWarnings("squid:S1210")
232
        public int compareTo(PatientIdentifier other) {
233
                DefaultComparator piDefaultComparator = new DefaultComparator();
1✔
234
                return piDefaultComparator.compare(this, other);
1✔
235
        }
236
        
237
        /**
238
         * @since 1.5
239
         * @see org.openmrs.OpenmrsObject#getId()
240
         */
241
        @Override
242
        public Integer getId() {
243
                return getPatientIdentifierId();
1✔
244
        }
245
        
246
        /**
247
         * @since 1.5
248
         * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
249
         */
250
        @Override
251
        public void setId(Integer id) {
252
                setPatientIdentifierId(id);
×
253
        }
×
254
        
255
        /**
256
         * @since 1.5
257
         * @return the patientIdentifierId
258
         */
259
        public Integer getPatientIdentifierId() {
260
                return patientIdentifierId;
1✔
261
        }
262
        
263
        /**
264
         * @since 1.5
265
         * @param patientIdentifierId the patientIdentifierId to set
266
         */
267
        public void setPatientIdentifierId(Integer patientIdentifierId) {
268
                this.patientIdentifierId = patientIdentifierId;
1✔
269
        }
1✔
270

271
        /**
272
         * bitwise copy of the PatientIdentifier object. NOTICE: THIS WILL NOT COPY THE PATIENT OBJECT. The
273
         * PatientIdentifier.patient object in this object AND the cloned object will point at the same
274
         * patient
275
         *
276
         * @return New PatientIdentifier object
277
         * @since 2.2.0
278
         */
279
        @Override
280
        public Object clone() {
281
                try {
282
                        return super.clone();
1✔
283
                }
284
                catch (CloneNotSupportedException e) {
×
285
                        throw new InternalError("PatientIdentifier should be cloneable");
×
286
                }
287
        }
288
        
289
        /**
290
         Provides a default comparator.
291
         @since 1.12
292
         **/
293
        public static class DefaultComparator implements Comparator<PatientIdentifier>, Serializable {
1✔
294

295
                private static final long serialVersionUID = 1L;
296
                
297
                @Override
298
                public int compare(PatientIdentifier pi1, PatientIdentifier pi2) {
299
                        int retValue = 0;
1✔
300
                        if (pi2 != null) {
1✔
301
                                retValue = pi1.getVoided().compareTo(pi2.getVoided());
1✔
302
                                if (retValue == 0) {
1✔
303
                                        retValue = pi1.getPreferred().compareTo(pi2.getPreferred());
1✔
304
                                }
305
                                if (retValue == 0) {
1✔
306
                                        retValue = OpenmrsUtil.compareWithNullAsLatest(pi1.getDateCreated(), pi2.getDateCreated());
1✔
307
                                }
308
                                if (pi1.getIdentifierType() == null && pi2.getIdentifierType() == null) {
1✔
309
                                        return 0;
1✔
310
                                }
311
                                if (pi1.getIdentifierType() == null && pi2.getIdentifierType() != null) {
1✔
312
                                        retValue = 1;
×
313
                                }
314
                                if (pi1.getIdentifierType() == null && pi2.getIdentifierType() != null) {
1✔
315
                                        retValue = -1;
×
316
                                }
317
                                if (retValue == 0) {
1✔
318
                                        retValue = OpenmrsUtil.compareWithNullAsGreatest(pi1.getIdentifierType().getPatientIdentifierTypeId(),
1✔
319
                                            pi2.getIdentifierType().getPatientIdentifierTypeId());
1✔
320
                                }
321
                                if (retValue == 0) {
1✔
322
                                        retValue = OpenmrsUtil.compareWithNullAsGreatest(pi1.getIdentifier(), pi2.getIdentifier());
1✔
323
                                }
324
                                
325
                                // if we've gotten this far, just check all identifier values.  If they are
326
                                // equal, leave the objects at 0.  If not, arbitrarily pick retValue=1
327
                                // and return that (they are not equal).
328
                                if (retValue == 0 && !pi1.equalsContent(pi2)) {
1✔
329
                                        retValue = 1;
1✔
330
                                }
331
                        }
332
                        
333
                        return retValue;
1✔
334
                }
335
        }
336

337

338
        /**
339
         * Gets patient program associated to the identifier in context
340
         * @since 2.6.0
341
         * @return patientProgram the patient program associated to an identifier
342
         */
343
        public PatientProgram getPatientProgram() {
344
                return patientProgram;
1✔
345
        }
346

347
        /**
348
         * This method sets the patient program on a patient Identifier
349
         * @since 2.6.0
350
         * @param patientProgram The patientProgram to set.
351
         */
352
        public void setPatientProgram(PatientProgram patientProgram) {
353
                this.patientProgram = patientProgram;
1✔
354
        }
1✔
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