Making a question as READ-ONLY based on certain criteria

Hi,

I am collecting patient information, and based on a certain criteria (the logic of which I am collecting from the answers of the previous questions the user filled), I need to decide whether there is a need to refer the person to a doctor or not. If the logic is fulfilled, I want to lock the question that asks whether the referral should be done or not (probably by fixing the answer as YES and making READ-ONLY so that user cannot change the answer. If the logic is not met, the referral question remains open and user is free to choose from YES or NO.

How to make READ-ONLY programmable? One idea is to calculate a variable and switch it from NO to YES based on logic. Any other way?

Thanks,
Saad

Hi @Saad,
What about 2 questions, one writable and one read-only. Then you show the one you want depending on your variable with a relevant condition?

2 Likes

Hi @Saad,

Instead of what you are exactly looking for, you can try this approach as an alternative.
Read Only alternatives.xlsx (9.7 KB)

Regards,
Raj

First have the to-be read only state (false and true) as a calculate question, say named determined_referral. Under the calculation column of this question, use a conditional statement such as if(${S1_Q1}='1' and ${S1_Q2}='2',"True","False"). Now, the read_only column of the question asking whether the referral should be done or not will just have what the calculate question resolved.

I tried to do exactly the same, but it is not working.

Can you test and share the working code if possible? Thanks.

Could you share your form so that we know what you have tried?

Hi Saad,
You can try this: in the readonly column for the question you want to disable, input your condition in the format as below it should work.
if(${question1}='yes',"TRUE","FALSE"))

note: the true/false values must be in quotes.
all the best

Hi,

I tested it already. It does not work. Infact, when I do this, the question text for the readonly question goes invisible.

Saad

Thanks for attempting, we hope to get there:

Have you tried to do under calculate for the question, put this condition so that it preloads a YES, in addition to the condition I gave earlier, for the readonly question.
if(${question1}='yes',"Yes","No"))

Note: Ensure that the Values for Yes/No are the values in the choices sheet under name of the list group. Hope this works
Thanks,

Hi @Saad

It depends what tool you are using. If it's ODK Collect then yes dynamic read_only is supported and here is an example:
read_only dynamic 02.xlsx (5.4 KB)
But enketo doesn't support it (see: https://github.com/enketo/enketo-core/issues/391)