fix: Convert historical liquid medicine dosages to user's preferred unit
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:
@@ -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}` : ''}`;
|
||||
}
|
||||
|
||||
@@ -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)}`;
|
||||
|
||||
Reference in New Issue
Block a user