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

openmrs / openmrs-core / 42638912720

09 Nov 2026 02:52PM UTC coverage: 66.721% (-0.05%) from 66.768%
42638912720

push

github

web-flow
Revert "TRUNK-6848: Reject invalid dates and times in Obs.setValueAsString for DT and TM datatypes (#6732)" (#6816)

This reverts commit 4572518d7.

Reverting while the behavior changes are reviewed. Strict DT parsing rejects
"yyyy-MM-dd HH:mm[:ss]" values that existing clients send for DT obs (e.g.
labtrackingapp), and the ISO fallback now stores a time component on DT obs
instead of truncating to the date. See TRUNK-6848 for details.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

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

6 existing lines in 4 files now uncovered.

26246 of 39337 relevant lines covered (66.72%)

0.67 hits per line

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

76.92
/api/src/main/java/org/openmrs/ConceptName.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.Date;
14
import java.util.HashSet;
15
import java.util.Locale;
16

17
import org.apache.commons.lang3.StringUtils;
18
import org.codehaus.jackson.annotate.JsonIgnore;
19
import org.hibernate.envers.Audited;
20
import org.openmrs.util.CollectionUtil;
21
import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.ValueBridgeRef;
22
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;
23
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
24
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField;
25
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
26
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded;
27
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField;
28
import org.openmrs.api.ConceptNameType;
29
import org.openmrs.api.db.hibernate.search.SearchAnalysis;
30
import org.openmrs.api.db.hibernate.search.bridge.LocaleValueBridge;
31

32
/**
33
 * ConceptName is the real world term used to express a Concept within the idiom of a particular
34
 * locale.
35
 */
36
@Indexed
37
@Audited
38
public class ConceptName extends BaseOpenmrsObject implements Auditable, Voidable, java.io.Serializable {
39
        
40
        public static final long serialVersionUID = 2L;
41
        
42
        @DocumentId
43
        private Integer conceptNameId;
44
        
45
        @IndexedEmbedded(includeEmbeddedObjectId = true)
46
        private Concept concept;
47
        
48
        @FullTextField(analyzer = SearchAnalysis.NAME_ANALYZER)
49
        private String name;
50
        
51
        @KeywordField(valueBridge = @ValueBridgeRef(type = LocaleValueBridge.class))
52
        private Locale locale; 
53
        
54
        private User creator;
55
        
56
        private Date dateCreated;
57
        
58
        @GenericField
1 ✔
59
        private Boolean voided = false;
1 ✔
60
        
61
        private User voidedBy;
62
        
63
        private Date dateVoided;
64
        
65
        private String voidReason;
66
        
67
        private Collection<ConceptNameTag> tags;
68
        
69
        @GenericField
70
        private ConceptNameType conceptNameType;
71
        
72
        @GenericField
1 ✔
73
        private Boolean localePreferred = false;
1 ✔
74
        
75
        private User changedBy;
76
        
77
        private Date dateChanged;
78
        
79
        // Constructors
80
        
81
        /** default constructor */
82
        public ConceptName() {
1 ✔
83
        }
1 ✔
84
        
85
        /**
86
         * Convenience constructor to create a ConceptName object by primary key
87
         *
88
         * @param conceptNameId
89
         */
90
        public ConceptName(Integer conceptNameId) {
1 ✔
91
                this.conceptNameId = conceptNameId;
1 ✔
92
        }
1 ✔
93
        
94
        public ConceptName(String name, Locale locale) {
1 ✔
95
                setName(name);
1 ✔
96
                setLocale(locale);
1 ✔
97
        }
1 ✔
98
        
99
        /**
100
         * @return Returns the conceptId.
101
         */
102
        public Integer getConceptNameId() {
103
                return conceptNameId;
1 ✔
104
        }
105
        
106
        /**
107
         * @param conceptNameId The conceptId to set.
108
         */
109
        public void setConceptNameId(Integer conceptNameId) {
110
                this.conceptNameId = conceptNameId;
1 ✔
111
        }
1 ✔
112
        
113
        public Concept getConcept() {
114
                return concept;
1 ✔
115
        }
116
        
117
        public void setConcept(Concept concept) {
118
                this.concept = concept;
1 ✔
119
        }
1 ✔
120
        
121
        public String getName() {
122
                return name;
1 ✔
123
        }
124
        
125
        public void setName(String name) {
126
                if (name != null && StringUtils.isBlank(name) && StringUtils.isNotBlank(this.name)
1 ✔
127
                        && this.getConceptNameType().equals(ConceptNameType.SHORT)) {
×
128
                        this.setVoided(true);
×
129
                } else {
130
                        this.name = name;
1 ✔
131
                }
132
        }
1 ✔
133
        
134
        public Locale getLocale() {
135
                return locale;
1 ✔
136
        }
137
        
138
        public void setLocale(Locale locale) {
139
                this.locale = locale;
1 ✔
140
        }
1 ✔
141

142
        /**
143
         * @return Returns the creator.
144
         */
145
        @Override
146
        public User getCreator() {
147
                return creator;
1 ✔
148
        }
149
        
150
        /**
151
         * @param creator The creator to set.
152
         */
153
        @Override
154
        public void setCreator(User creator) {
155
                this.creator = creator;
1 ✔
156
        }
1 ✔
157
        
158
        /**
159
         * @return Returns the dateCreated.
160
         */
161
        @Override
162
        public Date getDateCreated() {
163
                return dateCreated;
1 ✔
164
        }
165
        
166
        /**
167
         * @param dateCreated The dateCreated to set.
168
         */
169
        @Override
170
        public void setDateCreated(Date dateCreated) {
171
                this.dateCreated = dateCreated;
1 ✔
172
        }
1 ✔
173
        
174
        /**
175
         * Returns whether the ConceptName has been voided.
176
         *
177
         * @return true if the ConceptName has been voided, false otherwise.
178
         * 
179
         * @deprecated as of 2.0, use {@link #getVoided()}
180
         */
181
        @Override
182
        @Deprecated
183
        @JsonIgnore
184
        public Boolean isVoided() {
185
                return getVoided();
1 ✔
186
        }
187
        
188
        /**
189
         * Returns whether the ConceptName has been voided.
190
         *
191
         * @return true if the ConceptName has been voided, false otherwise.
192
         */
193
        @Override
194
        public Boolean getVoided() {
195
                return voided;
1 ✔
196
        }
197
        
198
        /**
199
         * Sets the voided status of this ConceptName.
200
         *
201
         * @param voided the voided status to set.
202
         */
203
        @Override
204
        public void setVoided(Boolean voided) {
205
                this.voided = voided;
1 ✔
206
        }
1 ✔
207
        
208
        /**
209
         * Returns the User who voided this ConceptName.
210
         *
211
         * @return the User who voided this ConceptName, or null if not set
212
         */
213
        @Override
214
        public User getVoidedBy() {
215
                return voidedBy;
1 ✔
216
        }
217
        
218
        /**
219
         * Sets the User who voided this ConceptName.
220
         *
221
         * @param voidedBy the user who voided this ConceptName.
222
         */
223
        @Override
224
        public void setVoidedBy(User voidedBy) {
225
                this.voidedBy = voidedBy;
1 ✔
226
        }
1 ✔
227
        
228
        /**
229
         * Returns the Date this ConceptName was voided.
230
         *
231
         * @return the Date this ConceptName was voided.
232
         */
233
        @Override
234
        public Date getDateVoided() {
235
                return dateVoided;
1 ✔
236
        }
237
        
238
        /**
239
         * Sets the Data this ConceptName was voided.
240
         *
241
         * @param dateVoided the date the ConceptName was voided.
242
         */
243
        @Override
244
        public void setDateVoided(Date dateVoided) {
245
                this.dateVoided = dateVoided;
1 ✔
246
        }
1 ✔
247
        
248
        /**
249
         * Returns the reason this ConceptName was voided.
250
         *
251
         * @return the reason this ConceptName was voided
252
         */
253
        @Override
254
        public String getVoidReason() {
255
                return voidReason;
1 ✔
256
        }
257
        
258
        /**
259
         * Sets the reason this ConceptName was voided.
260
         *
261
         * @param voidReason the reason this ConceptName was voided
262
         */
263
        @Override
264
        public void setVoidReason(String voidReason) {
265
                this.voidReason = voidReason;
1 ✔
266
        }
1 ✔
267
        
268
        /**
269
         * Returns the tags which have been attached to this ConceptName.
270
         *
271
         * @return the tags.
272
         */
273
        public Collection<ConceptNameTag> getTags() {
274
                return tags;
1 ✔
275
        }
276
        
277
        /**
278
         * Set the tags which are attached to this ConceptName.
279
         *
280
         * @see Concept#setPreferredName(ConceptName)
281
         * @see Concept#setFullySpecifiedName(ConceptName)
282
         * @see Concept#setShortName(ConceptName)
283
         * @param tags the tags to set.
284
         */
285
        public void setTags(Collection<ConceptNameTag> tags) {
286
                this.tags = CollectionUtil.setCollection(this.tags, tags);
1 ✔
287
        }
1 ✔
288
        
289
        /**
290
         * @return the conceptNameType
291
         */
292
        public ConceptNameType getConceptNameType() {
293
                return this.conceptNameType;
1 ✔
294
        }
295
        
296
        /**
297
         * @param conceptNameType the conceptNameType to set
298
         */
299
        public void setConceptNameType(ConceptNameType conceptNameType) {
300
                this.conceptNameType = conceptNameType;
1 ✔
301
        }
1 ✔
302
        
303
        /**
304
         * Getter for localePreferred
305
         *
306
         * @return localPreferred
307
         * 
308
         * @deprecated as of 2.0, use {@link #getLocalePreferred()}
309
         */
310
        @Deprecated
311
        @JsonIgnore
312
        public Boolean isLocalePreferred() {
UNCOV
313
                return getLocalePreferred();
×
314
        }
315
        
316
        /**
317
         *
318
         * @return true if it is the localePreferred name otherwise false
319
         */
320
        public Boolean getLocalePreferred() {
321
                return localePreferred;
1 ✔
322
        }
323
        
324
        /**
325
         * @param localePreferred the localePreferred to set
326
         */
327
        public void setLocalePreferred(Boolean localePreferred) {
328
                this.localePreferred = localePreferred;
1 ✔
329
        }
1 ✔
330
        
331
        /**
332
         * Adds a tag to the concept name. If the tag is new (has no existing occurrences) a new
333
         * ConceptNameTag will be created with a blank description.
334
         *
335
         * @see Concept#setPreferredName(ConceptName)
336
         * @see Concept#setFullySpecifiedName(ConceptName)
337
         * @see Concept#setShortName(ConceptName)
338
         * @param tag human-readable text string for the tag
339
         */
340
        public void addTag(String tag) {
341
                addTag(tag, "");
1 ✔
342
        }
1 ✔
343
        
344
        /**
345
         * Adds a tag to the concept name. If the tag is new (has no existing occurrences) a new
346
         * ConceptNameTag will be created with the given description.
347
         *
348
         * @see Concept#setPreferredName(ConceptName)
349
         * @see Concept#setFullySpecifiedName(ConceptName)
350
         * @see Concept#setShortName(ConceptName)
351
         * @param tag human-readable text string for the tag
352
         * @param description description of the tag's purpose
353
         */
354
        public void addTag(String tag, String description) {
355
                ConceptNameTag nameTag = new ConceptNameTag(tag, description);
1 ✔
356
                addTag(nameTag);
1 ✔
357
        }
1 ✔
358
        
359
        /**
360
         * Attaches a tag to the concept name.
361
         *
362
         * @see Concept#setPreferredName(ConceptName)
363
         * @see Concept#setFullySpecifiedName(ConceptName)
364
         * @see Concept#setShortName(ConceptName)
365
         * @param tag the tag to add
366
         */
367
        public void addTag(ConceptNameTag tag) {
368
                if (tags == null) {
1 ✔
369
                        tags = new HashSet<>();
1 ✔
370
                }
371
                
372
                if (!tags.contains(tag)) {
1 ✔
373
                        tags.add(tag);
1 ✔
374
                }
375
        }
1 ✔
376
        
377
        /**
378
         * Removes a tag from the concept name.
379
         *
380
         * @see Concept#setPreferredName(ConceptName)
381
         * @see Concept#setFullySpecifiedName(ConceptName)
382
         * @see Concept#setShortName(ConceptName)
383
         * @param tag the tag to remove
384
         */
385
        public void removeTag(ConceptNameTag tag) {
386
                if (tags.contains(tag)) {
×
387
                        tags.remove(tag);
×
388
                }
389
        }
×
390
        
391
        /**
392
         * Checks whether the name has a particular tag.
393
         *
394
         * @see #isPreferred()
395
         * @see #isFullySpecifiedName()
396
         * @see #isIndexTerm()
397
         * @see #isSynonym()
398
         * @see #isShort()
399
         * @param tagToFind the tag for which to check
400
         * @return true if the tags include the specified tag, false otherwise
401
         */
402
        public Boolean hasTag(ConceptNameTag tagToFind) {
403
                return hasTag(tagToFind.getTag());
×
404
        }
405
        
406
        /**
407
         * Checks whether the name has a particular tag.
408
         *
409
         * @see #isPreferred()
410
         * @see #isFullySpecifiedName()
411
         * @see #isIndexTerm()
412
         * @see #isSynonym()
413
         * @see #isShort()
414
         * @param tagToFind the string of the tag for which to check
415
         * @return true if the tags include the specified tag, false otherwise
416
         */
417
        public Boolean hasTag(String tagToFind) {
418
                boolean foundTag = false;
×
419
                if (tags != null) {
×
420
                        for (ConceptNameTag nameTag : getTags()) {
×
421
                                if (nameTag.getTag().equals(tagToFind)) {
×
422
                                        foundTag = true;
×
423
                                        break;
×
424
                                }
425
                        }
×
426
                }
427
                return foundTag;
×
428
        }
429
        
430
        /**
431
         * Checks whether the name is explicitly marked as preferred in a locale with a matching
432
         * language. E.g 'en_US' and 'en_UK' for language en
433
         *
434
         * @see #isPreferredForLocale(Locale)
435
         * @param language ISO 639 2-letter code for a language
436
         * @return true if the name is preferred in a locale with a matching language code, otherwise
437
         *         false
438
         */
439
        public Boolean isPreferredInLanguage(String language) {
440
                return !StringUtils.isBlank(language) && this.locale != null && isPreferred()
×
441
                                && this.locale.getLanguage().equals(language);
×
442

443
        }
444
        
445
        /**
446
         * Checks whether the name is explicitly marked as preferred in a locale with a matching country
447
         * code E.g 'fr_RW' and 'en_RW' for country RW
448
         *
449
         * @see #isPreferredForLocale(Locale)
450
         * @param country ISO 3166 2-letter code for a country
451
         * @return true if the name is preferred in a locale with a matching country code, otherwise
452
         *         false
453
         */
454
        public Boolean isPreferredInCountry(String country) {
455
                return !StringUtils.isBlank(country) && this.locale != null && isPreferred()
×
456
                                && this.locale.getCountry().equals(country);
×
457

458
        }
459
        
460
        /**
461
         * Checks whether the name is explicitly marked as preferred for any locale. Note that this
462
         * method is different from {@link #isPreferredForLocale(Locale)} in that it checks if the given
463
         * name is marked as preferred irrespective of the locale in which it is preferred.
464
         *
465
         * @see #isPreferredForLocale(Locale)
466
         */
467
        public Boolean isPreferred() {
468
                return getLocalePreferred();
1 ✔
469
        }
470
        
471
        /**
472
         * Checks whether the name is explicitly marked as preferred for the given locale
473
         *
474
         * @param locale the locale in which the name is preferred
475
         * @return true if the name is marked as preferred for the given locale otherwise false.
476
         */
477
        public Boolean isPreferredForLocale(Locale locale) {
478
                return getLocalePreferred() && this.locale.equals(locale);
×
479
        }
480
        
481
        /**
482
         * Checks whether the concept name is explicitly marked as fully specified
483
         *
484
         * @return true if the name is marked as 'fully specified' otherwise false
485
         * @since Version 1.7
486
         */
487
        public Boolean isFullySpecifiedName() {
488
                return ConceptNameType.FULLY_SPECIFIED.equals(getConceptNameType());
1 ✔
489
        }
490
        
491
        /**
492
         * Convenience method for determining whether this is a short name.
493
         *
494
         * @return true if the name is marked as a short name, otherwise false
495
         */
496
        public Boolean isShort() {
497
                return ConceptNameType.SHORT.equals(getConceptNameType());
1 ✔
498
        }
499
        
500
        /**
501
         * Convenience method for checking whether this is an index Term.
502
         *
503
         * @return true if the name is marked as an index term, otherwise false
504
         * @since Version 1.7
505
         */
506
        public Boolean isIndexTerm() {
507
                return ConceptNameType.INDEX_TERM.equals(getConceptNameType());
1 ✔
508
        }
509
        
510
        /**
511
         * Convenience method for determining whether this is an index Term for a given locale.
512
         *
513
         * @param locale The locale in which this concept name should belong as an index term
514
         * @return true if the name is marked as an index term, otherwise false
515
         */
516
        public Boolean isIndexTermInLocale(Locale locale) {
517
                return getConceptNameType() != null && getConceptNameType().equals(ConceptNameType.INDEX_TERM)
×
518
                        && locale.equals(getLocale());
×
519
        }
520
        
521
        /**
522
         * Convenience method for determining whether this is a synonym in a given locale.
523
         *
524
         * @param locale The locale in which this synonym should belong
525
         * @return true if the concept name is marked as a synonym in the given locale, otherwise false
526
         */
527
        public Boolean isSynonymInLocale(Locale locale) {
528
                return getConceptNameType() == null && locale.equals(getLocale());
×
529
        }
530
        
531
        /**
532
         * Convenience method for checking whether this is a a synonym.
533
         *
534
         * @return true if the name is tagged as a synonym, false otherwise
535
         * @since Version 1.7
536
         */
537
        public Boolean isSynonym() {
538
                return getConceptNameType() == null;
1 ✔
539
        }
540
        
541
        /**
542
         * @see java.lang.Object#toString()
543
         */
544
        @Override
545
        public String toString() {
546
                if (this.name == null) {
1 ✔
547
                        return "ConceptNameId: " + this.conceptNameId;
×
548
                }
549
                
550
                return this.name;
1 ✔
551
        }
552
        
553
        /**
554
         * @since 1.5
555
         * @see org.openmrs.OpenmrsObject#getId()
556
         */
557
        @Override
558
        public Integer getId() {
559
                return getConceptNameId();
1 ✔
560
        }
561
        
562
        /**
563
         * @since 1.5
564
         * @see org.openmrs.OpenmrsObject#setId(java.lang.Integer)
565
         */
566
        @Override
567
        public void setId(Integer id) {
568
                setConceptNameId(id);
1 ✔
569
        }
1 ✔
570
        
571
        /**
572
         * @return Returns the changedBy.
573
         */
574
        @Override
575
        public User getChangedBy() {
576
                return changedBy;
1 ✔
577
        }
578
        
579
        /**
580
         * @param changedBy The user that changed this object
581
         */
582
        @Override
583
        public void setChangedBy(User changedBy) {
584
                this.changedBy = changedBy;
1 ✔
585
        }
1 ✔
586
        
587
        /**
588
         * @return Returns the date this object was changed
589
         */
590
        @Override
591
        public Date getDateChanged() {
592
                return dateChanged;
1 ✔
593
        }
594
        
595
        /**
596
         * @param dateChanged The date this object was changed
597
         */
598
        @Override
599
        public void setDateChanged(Date dateChanged) {
600
                this.dateChanged = dateChanged;
1 ✔
601
        }
1 ✔
602
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc