Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#250 - Add new Queue domain #251

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ This is the list of currently supported domains in their loading order:
1. [Bahmni Appointment Specialities (CSV files)](readme/appointmentspecialities.md)
1. [Bahmni Appointment Service Definitions (CSV files)](readme/appointmentservices.md#domain-appointmentservicedefinitions)
1. [Bahmni Appointment Service Types (CSV files)](readme/appointmentservices.md#domain-appointmentservicetypes)
1. [Queues (CSV files)](readme/queues.md#domain-queues)
1. [Data Filter Entity-Basis Mappings (CSV files)](readme/datafiltermappings.md)
1. [Metadata Sets (CSV files)](readme/mdm.md#domain-metadatasets)
1. [Metadata Set Members (CSV files)](readme/mdm.md#domain-metadatasetmembers)
Expand Down Expand Up @@ -188,6 +189,7 @@ See the [documentation on Initializer's logging properties](readme/rtprops.md#lo
## Releases notes

#### Version 2.7.0
* Added support for Queues

#### Version 2.6.0
* Added support for Cohort Attribute types
Expand Down
7 changes: 7 additions & 0 deletions api-2.3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@
<groupId>org.openmrs.module</groupId>
<artifactId>openconceptlab-api</artifactId>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>queue-api</artifactId>
<version>${queueVersion}</version>
<scope>provided</scope>
</dependency>

<!-- Dependencies required to compile against Java 11 -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.openmrs.module.initializer.api.queues;

import org.apache.commons.lang3.StringUtils;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.initializer.Domain;
import org.openmrs.module.initializer.api.BaseLineProcessor;
import org.openmrs.module.initializer.api.CsvLine;
import org.openmrs.module.initializer.api.CsvParser;
import org.openmrs.module.queue.api.QueueService;
import org.openmrs.module.queue.model.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

@OpenmrsProfile(modules = { "queue:*" })
public class QueueCsvParser extends CsvParser<Queue, BaseLineProcessor<Queue>> {

private final QueueService queueService;

@Autowired
public QueueCsvParser(@Qualifier("queue.QueueService") QueueService queueService, QueueLineProcessor processor) {
super(processor);
this.queueService = queueService;
}

@Override
public Domain getDomain() {
return Domain.QUEUES;
}

@Override
public Queue bootstrap(CsvLine line) throws IllegalArgumentException {
String uuid = line.getUuid();
Queue queue = queueService.getQueueByUuid(uuid).orElse(new Queue());
if (StringUtils.isNotBlank(uuid)) {
queue.setUuid(uuid);
}
return queue;
}

@Override
public Queue save(Queue instance) {
return queueService.createQueue(instance);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.openmrs.module.initializer.api.queues;

import org.apache.commons.lang3.StringUtils;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.api.ConceptService;
import org.openmrs.api.LocationService;
import org.openmrs.module.initializer.api.BaseLineProcessor;
import org.openmrs.module.initializer.api.CsvLine;
import org.openmrs.module.initializer.api.utils.Utils;
import org.openmrs.module.queue.model.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

/**
* This is the first level line processor for a Queue
*/
@OpenmrsProfile(modules = { "queue:*" })
public class QueueLineProcessor extends BaseLineProcessor<Queue> {

protected static String HEADER_SERVICE = "service";

protected static String HEADER_LOCATION = "location";

private final ConceptService conceptService;

private final LocationService locationService;

@Autowired
public QueueLineProcessor(@Qualifier("conceptService") ConceptService conceptService,
@Qualifier("locationService") LocationService locationService) {
super();
this.conceptService = conceptService;
this.locationService = locationService;
}

@Override
public Queue fill(Queue queue, CsvLine line) throws IllegalArgumentException {
queue.setName(line.get(HEADER_NAME, true));
queue.setDescription(line.getString(HEADER_DESC));
if (line.containsHeader(HEADER_SERVICE)) {
String service = line.getString(HEADER_SERVICE);
if (StringUtils.isNotBlank(service)) {
queue.setService(Utils.fetchConcept(service, conceptService));
} else {
queue.setService(null);
}
}
if (line.containsHeader(HEADER_LOCATION)) {
String location = line.getString(HEADER_LOCATION);
if (StringUtils.isNotBlank(location)) {
queue.setLocation(Utils.fetchLocation(location, locationService));
} else {
queue.setLocation(null);
}
}
return queue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.openmrs.module.initializer.api.queues;

import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.initializer.api.loaders.BaseCsvLoader;
import org.openmrs.module.queue.model.Queue;
import org.springframework.beans.factory.annotation.Autowired;

@OpenmrsProfile(modules = { "queue:*" })
public class QueueLoader extends BaseCsvLoader<Queue, QueueCsvParser> {

@Autowired
public void setParser(QueueCsvParser parser) {
this.parser = parser;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,26 @@
*/
package org.openmrs.module.initializer;

import org.openmrs.module.Module;
import org.openmrs.module.ModuleFactory;

import java.io.File;

/**
* This allows to perform Spring context sensitive tests when Data Filter API is a dependency. In
* that case it is necessary for each context sensitive test to update the search index.
*/
public abstract class DomainBaseModuleContextSensitive_2_3_Test extends DomainBaseModuleContextSensitiveTest {

public DomainBaseModuleContextSensitive_2_3_Test() {
super();
{
Module mod = new Module("", "queue", "", "", "", "1.0.0");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}
}

@Override
public void updateSearchIndex() {
// to prevent Data Filter's 'Illegal Record Access'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.initializer.api.queues;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.module.initializer.DomainBaseModuleContextSensitive_2_3_Test;
import org.openmrs.module.queue.api.QueueService;
import org.openmrs.module.queue.model.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

public class QueueLoaderIntegrationTest extends DomainBaseModuleContextSensitive_2_3_Test {

@Autowired
@Qualifier("queue.QueueService")
private QueueService queueService;

@Autowired
private QueueLoader loader;

@Before
public void setup() throws Exception {
executeDataSet("testdata/test-queues.xml");
}

@Test
public void load_shouldLoadAccordingToCsvFiles() throws Exception {

// Initial Queue
{
Queue queue = queueService.getQueueByUuid("2a0e0eee-6888-11ee-ab8d-0242ac120002").orElse(null);
Assert.assertNotNull(queue);
Assert.assertEquals("Initial Queue", queue.getName());
Assert.assertEquals("", queue.getDescription());
Assert.assertEquals(2001, queue.getService().getConceptId().intValue());
Assert.assertEquals(1, queue.getLocation().getLocationId().intValue());
}

loader.load();

// Revised Queue
{
Queue queue = queueService.getQueueByUuid("2a0e0eee-6888-11ee-ab8d-0242ac120002").orElse(null);
Assert.assertNotNull(queue);
Assert.assertEquals("Revised Queue", queue.getName());
Assert.assertEquals("Revised Description", queue.getDescription());
Assert.assertEquals(2002, queue.getService().getConceptId().intValue());
Assert.assertEquals(2, queue.getLocation().getLocationId().intValue());
}
// New Queue
{
Queue queue = queueService.getQueueByUuid("288db1cc-688a-11ee-ab8d-0242ac120002").orElse(null);
Assert.assertNotNull(queue);
Assert.assertEquals("New Queue", queue.getName());
Assert.assertEquals("New Description", queue.getDescription());
Assert.assertEquals(2001, queue.getService().getConceptId().intValue());
Assert.assertEquals(3, queue.getLocation().getLocationId().intValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum Domain {
APPOINTMENT_SPECIALITIES,
APPOINTMENT_SERVICE_DEFINITIONS,
APPOINTMENT_SERVICE_TYPES,
QUEUES,
DATAFILTER_MAPPINGS,
METADATA_SETS,
METADATA_SET_MEMBERS,
Expand Down
16 changes: 16 additions & 0 deletions api/src/test/resources/testdata/test-queues.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version='1.0' encoding='UTF-8'?>
<dataset>

<concept concept_id="2000" retired="false" is_set="true" creator="1" date_created="2022-02-02 14:31:00.0" uuid="907eba27-2b38-43e8-91a9-4dfe3956a35t"/>
<concept concept_id="2001" retired="false" is_set="false" creator="1" date_created="2022-02-02 14:40:00.0" uuid="67b910bd-298c-4ecf-a632-661ae2f446op"/>
<concept concept_id="2002" retired="false" is_set="false" creator="1" date_created="2022-03-08 15:40:00.0" uuid="68b910bd-298c-4ecf-a632-661ae2f446op"/>
<concept_name concept_name_id="893" concept_id="2000" name="Queue Service" locale="en" creator="1" date_created="2022-02-02 14:40:00.0" voided="0" uuid="9cp62348-5bf2-4050-b824-0aa009436ed6" concept_name_type="FULLY_SPECIFIED" locale_preferred="0"/>
<concept_name concept_name_id="210" concept_id="2001" name="Triage" locale="en" creator="1" date_created="2022-02-02 14:40:00.0" voided="0" uuid="9i667348-5bf2-4050-b824-0aa009436kl0" concept_name_type="FULLY_SPECIFIED" locale_preferred="0"/>
<concept_name concept_name_id="211" concept_id="2002" name="Consultation" locale="en" creator="1" date_created="2022-02-02 14:40:00.0" voided="0" uuid="5t747348-5bf2-4050-b824-0aa009436kl0" concept_name_type="FULLY_SPECIFIED" locale_preferred="0"/>
<concept_set concept_set_id="389000" concept_set="2000" concept_id="2001" sort_weight="0" date_created="2022-02-02 14:40:00.0" creator="1" uuid="470b910bd-298c-4ecf-a632-661ae2f886bf"/>
<concept_set concept_set_id="389001" concept_set="2000" concept_id="2002" sort_weight="0" date_created="2022-03-08 15:50:00.0" creator="1" uuid="380b910bd-298c-4ecf-a632-661ae2f886bf"/>

<global_property property="queue.serviceConceptSetName" property_value="Queue Service" uuid="69006997-6898-11ee-ab8d-0242ac120002"/>

<queue queue_id="1" uuid="2a0e0eee-6888-11ee-ab8d-0242ac120002" name="Initial Queue" description="" location_id="1" service="2001" creator="1" date_created="2020-03-11 15:59:20.0" retired="false"/>
</dataset>
3 changes: 3 additions & 0 deletions omod/src/main/resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<aware_of_module version="${fhir2Version}">
org.openmrs.module.fhir2
</aware_of_module>
<aware_of_module version="${queueVersion}">
org.openmrs.module.queue
</aware_of_module>
</aware_of_modules>

<!-- Internationalization -->
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

<!-- Modules compatibility > Core 2.3.0 -->
<datafilterVersion>1.0.0</datafilterVersion>
<queueVersion>1.0.0-SNAPSHOT</queueVersion>

<!-- For Validator -->
<reportingVersion>1.19.0</reportingVersion>
Expand Down
36 changes: 36 additions & 0 deletions readme/queues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Domain 'queues'
The **queues** subfolder contains CSV import files for saving queues in bulk. This is a possible example of its content:
```bash
queues/
├──queues.csv
└── ...
```
There is currently only one format for the queue CSV line, here are the possible headers with a sample data set:

|<sub>Uuid</sub> |<sub>Void/Retire</sub> |<sub>Name</sub> | <sub>Description</sub> | <sub>Service</sub> | <sub>Location</sub> | <sub>_order:1000</sub> |
| - | - | - | - | - |
|<sub>32176576-1652-4835-8736-826eb0237482</sub>|<sub></sub>| <sub>Clinical Consultation Queue</sub> | <sub>Consult Queue</sub> |<sub></sub>| <sub>Outpatient Service</sub>| <sub>Outpatient Clinic</sub>|

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.

Let's review some important headers.

###### Header `Name` *(mandatory)*
This is _not_ a localized header.
<br/>The name is _not_ a secondary identifier to access a queue type. UUID must be provided for each Queue.

###### Header `Description`
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 `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 OpenMRS version must be 2.3 or higher

#### Further examples:
Please look at the test configuration folder for sample import files for all domains, see [here](../api/src/test/resources/testAppDataDir/configuration).
8 changes: 8 additions & 0 deletions validator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@
<scope>runtime</scope>
<type>jar</type>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>queue-api</artifactId>
<version>${queueVersion}</version>
<scope>runtime</scope>
<type>jar</type>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
Expand Down
Loading