Skip to content

Commit

Permalink
populate doctors and pharmacy in profile
Browse files Browse the repository at this point in the history
  • Loading branch information
findthelorax committed Mar 2, 2024
1 parent 0184cc8 commit 94eed3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 4 additions & 4 deletions controllers/medicationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ exports.createMedication = async (req, res) => {
quantity,
associatedDrug: drug,
dateAdded: new Date(),
doctor: { profile: profile._id, doctor },
pharmacy: { profile: profile._id, pharmacy }
doctor,
pharmacy,
};
const medicationDoc = profile.medications.create(newMedication);
profile.medications.push(medicationDoc);
Expand All @@ -60,8 +60,8 @@ exports.createMedication = async (req, res) => {
exports.getAllMedications = async(req,res) => {
try {
const { profileId } = req.params;
const profile = await models.Profile.findById(profileId).populate('medications.associatedDrug');
const profile = await models.Profile.findById(profileId).populate(['medications.associatedDrug']);

if (!profile) {
return helpers.incomplete(res, 'Profile not found');
}
Expand Down
6 changes: 2 additions & 4 deletions models/medicationModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ const MedicationSchema = new Schema({
},
// prescriber: String,
doctor: {
profile: { type: Schema.Types.ObjectId, ref: 'Profile' },
doctor: Schema.Types.ObjectId,
doctor: { type: Schema.Types.ObjectId, ref: 'Doctor' },
},
pharmacy: {
profile: { type: Schema.Types.ObjectId, ref: 'Profile' },
pharmacy: Schema.Types.ObjectId,
pharmacy: { type: Schema.Types.ObjectId, ref: 'Pharmacy' }
},
associatedDrug: { type: Schema.Types.ObjectId, ref: 'Drug' },
medicationIntakes: [MedicationIntakeSchema],
Expand Down

0 comments on commit 94eed3a

Please sign in to comment.