Skip to content

Dispense med function#37

Merged
devandres-tech merged 5 commits intomainfrom
DispenseMedFunction
Jan 1, 2025
Merged

Dispense med function#37
devandres-tech merged 5 commits intomainfrom
DispenseMedFunction

Conversation

@up2code3
Copy link
Copy Markdown
Collaborator

Description

1) What does this PR do? 2) List out what you did.

Dispense medication

  1. finds medication
  2. ensure med store matches user store
  3. ensures enough is in stock
  4. Deducts quantity from stock
  5. saves new quantity
  6. creates a dispense log.

Feature update/change/addition, bug fix, styling update, etc.

new feature

Testing Instructions

end point and body
Screenshot 2024-12-21 124740

note: I included , creating a dispenseLog model, and a "retrieve Dispense Log" controller , located directly under the dispense medication controller. I have not figured out how this works yet, I just new it would be the 2nd part of the dispense med function. Both are located in the medication controller.

@up2code3
Copy link
Copy Markdown
Collaborator Author

oooooooo.... I pulled up mongo compass, and checked the dispense logs there, it is in fact logging every time a medication was dispensed. So they only thing that is not working is my controller, to get the dispense log.

@up2code3
Copy link
Copy Markdown
Collaborator Author

Screenshot 2024-12-21 131529

@GinaCastromonte
Copy link
Copy Markdown
Collaborator

Screenshot 2024-12-23 at 12 28 19 PM

Will the user be able to choose the date? If so, we need to add it to the frontend. If not, then we don't need the dispenseDate on the model because you already have the timestamps.

Make sure dispense model has its own controller and route files to keep the code easier to maintain. When I was testing with Postman, the server kept crashing, and I found the the issue was due to the route order in the medication routes file. The route /:id was placed before other more specific routes like /dispense-logs and /dispense. Try to always place /:id at the end of the route definitions to avoid issues.

@up2code3
Copy link
Copy Markdown
Collaborator Author

ahh ok, Yea maybe just quantity on the dispense form for the front end.

@up2code3
Copy link
Copy Markdown
Collaborator Author

I just changed the dispense controller to use populate, and took store , lot , and ndc, off of the log model .

@up2code3
Copy link
Copy Markdown
Collaborator Author

Changed Create and Dispense Controllers, and
Changed the Medication, and DispenseLog Model.
got the opportunity to use populate in my controller, So i think i understand it a little better now. :)

@GinaCastromonte
Copy link
Copy Markdown
Collaborator

Awesome job implementing all of this!

  • I kept getting an "invalid token" error, and I believe it might be related to the "expires in 1hr" setting in the token configuration. It might not be necessary in this case

  • The issue with the dispense logs was that/inventory/:idwas matching paths like dispense-logs because Express evaluates routes in the order they’re defined. By moving the dispense logs route above /inventory/:id, I makes sure it was processed first, which resolved the error. OR just consider making a separate file.

  • Lastly, do we need to know which user dispensed the medication? If so, you might have to create another populate method to get user name, store, name of medication. It depends on what the frontend will need for reports (?)

@up2code3
Copy link
Copy Markdown
Collaborator Author

up2code3 commented Dec 31, 2024

It is working and now it has its own controller and route files.

note for testing in post man , the route name changed, instead of
http://localhost:8000/api/v1/inventory/dispense-logs /dispense (no more inventory in the name.)
it is now
http://localhost:8000/api/v1/dispense and /dispense-logs

@up2code3
Copy link
Copy Markdown
Collaborator Author

I kept getting an "invalid token" error, and I believe it might be related to the "expires in 1hr" setting in the token configuration. It might not be necessary in this case

I changed it to 24 hours,

@up2code3
Copy link
Copy Markdown
Collaborator Author

I fix the dispense details for the log
Screenshot 2024-12-30 220211

@up2code3
Copy link
Copy Markdown
Collaborator Author

conflicts resolved

Copy link
Copy Markdown
Collaborator

@devandres-tech devandres-tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes look good

@devandres-tech devandres-tech merged commit 0c07e3d into main Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants