Revised October 2012
Description
The answer of the question is evaluated, and in turn will receive next question or the result if final question is reached.
URL:
Sample Request Format of Questionnaire Type 2
<URLBASE>/answer
Logic
When the user request received, the presence and validity of the token_id and question_id or the sub_question_id are checked. The token_id, question_id, sub_question_id and the selected option_ids will be saved to DB. Corresponding option values and the next_rule of the current question is retrieved from DB. The next_rule is then evaluated using the corresponding sub_question option_values. According to the output of the evaluated next_rule next step is determined. According to the next step, API may return the next question, an error message or the result.
Sample Request Format of Questionnaire Type 1
{
"key": "qtye456ceger",
"token_id": 21,
"question_id": "1",
"answers": [
{
"sub_question_id": "1",
"option_id": "1"
},
{
"sub_question_id": "2",
"option_id": "2"
},
{
"sub_question_id": "3",
"option_id": "3"
},
{
"sub_question_id": "4",
"option_id": "4"
}
]
}
If the question_id is 2 then the request should include the user_specific_sub_question and in the answers array another entry having sub_question_id of 0 and its selected option_id. Given a sample request with user_specified_sub_question.
{
"token_id": 21,
"question_id": "2",
"user_specified_sub_question" : "Sample sub question",
"answers": [
{
"sub_question_id": "0",
"option_id": "6"
},
{
"sub_question_id": "1",
"option_id": "7"
},
{
"sub_question_id": "2",
"option_id": "6"
},
{
"sub_question_id": "3",
"option_id": "6"
},
{
"sub_question_id": "4",
"option_id": "6"
}
]
}
Params
| token_id | required |
| question_id | required |
| answers | required, Each entry must have a 'sub_question_id' and its selected 'option_id'. |
Sample Request Format of Questionnaire Type 2
{
"key": "qtye456ceger",
'token_id' : 21,
'sub_question_id': '8',
'answers' : [
{
"question_id" : '3',
"option_id" : '2'
},
{
"question_id" : '4',
"option_id" : '4'
},
{
"question_id" : '6',
"option_id" : '1'
}
]
}
Answer request of first and second question will be in the same format of questionnaire type 1. All other request will accept the above format.
Params
| token_id | required |
| sub_question_id | required |
| answers | required, Each entry must have a 'question_id' and its selected 'option_id'. |
Method
(GET|POST)
Response
All the response of Submit answer request of questionnaire type 2 will be similar to either get_question request or get_result request. Response of Submit answer request of questionnaire type 1 will be similar to get_question request or get_result request or of the following format:
{
"status": 1,
"sub_question": {
"sub_question_id": 11,
"name": "Hallucinogens(LSD, acid, mushrooms, PCP, Special K, ecstasy, etc.)",
"questions": [
{
"question_id": 3,
"description": "In the past three months, how often have you used the substances you mentioned(first drug, second drug, etc)?",
"comment": null,
"options": [
{
"name": "Never",
"option_id": 1,
"option_value": 0,
"question_id": 3
},
{
"name": "Once or Twice",
"option_id": 2,
"option_value": 2,
"question_id": 3
},
]
},
{
"question_id": 4,
"description": "In the past three months, how often you had a strong desire or urge to use(first drug, second drug, etc)?",
"comment": null,
"options": [
{
"name": "Never",
"option_id": 1,
"option_value": 0,
"question_id": 4
},
{
"name": "Once or Twice",
"option_id": 2,
"option_value": 3,
"question_id": 4
},
]
},
{
// Another question
},
.
.
.
]
}
}
Response fields
| status | Status of the API request |
| errors | Errors if any |
| messages | Messages if any |
| sub_question | Includes sub_question_id, its name and questions. |
| questions | An array which includes all the questions. Each question has its question_id, description, comment if any and its available options. |
| options | An array which includes all the option of the current question.Each option has an option_id and name. |
