Skip to content

Commit

Permalink
RA-1857: appConfig to always provide dateFormat and JSDateFormat.
Browse files Browse the repository at this point in the history
  • Loading branch information
mogoodrich authored Feb 22, 2021
1 parent b66a48e commit 27573e6
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import org.openmrs.Patient;
import org.openmrs.PatientProgram;
import org.openmrs.Program;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.ProgramWorkflowService;
import org.openmrs.api.context.Context;
import org.openmrs.module.appframework.domain.AppDescriptor;
import org.openmrs.module.emrapi.patient.PatientDomainWrapper;
import org.openmrs.ui.framework.UiFrameworkConstants;
import org.openmrs.ui.framework.annotation.FragmentParam;
import org.openmrs.ui.framework.annotation.InjectBeans;
import org.openmrs.ui.framework.annotation.SpringBean;
Expand All @@ -25,7 +27,9 @@
public class ProgramHistoryFragmentController {

public void controller(FragmentConfiguration config, @FragmentParam("app") AppDescriptor app, @InjectBeans PatientDomainWrapper patientWrapper,
@SpringBean("programWorkflowService") ProgramWorkflowService programWorkflowService) throws IOException {
@SpringBean("programWorkflowService") ProgramWorkflowService programWorkflowService,
@SpringBean("adminService")AdministrationService adminService
) throws IOException {

ObjectMapper mapper = new ObjectMapper();

Expand All @@ -51,6 +55,13 @@ public void controller(FragmentConfiguration config, @FragmentParam("app") AppDe
ObjectNode appConfig = app.getConfig();
appConfig.put("patientUuid", patientWrapper.getPatient().getUuid());

if (appConfig.get("dateFormat") == null) {
appConfig.put("dateFormat", adminService.getGlobalProperty(UiFrameworkConstants.GP_FORMATTER_DATE_FORMAT, "yyyy-MM-dd"));
}
if (appConfig.get("JSDateFormat") == null) {
appConfig.put("JSDateFormat", adminService.getGlobalProperty(UiFrameworkConstants.GP_FORMATTER_JS_DATE_FORMAT, "YYYY-MMM-DD"));
}

if (appConfig.get("program") == null || StringUtils.isEmpty(appConfig.get("program").getTextValue())) {
throw new MissingPropertyException("Program must be specified");
}
Expand Down Expand Up @@ -82,6 +93,7 @@ public void controller(FragmentConfiguration config, @FragmentParam("app") AppDe
Map<String, Object> appConfigMap = mapper.convertValue(appConfig, Map.class);
config.merge(appConfigMap);
config.addAttribute("programJson", programJson);

}

}

0 comments on commit 27573e6

Please sign in to comment.