Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hospital detail pages #42

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.DS_Store
.env
61 changes: 59 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,68 @@
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
require("dotenv").config();

const cooperativeDoctorsRouter = require("./routes/cooperative-doctors.routes");
const prospectiveDoctorsRouter = require("./routes/prospective-doctors.routes");
const hospitalsRouter = require("./routes/hospitals.routes");
const usersRouter = require("./routes/users.routes")

const { auth } = require("express-oauth2-jwt-bearer");

const app = express();
const port = process.env.PORT || 3001;
const dbConnectionString = process.env.MongoURI;

const jwtCheck = auth({
audience: "https://nehlc.org",
issuerBaseURL: "https://dev-tiokiwpanv8xk8a2.us.auth0.com/",
tokenSigningAlg: "RS256",
});

mongoose
.connect(dbConnectionString, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("DB Connected"))
.catch((err) => console.log(err));

app.get("/", (req, res) => res.type('html').send(html));
mongoose.Promise = global.Promise;

app.use(
cors({
origin: "*",
})
);

// enforce on all endpoints
app.use(jwtCheck);
app.use(bodyParser.json())

app.use("/cooperative-doctors", jwtCheck, cooperativeDoctorsRouter);
app.use("/prospective-doctors", jwtCheck, prospectiveDoctorsRouter);
app.use("/hospitals", jwtCheck, hospitalsRouter);
app.use("/users", jwtCheck, usersRouter);

app.get("/", (req, res) => res.type("html").send(html));

app.listen(port, () => console.log(`Example app listening on port ${port}!`));

// catch 404 and forward to error handler
app.use(function (req, res, next) {
res.status(404).json({
message: "No such route exists",
});
});

// error handler
app.use(function (err, req, res, next) {
res.status(err.status || 500).json({
message: "Error Message",
});
});

const html = `
<!DOCTYPE html>
Expand Down Expand Up @@ -56,4 +113,4 @@ const html = `
</section>
</body>
</html>
`
`;
35 changes: 35 additions & 0 deletions controllers/cooperative-doctors.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const CooperativeDoctor = require('../models/cooperative-doctor.model');

const getCooperativeDoctors = async (req, res) => {
let doctors = await CooperativeDoctor.find().populate('primaryFacility');

if(doctors) {
res.status(200).json(doctors);
} else {
res.status(400).json()
}
}

const getCooperativeDoctor = async (req, res) => {
let doctor = await CooperativeDoctor.findById(req.params.id).populate('primaryFacility');

if(doctor) {
res.status(200).json(doctor);
} else {
res.status(400).json()
}
}

const createCooperativeDoctor = async (req, res) => {
let doctor = await CooperativeDoctor.create(req.body);
res.status(201).json(doctor);
}

const updateCooperativeDoctor = async (req, res) => {
let doctor = await CooperativeDoctor.findByIdAndUpdate(req.params.id, req.body, { new: true });
res.status(200).json(doctor);
}

module.exports = {
getCooperativeDoctors, getCooperativeDoctor, createCooperativeDoctor, updateCooperativeDoctor
}
36 changes: 36 additions & 0 deletions controllers/hospitals.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const Hospital = require('../models/hospital.model');

const getHospitals = async (req, res) => {
let hospitals = await Hospital.find();

if(hospitals) {
res.status(200).json(hospitals);
} else {
res.status(400).json()
}
}

const getHospital = async (req, res) => {
let hospital = await Hospital.findById(req.params.id);

if(hospital) {
res.status(200).json(hospital);
} else {
res.status(400).json()
}
}

const createHospital = async (req, res) => {
let hosptial = await Hospital.create(req.body);
res.status(201).json(hosptial);
}

const updateHospital = async (req, res) => {
let hosptial = await Hospital.findByIdAndUpdate(req.params.id, req.body, { new: true });
res.status(200).json(hosptial);
}


module.exports = {
getHospitals, getHospital, createHospital, updateHospital
}
35 changes: 35 additions & 0 deletions controllers/prospective-doctors.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const ProspectiveDoctor = require('../models/prospective-doctor.model');

const getProspectiveDoctors = async (req, res) => {
let doctors = await ProspectiveDoctor.find().populate('primaryFacility');

if(doctors) {
res.status(200).json(doctors);
} else {
res.status(400).json()
}
}

const getProspectiveDoctor = async (req, res) => {
let doctor = await ProspectiveDoctor.findById(req.params.id).populate('primaryFacility');

if(doctor) {
res.status(200).json(doctor);
} else {
res.status(400).json()
}
}

const createProspectiveDoctor = async (req, res) => {
let doctor = await ProspectiveDoctor.create(req.body);
res.status(201).json(doctor);
}

const updateProspectiveDoctor = async (req, res) => {
let doctor = await ProspectiveDoctor.findByIdAndUpdate(req.params.id, req.body, { new: true });
res.status(200).json(doctor);
}

module.exports = {
getProspectiveDoctors, getProspectiveDoctor, createProspectiveDoctor, updateProspectiveDoctor
}
11 changes: 11 additions & 0 deletions controllers/users.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const decode = require('jwt-decode');

const getUserPermissions = async (req, res) => {
let permissions = decode(req.headers.authorization).permissions;

res.status(200).json(permissions);
}

module.exports = {
getUserPermissions
}
35 changes: 35 additions & 0 deletions models/cooperative-doctor.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const mongoose = require("mongoose");
const opts = { toJSON: { virtuals: true } };

const cooperativeDoctorSchema = new mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
firstname: String,
lastname: String,
consulting: Boolean,
notes: String,
specialty: String,
primaryFacilityId: String,
phoneNumbers: Array,
otherFacilites: Array
}, opts);

cooperativeDoctorSchema.virtual('id').get(function() {
return this._id.toString();
})

cooperativeDoctorSchema.virtual('fullname').get(function() {
return this.firstname + " " + this.lastname;
})

cooperativeDoctorSchema.virtual('primaryPhone').get(function() {
return this.phoneNumbers[0];
})

cooperativeDoctorSchema.virtual('primaryFacility', {
ref: 'Hospital',
localField: 'primaryFacilityId',
foreignField: '_id',
justOne: true
});

module.exports = mongoose.model("CooperativeDoctor", cooperativeDoctorSchema, "cooperativeDoctors");
24 changes: 24 additions & 0 deletions models/hospital.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const mongoose = require("mongoose");
const opts = { toJSON: { virtuals: true } };

const hospitalSchema = new mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
hospitalName: String,
healthCareSystem: String,
cms: String,
hospitalType: String,
emergencyServices: Boolean,
traumaCenter: Boolean,
beds: Number,
address: String,
city: String,
state: String,
zip: String,
telephone: String
}, opts);

hospitalSchema.virtual('id').get(function() {
return this._id.toString();
})

module.exports = mongoose.model("Hospital", hospitalSchema, "hospitals");
29 changes: 29 additions & 0 deletions models/prospective-doctor.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const mongoose = require("mongoose");
const opts = { toJSON: { virtuals: true } };

const prospectiveDoctorSchema = new mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
firstname: String,
lastname: String,
specialty: String,
primaryFacilityId: String,
phone: String,
isCooperative: Boolean
}, opts);

prospectiveDoctorSchema.virtual('id').get(function() {
return this._id.toString();
})

prospectiveDoctorSchema.virtual('fullname').get(function() {
return this.firstname + " " + this.lastname;
})

prospectiveDoctorSchema.virtual('primaryFacility', {
ref: 'Hospital',
localField: 'primaryFacilityId',
foreignField: '_id',
justOne: true
});

module.exports = mongoose.model("ProspectiveDoctor", prospectiveDoctorSchema, "prospectiveDoctors");
Empty file added models/user.model.js
Empty file.
24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
{
"name": "express-hello-world",
"name": "omahahlc-api",
"version": "1.0.0",
"description": "Express Hello World on Render",
"description": "Omaha HLC Api on render",
"main": "app.js",
"repository": "https://github.com/render-examples/express-hello-world",
"author": "Render Developers",
"repository": "https://github.com/erowe-dev/omahahlc-api",
"author": "erowe",
"license": "MIT",
"private": false,
"scripts": {
"start": "node app.js"
"start": "nodemon app.js"
},
"dependencies": {
"express": "^4.18.2"
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"dotenv": "^16.1.4",
"express": "^4.18.2",
"express-jwt-permissions": "^1.3.7",
"express-oauth2-jwt-bearer": "^1.5.0",
"jwt-decode": "^3.1.2",
"mongodb": "^5.6.0",
"mongoose": "^7.2.2",
"yarn": "^1.22.19"
},
"engines": {
"node": ">=14"
},
"devDependencies": {
"nodemon": "^2.0.22"
}
}
Empty file added routes/appointments.routes.js
Empty file.
Empty file added routes/contact-logs.routes.js
Empty file.
10 changes: 10 additions & 0 deletions routes/cooperative-doctors.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require('express');
const cooperativeDoctorsController = require('../controllers/cooperative-doctors.controller');
const router = express.Router();

router.get('/', cooperativeDoctorsController.getCooperativeDoctors);
router.get('/:id', cooperativeDoctorsController.getCooperativeDoctor);
router.post('/', cooperativeDoctorsController.createCooperativeDoctor);
router.put('/:id', cooperativeDoctorsController.updateCooperativeDoctor);

module.exports = router
10 changes: 10 additions & 0 deletions routes/hospitals.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require('express');
const hospitalsContoller = require('../controllers/hospitals.controller')
const router = express.Router();

router.get('/', hospitalsContoller.getHospitals);
router.get('/:id', hospitalsContoller.getHospital);
router.post('/', hospitalsContoller.createHospital);
router.put('/:id', hospitalsContoller.updateHospital);

module.exports = router
10 changes: 10 additions & 0 deletions routes/prospective-doctors.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require('express');
const prospectiveDoctorsContoller = require('../controllers/prospective-doctors.controller');
const router = express.Router();

router.get('/', prospectiveDoctorsContoller.getProspectiveDoctors);
router.get('/:id', prospectiveDoctorsContoller.getProspectiveDoctor);
router.post('/', prospectiveDoctorsContoller.createProspectiveDoctor);
router.put('/:id', prospectiveDoctorsContoller.updateProspectiveDoctor);

module.exports = router
7 changes: 7 additions & 0 deletions routes/users.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const express = require('express');
const router = express.Router();
const usersController = require('../controllers/users.controller')

router.get('/permissions', usersController.getUserPermissions);

module.exports = router
Loading