Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit f53b552

Browse files
committed
NavigationFromChatBot
1 parent 312680a commit f53b552

File tree

8 files changed

+184
-87
lines changed

8 files changed

+184
-87
lines changed

config/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
PASSWORD: 'pcprepkit9'
1414
},
1515
apiai: {
16-
clientToken: '2da698372070440e9ac9ac5c96917147'
16+
clientToken: '0f67eb54f1d74ea4a3d9c34a76da68ca'
1717
},
1818
databaseSetup: {
1919
DATABASE_NAME: 'pcprepkit',

helpers/chatbot/intentResponse.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
const fs = require('fs');
2+
const response = JSON.parse(fs.readFileSync('./helpers/chatbot/response.json'));
3+
4+
// Function to manage custom intents are defined here
5+
module.exports = {
6+
CheckMalariaSymptoms: function(parameters, done) {
7+
8+
const symptomScores = {
9+
chills: 2,
10+
fatigue: 2,
11+
fever: 2,
12+
malaise: 2,
13+
shivering: 2,
14+
sweating: 2,
15+
headache: 1,
16+
nausea: 1,
17+
'pain in muscles': 1,
18+
'faster heart rate': 1
19+
};
20+
21+
const symptoms = parameters.Symptoms;
22+
let length = symptoms.length;
23+
let malariaRisk = 0;
24+
25+
symptoms.forEach(function(symptom) {
26+
malariaRisk += symptomScores[symptom];
27+
let reply;
28+
if (--length === 0) {
29+
if (malariaRisk > 6) {
30+
reply = response.malariaRisk.level3;
31+
} else if (malariaRisk > 3) {
32+
reply = response.malariaRisk.level2;
33+
} else {
34+
reply = response.malariaRisk.level1;
35+
}
36+
done(reply);
37+
}
38+
});
39+
},
40+
41+
medicineSafeCheck: function(contextParameters, done) {
42+
const gender = contextParameters.gender;
43+
let reply;
44+
45+
if (gender === 'male') {
46+
reply = response.medicineSafe.gender.male;
47+
} else {
48+
reply = response.medicineSafe.gender.female;
49+
}
50+
done(reply);
51+
},
52+
53+
suggestPreventionTips: function(done) {
54+
let reply = {
55+
message: response.preventionTip.message,
56+
link: [{name: 'StopTheBreed', href: 'prevent/stop-the-breed/game'}, {name: 'StrideAgainstMalaria', href: 'prevent/stride-against-malaria/game'}],
57+
image: 'assets/img/prevent.png'
58+
};
59+
done(reply);
60+
},
61+
62+
suggestMedicine: function(done) {
63+
let reply = {
64+
message: response.suggestMedicine.message,
65+
link: [{name: 'MatchTheMeds', href: 'meds-n-labels/activity-1'}, {name: 'MemoryGame', href: 'meds-n-labels/activity-2'}],
66+
image: 'assets/img/meds.png'
67+
};
68+
done(reply);
69+
},
70+
71+
medicineSideEffects: function(parameters, done) {
72+
const medicine = parameters.medicine;
73+
const medSideEffects = {
74+
malarone: response.medicineSideEffects.malarone,
75+
mefloquine: response.medicineSideEffects.mefloquine,
76+
doxycycline: response.medicineSideEffects.doxycycline
77+
};
78+
79+
done(medSideEffects[medicine]);
80+
},
81+
82+
introductionMalaria: function(done) {
83+
let reply = {
84+
message: response.introductionMalaria.message,
85+
link: [{name: 'Highlight The Definition', href: 'introduction/activity-1'}, {name: 'An interactive Video', href: 'malaria-101/activity-1-1'}, {name: 'Life cycle of malarial Mosquito', href: 'malaria-101/activity-1-2'}],
86+
image: 'assets/img/intro.png'
87+
};
88+
done(reply);
89+
},
90+
91+
onFallback: function(done) {
92+
// Reply would be generated by our newly created Bot
93+
done();
94+
}
95+
};

helpers/chatbot/response.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"malariaRisk": {
3+
"level1": "It is less likely that you are infected with malaria. However it is always recommended you visit a doctor since malaria can turn out to be life threatening.",
4+
"level2": "There are chances of you being infected with malaria. Malaria can be a threat to life, It is always recommended you visit your doctor if you have any doubts.",
5+
"level3": "You seem to have quite a lot of symptoms related to malaria. Malaria can be a threat to life, please visit your doctor Immediately."
6+
},
7+
"medicineSafe": {
8+
"gender": {
9+
"male": "Wrong medication may cause adverse side effects, please consult your doctor",
10+
"female": "Wrong medication may cause adverse side effects, malaria is very harmful in case of pregnancies. Please consult your doctor."
11+
}
12+
},
13+
"preventionTip": {
14+
"message": "Using Mosquito repellent will be of a great help. Wear long sleeve clothes. You could check for any stagnant water."
15+
},
16+
"suggestMedicine": {
17+
"message": "The medicines which are used to treat malaria are called antimalarials. The medicine you take will depend on your location and your current health condition. Drug Treatment is based on species of parasites you are infected with. If you are infected with P. falciparum, it can be life threatening. Infection caused by other species are rarely life threatening. The popular medicines for malaria are Mefloquine, malarone , doxycycline."
18+
},
19+
"medicineSideEffects": {
20+
"malarone": "Malarone may cause nausea, vomiting, stomach pain, headache, diarrhea.",
21+
"mefloquine": "Mefloquine has some neuropsychiatric side effects, it may cause headache, nausea, dizziness and stomach upset",
22+
"doxycycline": "Doxycycline may cause stomach upset and sensitivity to sunlight"
23+
},
24+
"introductionMalaria": {
25+
"message": "An intermittent and remittent fever caused by a protozoan parasite that invades the red blood cells. The parasite is transmitted by mosquitoes in many tropical and subtropical regions."
26+
}
27+
}

routes/doctor.js

Lines changed: 24 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,36 @@
1+
const intentFunctions = require('../helpers/chatbot/intentResponse');
12
const getReply = function(chatResponse, done) {
23
let result = chatResponse.result;
34
const parameters = result.parameters;
45
const intentName = result.metadata.intentName;
5-
if (intentName === 'CheckMalariaSymptoms') {
6-
CheckMalariaSymptoms(parameters, function(reply) {
7-
done(reply);
8-
});
9-
} else if (intentName === 'medicineSafeCheckQuestion') {
10-
const contextParameters = result.contexts[0].parameters;
11-
medicineSafeCheck(contextParameters, function(reply) {
12-
done(reply);
13-
});
14-
} else if (intentName === 'medicineSideEffects') {
15-
medicineSideEffects(parameters, function(reply) {
6+
7+
if (Object.keys(parameters).length !== 0) {
8+
intentResponse[`${intentName}`](parameters, function(reply) {
169
done(reply);
1710
});
1811
}
19-
}
20-
21-
22-
const CheckMalariaSymptoms = function(parameters, done) {
23-
24-
const symptomScores = {
25-
chills: 2,
26-
fatigue: 2,
27-
fever: 2,
28-
malaise: 2,
29-
shivering: 2,
30-
sweating: 2,
31-
headache: 1,
32-
nausea: 1,
33-
'pain in muscles': 1,
34-
'faster heart rate': 1
35-
}
36-
37-
const symptoms = parameters.Symptoms;
38-
let length = symptoms.length;
39-
let malariaRisk = 0;
40-
41-
symptoms.forEach(function(symptom) {
42-
malariaRisk += symptomScores[symptom];
43-
if (--length === 0) {
44-
generateSymptomsReply(malariaRisk, function(reply) {
45-
done(reply);
46-
});
47-
}
48-
});
49-
}
50-
51-
const generateSymptomsReply = function(malariaRisk, done) {
52-
let reply;
53-
54-
if (malariaRisk > 6) {
55-
reply = 'You seem to have quite a lot of symptoms related to malaria. Malaria can be a threat to life, please visit your doctor Immediately.';
56-
} else if (malariaRisk > 3) {
57-
reply = 'There are chances of you being infected with malaria. Malaria can be a threat to life, It is always recommended you visit your doctor if you have any doubts.';
58-
} else {
59-
reply = 'It is less likely that you are infected with malaria. However it is always recommended you visit a doctor since malaria can turn out to be life threatening.';
60-
}
61-
done(reply);
62-
}
6312

64-
const medicineSafeCheck = function(contextParameters, done) {
65-
const gender = contextParameters.gender;
66-
const medicine = contextParameters.medicine;
67-
const age = contextParameters.age.amount;
68-
/**
69-
* Feature incomplete
70-
* Informaltion of Limited medicines available
71-
* Descision can be based upon gender medicine and age.
72-
*/
73-
74-
let reply;
75-
76-
if (gender === 'male') {
77-
reply = 'Wrong medication may cause adverse side effects, please consult your doctor';
78-
} else {
79-
reply = 'Wrong medication may cause adverse side effects, malaria is very harmful in case of pregnancies. Please consult your doctor.';
13+
else if (result.contexts.length !== 0) {
14+
intentResponse[`${intentName}`](result.contexts[0].parameters, function(reply) {
15+
done(reply);
16+
});
8017
}
81-
done(reply);
82-
}
8318

84-
const medicineSideEffects = function(parameters, done) {
85-
const medicine = parameters.medicine;
86-
const medSideEffects = {
87-
malarone: 'Malarone may cause nausea, vomiting, stomach pain, headache, diarrhea.',
88-
mefloquine: 'Mefloquine has some neuropsychiatric side effects, it may cause headache, nausea, dizziness and stomach upset',
89-
doxycycline: 'Doxycycline may cause stomach upset and sensitivity to sunlight'
19+
else {
20+
intentResponse[`${intentName}`](function(reply) {
21+
done(reply);
22+
});
9023
}
91-
92-
done(medSideEffects[medicine]);
93-
}
94-
24+
};
25+
26+
// Maps intents with the functions
27+
const intentResponse = {
28+
preventionTips: intentFunctions.suggestPreventionTips,
29+
CheckMalariaSymptoms: intentFunctions.CheckMalariaSymptoms,
30+
medicineSafeCheckQuestion: intentFunctions.medicineSafeCheck,
31+
medicineSideEffects: intentFunctions.medicineSideEffects,
32+
Medicine: intentFunctions.suggestMedicine,
33+
introductionMalaria: intentFunctions.introductionMalaria,
34+
fallback: intentFunctions.onFallback
35+
};
9536
module.exports = getReply;

src/app/meds-n-labels/activity-3/activity-3.component.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
<div class="col-md-4 col-xs-6 col-md-offset-4 col-xs-offset-3">
1+
<div class="col-md-5 col-xs-6 col-md-offset-3 col-xs-offset-3" id="chatBox">
22
<div class="chat-window">
33
<H3 class="text-center stage-header">{{language?.heading}}</H3>
44
<div class="chats" #chats>
55
<div [className]="chat.status" *ngFor="let chat of messages">
66
{{chat.message}}
7+
<img [src]="chat.image" *ngIf="chat.image">
8+
<div *ngIf="chat.link">
9+
{{language?.activityIndicationMessage}}
10+
<div *ngFor="let link of chat.link">
11+
<a [href] = "link.href"><button mat-stroked-button class="link-button">{{link.name}}</button></a>
12+
</div>
13+
</div>
714
</div>
815
</div>
916
<div class="send-message input-group">

src/app/meds-n-labels/activity-3/activity-3.component.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
@import "../../styles/main";
22

3+
// variables
4+
$button-margin: 5px;
5+
$button-height: 25px;
6+
$button-line-height: 25px;
7+
$box-margin-left: 340px;
8+
39
.chats {
410
height: 300px;
511
overflow: auto;
@@ -23,3 +29,19 @@
2329
padding: $padding-med;
2430
background: $pale-green;
2531
}
32+
33+
.link-button {
34+
border-radius: $border-radius;
35+
margin: $button-margin;
36+
height: $button-height;
37+
line-height: $button-line-height;
38+
color: $white;
39+
}
40+
41+
#chatBox {
42+
margin-left: $box-margin-left;
43+
}
44+
45+
img {
46+
display: block;
47+
}

src/app/meds-n-labels/activity-3/activity-3.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ export class DoctorchatComponent implements OnInit, AfterViewChecked {
4444
this.messages.push({message: sentMessage, status: 'sent-message'});
4545
if (localStorage.getItem(DoctorchatComponent._localStorageKey)) {
4646
this._doctorchat.doctorMessage({message: sentMessage}).subscribe(response => {
47-
this.messages.push({message: response.reply, status: 'recv-message'});
47+
if (response.reply.hasOwnProperty('link') && response.reply.hasOwnProperty('image')) {
48+
this.messages.push({message: response.reply.message, status: 'recv-message', link: response.reply.link, image: response.reply.image});
49+
} else {
50+
this.messages.push({message: response.reply, status: 'recv-message'});
51+
}
4852
});
4953
}
5054
}

src/assets/languages/english.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@
295295
},
296296
"doctorChat": {
297297
"heading": "Chat With Doctor",
298-
"introMessage": "Hi, I am a doctor, if you need any help related to malaria, feel free to talk to me"
298+
"introMessage": "Hi, I am a doctor, if you need any help related to malaria, feel free to talk to me",
299+
"activityIndicationMessage": "You can play these games in PC-Prep-Kit to know more about it."
299300
}
300301
},
301302
"peaceCorps": {

0 commit comments

Comments
 (0)