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

(feat) O3-3259 Add ability to deduct stock items while performing dispensing medication #107

Merged
merged 4 commits into from
May 28, 2024

Conversation

donaldkibet
Copy link
Member

@donaldkibet donaldkibet commented May 22, 2024

Requirements

  • This PR has a title that briefly describes the work done, including the ticket number if there is a ticket.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

Summary

See https://openmrs.atlassian.net/browse/O3-3259

Screenshots

Related Issue

For the feature to work, the pharmacist has to be given the privileges required to access stock and inventory rest endpoints.

Other

@donaldkibet donaldkibet requested review from denniskigen, mogoodrich, slubwama and ojwanganto and removed request for denniskigen May 22, 2024 05:21
Copy link

@jabahum jabahum left a comment

Choose a reason for hiding this comment

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

Please share a gif

src/routes.json Outdated
@@ -1,7 +1,8 @@
{
"backendDependencies": {
"fhir2": ">=1.2",
"webservices.rest": "^2.2.0"
"webservices.rest": "^2.2.0",
"stockmanagement": "^1.0.0"
Copy link

Choose a reason for hiding this comment

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

change stockmanagement version to ^1.4.1 >

batchNumber: inventoryItems.batchNumber,
quantity: Math.floor(inventoryItems.quantity),
quantityUoM: inventoryItems.quantityUoM,
expiration: formatDate(new Date(inventoryItems.expiration)),
Copy link

Choose a reason for hiding this comment

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

format this to MM/YYYY

Copy link
Member Author

Choose a reason for hiding this comment

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

Any specific reason why it should marked that way?

Copy link

Choose a reason for hiding this comment

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

not really but it looks better when shorter

Copy link
Member

Choose a reason for hiding this comment

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

Date formatting should remain consistent within the application unless there's a strong reason not to, so I think formatDate() is more likely to be correct here.

Copy link
Member

Choose a reason for hiding this comment

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

Tend to agree with @ibacher

* Interface for the stock dispense request object.
*/
export type StockDispenseRequest = {
locationUuid: string;
Copy link

Choose a reason for hiding this comment

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

this too changes to dispenseLocationUuid

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated with the requested changes, according to @slubwama PR this should be dispenseLocation

Copy link

Choose a reason for hiding this comment

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

as per the request body and not the response ?

*/
export type StockDispenseRequest = {
locationUuid: string;
patientUuid: string;
Copy link

Choose a reason for hiding this comment

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

this is just patient,order,encounter,stockItem,stockBatch as per new version of stockmanagement 1.4.0

src/routes.json Outdated
@@ -1,7 +1,8 @@
{
"backendDependencies": {
"fhir2": ">=1.2",
"webservices.rest": "^2.2.0"
"webservices.rest": "^2.2.0",
"stockmanagement": "^1.4.1 "
Copy link
Member

@pirupius pirupius May 22, 2024

Choose a reason for hiding this comment

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

@donaldkibet won't this mean implementations that don't use stock management will keep getting dependency errors? Is there a middle ground for this?

Copy link
Member

Choose a reason for hiding this comment

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

Agree with @pirupius , thanks for flagging this.

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm... We probably do need a way of indicating optional dependencies, though, right, i.e., if this only works with stockmanagement >= 1.4.1, then we do want some way of flagging that for implementations that do use stockmanagement.

Copy link
Member

Choose a reason for hiding this comment

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

Another thing for the backlog: https://openmrs.atlassian.net/browse/O3-3266

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried to relax this with

"stockmanagement": ">=1.4.1"

Copy link
Member

Choose a reason for hiding this comment

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

Either way, for now, we can't have it in backend dependencies, because it will create an annoying pop-up for everyone who's not using stock management, hence the ticket.

Choose a reason for hiding this comment

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

should it then be removed entirely? If yes, how best can we still have this requirement, at least somewhere in the application?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. For now, I don't think we can. We need this feature to properly support that.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this needs to be removed for now.

@mogoodrich
Copy link
Member

Thanks @donaldkibet ! Looking forward to adding this functionality... I should be able to review this today and will follow up with questions... would it be possible to add a little more details to the ticket about the approach we are taking for this?

Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

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

Generally looks good @donaldkibet though I added some requests for changes.

Would be great to see some screen shots of this as well when you get a chance.

enableStockDispense: {
_type: Type.Boolean,
_description: 'To enable or disable the deduction of stock during the dispensing process',
_default: true,
Copy link
Member

Choose a reason for hiding this comment

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

To maintain the same behavior by default, this default value should be false.

Copy link

Choose a reason for hiding this comment

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

i agree

src/routes.json Outdated
@@ -1,7 +1,8 @@
{
"backendDependencies": {
"fhir2": ">=1.2",
"webservices.rest": "^2.2.0"
"webservices.rest": "^2.2.0",
"stockmanagement": "^1.4.1 "
Copy link
Member

Choose a reason for hiding this comment

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

Agree with @pirupius , thanks for flagging this.

@@ -0,0 +1,79 @@
import useSWR from 'swr';
Copy link
Member

Choose a reason for hiding this comment

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

I know we've started a pattern of calling something "useDispenseStock" but then including multiple different hooks in it, but I think it would be better to get away from this and call this something like stock.resource.tsx or stock-management.resource.tsx. Do you agree @denniskigen @ibacher ?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, that's substantially more consistent with every other app in the ecosystem.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @ibacher ! So @donaldkibet yes, let's please change the name of this file.

/**
* Interface for the stock dispense request object.
*/
export type StockDispenseRequest = {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to include this here instead of in types?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was left by mistake, moved to types file

* @param {string} drugUuid - The UUID of the drug.
* @returns {Array} - The inventory items.
*/
export const useDispenseStock = (drugUuid: string) => {
Copy link
Member

Choose a reason for hiding this comment

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

I see you are setting limit=10, will there be a problem if there are more than 10 matching inventory items?

Copy link

Choose a reason for hiding this comment

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

@slubwama can give us a clear explanation why we need to add this and if its really necessary we find how to pass it from the UI.

@@ -67,6 +77,30 @@ const DispenseForm: React.FC<DispenseFormProps> = ({
medicationRequestBundle,
config.dispenseBehavior.restrictTotalQuantityDispensed,
);

if (config.enableStockDispense) {
Copy link
Member

Choose a reason for hiding this comment

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

This is breaking up the logic around fulfiller status, can we break this up into a separate "then" block, or at least move it up to line 73, before the "const newFulfillerStatus..." line?

Also, defer to you about the order operations... ie, would you want to move the dispense request before the "saveMedicationRequest" so that you only update the medication request if the stock update is successful? Of course, then you run into the opposite risk: that the stock could be updated and then the dispense fails. Would be great to make this a little more transactional, but, admittedly, that is likely difficult.

@donaldkibet
Copy link
Member Author

@mogoodrich @ibacher made the requested changes. Attached is an image of the changes

Kapture.2024-05-24.at.09.22.27.mp4

@donaldkibet donaldkibet force-pushed the O3-3259 branch 2 times, most recently from 713e06e to 008f671 Compare May 24, 2024 06:40
Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

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

@donaldkibet everything looks good to me, with the exception of the fact that it looks like we are still including the stock management dependency?

@donaldkibet
Copy link
Member Author

@mogoodrich removed the stock management requirement from the backend dependencies until this PR is merged in. I have also update comments on the config to make it explicit.

Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

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

Thanks @donaldkibet , LGTM!

Feel free to merge.

@ojwanganto
Copy link

Thanks, @mogoodrich

@ojwanganto ojwanganto merged commit 347959b into main May 28, 2024
4 checks passed
@ojwanganto ojwanganto deleted the O3-3259 branch May 28, 2024 13:21
mogoodrich added a commit that referenced this pull request May 28, 2024
…pensing medication (#107)

(fix bug with stock dispense conditional)
*/
export const useDispenseStock = (drugUuid: string) => {
const session = useSession();
const url = `/ws/rest/v1/stockmanagement/stockiteminventory?v=default&totalCount=true&drugUuid=${drugUuid}&includeBatchNo=true&groupBy=LocationStockItemBatchNo&dispenseLocationUuid=${session?.sessionLocation?.uuid}&includeStrength=1&includeConceptRefIds=1&emptyBatch=1&emptyBatchLocationUuid=${session?.sessionLocation?.uuid}&dispenseAtLocation=1`;
Copy link
Member

Choose a reason for hiding this comment

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

Not to weigh into this after the fact, but, thinking about the TAC call we are on right now, it would be great if, long-term, the stock management module support an FHIR endpoint so that it would hopefully be more standardized.

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.

6 participants