@@ -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 *
0 commit comments