Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Murithijoshua authored Mar 20, 2024
2 parents ba3f4da + 9b5eabc commit 072e31a
Show file tree
Hide file tree
Showing 8 changed files with 2,698 additions and 2,184 deletions.
22 changes: 22 additions & 0 deletions models/n_courier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const sequelize = require("../db_config");
const Sequelize = require("sequelize");
const Joi = require("joi");

const NCourier= sequelize.sequelize.define(
"tbl_nishauri_courier", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},

name:Sequelize.STRING
}, {
timestamps: true,
paranoid: true,
underscored: true,
freezeTableName: true,
tableName: "tbl_nishauri_courier"
}
);
exports.NCourier = NCourier;
24 changes: 24 additions & 0 deletions models/n_drug_delivery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const sequelize = require("../db_config");
const Sequelize = require("sequelize");
const Joi = require("joi");

const NDrugDelivery = sequelize.sequelize.define(
"tbl_nishauri_drug_delivery", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},

program_identifier:Sequelize.INTEGER,
order_id:Sequelize.INTEGER,
initiated_by:Sequelize.INTEGER
}, {
timestamps: true,
paranoid: true,
underscored: true,
freezeTableName: true,
tableName: "tbl_nishauri_drug_delivery"
}
);
exports.NDrugDelivery = NDrugDelivery;
36 changes: 36 additions & 0 deletions models/n_drug_order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const sequelize = require("../db_config");
const Sequelize = require("sequelize");
const Joi = require("joi");

const NDrugOrder = sequelize.sequelize.define(
"tbl_nishauri_drug_order", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},

program_identifier:Sequelize.INTEGER,
appointment_id:Sequelize.INTEGER,
event_id:Sequelize.INTEGER,
delivery_address:Sequelize.STRING,
delivery_lat:Sequelize.STRING,
delivery_long:Sequelize.STRING,
delivery_method:Sequelize.STRING,
courier_service:Sequelize.INTEGER,
delivery_person:Sequelize.STRING,
delivery_person_id:Sequelize.STRING,
delivery_person_contact:Sequelize.STRING,
order_by:Sequelize.INTEGER,
mode:Sequelize.STRING,
delivery_pickup_time:Sequelize.DATE,
client_phone_no:Sequelize.STRING
}, {
timestamps: true,
paranoid: true,
underscored: true,
freezeTableName: true,
tableName: "tbl_nishauri_drug_order"
}
);
exports.NDrugOrder = NDrugOrder;
25 changes: 25 additions & 0 deletions models/n_program_type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const sequelize = require("../db_config");
const Sequelize = require("sequelize");
const Joi = require("joi");

const NprogramTypes = sequelize.sequelize.define(
"tbl_nishauri_program_type", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},

name:Sequelize.STRING,
program_code:Sequelize.STRING,
description:Sequelize.STRING,
is_active:Sequelize.STRING
}, {
timestamps: true,
paranoid: true,
underscored: true,
freezeTableName: true,
tableName: "tbl_nishauri_program_type"
}
);
exports.NprogramTypes = NprogramTypes;
40 changes: 40 additions & 0 deletions models/n_user_profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const sequelize = require("../db_config");
const Sequelize = require("sequelize");
const Joi = require("joi");

const NUserProfile = sequelize.sequelize.define(
"tbl_nishauri_user_profile", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},

user_id:Sequelize.INTEGER,
f_name:Sequelize.STRING,
l_name:Sequelize.STRING,
email:Sequelize.STRING,
phone_no:Sequelize.STRING,
dob:Sequelize.DATEONLY,
gender:Sequelize.STRING,
landmark:Sequelize.STRING,
blood_group: Sequelize.STRING,
weight:Sequelize.STRING,
height:Sequelize.STRING,
marital: Sequelize.STRING,
education: Sequelize.STRING,
primary_language: Sequelize.STRING,
occupation: Sequelize.STRING,
allergies: Sequelize.STRING,
chronics: Sequelize.STRING,
disabilities: Sequelize.STRING

}, {
timestamps: true,
paranoid: true,
underscored: true,
freezeTableName: true,
tableName: "tbl_nishauri_user_profile"
}
);
exports.NUserProfile = NUserProfile;
110 changes: 79 additions & 31 deletions routes/processes/nishauri.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require("dotenv").config();


//const Op = require("sequelize");
const { Op } = require("sequelize");
var { Op, Sequelize } = require("sequelize");
var bcrypt = require('bcrypt');

//const Sequelize = require("sequelize");
Expand Down Expand Up @@ -303,6 +303,7 @@ router.post('/resetpassword', async(req, res) => {
}
});


if(check_username)
{
//Generate OTP and send to Users Via Email or Telephone Number
Expand Down Expand Up @@ -473,7 +474,7 @@ router.post('/updatepassword', async(req, res) => {
router.post('/validate_program', async(req, res) => {
let ccc_no = req.body.ccc_no;
let upi_no = req.body.upi_no;
let firstname = req.body.firstname;
let firstname = req.body.firstname.toUpperCase().trim(); //Trim & Capitalize FirstName
let user_id = req.body.user_id;
let today = moment(new Date().toDateString()).tz("Africa/Nairobi").format("YYYY-MM-DD H:M:S");

Expand All @@ -490,27 +491,33 @@ router.post('/validate_program', async(req, res) => {
}

//Check If User Exists
let check_username= await NUsers.findOne({
var check_username= await NUsers.findOne({
where: {
[Op.and]: [
{ is_active: '0'},
{ id: base64.decode(user_id) }
]
}
});




//User Is Not Active
//Validate Program In HIV
let check_program_valid= await Client.findOne({
where: {
[Op.and]: [
{ f_name: firstname},
{ clinic_number: ccc_no}
]
}
});

const check_program_valid= await Client.findOne({
where:{
[Op.and]: [
Sequelize.where(
Sequelize.fn('UPPER', Sequelize.col('f_name')),
Sequelize.fn('UPPER', firstname)
),
{ clinic_number: ccc_no }
]
}
});

//console.log(check_program_valid);

if(!check_program_valid)
{
Expand All @@ -520,15 +527,50 @@ router.post('/validate_program', async(req, res) => {
success: false,
msg: `Invalid CCC Number/ First Name Match: ${ccc_no}, The CCC Number/First Name does not match in Nishauri`,
});

}

if(check_username) //User Account Not Active- Show Page to Enter Program Indentification Details
{
let vOTP='';
//Generate OTP
//Generate OTP and send to Users Via Email or Telephone Number
let vOTP=generateOtp(5);
//Check if OTP was generated and has not expired
if((check_username.profile_otp_number!=null) || (check_username.profile_otp_date!=null))
{

let date_diff = moment(today).diff(
moment(check_username.profile_otp_date).format("YYYY-MM-DD HH:MM:SS"),
"seconds"
);
console.log(date_diff);
if(date_diff<=3600) //60 Seconds
{
vOTP=check_username.profile_otp_number //Use OTP

}else
{
vOTP=generateOtp(5); //OTP expired or Not sent yet.. Generate a New OTP
//Update New OTP
const log_OTP = await NUsers.update(
{ profile_otp_date: today, profile_otp_number: vOTP},
{ where: { id: base64.decode(user_id) } }
);

}

}else
{
vOTP=generateOtp(5); //OTP expired or Not sent yet.. Generate a New OTP
//Update New OTP
const log_OTP = await NUsers.update(
{ profile_otp_date: today, profile_otp_number: vOTP},
{ where: { id: base64.decode(user_id) } }
);
}




//Send SMS
const header_details= {
"rejectUnauthorized": false,
Expand All @@ -548,25 +590,27 @@ router.post('/validate_program', async(req, res) => {
}
}

//console.log(header_details);
request.post(header_details, (err, res, body) => {
if(err)
{
console.log(err);
//console.log(err);
//Error Sending OTP
return res
.status(200)
.json({
success: false,
msg: 'Error Sending OTP',
});
}
}else if (res.statusCode !== 200) {
console.error('Request failed with status code:', res.statusCode);
} else {
// Success! Do something with the response body
console.log('Success:', body.status);
}
});

//Save OTP Details
const log_OTP = await NUsers.update(
{ profile_otp_date: today, profile_otp_number: vOTP},
{ where: { id: base64.decode(user_id) } }
);


var l = {
user_id: base64.encode(check_username.id),
Expand Down Expand Up @@ -605,7 +649,7 @@ router.post('/validate_program', async(req, res) => {
router.post('/setprogram', async(req, res) => {
let ccc_no = req.body.ccc_no;
let upi_no = req.body.upi_no;
let firstname = req.body.firstname;
let firstname = req.body.firstname.toUpperCase().trim(); //Trim & Capitalize FirstName
let user_id = req.body.user_id;
let otp=req.body.otp_number;
let today = moment(new Date().toDateString()).tz("Africa/Nairobi").format("YYYY-MM-DD H:M:S");
Expand Down Expand Up @@ -635,15 +679,19 @@ router.post('/setprogram', async(req, res) => {


//User Is Not Active
//Validate Program In HIV
let check_program_valid= await Client.findOne({
where: {
[Op.and]: [
{ f_name: firstname},
{ clinic_number: ccc_no}
]
}
});
//Validate Program In HI

const check_program_valid= await Client.findOne({
where:{
[Op.and]: [
Sequelize.where(
Sequelize.fn('UPPER', Sequelize.col('f_name')),
Sequelize.fn('UPPER', firstname.toUpperCase())
),
{ clinic_number: ccc_no }
]
}
});

if(!check_program_valid)
{
Expand Down
2 changes: 1 addition & 1 deletion routes/processes/nishauri_chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# take passed variable values
question = sys.argv[1];
# question = 'How do i reschedule appointment?';
#question = 'How do i reschedule appointment?';
#token = sys.argv[2];


Expand Down
Loading

0 comments on commit 072e31a

Please sign in to comment.