Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
raedawwad95 committed Jul 5, 2018
1 parent 9083ece commit 536af9e
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 254 deletions.
1 change: 0 additions & 1 deletion react-client/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
}
</style>

<title>Item List</title>
<!-- Latest compiled and minified CSS -->

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
Expand Down
51 changes: 28 additions & 23 deletions react-client/src/components/Nearest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,36 @@ class Map extends React.Component {
* Ajax request fetch the nearest three Doctors from the data base
*/
showNearest(){
var that=this
$.ajax({
url:'/docNearst/'+that.props.specialty,
type:'GET',
success:function(data){
var arr=[]
for (var i = 0; i < data.length; i++) {
var dLat =(that.props.lat-data[i].address.lat) * (Math.PI/180);
var dLng = (that.props.lng-data[i].address.lng) * (Math.PI/180);
var math = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(that.props.lat * (Math.PI/180)) * Math.cos(data[i].address.lat * (Math.PI/180)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
var c = 2 * Math.atan2(Math.sqrt(math), Math.sqrt(1-math));
var that=this
$.ajax({
url:'/docNearst/'+that.props.specialty,
type:'GET',
success:function(data){
var arr=[]

var distance= 6372.797 * c;
data[i].des = distance
arr.push(data[i])
}
arr.sort(function(a, b){return a.des - b.des});
arr.splice(3,arr.length-1)
that.setState({
specialties:arr
})
for (var i = 0; i < data.length; i++) {
var dLat =(that.props.lat-data[i].address.lat) * (Math.PI/180);
var dLng = (that.props.lng-data[i].address.lng) * (Math.PI/180);
var math = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(that.props.lat * (Math.PI/180)) * Math.cos(data[i].address.lat * (Math.PI/180)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
var c = 2 * Math.atan2(Math.sqrt(math), Math.sqrt(1-math));

var distance= 6372.797 * c;
data[i].des = distance
arr.push(data[i])
}
})

arr.sort(function(a, b){
return a.des - b.des
});

arr.splice(3,arr.length-1)
that.setState({
specialties:arr
})
}
})
}
/*
* rendering the nearest three doctors after determing the user loction
Expand Down
109 changes: 55 additions & 54 deletions react-client/src/components/Rate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,68 @@ import Map from './Map.jsx'
* This is an react component shows the highest Doctor rate
*/
class Rate extends React.Component{
constructor(props){
super(props)
this.state={
specialties:[]
}
this.showRate = this.showRate.bind(this);
}
constructor(props){
super(props);
this.state={
specialties:[]
}
this.showRate = this.showRate.bind(this);
}
/*
* Ajax request fetch the highet rate for Doctors from the data base
*/
showRate(){
var that = this;
if(this.props.specialty){
$.ajax({
url:'/doctors/'+that.props.specialty,
type:'GET',
success:function(data){

that.setState({
specialties:data
})
},
error:function(err){
console.log(err)
}
showRate(){
var that = this;

if(this.props.specialty){
$.ajax({
url:'/doctors/'+that.props.specialty,
type:'GET',
success:function(data){
that.setState({
specialties:data
})
}
}
},
error:function(err){
console.log(err)
}
})
}

}
/*
* Render the highest Doctor rate and call Map file
*/
render(){
return(
<div>
<div className="row">
<div className="col-sm-6">
<button onClick ={this.showRate}type="button" className='btn btn-info btn-transparent homebtn'>Rate</button>
<br/>
<br/>
{this.state.specialties.map(function(spe,index){
return(
<div className="container " key={index}>
<div className="jumbotron docInfo">
<div className="card-body">
<img src='../../photos/five.png' alt="Card image" id='docImg'/>
<h2 className="DocName">Dr.{spe.name}</h2>
<h3 className="cardText">Rate: {spe.rate}</h3>
<h3 className="cardText">Tel: {spe.tel}</h3>
</div>
</div>
</div>
)
})}
</div>
<div className="col-sm-6">
<Map specialty={this.props.specialty}/>
</div>
</div>
</div>
)
}
render(){
return(
<div>
<div className="row">
<div className="col-sm-6">
<button onClick ={this.showRate}type="button" className='btn btn-info btn-transparent homebtn'>Rate</button>
<br/>
<br/>
{this.state.specialties.map(function(spe,index){
return(
<div className="container " key={index}>
<div className="jumbotron docInfo">
<div className="card-body">
<img src='../../photos/five.png' alt="Card image" id='docImg'/>
<h2 className="DocName">Dr.{spe.name}</h2>
<h3 className="cardText">Rate: {spe.rate}</h3>
<h3 className="cardText">Tel: {spe.tel}</h3>
</div>
</div>
</div>
)
})}
</div>
<div className="col-sm-6">
<Map specialty={this.props.specialty}/>
</div>
</div>
</div>
)
}
}


Expand Down
64 changes: 32 additions & 32 deletions react-client/src/components/Specialties.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,45 @@ import Rate from './Rate.jsx'
* This is an react component renders the specialies using the DropdownButton and onSelect
*/
export default class Specialties extends Component{
constructor(props){
super(props)
this.state={
specialty:'',
}
this.onSelect=this.onSelect.bind(this)
}
onSelect(e){
this.setState({
specialty:e
})
constructor(props){
super(props)
this.state={
specialty:'',
}
this.onSelect=this.onSelect.bind(this)
}
onSelect(e){
this.setState({
specialty:e
})
}
render(){
return (
<div>
<div id="home" className=" container spbutton">
<div className='row'>
<div className='col-sm-4'>
<ButtonToolbar >
<DropdownButton className="btn btn-info homebtn" onSelect={this.onSelect} title ='choose specialty'
noCaret
id='dropdown-no-caret'>
<MenuItem eventKey='otolaryngologists(ear,nose,throat)'>otolaryngologists(ear,nose,throat)</MenuItem>
<MenuItem eventKey='cardiology(heart)'>cardiology(heart)</MenuItem>
<MenuItem eventKey='neurologists(brain and nervus system)'>neurologists(brain and nervus system)</MenuItem>
<MenuItem eventKey='opthalmologist(eye)'>opthalmologist(eye)</MenuItem>
<MenuItem eventKey='Pulmonolgy (respiratory)'>Pulmonolgy (respiratory)</MenuItem>
<MenuItem eventKey='general'>general </MenuItem>
<MenuItem eventKey='dermatology(skin)'>dermatology(skin) </MenuItem>
<MenuItem eventKey='Pediatric(children)'>Pediatric(children) </MenuItem>
<MenuItem eventKey='allergologist'>allergologist </MenuItem>
</DropdownButton>
</ButtonToolbar>
<br/> <br/>
<div style={{fontSize:16}} > {this.state.specialty}</div>
</div>
<div className='col-sm-8'>
<Rate specialty={this.state.specialty}/>
<div className='col-sm-4'>
<ButtonToolbar >
<DropdownButton className="btn btn-info homebtn" onSelect={this.onSelect} title ='choose specialty'
noCaret
id='dropdown-no-caret'>
<MenuItem eventKey='otolaryngologists(ear,nose,throat)'>otolaryngologists(ear,nose,throat)</MenuItem>
<MenuItem eventKey='cardiology(heart)'>cardiology(heart)</MenuItem>
<MenuItem eventKey='neurologists(brain and nervus system)'>neurologists(brain and nervus system)</MenuItem>
<MenuItem eventKey='opthalmologist(eye)'>opthalmologist(eye)</MenuItem>
<MenuItem eventKey='Pulmonolgy (respiratory)'>Pulmonolgy (respiratory)</MenuItem>
<MenuItem eventKey='general'>general </MenuItem>
<MenuItem eventKey='dermatology(skin)'>dermatology(skin) </MenuItem>
<MenuItem eventKey='Pediatric(children)'>Pediatric(children) </MenuItem>
<MenuItem eventKey='allergologist'>allergologist </MenuItem>
</DropdownButton>
</ButtonToolbar>
<br/> <br/>
<div style={{fontSize:16}} > {this.state.specialty}</div>
</div>
<div className='col-sm-8'>
<Rate specialty={this.state.specialty}/>
</div>
</div>
</div>
</div>
Expand Down
64 changes: 35 additions & 29 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ app.use(express.static(__dirname + '/../react-client/dist'))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

// app.use(cookieParser);

// use session middleware and configure it
app.use(session({secret:'mysecretsession',resave:true,saveUninitialized: true,

store:new mongoStore({mongooseConnection: mongoose.connection,collection: 'session',})
}))

Expand Down Expand Up @@ -58,9 +55,9 @@ app.post('/admin/doctorform',function(req,res){
lat:parseFloat(latlngStr.split(",")[0]),
lng:parseFloat(latlngStr.split(",")[1])
};

// we have three option here
if(req.body.action==="Add doctor"){

//create a variable doctor_data hold all new data
var doctor_data={
name:req.body.name,
Expand All @@ -74,6 +71,7 @@ app.post('/admin/doctorform',function(req,res){
var newDoc=new dataModels.Doctor(doctor_data);

newDoc.save(function(err,doc){

if(err){
console.log("error in saving a new doctor");
res.status(500);
Expand All @@ -83,47 +81,55 @@ app.post('/admin/doctorform',function(req,res){
res.status(302);
res.redirect('/admin/doctorform');
}

})
}

else if(req.body.action==="Delete doctor"){
// delete doctor by finding his name and delete it{ name } using deleteOne
dataModels.Doctor.findOneAndRemove({ 'name': req.body.name }, function (err, doctor) {
dataModels.Doctor.findOneAndRemove({ 'name': req.body.name },
function (err, doctor) {

if (err || doctor===null) {
res.status(500);
res.send("error");

}
else {
res.status(302);
res.render('doctorform');
};

});
}
else{
else{
// modify doctor by finding his name and modify it{ name } using findone and modify data in result
dataModels.Doctor.findOne( { "name":req.body.name}, function(err, result){
if (!err && result) {
result.specialization = req.body.specialization; // update ur values goes here
result.address = latlngObj;
result.tel = req.body.tel;
result.rate = req.body.rate;
var newDoctor = new dataModels.Doctor(result);
newDoctor.save(function(err, result2){
if(!err) {
res.render('doctorform')
} else {
res.status(500);
res.send(err);
}
})
}
else {
res.status(500);
res.send(err);
}
});
}
dataModels.Doctor.findOne( { "name":req.body.name},
function(err, result){

if (!err && result) {
result.specialization = req.body.specialization; // update ur values goes here
result.address = latlngObj;
result.tel = req.body.tel;
result.rate = req.body.rate;
var newDoctor = new dataModels.Doctor(result);
newDoctor.save(function(err, result2){

if(!err) {
res.render('doctorform')
} else {
res.status(500);
res.send(err);
}
})
}
else {
res.status(500);
res.send(err);
}

});
}

})

app.post('/admin/signup',passport.authenticate('local.signup',{
Expand Down
2 changes: 0 additions & 2 deletions views/admin.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"/>


<title> Admin Panel</title>
</head>
<body>
Expand Down
Loading

0 comments on commit 536af9e

Please sign in to comment.