Skip to content

Commit

Permalink
TRUNK-6245 - Save concept reference ranges in the same order as from …
Browse files Browse the repository at this point in the history
…UI (openmrs#4769)
  • Loading branch information
dicksonmulli authored Oct 3, 2024
1 parent 45cfd84 commit 543df8f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions api/src/main/java/org/openmrs/ConceptNumeric.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.openmrs;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.TreeSet;

Expand Down Expand Up @@ -58,7 +59,7 @@ public class ConceptNumeric extends Concept {

/** default constructor */
public ConceptNumeric() {
referenceRanges = new HashSet<>();
referenceRanges = new LinkedHashSet<>();
}

/**
Expand Down Expand Up @@ -132,7 +133,7 @@ public ConceptNumeric(Concept c) {
this.units = "";
this.allowDecimal = false;

referenceRanges = new HashSet<>();
referenceRanges = new LinkedHashSet<>();
}

// Property accessors
Expand Down
32 changes: 32 additions & 0 deletions api/src/test/java/org/openmrs/ConceptNumericTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import org.openmrs.api.context.Context;
import org.openmrs.test.jupiter.BaseContextSensitiveTest;

import java.util.ArrayList;
import java.util.List;

/**
* Tests the {@link ConceptNumeric} object
*/
Expand Down Expand Up @@ -148,4 +151,33 @@ public void shouldRemoveReferenceRangeFromConceptNumeric() {
Context.getConceptService().saveConcept(cn);
assertEquals(1, Context.getConceptService().getConceptNumeric(22).getReferenceRanges().size());
}

@Test
public void shouldMaintainInsertionOrderOfReferenceRangesWithConstructor() {
Concept concept = new Concept();
concept.setConceptId(1);

ConceptNumeric conceptNumeric = new ConceptNumeric(concept);

ConceptReferenceRange referenceRange1 = new ConceptReferenceRange();
referenceRange1.setId(1);
ConceptReferenceRange referenceRange2 = new ConceptReferenceRange();
referenceRange2.setId(2);
ConceptReferenceRange referenceRange3 = new ConceptReferenceRange();
referenceRange3.setId(3);
ConceptReferenceRange referenceRange4 = new ConceptReferenceRange();
referenceRange4.setId(4);

conceptNumeric.addReferenceRange(referenceRange1);
conceptNumeric.addReferenceRange(referenceRange2);
conceptNumeric.addReferenceRange(referenceRange3);
conceptNumeric.addReferenceRange(referenceRange4);

List<ConceptReferenceRange> referenceRangeList = new ArrayList<>(conceptNumeric.getReferenceRanges());

assertEquals(1, referenceRangeList.get(0).getId().intValue());
assertEquals(2, referenceRangeList.get(1).getId().intValue());
assertEquals(3, referenceRangeList.get(2).getId().intValue());
assertEquals(4, referenceRangeList.get(3).getId().intValue());
}
}

0 comments on commit 543df8f

Please sign in to comment.