Bahmni UI modify javascript for registration module

Tags: #<Tag:0x00007f829017fb50> #<Tag:0x00007f829017f9e8> #<Tag:0x00007f829017f7e0> #<Tag:0x00007f829017f5d8>

Hello Bahmni Developers comunity, i need your help.

In fact, i’m trying to modify a little bit the second page of the registration module. I want to determine the lenght of stay of a patient who has been in our facility. For that, i would like to do the difference between the registration date and the expected release date of the patient that will be filled by the operator. I’ve created a new conceptset (including the expected release date of the patient) and modified the extension.json of the registration module to show the related fields as you can see on the image below.

I know this can be done with Javascript, but i don’t know how to proceed (use those fields as variables in the javascript code). I need some guideance.

Your help will be appreciated.

Thanks

Hi @soopafly,

Unable to get your query. Can you please provide some more info? Are you want to show/hide these concepts conditionally? If yes, please check this.

@soopafly you should be able to get this through Groovy script. check this documentation and sample for BMI calculation.
https://bahmni.atlassian.net/wiki/spaces/BAH/pages/97812538/Groovy+Scripts

I want to determine the duration of stay of a patient in a facility. For that i want to use 3 elements to do this operation:

  • Registration date of patient (captured when the patient is registered) or patient admission date (when it is set)
  • Release date of patient (It’s a new date type concept defined by us, containing a future date set by an operator) (not the discharge date, because we want the patient to know the duration of his stay in advance).
  • Duration of stay in days (which will capture the duration or the operation result)

To make it simple : ‘Duration of stay’ = ‘Release date of patient’ - ‘Registration date of patient’

I want to perform this operation in the “Extension.json” file of the “Registration” Module.

I hope it is more explicit now.

Bahmni 0.90 allows to display a form on Registration page. The form designed through Implementer’s Interface can include script. Please check if this helps.

I finally found a way to handle the calculation in the Control Event

Here is the code

function(form) {
   if (form.get('Registration date of patient').getValue()) {
		if (form.get('Release date of patient').getValue()) {
            var duration = Bahmni.Common.Util.DateUtil.diffInDays(form.get('Release date of patient').getValue(), form.get('Registration date of patient').getValue());				
            form.get('Duration of stay').setValue(duration);
			form.get('Duration of stay').setEnabled(false);
		}		
    }
}

result3

I hope it will help others. Thanks to @pkanchankar for his assitance.