Skip to content

Commit

Permalink
PROV103: fixing Provider Management UI crashes (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephbate authored Nov 16, 2023
1 parent c5f84fd commit 5b23dc4
Showing 1 changed file with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,46 @@

package org.openmrs.module.providermanagement.fragment.controller;

import org.openmrs.layout.web.name.NameSupport;
import java.lang.reflect.Method;

import org.openmrs.ui.framework.fragment.FragmentModel;

public class PersonNameFragmentController {

public void controller(FragmentModel model) {
model.addAttribute("layoutTemplate", NameSupport.getInstance().getDefaultLayoutTemplate());
}
/**
* Controller method to retrieve the layout template and add it to the model.
*
* @param model The fragment model to which the layout template will be added.
* @throws Exception If there are any issues during reflection or if the layout template retrieval fails.
*/

public void controller(FragmentModel model)throws Exception {

Class<?> nameSupport;

try {
// Attempt to load the NameSupport class from org.openmrs.layout.name
nameSupport = Class.forName("org.openmrs.layout.name.NameSupport");
} catch (ClassNotFoundException e) {
// If the NameSupport class is not found in org.openmrs.layout.name, try loading it from org.openmrs.layout.web.name
nameSupport = Class.forName("org.openmrs.layout.web.name.NameSupport");
}

if (nameSupport == null) {
// If the NameSupport class couldn't be loaded, return.
return;
}

// Use reflection to invoke the "getInstance" method
Method getInstance = nameSupport.getDeclaredMethod("getInstance");
Object instance = getInstance.invoke(null);

// Use reflection to invoke the "getDefaultLayoutTemplate" method
Method getLayoutTemplate = nameSupport.getMethod("getDefaultLayoutTemplate");
Object layoutTemplate = getLayoutTemplate.invoke(instance);

// Add the layoutTemplate to the model
model.addAttribute("layoutTemplate", layoutTemplate);

}
}

0 comments on commit 5b23dc4

Please sign in to comment.