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

#6284 Prescriptions per program #6371

Merged
merged 12 commits into from
Feb 3, 2025
Merged

Conversation

CarlosNZ
Copy link
Contributor

@CarlosNZ CarlosNZ commented Jan 31, 2025

Fixes #6284

πŸ‘©πŸ»β€πŸ’» What does this PR do?

Bit of a biggie this one, but a lot of the changed files are just adding a field to Rust types.

Quick summary of changes:

  • Update "items" node to be filterable by "masterListId"
  • Add "master_list_id" field to "invoice" table
  • Prescriptions toolbar makes a query useListPrograms to get a list of programs, and if any exist, presents a "Program" selector on the Prescription page
  • Program selector is loaded with the value attached to the current prescription/invoice
  • Changing the program removes all items already added to prescription
  • The masterListId of the selected program is passed down into the StockItemSearchInput, and included in the filter (so will only show items belonging to selected program)

Screenshot 2025-01-31 at 1 32 52β€―PM

πŸ’Œ Any notes for the reviewer?

There's two tiny off-road fixes I've included here too:

  • Pluralised the Breadcrumb heading to "Prescriptions" rather than "Prescription" to be consistent with everything else.
  • Removed the double-scroll bar from Detail View (it's still there on other things though -- have made an issue: My nemesis the double-scroll bar is back!Β #6370)

πŸ§ͺ Testing

If you have no programs defined yet:

  • Confirm the "Program" selector does NOT appear on the Prescription, and that there is no restrictions on the Item search

Then create some programs, and associate some items with them (instructions elsewhere, sorry)

  • Prescription should now have "Program" selector
  • After selecting a program, the "Items" search should be restricted to only the items of that program
  • Clear the program (set it to nothing) -- it should work without any warnings or other changes to the prescription
  • Select another program -- you should be warned that it will remove all items already added
    • "OK" clears the items and changes the program
    • "Cancel" changes nothing

@github-actions github-actions bot added this to the v2.6.0 milestone Jan 31, 2025
@github-actions github-actions bot added Team Piwakawaka James, Carl, John, Zachariah feature: dispensing labels Jan 31, 2025
Copy link

github-actions bot commented Jan 31, 2025

Bundle size difference

Comparing this PR to main

Old size New size Diff
5.27 MB 5.27 MB 2.28 KB (0.04%)

@@ -1595,7 +1595,7 @@
"placeholder.search-by-name-or-code": "Search by name or code",
"placeholder.search-by-notes": "Search by notes",
"preferences": "Preferences",
"prescription": "Prescription",
"prescription": "Prescriptions",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is super annoying -- I tried for ages to figure out where the keys were defined in the breadcrumbs, and couldn't figure out how to change it to the plural version. But it turns out all the other areas (Outbound shipments, etc) have just put the plural version in the singular key! πŸ™„

Not a great pattern, but too hard to fix right now.

@@ -71,7 +71,7 @@ const mapRoute = (route: string): RouteMapping => {
case inRoute(AppRoute.Patients):
return { title: 'patients', docs: '/dispensary/patients/' };
case inRoute(AppRoute.Prescription):
return { title: 'prescription', docs: '/dispensary/prescriptions/' };
return { title: 'prescriptions', docs: '/dispensary/prescriptions/' };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this too -- don't think it breaks anything (it's consistent with the other ones)

@@ -48,24 +47,22 @@ export const ContentAreaComponent: FC<ContentAreaProps> = ({
if (!rows) return null;

return (
<Box flexDirection="column" display="flex" flex={1}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just removing the outer <div> to fix the double scrollbar problem

flexDirection="column"
flex={1}
marginLeft={3}
gap={1}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just added gap

@@ -7,7 +7,7 @@ import { ProgramFragment } from '../operations.generated';
import { useProgramsGraphQL } from '../useProgramsGraphQL';
import { LIST, PROGRAM } from './keys';

export const useProgramList = () => {
export const useProgramList = (includeImmunisation?: boolean) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just made an additional configuration rather than creating a whole new hook for this. I assume we want all programs, including immunisation ones?

import React from 'react';
import { FC } from 'react';

interface ProgramSearchInputProps {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty much a copy of "ClinicianSearchInput". The only difference is I did the query (to get the program list) in the Toolbar (parent) rather than in here, as I wanted to be able to not show the program selector if there are no programs.

@GeronimoJohn GeronimoJohn self-assigned this Jan 31, 2025
sql!(
connection,
r#"
ALTER TABLE invoice ADD COLUMN master_list_id TEXT
Copy link
Contributor

@roxy-dao roxy-dao Jan 31, 2025

Choose a reason for hiding this comment

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

Since this is linking the invoice to program, should be renamed to program_id and reference the program table. Could you also do a migration to add and save the period_id as well? Might need mSupply implementation for period_id too for syncing. Then you don't need to serde rename in translation!

Copy link
Contributor

@GeronimoJohn GeronimoJohn 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 the hardwork on this @CarlosNZ. Looking good to me! The tests just need the programId field to be added. Approving with the note to include it

// For simplicity, we currently delete all items that have already been
// added when switching programs. We may wish to improve this in the
// future to only remove items that don't belong to the new program
await deleteAll();
Copy link
Contributor

Choose a reason for hiding this comment

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

Very Minor - Just a small behaviour question: If a user removes and then reselects the same program, it warns them about deleting all their current lines. Wondering if it would be nice if it didn't for that use case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I see what you mean. But once they've removed the program selection, we no longer have any record of what was previously selected. I could add a new previousSelection state value, but seems a bit overkill for a fairly edge case.

I actually think we should do the more sophisticated thing and only remove the items that are not part of the new program, and that would take care of this problem, but was told to just deleteAll for now. So any further changes seem like fixing the wrong problem if you know what I mean πŸ˜†

@CarlosNZ CarlosNZ force-pushed the 6284-prescriptions-per-program branch from 69876ef to b312ee3 Compare February 3, 2025 03:23
@CarlosNZ
Copy link
Contributor Author

CarlosNZ commented Feb 3, 2025

Thanks for the review @GeronimoJohn -- have fixed the tests now: b312ee3

@CarlosNZ CarlosNZ merged commit ccde2b2 into develop Feb 3, 2025
3 of 6 checks passed
@CarlosNZ CarlosNZ deleted the 6284-prescriptions-per-program branch February 3, 2025 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: dispensing Team Piwakawaka James, Carl, John, Zachariah
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prescriptions Per Program
3 participants