Program enrollment validation and Program attributes custom control and default value

  1. I have created a program for ‘Antenatal Care’ and i only want female patients to be enrolled to that program. I restrain from use adding a where statement to sqlSearch global property since it will restrict male patients from all programs. What is the best way to restrict enrolling a male patient to the program.

  2. Within that program i want to set the start date attribute default to today. And i have added two other attributes lmp and edd which are both dates. I want to restrict setting lmp only to past dates then after lmp is set i want to restrict selection for edd dates 280 days before the date of lmp. edd can only be set 280 days after the date of lmp.

What are the best way to implement those?

  1. AFAIK There is no way in Bahmni to prevent a male patient from being enrolled in a program, but you should be able to change the Patient List screen (tab) to show only female patients while searching. That can possibly help ensure that only female patients (Gender=F) are selected while enrolling. You can read more about how to configure search result criteria here: Configure Patient List queues. Please note, the patient list screen is shared across Clinical / Programs tab, so ensure while adding/modifying TAB you test accordingly. You can also introduce a privilege (e.g hasProgramsAccess) to ensure in Programs section only this TAB is visible, and maybe others are hidden.

  2. I am not sure I understand your requirement. Can you explain where the new attributes (lmp and edd) are added and where do you intend to show them?

  1. I used the bahmni config js file to intercept the program enroll event and return an error if they wish to enroll a M patient like
$scope.enrollPatient = function () {
    if ($scope.patient.gender !== 'F' && $ === '<Program Name>') {
        messagingService.showMessage("error", "Only female patient can enroll to an ANC Program");
        return $q.when({});
  1. I used the form condition of bahmni config to inject my javascript code to make the necessary validation on the program attributes
1 Like

I see, you modified UI code. Can you provide the full path of the code file you modified for this? Thanks!

Okay. i added the code in $scope.enrollPatient event on openmrs-module-bahmniapps/ui/app/common/uicontrols/programmanagement/controllers/manageProgramController.js. I think you can implement a way to validate it on the bahmni config

Thanks. I see this now, openmrs-module-bahmniapps/manageProgramController.js at master · Bahmni/openmrs-module-bahmniapps · GitHub

Glad to know this worked for you. Please note than whenever you update your Bahmni version later, the UI code base will also upgrade. So, you will need to make the same change in new Bahmni code file, as this is not a configuration change. But does seem like a small enough change, for the given requirement.

I have a fork for both bahmni-config and bahmni-web projects. And yeah when a new version is pushed i’ll do the merge manually to my forks.

1 Like