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

openmrs / openmrs-core / 9449810392

10 Jun 2024 02:04PM UTC coverage: 63.671% (-0.008%) from 63.679%
9449810392

push

github

ibacher
Revert "TRUNK-6242: editing the hydrate() to fetch concepts by id/Uuid/mappings by replacing ConceptService#getConcept() with  ConceptService#getConceptByReference() (#4660)"

This reverts commit 87b52cd5d.

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

6 existing lines in 4 files now uncovered.

21662 of 34022 relevant lines covered (63.67%)

0.64 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.apache.lucene.analysis.core.LowerCaseFilterFactory;
19
import org.apache.lucene.analysis.standard.StandardFilterFactory;
20
import org.apache.lucene.analysis.standard.StandardTokenizerFactory;
21
import org.codehaus.jackson.annotate.JsonIgnore;
22
import org.hibernate.search.annotations.Analyze;
23
import org.hibernate.search.annotations.Analyzer;
24
import org.hibernate.search.annotations.AnalyzerDef;
25
import org.hibernate.search.annotations.DocumentId;
26
import org.hibernate.search.annotations.Field;
27
import org.hibernate.search.annotations.FieldBridge;
28
import org.hibernate.search.annotations.Indexed;
29
import org.hibernate.search.annotations.IndexedEmbedded;
30
import org.hibernate.search.annotations.TokenFilterDef;
31
import org.hibernate.search.annotations.TokenizerDef;
32
import org.openmrs.api.ConceptNameType;
33
import org.openmrs.api.db.hibernate.search.bridge.LocaleFieldBridge;
34

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

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

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

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