From ae685097767c5c073b83dfede7844e79fd86ec4f Mon Sep 17 00:00:00 2001 From: Kavitha S Date: Mon, 3 Jun 2024 15:05:11 +0530 Subject: [PATCH 1/2] BAH-3842|refactor events config to be read from global property --- .../module/ipd/api/events/ConfigLoader.java | 16 +++++++++--- api/src/main/resources/eventsConfig.json | 26 +++++++++++++++++++ api/src/main/resources/liquibase.xml | 14 ++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 api/src/main/resources/eventsConfig.json diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/ConfigLoader.java b/api/src/main/java/org/openmrs/module/ipd/api/events/ConfigLoader.java index fc58629..a90d29b 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/ConfigLoader.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/ConfigLoader.java @@ -3,13 +3,15 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.openmrs.api.context.Context; import org.openmrs.module.ipd.api.events.model.ConfigDetail; -import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.FileSystemResource; import org.springframework.stereotype.Component; import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; @@ -20,8 +22,7 @@ public class ConfigLoader { private ObjectMapper objectMapper = new ObjectMapper(); - @Value("${config-file.path}") - private String routeConfigurationFileLocation; + private static final String CONFIG_FILE_NAME = "eventsConfig.json"; public List getConfigs() { if (configs.isEmpty()) { @@ -31,11 +32,20 @@ public List getConfigs() { } private void loadConfiguration() { + String routeConfigurationFileLocation = Context.getAdministrationService().getGlobalProperty("ipd.eventsConfig.filepath"); try { + if (StringUtils.isBlank(routeConfigurationFileLocation)) { + File file = new File(this.getClass().getClassLoader().getResource(CONFIG_FILE_NAME).toURI()); + routeConfigurationFileLocation = file.getAbsolutePath(); + } + File routeConfigurationFile = new FileSystemResource(routeConfigurationFileLocation).getFile(); this.configs = objectMapper.readValue(routeConfigurationFile, new TypeReference>() {}); } catch (IOException exception) { log.error("Failed to load configuration for file : " + routeConfigurationFileLocation, exception); } + catch (URISyntaxException exception) { + log.error("Failed to find file : " + CONFIG_FILE_NAME, exception); + } } } diff --git a/api/src/main/resources/eventsConfig.json b/api/src/main/resources/eventsConfig.json new file mode 100644 index 0000000..ad33a62 --- /dev/null +++ b/api/src/main/resources/eventsConfig.json @@ -0,0 +1,26 @@ +[ + { + "type": "PATIENT_ADMIT", + "tasks": [ + { + "name": "Check Ward Instructions" + } + ] + }, + { + "type": "SHIFT_START_TASK", + "tasks": [ + { + "name": "Check Care Plan" + } + ] + }, + { + "type": "ROLLOVER_TASK", + "tasks": [ + { + "name": "Check Ward Instructions" + } + ] + } +] diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index df5fc2f..041550e 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -527,4 +527,18 @@ + + + + + select count(*) from global_property where property = 'ipd.eventsConfig.filepath'; + + + Add global property to add filepath for the events config json file + + INSERT INTO global_property (property, property_value, description, uuid) + VALUES ('ipd.eventsConfig.filepath', '', + 'File path of the events configuration json file', uuid()) + + From b49cd675ec4bf361759d45db67ffd792d91de1e3 Mon Sep 17 00:00:00 2001 From: Kavitha S Date: Mon, 3 Jun 2024 18:07:46 +0530 Subject: [PATCH 2/2] BAH-3842|removed tasks from config file --- api/src/main/resources/eventsConfig.json | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/api/src/main/resources/eventsConfig.json b/api/src/main/resources/eventsConfig.json index ad33a62..c555735 100644 --- a/api/src/main/resources/eventsConfig.json +++ b/api/src/main/resources/eventsConfig.json @@ -1,26 +1,14 @@ [ { "type": "PATIENT_ADMIT", - "tasks": [ - { - "name": "Check Ward Instructions" - } - ] + "tasks": [] }, { "type": "SHIFT_START_TASK", - "tasks": [ - { - "name": "Check Care Plan" - } - ] + "tasks": [] }, { "type": "ROLLOVER_TASK", - "tasks": [ - { - "name": "Check Ward Instructions" - } - ] + "tasks": [] } ]