How to have attribute or data element show the default value

we have some data element with option set.

want to set these data element in the program - stage with the default value. so users dont have to choose any time.

what is the best way to have this.

2 Likes

HI @nanwang,

DId you manage to sort this? If not, I would recommend using program rules to do this for you based on what exactly you need i.e. if the question you want to be prefilled is dependent on another question the user has to fill on the same or different stage. After user selects the option i.e. Age, Sex to calculate the BMI, the BMI field will come prefilled

Let me know what you think about this.

Best,
James.

I have the same question @jomutsani.


Say I have a Yes/No question like this:

Send patient SMS messages?
:circle_o: YES :circle_o: NO


Can I default one of the options to ‘selected’ but let the user change the selection?

Send patient SMS messages?
:check_circle: YES :circle_o: NO


When I try to do this with Program rules, the radio buttons are greyed out and the user can’t edit the selection.

image


For what it’s worth, this is exactly what the ‘checked’ is for in HTML forms.

<p>Send patient SMS messages?</p>
<input type="radio" id="yes" name="sms" checked>
<label for="yes">YES</label>
<input type="radio" id="no" name="sms">
<label for="no">NO</label>

@dburka We’ve noticed this as well that when you assign values, its kind of two actions in 1; it assigns a value and then makes the Data Element Read Only.

The work that we’ve done is to add a && !d2:hasValue() into the expression, referencing the exact data Element that we’re assigning. This makes it so that the value is assigned, and then “released” if you will from the program rule.

2 Likes

Thank you @Matthew_Boddie! Will give it a shot.

2 Likes

@Matthew_Boddie

This is very helpful.

Are you able to show how this expression is used inside the program rules?

We have tried so many variations but were unable to reach a working solution.

Here is one of the many options we tried


Thank you for your help

1 Like

Hi @jamiecarter7

I think you’d want to modify the program rule expression and the action expression to assign the value.

In the program rule expression instead of true, !d2:hasValue(A{YesHasHypertension})

And in the ‘assign value’ action expression: ‘HTN_YES’ (the value to be assigned?)

Hope this works. To be honest, I’m guessing based on your screenshot but if it doesn’t acheive the desired result maybe you could explain further.

Thanks!

1 Like

Ditto @Gassim ! His explanation is more what I was meaning. Basically that the expression would register as true when there was no data, and once the program rule action fired, the expression would register as false. Thus, the assign value is “released”, and the value remains but the cell can now be edited.

1 Like

Hi @Matthew_Boddie , I’ve been taking a crack at this problem and sort of got it to work through a different method. I tried what you and @Gassim suggested, using !d2:hasValue(A{YesHasHypertension}) as a condition, but could not get it to work.

I used an extra “enabler field” that acts like a check.

I’m using 2 types of fields:

  1. The original field I want auto-filled (Eg. Does patient have Diabetes?)
  2. An enabler field that serves only as a check for program rules (name: Enabler for autofilling fields)

I also used 2 program rules:
Rule 1: When user lands on a screen, it checks whether “enabler field” is empty. If it is, then it auto-fills the original field (ie. Does patient have Diabetes? = Yes).

Rule 2: Checks whether original field, is empty. If it is, it auto-fills “enabler field” (Enabler for autofilling fields = true). Reason: When I tap “x” on original field to remove the value, it was changing to read-only state. Now because of Rule 2, “enabler field” is filled, Rule 1 does not trigger.

Current challenge:
The issue I am facing now is that I want to hide the “enabler field” from users. But when I set up a program rule to hide that field, the other program rules that depend on the “enabler field” stop working. Do you know if there is a way to hide the “enabler field” but still let it be used by program rules?

Hi there @tonyjoy ! Interesting that the way wasn’t functional–would be curious on your version and where you are entering.

I’m imagining that if you had the enabler field as a ProgramRuleVariable only and not as a dataElement in the program, then you could still assign values to it but it wouldn’t have to be visible at any point to the end-user. And you should still be able to use the variable in the same way. Does that make sense?

Sorry, let me clarify. Using !d2:hasValue(A{YesHasHypertension}) as a condition worked in that it “released” the field from being read-only. But when I hit the “x” to remove the filled value, it goes back to being read-only. Was it the same behaviour on your end?

I am on version 2.40.0.1.
Trying to auto-fill the question “Does patient have Hypertension?” to “Yes” via Android phone.

Related to your idea: using enabler field as a ProgramRuleVariable only and not as a dataElement in the program. Tried but not working as expected.

As of now, the solution I arrived at looks like this. That extra field can be used as a check to auto-fill any number of fields.

I learnt that using a Program Rule to hide a value field (TEI Attribute or Data element) will also erase the value of that field. There is currently a JIRA ticket to hide sections in enrollment form. Once that JIRA issue is resolved, this solution should work.