A big part of our service is to have users take part in the triage process by letting them answers questions about their problems and symptoms. This can be done in many ways, and we will try to craft a simplistic solution for this.
Create an implementation that runs in a browser, using React(?).
- parse the given JSON data and show the questions to the user, on after the other in the given order.
- validate the users answer before allowing the user to advance to the next question
- show previously answered questions
- styling
- tests
In real life, the questions to ask would be delivered from our server. For this example we've setup a small json payload that can be requested from
GET http://api.jsonbin.io/b/5a7c3e5d04b9c21255e42ac2/1
It has the following format:
type Response: {
data: {
questions: Array<Question>
}
}
// With the following subtypes
type Option = {
id: number,
text: string
};
type Question = {
id: number,
type: 'text' | 'option',
text?: string,
validation: {
required: boolean, // if an empty / no answer is acceptable.
maxLength?: number, // only for text, the maximum number of chars in the answer
minLength?: number, // only for text, the minimum number of chars in the answer
},
multiple?: boolean, // only for type 'option', indicates if the user should be able to select more than one of the options
options?: Array<Option> // only for type 'option'
}HTTP/1.1 200 OK
Date: Thu, 08 Feb 2018 12:30:32 GMT
Content-Type: application/json; charset=utf-8
Set-Cookie: __cfduid=dfca965e6df120871c52b725a423bdff11518093032; expires=Fri, 08-Feb-19 12:30:32 GMT; path=/; domain=.jsonbin.io; HttpOnly
X-Powered-By: Express
Access-Control-Allow-Origin: *
ETag: W/"346-drU/w7zFDr5exRSRf7G7HHCeqDI"
Server: cloudflare
CF-RAY: 3e9e99cb510576a2-ARN
Content-Encoding: gzip
Accept-Ranges: none
Content-Length: 354
Via: HTTP/1.1 sophos.http.proxy:3128
Connection: keep-alive
{
"data": {
"questions": [
{
"text": "What is your primary problem?",
"required": true,
"type": "text",
"id": 0
},
{
"text": "When did your first notice your problem?",
"required": true,
"type": "text",
"id": 1
},
{
"options": [
{
"text": "Yes",
"id": 0
},
{
"text": "No",
"id": 1
}
],
"text": "Have you had this problem before?",
"multiple": "false",
"required": true,
"type": "option",
"id": 2
},
{
"options": [
{
"text": "Headache",
"id": 0
},
{
"text": "Fever",
"id": 1
},
{
"text": "Heart failure",
"id": 3
},
{
"text": "Stomach cramps",
"id": 4
},
{
"text": "Osteoarthritis",
"id": 5
}
],
"text": "Have you had any of these problems before?",
"multiple": true,
"required": false,
"type": "option",
"id": 3
},
{
"text": "What kind of help do you expect from the doctor?",
"required": true,
"type": "text",
"id": 4
},
{
"text": "Please note any other information that could be of value to the doctor.",
"required": false,
"type": "text",
"id": 5
}
]
}
}
}