Search code examples
database-designuser-registration

Best approach for storing questions in a registration form


I am working on a simple page where a participant needs to fill in a registration form (Name, Address etc.) and then a set of questions (20 questions roughly) about their hearing health - such as do you experience hearing health problems, what ear do you experience the problems in, do you wear a hearing device and if yes what type etc.

Upon completion a new participant row is created in a DB. I then want to be able to query this data for participants that have hearing problems, for participants that have a hearing problem in their left ear, for their devices etc.

Currently the questions are hardcoded in the HTML and that feels like a wrong approach.

But if I stored them in a DB and used something like Question, Answer, ParticipantAnswer tables to have a more dynamic approach then how would I easily query for information as outlined above?

What is the best approach here?


Solution

  • I then want to be able to query this data for participants that have hearing problems, for participants that have a hearing problem in their left ear, for their devices, etc.

    This is a good start. You can't query a database with information that's not in the database.

    Participants that have hearing problems

    Somewhere, you have to ask the question, "Do you have a hearing problem?" You start with the "yes" answers and have to get to the participants. That means there needs to be a link between participant answers and participants, probably a participant id.

    Participants that have a hearing problem in their left ear

    Similar to the last point. You have to ask the question, "Which ear(s) has the hearing problem?" You start with the "left" and "both" answers and get to the participants.

    What devices do you have

    You have to ask the question, "What devices are you using?" and get the answer in a standard format. If participants just type the answers, you'll never get good matches. You can have an "Other" selection, but you need to add devices to the standard format. You'll probably want a Device entity for this purpose.

    The point of this long comment is to keep asking questions of your database, and reworking your entities until you can answer all your questions.