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

6180 prescribed quantity #6345

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e820418
added prescribed quantity input
GeronimoJohn Jan 23, 2025
7f103eb
add prescribed_quantity field to invoice_line
GeronimoJohn Jan 27, 2025
326c900
remove comment
GeronimoJohn Jan 27, 2025
4d05f20
render prescribed quantity for an item
GeronimoJohn Jan 28, 2025
58d3fba
enable input field to update for prescribe quantity client
GeronimoJohn Jan 28, 2025
994ffdc
add prescribed quantity to input
GeronimoJohn Jan 28, 2025
1b01922
add prescribed quantity to input backend
GeronimoJohn Jan 28, 2025
558feaa
update prescribed_quantity to be nullable
GeronimoJohn Jan 29, 2025
de7d334
updated default value to be none
GeronimoJohn Jan 29, 2025
39c5b7a
initial prescribed quantity tests
GeronimoJohn Jan 29, 2025
9eaeb24
add sync test
GeronimoJohn Jan 29, 2025
2b59e30
Merge branch 'develop' into 6180-prescribed-quantity
GeronimoJohn Jan 29, 2025
5143f28
add prescribed quantity to lines with items issued
GeronimoJohn Jan 30, 2025
4147c26
update mocked values
GeronimoJohn Jan 30, 2025
d35460b
Merge branch 'develop' into 6180-prescribed-quantity
GeronimoJohn Jan 30, 2025
a2893eb
add prescribed quantity to insert input
GeronimoJohn Jan 30, 2025
457d0bd
refined logic to add prescribed quantity when allocating
GeronimoJohn Jan 30, 2025
99e53db
updated according to design feedback
GeronimoJohn Jan 30, 2025
0421d79
Merge branch 'develop' into 6180-prescribed-quantity
GeronimoJohn Jan 30, 2025
164f6cb
assign prescribed quantity
GeronimoJohn Jan 31, 2025
24b52b5
remove console log
GeronimoJohn Jan 31, 2025
4c6712c
updated test data
GeronimoJohn Feb 2, 2025
ee12f7e
updated prescribedQuantity checks
GeronimoJohn Feb 2, 2025
751f0e5
move input focus to prescribed quantity
GeronimoJohn Feb 2, 2025
0c9e527
Merge pull request #6387 from msupply-foundation/6353-prescribed-quan…
GeronimoJohn Feb 2, 2025
939fcd7
Merge branch 'develop' into 6180-prescribed-quantity
GeronimoJohn Feb 2, 2025
f1d4ecb
code review changes
GeronimoJohn Feb 3, 2025
26bb501
Merge branch 'develop' into 6180-prescribed-quantity
GeronimoJohn Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/packages/common/src/intl/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@
"label.picked": "Picked",
"label.placeholder": "Placeholder",
"label.prescription-date": "Prescription Date",
"label.prescribed-quantity": "Prescribed Quantity",
"label.previous-encounters": "Previous Encounters",
"label.prescriber": "Prescriber",
"label.pricing": "Pricing",
Expand Down
4 changes: 4 additions & 0 deletions client/packages/common/src/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2949,6 +2949,7 @@ export type InsertPrescriptionLineInput = {
invoiceId: Scalars['String']['input'];
note?: InputMaybe<Scalars['String']['input']>;
numberOfPacks: Scalars['Float']['input'];
prescribedQuantity?: InputMaybe<Scalars['Float']['input']>;
stockLineId: Scalars['String']['input'];
};

Expand Down Expand Up @@ -3424,6 +3425,7 @@ export type InvoiceLineNode = {
note?: Maybe<Scalars['String']['output']>;
numberOfPacks: Scalars['Float']['output'];
packSize: Scalars['Float']['output'];
prescribedQuantity?: Maybe<Scalars['Float']['output']>;
pricing: PricingNode;
returnReason?: Maybe<ReturnReasonNode>;
returnReasonId?: Maybe<Scalars['String']['output']>;
Expand Down Expand Up @@ -8264,6 +8266,7 @@ export type UpdateOutboundShipmentLineErrorInterface = {
export type UpdateOutboundShipmentLineInput = {
id: Scalars['String']['input'];
numberOfPacks?: InputMaybe<Scalars['Float']['input']>;
prescribedQuantity?: InputMaybe<Scalars['Float']['input']>;
stockLineId?: InputMaybe<Scalars['String']['input']>;
tax?: InputMaybe<TaxInput>;
};
Expand Down Expand Up @@ -8416,6 +8419,7 @@ export type UpdatePrescriptionLineInput = {
id: Scalars['String']['input'];
note?: InputMaybe<Scalars['String']['input']>;
numberOfPacks?: InputMaybe<Scalars['Float']['input']>;
prescribedQuantity?: InputMaybe<Scalars['Float']['input']>;
stockLineId?: InputMaybe<Scalars['String']['input']>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const OutboundLineEdit: React.FC<ItemDetailsModalProps> = ({
const newAllocateQuantities = allocateQuantities(
status,
draftStockOutLines
)(newVal, packSize);
)(newVal, packSize, undefined, null);
setIsDirty(true);
setDraftStockOutLines(newAllocateQuantities ?? draftStockOutLines);
setIsAutoAllocated(autoAllocated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const createDraftLine = ({
totalAfterTax: 0,
totalBeforeTax: 0,
numberOfPacks: 0,
prescribedQuantity: 0,
packSize: 0,
sellPricePerPack: 0,
note: '',
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const PrescriptionLineEdit: React.FC<PrescriptionLineEditProps> = ({
isDisabled,
} = usePrescription();
const { status = InvoiceNodeStatus.New, prescriptionDate } = data ?? {};
const { updateQuantity, isLoading, updateNotes } = useDraftPrescriptionLines(
const { isLoading, updateQuantity, updateNotes } = useDraftPrescriptionLines(
currentItem,
draftPrescriptionLines,
updateLines,
Expand All @@ -65,12 +65,13 @@ export const PrescriptionLineEdit: React.FC<PrescriptionLineEditProps> = ({
const onAllocate = (
numPacks: number,
packSize: number | null,
autoAllocated = false
autoAllocated = false,
prescribedQuantity: number | null
) => {
const newAllocateQuantities = allocateQuantities(
status,
draftPrescriptionLines
)(numPacks, packSize, true);
)(numPacks, packSize, true, prescribedQuantity);

// Don't make saveable (isDirty) if item is new and has no auto-allocatable
// stock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ interface PrescriptionLineEditFormProps {
onChangeQuantity: (
quantity: number,
packSize: number | null,
isAutoAllocated: boolean
isAutoAllocated: boolean,
prescribedQuantity: number | null
) => DraftStockOutLine[] | undefined;
packSizeController: PackSizeController;
disabled: boolean;
Expand Down Expand Up @@ -82,21 +83,28 @@ export const PrescriptionLineEditForm: React.FC<
programId,
}) => {
const t = useTranslation();
const [allocationAlerts, setAllocationAlerts] = useState<StockOutAlert[]>([]);
const [issueUnitQuantity, setIssueUnitQuantity] = useState(0);
const { format } = useFormatNumber();
const { rows: items } = usePrescription();

const [issueUnitQuantity, setIssueUnitQuantity] = useState(0);
const [prescribedQuantity, setPrescribedQuantity] = useState(0);
const [allocationAlerts, setAllocationAlerts] = useState<StockOutAlert[]>([]);

const debouncedSetAllocationAlerts = useDebounceCallback(
warning => setAllocationAlerts(warning),
[]
);

const allocate = (numPacks: number, packSize: number) => {
const allocate = (
numPacks: number,
packSize: number,
prescribedQuantity: number
) => {
const newAllocateQuantities = onChangeQuantity(
numPacks,
packSize === -1 || packSize === 1 ? null : packSize,
true
true,
prescribedQuantity
);
const placeholderLine = newAllocateQuantities?.find(isA.placeholderLine);
const allocatedQuantity =
Expand Down Expand Up @@ -147,15 +155,18 @@ export const PrescriptionLineEditForm: React.FC<
// See https://github.com/msupply-foundation/open-msupply/issues/2727
// and https://github.com/msupply-foundation/open-msupply/issues/3532
const debouncedAllocate = useDebouncedValueCallback(
(numPacks, packSize) => {
allocate(numPacks, packSize);
(numPacks, packSize, prescribedQuantity) => {
allocate(numPacks, packSize, prescribedQuantity);
},
[],
500,
[draftPrescriptionLines] // this is needed to prevent a captured enclosure of onChangeQuantity
);

const handleIssueQuantityChange = (inputUnitQuantity?: number) => {
const handleIssueQuantityChange = (
inputUnitQuantity?: number,
quantityType: 'issue' | 'prescribed' = 'issue'
) => {
// this method is also called onBlur... check that there actually has been a
// change in quantity (to prevent triggering auto allocation if only focus
// has moved)
Expand All @@ -170,13 +181,34 @@ export const PrescriptionLineEditForm: React.FC<
: 1;

const numPacks = quantity / packSize;
debouncedAllocate(numPacks, Number(packSize));
debouncedAllocate(
numPacks,
Number(packSize),
quantityType === 'prescribed' ? inputUnitQuantity : prescribedQuantity
);
};

const handlePrescribedQuantityChange = (inputPrescribedQuantity?: number) => {
if (inputPrescribedQuantity == null) return;
setPrescribedQuantity(inputPrescribedQuantity);
handleIssueQuantityChange(inputPrescribedQuantity, 'prescribed');
};

const prescriptionLineWithNote = draftPrescriptionLines.find(l => !!l.note);
const note = prescriptionLineWithNote?.note ?? '';

useEffect(() => {
const selectedItem = items.find(
prescriptionItem => prescriptionItem.id === item?.id
);
const newPrescribedQuantity: number =
selectedItem?.lines?.find(
({ prescribedQuantity }) =>
prescribedQuantity != null && prescribedQuantity > 0
)?.prescribedQuantity ?? 0;

setPrescribedQuantity(newPrescribedQuantity);

const newIssueQuantity = Math.round(
allocatedUnits / Math.abs(Number(packSizeController.selected?.value || 1))
);
Expand Down Expand Up @@ -242,26 +274,34 @@ export const PrescriptionLineEditForm: React.FC<
alignItems="center"
display="flex"
flexDirection="row"
justifyContent="flex-start"
gap={1}
gap={5}
>
<Grid>
<InputLabel style={{ fontSize: 12 }}>
{t('label.issue')}
<Grid display="flex" alignItems="center" gap={1}>
<InputLabel sx={{ fontSize: 12 }}>
{t('label.prescribed-quantity')}
</InputLabel>
</Grid>
<Grid>
<NumericTextInput
autoFocus
disabled={disabled}
value={prescribedQuantity}
onChange={handlePrescribedQuantityChange}
min={0}
decimalLimit={2}
onBlur={() => {}}
/>
</Grid>
<Grid display="flex" alignItems="center" gap={1}>
<InputLabel sx={{ fontSize: 12 }}>
{t('label.issue')}
</InputLabel>
<NumericTextInput
disabled={disabled}
value={issueUnitQuantity}
onChange={handleIssueQuantityChange}
min={0}
decimalLimit={2}
/>
</Grid>
<Grid>
<InputLabel style={{ fontSize: 12 }}>
<InputLabel sx={{ fontSize: 12 }}>
{t('label.unit-plural', {
count: issueUnitQuantity,
unit: item?.unitName,
Expand Down Expand Up @@ -296,7 +336,7 @@ export const PrescriptionLineEditForm: React.FC<
updateNotes(e.target.value);
}}
fullWidth
style={{ flex: 1 }}
sx={{ flex: 1 }}
/>
</AccordionPanelSection>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ const useSaveLines = (id: string, invoiceNum: number) => {
),
updatePrescriptionLines: draftPrescriptionLines
.filter(
({ type, isCreated, isUpdated, numberOfPacks }) =>
({ type, isCreated, isUpdated, numberOfPacks, prescribedQuantity }) =>
!isCreated &&
isUpdated &&
type === InvoiceLineNodeType.StockOut &&
numberOfPacks > 0
numberOfPacks > 0 &&
(prescribedQuantity ?? 0) >= 0
)
.map(
line =>
Expand Down
5 changes: 3 additions & 2 deletions client/packages/invoices/src/Prescriptions/api/hooks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ export const createInputObject = (
line: DraftStockOutLine,
type: 'insert' | 'update' | 'delete'
) => {
const { id, numberOfPacks, stockLine, invoiceId, note } = line;
const { id, numberOfPacks, prescribedQuantity, stockLine, invoiceId, note } =
line;

const stockLineId = stockLine?.id ?? '';
const output = { id, numberOfPacks, stockLineId, note };
const output = { id, numberOfPacks, stockLineId, note, prescribedQuantity };

switch (type) {
case 'delete':
Expand Down
Loading
Loading