From 5b8aebfeeeb85853d26e089ff7ffbed0cbfc3633 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Tue, 3 Mar 2026 13:38:43 -0500 Subject: [PATCH 1/2] #315 - Concept Sets domain incorrectly unretires referenced concepts --- .../module/initializer/api/CsvParser.java | 24 ++++++++++++++----- .../api/c/ConceptSetsCsvParser.java | 12 ++++++++++ .../api/ConceptSetsLoaderIntegrationTest.java | 17 +++++++++++++ .../api/c/ConceptsCsvParserTest.java | 4 +++- .../configuration/concepts/concepts_base.csv | 3 ++- .../conceptsets/concept_sets.csv | 4 +++- .../test/resources/testdata/test-concepts.xml | 2 ++ 7 files changed, 57 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/initializer/api/CsvParser.java b/api/src/main/java/org/openmrs/module/initializer/api/CsvParser.java index cc952bfc3..3bf5b565f 100644 --- a/api/src/main/java/org/openmrs/module/initializer/api/CsvParser.java +++ b/api/src/main/java/org/openmrs/module/initializer/api/CsvParser.java @@ -191,20 +191,21 @@ public List getLines() { public CsvFailingLines process(List lines) { // Save cached objects to avoid losing them prematurely by other Parsers // See DisplaysCsvParser#save(OpenmrsObject) - Context.flushSession(); - Context.clearSession(); - CsvFailingLines result = new CsvFailingLines(); + log.debug(getClass() + " processing " + lines.size() + " lines"); int saved = 0; + clearAndFlushSession(saved); + + CsvFailingLines result = new CsvFailingLines(); + for (String[] line : lines) { T instance = null; try { instance = initialize(line); save(instance); saved++; - if (saved > 250) { // TODO make this configurable - Context.flushSession(); - Context.clearSession(); + if (saved % 250 == 0) { // TODO make this configurable + clearAndFlushSession(saved); } } catch (Exception e) { @@ -218,6 +219,17 @@ public CsvFailingLines process(List lines) { return result; } + /** + * Flushes and clears the hibernate session + * + * @param saved the current count of saved items to log + */ + private void clearAndFlushSession(int saved) { + Context.flushSession(); + Context.clearSession(); + log.debug("Number processed: " + saved); + } + /** * "Initializes" an instance from a CSV line. It bootstraps the instance, then retires early or * fills it. It returns an instance ready to be saved through the API service layer. diff --git a/api/src/main/java/org/openmrs/module/initializer/api/c/ConceptSetsCsvParser.java b/api/src/main/java/org/openmrs/module/initializer/api/c/ConceptSetsCsvParser.java index 7bb6ecc43..b80451871 100644 --- a/api/src/main/java/org/openmrs/module/initializer/api/c/ConceptSetsCsvParser.java +++ b/api/src/main/java/org/openmrs/module/initializer/api/c/ConceptSetsCsvParser.java @@ -39,6 +39,18 @@ public Concept bootstrap(CsvLine line) throws IllegalArgumentException { return concept; } + @Override + public boolean setRetired(Concept instance, boolean retired) { + // The Concept Sets domain should never result in changing the retired status of the underlying concept + return false; + } + + @Override + protected boolean shouldFill(Concept instance, CsvLine csvLine) { + // We need to process all set members, whether the underlying concept is retired or not + return true; + } + @Override public Concept save(Concept instance) { return conceptService.saveConcept(instance); diff --git a/api/src/test/java/org/openmrs/module/initializer/api/ConceptSetsLoaderIntegrationTest.java b/api/src/test/java/org/openmrs/module/initializer/api/ConceptSetsLoaderIntegrationTest.java index 35a8ce31b..5abdba33f 100644 --- a/api/src/test/java/org/openmrs/module/initializer/api/ConceptSetsLoaderIntegrationTest.java +++ b/api/src/test/java/org/openmrs/module/initializer/api/ConceptSetsLoaderIntegrationTest.java @@ -27,6 +27,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class ConceptSetsLoaderIntegrationTest extends DomainBaseModuleContextSensitiveTest { @@ -49,6 +50,15 @@ public void setup() throws Exception { @Test public void load_shouldLoadConceptSetsAccordingToCsvFiles() { + // Test starting values + + { + Concept retiredSet = cs.getConceptByUuid("bcc1796a-16f1-11f1-a7b6-da82fbe923ea"); + assertNotNull(retiredSet); + assertTrue(retiredSet.getRetired()); + assertEquals(0, retiredSet.getSetMembers().size()); + } + // Load conceptsLoader.load(); conceptSetsLoader.load(); @@ -84,5 +94,12 @@ public void load_shouldLoadConceptSetsAccordingToCsvFiles() { assertEquals("Sight", senseAnswers.get(2).getAnswerConcept().getName().getName()); assertEquals(new Double(200), senseAnswers.get(2).getSortWeight()); } + + { + Concept retiredSet = cs.getConceptByUuid("bcc1796a-16f1-11f1-a7b6-da82fbe923ea"); + assertNotNull(retiredSet); + assertTrue(retiredSet.getRetired()); + assertEquals(2, retiredSet.getSetMembers().size()); + } } } diff --git a/api/src/test/java/org/openmrs/module/initializer/api/c/ConceptsCsvParserTest.java b/api/src/test/java/org/openmrs/module/initializer/api/c/ConceptsCsvParserTest.java index 79cd6e9ef..98027e0cd 100644 --- a/api/src/test/java/org/openmrs/module/initializer/api/c/ConceptsCsvParserTest.java +++ b/api/src/test/java/org/openmrs/module/initializer/api/c/ConceptsCsvParserTest.java @@ -55,7 +55,9 @@ public void setup() { ConceptClass classMisc = new ConceptClass(); classMisc.setName("Misc"); when(cs.getConceptClassByName(eq("Misc"))).thenReturn(classMisc); - + ConceptClass convSet = new ConceptClass(); + convSet.setName("ConvSet"); + when(cs.getConceptClassByName(eq("ConvSet"))).thenReturn(convSet); ConceptDatatype typeCoded = new ConceptDatatype(); typeCoded.setName("Coded"); when(cs.getConceptDatatypeByName(eq("Coded"))).thenReturn(typeCoded); diff --git a/api/src/test/resources/testAppDataDir/configuration/concepts/concepts_base.csv b/api/src/test/resources/testAppDataDir/configuration/concepts/concepts_base.csv index d82320450..773874b1d 100644 --- a/api/src/test/resources/testAppDataDir/configuration/concepts/concepts_base.csv +++ b/api/src/test/resources/testAppDataDir/configuration/concepts/concepts_base.csv @@ -16,5 +16,6 @@ foobar,,Cambodia_Lao,កម្ពុជា_ឡាវ,Lao,ឡាវ,,Lao,ឡា ,,,គំនិត_ដោយ_FSN,,ឈ្មោះខ្លីថ្មី,,,,Misc,Text,,,,, 4c93c34e-37c2-11ea-bd28-d70ffe7aa802,,MMR,,,,,,,Misc,N/A,,,,, 4d3cfdcf-1f3f-4b41-9b31-02dfd951c582,,CONCEPT_WITH_ATTRIBUTES,,,,,,,Misc,Text,,jdoe@example.com,2020-04-06,, -fda5cc2a-6245-4d91-be17-446d27aab33b,,Testing Fully Specified Name,,Testing Short Name,,,,,Misc,,,,,, +fda5cc2a-6245-4d91-be17-446d27aab33b,,Testing Fully Specified Name,,Testing Short Name,,,,,ConvSet,N/A,,,,, 1ddb8255-00d5-45e8-8830-f9567919a382,,Replaced Fully Specified Name,,Rpl SN,,Replaced Synonym,,,Misc,Text,,,,, +bcc1796a-16f1-11f1-a7b6-da82fbe923ea,true,Retired Set,,,,,,,ConvSet,N/A,,,,, diff --git a/api/src/test/resources/testAppDataDir/configuration/conceptsets/concept_sets.csv b/api/src/test/resources/testAppDataDir/configuration/conceptsets/concept_sets.csv index 50cb35db1..ef972225e 100644 --- a/api/src/test/resources/testAppDataDir/configuration/conceptsets/concept_sets.csv +++ b/api/src/test/resources/testAppDataDir/configuration/conceptsets/concept_sets.csv @@ -6,4 +6,6 @@ CIEL:SENSE_SET,CIEL:TOUCH,,4.0,, 54014540-311d-11ec-8d2b-0242ac110002,Sound,,50,, 5a393db9-311d-11ec-8d2b-0242ac110002,CIEL:SMELL,Q-AND-A,"",, How did you sense it?,CIEL:SIGHT,q-and-a,200,, -CIEL:SENSE_QUESTION,CIEL:SOUND,,100,, \ No newline at end of file +CIEL:SENSE_QUESTION,CIEL:SOUND,,100,, +bcc1796a-16f1-11f1-a7b6-da82fbe923ea,SMELL,concept-set,1.0,, +bcc1796a-16f1-11f1-a7b6-da82fbe923ea,TASTE,concept-set,2.0,, \ No newline at end of file diff --git a/api/src/test/resources/testdata/test-concepts.xml b/api/src/test/resources/testdata/test-concepts.xml index eb2ef27f9..aa7ad3ef0 100644 --- a/api/src/test/resources/testdata/test-concepts.xml +++ b/api/src/test/resources/testdata/test-concepts.xml @@ -20,6 +20,7 @@ + @@ -44,6 +45,7 @@ + From 6e11b41f2aac615fe49be8c8c7d782c3c1ac1b8d Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Tue, 3 Mar 2026 13:41:59 -0500 Subject: [PATCH 2/2] #315 - Concept Sets domain incorrectly unretires referenced concepts --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f4c883c15..213348f8e 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,8 @@ See the [documentation on Initializer's logging properties](readme/rtprops.md#lo ## Releases notes #### version 2.12.0 +* Fix conceptsets domain to prevent incorrect unretiring of associated concept + #### Version 2.11.0 * Added support for patient flags (flags, flagpriorities, flagtags) domains * Support for 'billing' (billableservices, paymentmodes, cashpoints) for Billing V2