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

Solved By Maryam Qays #8

Open
wants to merge 2 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
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express')
const app = express()
const patientsRouter = require('./src/routes/v1/patients')
const historyRouter = require('./src/routes/v1/history')
const prescriptionRouter = require('./src/routes/v1/prescription')

// Connecting to MongoDB
const mongoose = require('mongoose')
Expand All @@ -28,5 +29,5 @@ app.get('/', (req, res)=>{

app.use('/api/v1/patients',patientsRouter);
app.use('/api/v1/history',historyRouter);

app.use('/api/v1/prescription', prescriptionRouter)
app.listen(PORT)
32 changes: 28 additions & 4 deletions src/controllers/v1/history/HistoryController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Patient = require('../../../models/Patient');
const {History} = require('../../../models/History');

const {success, error} = require('../../../utils/responser')


Expand All @@ -9,9 +8,34 @@ const getAllHistory = async (req, res)=>{
let historyList = await History.find()
return res.status(200).json(success(200,historyList,"Success"))
}
const getHistory = async (req, res)=>{
const id = req.params.id;
let his = await History.findById(id)
return res.status(200).json(success(200,his,"Ok"))
}



const deleteHistory = async (req, res)=>{
const id = req.params.id;
// TO-DO
const hist = await History.findByIdAndRemove(id)
let p = await Patient.updateOne({
$pull:{
history: id
}
})
return res.status(200).json(success(200,hist,"Success"))
}
const createPrescription = async (req, res)=>{
const id = req.params.id;
let his = await History.findById(id)
his.prescription.push(req.body)
his.save()
return res.status(200).json(success(200,his,"Success"))
}

module.exports = {
getAllHistory
getAllHistory,
getHistory,
deleteHistory,
createPrescription
}
19 changes: 19 additions & 0 deletions src/controllers/v1/prescription/PrescriptionController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const {History} = require('../../../models/History');
const {Prescription} = require('../../../models/Prescriptions');
const {success, error} = require('../../../utils/responser')



const createPrescription = async (req, res)=>{
const id = req.params.id;
let his = await History.findById(id)
his.prescription.push(req.body)
his.save()
return res.status(200).json(success(200,his,"Success"))
}



module.exports = {
createPrescription
}
4 changes: 1 addition & 3 deletions src/models/History.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const HistorySchema = new Schema({
require:true
},
report: String,
prescription:[
// TO-DO
]
prescription:[]

})
const History = mongoose.model('History', HistorySchema);
Expand Down
11 changes: 11 additions & 0 deletions src/models/Prescriptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema

const prescriptionSchema = new Schema({
name:String,
dose: String
})
const Prescription = mongoose.model('Prescription', prescriptionSchema);
module.exports = {
Prescription, prescriptionSchema
}
5 changes: 4 additions & 1 deletion src/routes/v1/history.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const express = require('express')
const router = express.Router()
const {getAllHistory} = require('../../controllers/v1/history/HistoryController')
const {createPrescription, deleteHistory, getHistory,getAllHistory} = require('../../controllers/v1/history/HistoryController')


router.get('/', getAllHistory);
router.delete('/:id', deleteHistory);
router.get('/:id', getHistory);
router.post('/:id/prescription', createPrescription);
module.exports = router;
7 changes: 7 additions & 0 deletions src/routes/v1/prescription.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const express = require('express')
const router = express.Router()
const {createPrescription} = require('../../controllers/v1/prescription/PrescriptionController')


router.post('/:id', createPrescription);
module.exports = router;