fix: Convert historical liquid medicine dosages to user's preferred unit
Some checks failed
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled

Updated getMedicineDetails() in medicine tracking page to:
- Convert ml dosages to oz when user has imperial preference
- Display non-liquid units (mg, tablets, drops) as-is
- Match the pattern used in feeding page for consistency

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-03 13:03:06 +00:00
parent 9d66b58f20
commit 4be568742a
2 changed files with 28 additions and 1 deletions

View File

@@ -54,6 +54,8 @@ import { motion } from 'framer-motion';
import { useLocalizedDate } from '@/hooks/useLocalizedDate';
import { useTranslation } from '@/hooks/useTranslation';
import { UnitInput } from '@/components/forms/UnitInput';
import { convertVolume, getUnitSymbol } from '@/lib/utils/unitConversion';
import { MeasurementSystem } from '@/hooks/useLocale';
interface FeedingData {
feedingType: 'breast' | 'bottle' | 'solid';
@@ -302,7 +304,12 @@ function FeedingTrackPage() {
if (data.feedingType === 'breast') {
return `${data.side?.toUpperCase()} - ${data.duration || 0} min`;
} else if (data.feedingType === 'bottle') {
return `${data.amount || 0} ml - ${data.bottleType}`;
// Convert amount based on user preference
const measurementSystem: MeasurementSystem =
(user?.preferences?.measurementUnit as MeasurementSystem) || 'metric';
const converted = convertVolume(data.amount || 0, measurementSystem);
const roundedValue = Math.round(converted.value * 10) / 10; // Round to 1 decimal
return `${roundedValue} ${converted.unit} - ${data.bottleType}`;
} else if (data.feedingType === 'solid') {
return `${data.foodDescription}${data.amountDescription ? ` - ${data.amountDescription}` : ''}`;
}

View File

@@ -46,6 +46,8 @@ import { motion } from 'framer-motion';
import { useLocalizedDate } from '@/hooks/useLocalizedDate';
import { useTranslation } from '@/hooks/useTranslation';
import { UnitInput } from '@/components/forms/UnitInput';
import { convertVolume, getUnitSymbol } from '@/lib/utils/unitConversion';
import { MeasurementSystem } from '@/hooks/useLocale';
interface MedicineData {
medicineName: string;
@@ -223,6 +225,24 @@ function MedicineTrackPage() {
const getMedicineDetails = (activity: Activity) => {
const data = activity.data as MedicineData;
// Only convert if unit is ml (liquid medicine)
if (data.unit === 'ml') {
const measurementSystem: MeasurementSystem =
(user?.preferences?.measurementUnit as MeasurementSystem) || 'metric';
const converted = convertVolume(parseFloat(data.dosage), measurementSystem);
const roundedValue = Math.round(converted.value * 10) / 10; // Round to 1 decimal
let details = `${roundedValue} ${converted.unit}`;
if (data.route) {
details += ` - ${data.route.charAt(0).toUpperCase() + data.route.slice(1)}`;
}
if (data.reason) {
details += ` - ${data.reason}`;
}
return details;
}
// For non-liquid units (mg, tablets, drops), display as-is
let details = `${data.dosage} ${data.unit || ''}`;
if (data.route) {
details += ` - ${data.route.charAt(0).toUpperCase() + data.route.slice(1)}`;