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-2117: Save orders on a new encounter if there is no encounter #1727

Merged
merged 17 commits into from
May 31, 2024

Conversation

usamaidrsk
Copy link
Member

@usamaidrsk usamaidrsk commented Mar 10, 2024

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

Summary

This PR adds the functionality to save orders along with creating a new encounter if one didn't exist. Before two transactions existed, i.e one to create encounter first and then create orders.

Screenshots

add-orders-on-creating-encounters.mp4

Related Issue

O3-2117

Other

@denniskigen denniskigen changed the title (feat) O3-2117: Save oders on creating encounter (feat) O3-2117: Save orders and encounters in the same transaction Mar 19, 2024
@denniskigen denniskigen requested a review from brandones March 19, 2024 07:13
Copy link
Member

@denniskigen denniskigen left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, @usamaidrsk. I've left a few suggestions

@@ -116,21 +124,27 @@ const OrderBasket: React.FC<DefaultWorkspaceProps> = ({
<InlineNotification
kind="error"
title={t('errorCreatingAnEncounter', 'Error when creating an encounter')}
subtitle={t('tryReopeningTheWorkspaceAgain', 'Please try launching the workspace again')}
Copy link
Member

Choose a reason for hiding this comment

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

I think it's best to show the original message here instead of the error message from the backend, which we're already logging to the console on line 67.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that's right.
Just what I thought that given on creating the encounter we're adding orders too, then if the error was from the orders, showing the exact message might be helpful to the user what exactly is the issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Dennis may be the leading authority on UI copy; I would defer to him @usamaidrsk .

@usamaidrsk usamaidrsk requested a review from denniskigen March 26, 2024 12:22
@usamaidrsk usamaidrsk force-pushed the ft-send-orders-on-creating-enconter branch from 329e58a to 856641d Compare April 15, 2024 11:24
@denniskigen denniskigen requested a review from samuelmale May 9, 2024 07:34
Copy link
Member

@vasharma05 vasharma05 left a comment

Choose a reason for hiding this comment

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

A few changes

packages/esm-patient-orders-app/src/api/api.ts Outdated Show resolved Hide resolved
@usamaidrsk usamaidrsk force-pushed the ft-send-orders-on-creating-enconter branch from 08f3f41 to 641f32f Compare May 14, 2024 12:27
@usamaidrsk usamaidrsk requested a review from vasharma05 May 15, 2024 12:40
Copy link
Member

@samuelmale samuelmale left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 11 to 12
import { type OrderPost, useSystemVisitSetting, useVisitOrOfflineVisit } from '@openmrs/esm-patient-common-lib';
import { orderBasketStore, type OrderBasketStore } from '@openmrs/esm-patient-common-lib/src/orders/store';
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to use a single import statement?

Copy link
Member

Choose a reason for hiding this comment

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

You'll likely need to make sure that those exports are re-exported from https://github.com/openmrs/openmrs-esm-patient-chart/blob/main/packages/esm-patient-common-lib/src/orders/index.ts first. That might need to happen in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

This needs to be exported from the @openmrs/esm-patient-common-lib or else we will very likely end up with multiple copies of the orderBasketStore, since this import means that each app will load it's own copy.

To explain: code from things listed as peerDependencies like @openmrs/esm-patient-common-lib is treated as an external by Webpack, meaning this will compile to code that ensures @openmrs/esm-patient-common-lib is loaded and load the exports from the named module. Code imported from @openmrs/esm-patient-common-lib/src/..., however, does not get converted into an external, so the code ends up imported here like in a normal dependency, meaning you're working with an app-local copy of the orderBasketStore.

It's technically ok to do this with type-only imports, because those are not part of the runtime code, so none of that code makes it into the final bundle.

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed with @brandones , moving the implementation of saving the encounter and orders to the common-lib seemed like a better idea. Therefore, I have created the postOrdersOnNewEncounter function in the postOrders.ts file.

cc @ibacher @denniskigen @samuelmale

packages/esm-patient-orders-app/src/api/api.ts Outdated Show resolved Hide resolved
Comment on lines 11 to 12
import { type OrderPost, useSystemVisitSetting, useVisitOrOfflineVisit } from '@openmrs/esm-patient-common-lib';
import { orderBasketStore, type OrderBasketStore } from '@openmrs/esm-patient-common-lib/src/orders/store';
Copy link
Member

Choose a reason for hiding this comment

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

You'll likely need to make sure that those exports are re-exported from https://github.com/openmrs/openmrs-esm-patient-chart/blob/main/packages/esm-patient-common-lib/src/orders/index.ts first. That might need to happen in a separate PR.

@brandones
Copy link
Contributor

Please also modify here and here with the optional encounterUuid type.

@@ -116,21 +124,27 @@ const OrderBasket: React.FC<DefaultWorkspaceProps> = ({
<InlineNotification
kind="error"
title={t('errorCreatingAnEncounter', 'Error when creating an encounter')}
subtitle={t('tryReopeningTheWorkspaceAgain', 'Please try launching the workspace again')}
Copy link
Contributor

Choose a reason for hiding this comment

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

Dennis may be the leading authority on UI copy; I would defer to him @usamaidrsk .

packages/esm-patient-orders-app/src/api/api.ts Outdated Show resolved Hide resolved
@usamaidrsk usamaidrsk requested a review from brandones May 28, 2024 21:12
@usamaidrsk usamaidrsk changed the title (feat) O3-2117: Save orders and encounters in the same transaction (feat) O3-2117: Save orders on a new encounter if there is no encounter May 28, 2024
Copy link
Contributor

@brandones brandones left a comment

Choose a reason for hiding this comment

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

LGTM

@brandones
Copy link
Contributor

@jayasanka-sack The E2E tests kept getting canceled? Any idea what that's about? Can we go ahead and merge this or would we risk breaking the E2E tests?

@jayasanka-sack
Copy link
Member

Hey, I checked out the recordings, and it looks like the UI isn't doing anything after clicking the save button. Since other PRs and the main branch don't have this issue, it seems like this problem was introduced in this PR.

Recordings:

lab order
drug order

@brandones
Copy link
Contributor

Thanks @jayasanka-sack ! Ok @usamaidrsk we need to fix the E2E tests.

@jayasanka-sack
Copy link
Member

I ran the test locally but couldn't reproduce this behavior. The key difference when running E2E tests on GitHub compared to running them locally is that we don't use the dev server on GitHub. Instead, we build the frontend and serve it, which is somewhat similar to the dev3 environment.

However, I reviewed the trace from the report and found these console errors:

TypeError: (0 , c.postOrdersOnNewEncounter) is not a function
    at http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:14249
    at http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:13958
    at Object.next (http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:14063)
    at S (http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:9123)
    at a (http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:9326)
    at http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:9385
    at new Promise (<anonymous>)
    at http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:9266
    at Object.Re (http://localhost:8080/openmrs/spa/openmrs.167c04e490dfd1aa.js:2:954551)
    at Ve (http://localhost:8080/openmrs/spa/openmrs.167c04e490dfd1aa.js:2:954705)
Unhandled rejection:  TypeError: Cannot read properties of undefined (reading 'error')
    at http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:14503
    at http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:13958
    at Object.next (http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:14063)
    at S (http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:9123)
    at a (http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:9326)
    at http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:9385
    at new Promise (<anonymous>)
    at http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:9266
    at Object.Re (http://localhost:8080/openmrs/spa/openmrs.167c04e490dfd1aa.js:2:954551)
    at Ve (http://localhost:8080/openmrs/spa/openmrs.167c04e490dfd1aa.js:2:954705)
showToast must be called with an object having a 'description' property that is a non-empty string or object
Cannot read properties of undefined (reading 'error')
TypeError: Cannot read properties of undefined (reading 'error')
    at http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:14503
    at http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:13958
    at Object.next (http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:14063)
    at S (http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:9123)
    at a (http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:9326)
    at http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:9385
    at new Promise (<anonymous>)
    at http://localhost:8080/openmrs/spa/openmrs-esm-patient-orders-app-8.0.1/287.js:2:9266
    at Object.Re (http://localhost:8080/openmrs/spa/openmrs.167c04e490dfd1aa.js:2:954551)
    at Ve (http://localhost:8080/openmrs/spa/openmrs.167c04e490dfd1aa.js:2:954705)

@jayasanka-sack
Copy link
Member

Ah, I understand now. We don't package esm-patient-common-lib, which means the postOrdersOnNewEncounter function isn't available. This is why the UI doesn't proceed once we hit the save button. The PR is safe to merge. But we should update the setup to reflect changes in the esm-patient-common-lib.

Meanwhile, @usamaidrsk I wonder why the UI silenced the error. We should display an error message to the user if something goes wrong.

@usamaidrsk
Copy link
Member Author

Meanwhile, @usamaidrsk I wonder why the UI silenced the error. We should display an error message to the user if something goes wrong.

Thanks for the follow up @jayasanka-sack , however all errors are displayed by an inline notification on the UI. Not sure why it is skipping that on the tests

@brandones
Copy link
Contributor

Ok, since this is an E2E bug I'm going to go ahead and merge.

@brandones brandones merged commit c5cb4cc into openmrs:main May 31, 2024
5 of 6 checks passed
@denniskigen
Copy link
Member

Would you expect E2E tests to pass once this got merged in, @brandones? Still failing for new PRs surprisingly.

@ibacher
Copy link
Member

ibacher commented Jun 4, 2024

They should, but unfortunately the patient-common-lib is embedded in lots of places that are not the chart, so we may not be using the latest version in tests.

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.

8 participants