From 11d7c5cb61269bf35da92c739d978866eb9df3ee Mon Sep 17 00:00:00 2001 From: Ruhanga <41738040+Ruhanga@users.noreply.github.com> Date: Thu, 7 Dec 2023 19:07:53 +0300 Subject: [PATCH 1/3] [#257] Provision to allow overriding concepts datatype to 'Numeric'. (#258) --- .../api/c/ConceptNumericLineProcessor.java | 7 ++++++- .../c/ConceptNumericLineProcessorTest.java | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessor.java b/api/src/main/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessor.java index da25b8025..25ac69fc4 100644 --- a/api/src/main/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessor.java +++ b/api/src/main/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessor.java @@ -42,10 +42,15 @@ public Concept fill(Concept instance, CsvLine line) throws IllegalArgumentExcept return instance; } - ConceptNumeric cn = new ConceptNumeric(instance); + ConceptNumeric cn = null; if (instance.getId() != null) { // below overrides any other processors work, so this one should be called first cn = conceptService.getConceptNumeric(instance.getId()); } + + if (cn == null) { + cn = new ConceptNumeric(instance); + } + cn.setDatatype(conceptService.getConceptDatatypeByName(DATATYPE_NUMERIC)); cn.setHiAbsolute(line.getDouble(HEADER_AH)); diff --git a/api/src/test/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessorTest.java b/api/src/test/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessorTest.java index 8eb2da7e1..63fbd313c 100644 --- a/api/src/test/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessorTest.java +++ b/api/src/test/java/org/openmrs/module/initializer/api/c/ConceptNumericLineProcessorTest.java @@ -1,7 +1,9 @@ package org.openmrs.module.initializer.api.c; import static org.mockito.Matchers.any; +import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.junit.Assert; @@ -89,4 +91,22 @@ public void fill_shouldFailWhenCannotParse() { ConceptNumericLineProcessor p = new ConceptNumericLineProcessor(cs); p.fill(new Concept(), new CsvLine(headerLine, line)); } + + @Test + public void fill_shouldOverrideProvidedDataType() { + + // Setup + when(cs.getConceptNumeric(any(Integer.class))).thenReturn(null); + String[] headerLine = { "Data type", "Absolute low" }; + String[] line = { "Numeric", "11.11" }; + + // Replay + ConceptNumericLineProcessor p = new ConceptNumericLineProcessor(cs); + ConceptNumeric cn = (ConceptNumeric) p.fill(new Concept(1), new CsvLine(headerLine, line)); + + // Verify + verify(cs, atLeast(1)).getConceptNumeric(any(Integer.class)); + Assert.assertEquals(ConceptNumericLineProcessor.DATATYPE_NUMERIC, cn.getDatatype().getName()); + Assert.assertEquals(0, cn.getLowAbsolute().compareTo(11.11)); + } } From 935aaa238e6bd6e2032933308674afcecf2e50b1 Mon Sep 17 00:00:00 2001 From: Cosmin Date: Thu, 18 Jan 2024 13:58:08 -0500 Subject: [PATCH 2/3] O3-2446: 'queues' domain to support loading Status and Priority entries. (#260) --- .../api/queues/QueueLineProcessor.java | 20 +++++++++++++++++++ .../queues/QueueLoaderIntegrationTest.java | 11 ++++++++++ .../configuration/queues/queues.csv | 7 ++++--- .../test/resources/testdata/test-queues.xml | 4 ++++ pom.xml | 2 +- readme/queues.md | 14 +++++++++---- 6 files changed, 50 insertions(+), 8 deletions(-) diff --git a/api-2.3/src/main/java/org/openmrs/module/initializer/api/queues/QueueLineProcessor.java b/api-2.3/src/main/java/org/openmrs/module/initializer/api/queues/QueueLineProcessor.java index d675ceecd..370469079 100644 --- a/api-2.3/src/main/java/org/openmrs/module/initializer/api/queues/QueueLineProcessor.java +++ b/api-2.3/src/main/java/org/openmrs/module/initializer/api/queues/QueueLineProcessor.java @@ -19,6 +19,10 @@ public class QueueLineProcessor extends BaseLineProcessor { protected static String HEADER_SERVICE = "service"; + protected static String HEADER_STATUS_CONCEPT_SET = "status concept set"; + + protected static String HEADER_PRIORITY_CONCEPT_SET = "priority concept set"; + protected static String HEADER_LOCATION = "location"; private final ConceptService conceptService; @@ -45,6 +49,22 @@ public Queue fill(Queue queue, CsvLine line) throws IllegalArgumentException { queue.setService(null); } } + if (line.containsHeader(HEADER_STATUS_CONCEPT_SET)) { + String statusConceptSet = line.getString(HEADER_STATUS_CONCEPT_SET); + if (StringUtils.isNotBlank(statusConceptSet)) { + queue.setStatusConceptSet(Utils.fetchConcept(statusConceptSet, conceptService)); + } else { + queue.setStatusConceptSet(null); + } + } + if (line.containsHeader(HEADER_PRIORITY_CONCEPT_SET)) { + String priorityConceptSet = line.getString(HEADER_PRIORITY_CONCEPT_SET); + if (StringUtils.isNotBlank(priorityConceptSet)) { + queue.setPriorityConceptSet(Utils.fetchConcept(priorityConceptSet, conceptService)); + } else { + queue.setPriorityConceptSet(null); + } + } if (line.containsHeader(HEADER_LOCATION)) { String location = line.getString(HEADER_LOCATION); if (StringUtils.isNotBlank(location)) { diff --git a/api-2.3/src/test/java/org/openmrs/module/initializer/api/queues/QueueLoaderIntegrationTest.java b/api-2.3/src/test/java/org/openmrs/module/initializer/api/queues/QueueLoaderIntegrationTest.java index b8eed537d..736f5eb23 100644 --- a/api-2.3/src/test/java/org/openmrs/module/initializer/api/queues/QueueLoaderIntegrationTest.java +++ b/api-2.3/src/test/java/org/openmrs/module/initializer/api/queues/QueueLoaderIntegrationTest.java @@ -65,5 +65,16 @@ public void load_shouldLoadAccordingToCsvFiles() throws Exception { Assert.assertEquals(2001, queue.getService().getConceptId().intValue()); Assert.assertEquals(3, queue.getLocation().getLocationId().intValue()); } + // Queue with statuses + { + Queue queue = queueService.getQueueByUuid("4856c1c1-c9b3-4a7e-8669-4220051ab640").orElse(null); + Assert.assertNotNull(queue); + Assert.assertEquals("Triage Queue", queue.getName()); + Assert.assertEquals("Queue with custom statuses", queue.getDescription()); + Assert.assertEquals(2001, queue.getService().getConceptId().intValue()); + Assert.assertEquals(2003, queue.getStatusConceptSet().getConceptId().intValue()); + Assert.assertEquals("Triage queue priorities", queue.getPriorityConceptSet().getName().getName()); + Assert.assertEquals("Xanadu", queue.getLocation().getName()); + } } } diff --git a/api-2.3/src/test/resources/testAppDataDir/configuration/queues/queues.csv b/api-2.3/src/test/resources/testAppDataDir/configuration/queues/queues.csv index 9df55879c..9daa918a2 100644 --- a/api-2.3/src/test/resources/testAppDataDir/configuration/queues/queues.csv +++ b/api-2.3/src/test/resources/testAppDataDir/configuration/queues/queues.csv @@ -1,3 +1,4 @@ -Uuid,Void/Retire,Name,Description,Service,Location -2a0e0eee-6888-11ee-ab8d-0242ac120002,,Revised Queue,Revised Description,68b910bd-298c-4ecf-a632-661ae2f446op,Xanadu -288db1cc-688a-11ee-ab8d-0242ac120002,,New Queue,New Description,Triage,167ce20c-4785-4285-9119-d197268f7f4a +Uuid,Void/Retire,Name,Description,Service,Status Concept Set,Priority Concept Set,Location +2a0e0eee-6888-11ee-ab8d-0242ac120002,,Revised Queue,Revised Description,68b910bd-298c-4ecf-a632-661ae2f446op,,,Xanadu +288db1cc-688a-11ee-ab8d-0242ac120002,,New Queue,New Description,Triage,,,167ce20c-4785-4285-9119-d197268f7f4a +4856c1c1-c9b3-4a7e-8669-4220051ab640,,Triage Queue,Queue with custom statuses,67b910bd-298c-4ecf-a632-661ae2f446op,1d2a73ca-20aa-4218-b4d2-043024a9156e,24932838-60ca-44e8-840f-4184b368643c,Xanadu diff --git a/api/src/test/resources/testdata/test-queues.xml b/api/src/test/resources/testdata/test-queues.xml index 37016feb0..9e7765a01 100644 --- a/api/src/test/resources/testdata/test-queues.xml +++ b/api/src/test/resources/testdata/test-queues.xml @@ -4,9 +4,13 @@ + + + + diff --git a/pom.xml b/pom.xml index ec860eebb..1874b6070 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ 1.0.0 - 1.0.0-SNAPSHOT + 2.1.0 1.19.0 diff --git a/readme/queues.md b/readme/queues.md index 95b8ce5ce..aa24889d2 100644 --- a/readme/queues.md +++ b/readme/queues.md @@ -7,9 +7,9 @@ queues/ ``` There is currently only one format for the queue CSV line, here are the possible headers with a sample data set: -| Uuid | Void/Retire | Name | Description | Service | Location | -|--------------------------------------|-------------|-----------------------------|---------------|--------------------|--------------------| -| 32176576-1652-4835-8736-826eb0237482 | | Clinical Consultation Queue | Consult Queue | Outpatient Service | Outpatient Clinic| | +| Uuid | Void/Retire | Name | Description | Service | Status Concept Set | Priority Concept Set | Location | +|--------------------------------------|-------------|-----------------------------|---------------|--------------------|--------------------|-----------------------------------|--------------------| +| 32176576-1652-4835-8736-826eb0237482 | | Clinical Consultation Queue | Consult Queue | Outpatient Service |Queue entry statuses | Queue entry priorities | Outpatient Clinic| | Headers that start with an underscore such as `_order:1000` are metadata headers. The values in the columns under those headers are never read by the CSV parser. @@ -25,11 +25,17 @@ A description is optional and will populate the queue description ###### Header `Service` This is a reference (UUID, same as mapping or name) to an existing concept that defines the service associated with this queue. +###### Header `Status Concept Set` +This is a reference (UUID, same as mapping or name) to an existing concept set that defines the queue statuses that could be assigned to the entries in this queue. + +###### Header `Priority Concept Set` +This is a reference (UUID, same as mapping or name) to an existing concept set that defines the queue priorities that could be assigned to the entries in this queue. + ###### Header `Location` This is a reference (UUID or name) to an existing location that defines the location associated with this queue. #### Requirements -* The [queue module](https://github.com/openmrs/openmrs-module-queue) must be installed +* The [queue module](https://github.com/openmrs/openmrs-module-queue) version 2.1 or higher must be installed * The OpenMRS version must be 2.3 or higher #### Further examples: From 583aee2271dc8b49ae7fc5fce9f441f1984aac60 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Thu, 14 Mar 2024 11:16:28 -0400 Subject: [PATCH 3/3] #263 OCL loader should throw an exception upon failure (#264) --- README.md | 1 + .../api/loaders/OpenConceptLabLoader.java | 31 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5c3c0b710..6eb49b22a 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ See the [documentation on Initializer's logging properties](readme/rtprops.md#lo * Added support for 'queues' domain. * Added support for 'addresshierarchy' domain. * Fix for Liquibase Loader to ensure compatibility with OpenMRS versions 2.5.5+ +* Fix for OCL Loader to ensure it throws an Exception if the OCL import fails #### Version 2.6.0 * Added support for 'cohorttypes' and 'cohortattributetypes' domains. diff --git a/api/src/main/java/org/openmrs/module/initializer/api/loaders/OpenConceptLabLoader.java b/api/src/main/java/org/openmrs/module/initializer/api/loaders/OpenConceptLabLoader.java index c89619016..37f4b9a5b 100644 --- a/api/src/main/java/org/openmrs/module/initializer/api/loaders/OpenConceptLabLoader.java +++ b/api/src/main/java/org/openmrs/module/initializer/api/loaders/OpenConceptLabLoader.java @@ -1,13 +1,16 @@ package org.openmrs.module.initializer.api.loaders; -import java.io.File; -import java.util.zip.ZipFile; - +import org.apache.commons.lang.StringUtils; import org.openmrs.annotation.OpenmrsProfile; import org.openmrs.api.context.Context; import org.openmrs.module.initializer.Domain; +import org.openmrs.module.openconceptlab.Import; +import org.openmrs.module.openconceptlab.ImportService; import org.openmrs.module.openconceptlab.importer.Importer; +import java.io.File; +import java.util.zip.ZipFile; + @OpenmrsProfile(modules = { "openconceptlab:1.2.9" }) public class OpenConceptLabLoader extends BaseFileLoader { @@ -25,7 +28,29 @@ protected String getFileExtension() { protected void load(File file) throws Exception { ZipFile zip = new ZipFile(file); Importer importer = Context.getRegisteredComponent("openconceptlab.importer", Importer.class); + ImportService importService = Context.getService(ImportService.class); + + Import lastImport = importService.getLastImport(); + log.debug("Starting OCL importer"); importer.run(zip); + Import oclImport = importService.getLastImport(); + + // Import failed to start. This can happen another import is already currently running + if (oclImport == null || oclImport.equals(lastImport)) { + throw new IllegalStateException("OCL import did not start successfully"); + } + + // Import detected errors + if (StringUtils.isNotBlank(oclImport.getErrorMessage())) { + throw new IllegalStateException(oclImport.getErrorMessage()); + } + + // Import never stopped + if (!oclImport.isStopped()) { + throw new IllegalStateException("OCL import did not complete successfully"); + } + + log.debug("OCL import completed successfully: " + oclImport.getLocalDateStopped()); } }