How to check whether users have entered a unique value, e.g. Study ID code

From Lifeguide Wiki
Jump to: navigation, search

To check whether users have entered something unique into a text-entry box, the saveuniquevalue function can be used. saveuniquevalue is used in the same way as savevalue. The only difference is that with saveuniquevalue, if the value entered by an end-user is not unique, the data will return a false (negative) result, and you can use this to stop end-users continuing with the intervention until they have entered a value which is unique (and so gives a true result).

N.B. If you use saveuniquevalue for a specific interaction, e.g. Study ID number, you must use the saveuniquevalue every time you refer to the Study ID number, in order for the uniqueness to be saved each time. If you use saveuniquevalue the first time and then use savevalue, the uniqueness of the value will not be guaranteed (the value the end-user enters the second time may be unique, but this could be due to luck).

saveuniquevalue can be used in different ways. You can direct users to a different page if a variable they enter is not unique so they have to enter a value that is unique to carry on with the intervention. OR you can let users carry on if they enter a value that is not unique and you can alert the study coordinator of this by sending them an email.

Example 1

To save and check a variable entered by an end-user is unique:

saveuniquevalue(username, "studyid", page1.interaction1)

Example 2

To save 2 variables on the same page as unique (email address and study ID):

after registration if (and( saveuniquevalue(registration.username, "email", registration.email), saveuniquevalue(registration.username, "studyid", registration.studyid) )) goto registrationfinish

Example 3

To direct end-users to a different page if a variable entered by an end-user is not unique:

after page1 if (not(saveuniquevalue(username, "studyid", page1.interaction1) goto page_notunique

Example 4

If an end-user has entered a response that is not unique, you can allow them to continue with the intervention and send an email to the study coordinator.

after registration if (and(not(saveuniquevalue(username, "studyid", registration.interaction1)), sendemail( append(username,"not_unique"), "study@soton.ac.uk", "Participant - not unique", append("Participant ", loadvalue (username, "idnumber"), "has entered information that is not unique."),10) )) goto registrationfinish

Example 5

You can choose to send an email to the study coordinator if several specific values are not unique (e.g. surname, postcode and date of birth), as this could indicate that a participant is trying to register for your intervention more than once.

after registration if (and(not(saveuniquevalue(username, "surname", registration .interaction1)), not(saveuniquevalue(username, "postcode", registration.interaction2)), not(saveuniquevalue(username, "dob", registration.interaction3)), sendemail( append(username,"not_unique"), "study@soton.ac.uk", "Participant - not unique", append("Participant ", loadvalue (username, "idnumber"), "has entered information that is not unique."),10) )) goto registrationfinish

Tutorial

Please click here to view a demo of another way in which you can use saveuniquevalue. The demo allows users to enter a unique value and then change it to another value that has to be unique. To view the logic file, download this demo and import it to the LifeGuide authoring tool.