Skip to content

Commit ecbe0a3

Browse files
committed
change import path of profiles and sync tasks to a global property configuration path.
1 parent 39522cb commit ecbe0a3

5 files changed

Lines changed: 60 additions & 152 deletions

File tree

api/src/main/java/org/openmrs/module/ugandaemrsync/UgandaEMRSyncActivator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import org.apache.commons.logging.Log;
1313
import org.apache.commons.logging.LogFactory;
14+
import org.openmrs.Concept;
15+
import org.openmrs.api.context.Context;
1416
import org.openmrs.module.BaseModuleActivator;
1517
import org.openmrs.module.ugandaemrsync.io.impl.FhirProfileImportServiceImpl;
1618
import org.openmrs.module.ugandaemrsync.server.SyncGlobalProperties;
@@ -56,6 +58,7 @@ public void started() {
5658
*/
5759
private void importConfigurationsOnStartup() {
5860
try {
61+
String path = Context.getAdministrationService().getGlobalProperty(UgandaEMRSyncConfig.GP_CONFIGURATION_DIRECTORY);
5962
// Try to import from classpath resources first (bundled with module)
6063
FhirProfileImportServiceImpl importService = new FhirProfileImportServiceImpl();
6164
boolean importedFromClasspath = importService.importConfigurationsFromClasspath();

api/src/main/java/org/openmrs/module/ugandaemrsync/UgandaEMRSyncConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,8 @@ public class UgandaEMRSyncConfig {
103103
public static final String PATIENT_ID_TYPE_CROSS_BORDER_NAME = "Patient Unique ID Code (UIC)";
104104
public static final String FSHR_SYNC_FHIR_PROFILE_UUID = "f2190cf4-2236-11ee-be56-0242ac120002";
105105

106+
public static final String GP_CONFIGURATION_DIRECTORY = "ugandaemrsync.configuration.directory";
107+
public static final String GP_HIE_SETTINGS_IMPORT_DIRECTORY = "ugandaemrsync.hieSettingsImport.directory";
108+
106109

107110
}

api/src/main/java/org/openmrs/module/ugandaemrsync/io/impl/FhirProfileImportServiceImpl.java

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,19 +292,27 @@ public ValidationResult validateProfile(String jsonConfig) {
292292
* Import profiles from configuration directory on startup
293293
*
294294
* @param configPath Base configuration directory path (e.g., /path/to/configuration)
295-
* Expected subdirectories: hie/syncprofile/ and hie/synctasktype/
295+
* Expected subdirectories: syncprofile/ and synctasktype/
296+
* If null, reads from global property ugandaemrsync.configuration.directory
296297
*/
297298
public void importConfigurationsFromDirectory(String configPath) {
298-
Path configDir = Paths.get(configPath, "hie");
299-
if (!Files.exists(configDir)) {
300-
log.info("Configuration directory not found: " + configDir);
299+
// If no path provided, use global property default
300+
if (configPath == null) {
301+
configPath = getConfigDirectoryPath();
302+
}
303+
304+
// Import from syncprofile and synctasktype subdirectories directly
305+
// (not under hie/ - the global property can point to the exact location)
306+
Path baseConfigDir = Paths.get(configPath);
307+
if (!Files.exists(baseConfigDir)) {
308+
log.info("Configuration directory not found: " + baseConfigDir);
301309
return;
302310
}
303311

304-
log.info("Importing configurations from: " + configDir);
312+
log.info("Importing configurations from: " + baseConfigDir);
305313

306314
// Import profiles
307-
Path profileDir = configDir.resolve("syncprofile");
315+
Path profileDir = baseConfigDir.resolve("syncprofile");
308316
List<SyncFhirProfile> importedProfiles = new ArrayList<>();
309317
if (Files.exists(profileDir)) {
310318
try {
@@ -329,7 +337,7 @@ public void importConfigurationsFromDirectory(String configPath) {
329337
}
330338

331339
// Import task types
332-
Path taskTypeDir = configDir.resolve("synctasktype");
340+
Path taskTypeDir = baseConfigDir.resolve("synctasktype");
333341
if (Files.exists(taskTypeDir)) {
334342
try {
335343
Files.list(taskTypeDir).filter(p -> p.toString().endsWith(".json")).forEach(p -> {
@@ -346,6 +354,33 @@ public void importConfigurationsFromDirectory(String configPath) {
346354
}
347355
}
348356

357+
/**
358+
* Get the configuration directory path from global property.
359+
* First checks if the global property is set to an absolute path.
360+
* If not, resolves relative to OpenMRS application data directory.
361+
* Falls back to default "configuration/hie" if property is not set.
362+
*
363+
* @return Resolved configuration directory path
364+
*/
365+
private String getConfigDirectoryPath() {
366+
org.openmrs.api.AdministrationService adminService = Context.getService(org.openmrs.api.AdministrationService.class);
367+
String configDir = adminService.getGlobalProperty("ugandaemrsync.configuration.directory");
368+
369+
if (configDir == null || configDir.trim().isEmpty()) {
370+
configDir = "configuration/hie"; // Default
371+
}
372+
373+
// Check if it's an absolute path
374+
Path path = Paths.get(configDir);
375+
if (path.isAbsolute()) {
376+
return configDir;
377+
}
378+
379+
// Relative path - resolve against OpenMRS application data directory
380+
String openmrsDataDir = org.openmrs.util.OpenmrsUtil.getApplicationDataDirectory();
381+
return Paths.get(openmrsDataDir, configDir).toString();
382+
}
383+
349384
/**
350385
* Import configurations from classpath resources (bundled with module)
351386
*

api/src/main/resources/configuration/hie/syncprofile/profile-prison-patient-data-exchange.json

Lines changed: 0 additions & 144 deletions
This file was deleted.

omod/src/main/resources/config.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,18 @@
567567
The allowable test order to be referred and their data requirements.
568568
</description>
569569
</globalProperty>
570-
570+
571+
<!-- FHIR Profile Configuration Import -->
572+
<globalProperty>
573+
<property>ugandaemrsync.configuration.directory</property>
574+
<defaultValue>configuration/hie</defaultValue>
575+
<description>
576+
Directory path (relative to OpenMRS application data directory or module classpath) from which to import FHIR profile configurations.
577+
This can be an absolute path, a path relative to the OpenMRS application data directory, or a classpath-relative path.
578+
Default is 'configuration/hie' which looks for profiles in {OPENMRS_DATA_DIR}/configuration/hie/ and classpath:configuration/hie/
579+
</description>
580+
</globalProperty>
581+
571582
<!-- Internationalization -->
572583
<!-- All message codes should start with ugandaemrsync.* -->
573584
<messages>

0 commit comments

Comments
 (0)