Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -185,47 +185,95 @@

// Event handlers
function handleComparatorInputChange(newComparatorInput: Quantity['comparator'] | null) {
console.log('🔍 Comparator changed:', {
newComparatorInput,
valueInput,
hasValue: !!valueInput,
willUpdateQR: true
});

Check failure on line 194 in packages/smart-forms-renderer/src/components/FormComponents/QuantityItem/QuantityItem.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `····`
setComparatorInput(newComparatorInput);

// Only suppress feedback once (before first blur)
if (!hasBlurred) {
setShowFeedback(false);
}

if (!valueInput) return;

onQrItemChange({
...createEmptyQrItem(qItem, answerKey),
answer: createQuantityItemAnswer(
precision,
valueInput,
newComparatorInput,
unitInput,
answerKey
)
});
// Always update QR item, even if valueInput is empty
if (valueInput) {
const qrUpdate = {
...createEmptyQrItem(qItem, answerKey),
answer: createQuantityItemAnswer(
precision,
valueInput,
newComparatorInput,
unitInput,
answerKey
)
};
console.log('✅ Updating QR with comparator (with value):', qrUpdate);
onQrItemChange(qrUpdate);
} else {
// If no value input, still update with empty quantity to preserve comparator
const qrUpdate = {
...createEmptyQrItem(qItem, answerKey),
answer: createQuantityItemAnswer(

Check failure on line 220 in packages/smart-forms-renderer/src/components/FormComponents/QuantityItem/QuantityItem.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎··········precision,⏎··········'',⏎··········newComparatorInput,⏎··········unitInput,⏎··········answerKey⏎········` with `precision,·'',·newComparatorInput,·unitInput,·answerKey`
precision,
'',
newComparatorInput,
unitInput,
answerKey
)
};
console.log('✅ Updating QR with comparator (no value):', qrUpdate);
onQrItemChange(qrUpdate);
}
}

function handleUnitInputChange(newUnitInput: QuestionnaireItemAnswerOption | null) {
console.log('🔍 Unit changed:', {
newUnitInput: newUnitInput?.valueCoding?.display,
valueInput,
hasValue: !!valueInput,
willUpdateQR: true
});

Check failure on line 240 in packages/smart-forms-renderer/src/components/FormComponents/QuantityItem/QuantityItem.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `····`
setUnitInput(newUnitInput);

// Only suppress feedback once (before first blur)
if (!hasBlurred) {
setShowFeedback(false);
}

if (!valueInput) return;

onQrItemChange({
...createEmptyQrItem(qItem, answerKey),
answer: createQuantityItemAnswer(
precision,
valueInput,
comparatorInput,
newUnitInput,
answerKey
)
});
// Always update QR item, even if valueInput is empty
if (valueInput) {
const qrUpdate = {
...createEmptyQrItem(qItem, answerKey),
answer: createQuantityItemAnswer(
precision,
valueInput,
comparatorInput,
newUnitInput,
answerKey
)
};
console.log('✅ Updating QR with unit (with value):', qrUpdate);
onQrItemChange(qrUpdate);
} else {
// If no value input, still update with empty quantity to preserve unit
const qrUpdate = {
...createEmptyQrItem(qItem, answerKey),
answer: createQuantityItemAnswer(

Check failure on line 266 in packages/smart-forms-renderer/src/components/FormComponents/QuantityItem/QuantityItem.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎··········precision,⏎··········'',⏎··········comparatorInput,⏎··········newUnitInput,⏎··········answerKey⏎········` with `precision,·'',·comparatorInput,·newUnitInput,·answerKey`
precision,
'',
comparatorInput,
newUnitInput,
answerKey
)
};
console.log('✅ Updating QR with unit (no value):', qrUpdate);
onQrItemChange(qrUpdate);
}
}

function handleValueInputChange(newInput: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,31 @@
questionnaire: qQuantityCalculation
}
};

export const QuantityBasicComparator: Story = {
name: 'Quantity Basic Comparator',
args: {
questionnaire: qQuantityBasic
},
parameters: {
docs: {
description: {
story: 'Test case for quantity with comparator. After filling the input, the comparator should be "<" but store returns undefined.'

Check failure on line 81 in packages/smart-forms-renderer/src/stories/itemTypes/Quantity.stories.tsx

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎·········`
}
}
}
};

export const QuantityMultiUnit: Story = {
name: 'Quantity Multi Unit',
args: {
questionnaire: qQuantityUnitOption
},
parameters: {
docs: {
description: {
story: 'Test case for quantity with multiple units. After filling the input, the unit should be "Week(s)" but store returns "Day(s)".'

Check failure on line 95 in packages/smart-forms-renderer/src/stories/itemTypes/Quantity.stories.tsx

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎·········`
}
}
}
};
36 changes: 16 additions & 20 deletions packages/smart-forms-renderer/src/utils/quantity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,27 @@ export function createQuantityItemAnswer(
unitInput: QuestionnaireItemAnswerOption | null,
answerKey: string | undefined
): QuestionnaireResponseItemAnswer[] {
if (precision) {
return [
{
id: answerKey,
valueQuantity: {
value: parseDecimalStringToFloat(parsedNewInput, precision),
comparator: comparatorInput ?? undefined,
unit: unitInput?.valueCoding?.display,
system: unitInput?.valueCoding?.system,
code: unitInput?.valueCoding?.code
}
}
];
// Handle empty input - only include value if there's actual input
const valueQuantity: Quantity = {
comparator: comparatorInput ?? undefined,
unit: unitInput?.valueCoding?.display,
system: unitInput?.valueCoding?.system,
code: unitInput?.valueCoding?.code
};

// Only add value if there's actual input
if (parsedNewInput && parsedNewInput.trim() !== '') {
if (precision) {
valueQuantity.value = parseDecimalStringToFloat(parsedNewInput, precision);
} else {
valueQuantity.value = parseFloat(parsedNewInput);
}
}

return [
{
id: answerKey,
valueQuantity: {
value: parseFloat(parsedNewInput),
comparator: comparatorInput ?? undefined,
unit: unitInput?.valueCoding?.display,
system: unitInput?.valueCoding?.system,
code: unitInput?.valueCoding?.code
}
valueQuantity
}
];
}
Loading