cherry-picked relevant stuff from OpenClinica/enketo-express-oc