bug fixes
This commit is contained in:
@@ -147,7 +147,6 @@ export default function NewMedicationPage() {
|
||||
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 outline-none"
|
||||
>
|
||||
<option value="daily">Daily</option>
|
||||
<option value="twice_daily">Twice Daily</option>
|
||||
<option value="specific_days">Specific Days of Week</option>
|
||||
<option value="every_n_days">Every N Days</option>
|
||||
<option value="as_needed">As Needed (PRN)</option>
|
||||
@@ -205,7 +204,7 @@ export default function NewMedicationPage() {
|
||||
{/* Times picker — hidden for as_needed */}
|
||||
{frequency !== 'as_needed' && (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<label className="block text-sm font-medium text-gray-700">Times</label>
|
||||
<button
|
||||
type="button"
|
||||
@@ -215,6 +214,9 @@ export default function NewMedicationPage() {
|
||||
+ Add Time
|
||||
</button>
|
||||
</div>
|
||||
{frequency === 'daily' && (
|
||||
<p className="text-xs text-gray-400 mb-2">Add multiple times for 2x, 3x, or more doses per day</p>
|
||||
)}
|
||||
<div className="space-y-2">
|
||||
{times.map((time, index) => (
|
||||
<div key={index} className="flex gap-2">
|
||||
|
||||
@@ -32,6 +32,7 @@ interface TodaysMedication {
|
||||
};
|
||||
scheduled_times: string[];
|
||||
taken_times: string[];
|
||||
skipped_times?: string[];
|
||||
is_prn?: boolean;
|
||||
is_next_day?: boolean;
|
||||
is_previous_day?: boolean;
|
||||
@@ -44,10 +45,11 @@ interface AdherenceEntry {
|
||||
is_prn?: boolean;
|
||||
}
|
||||
|
||||
type TimeStatus = 'overdue' | 'due_now' | 'upcoming' | 'taken';
|
||||
type TimeStatus = 'overdue' | 'due_now' | 'upcoming' | 'taken' | 'skipped';
|
||||
|
||||
function getTimeStatus(scheduledTime: string, takenTimes: string[], now: Date): TimeStatus {
|
||||
function getTimeStatus(scheduledTime: string, takenTimes: string[], skippedTimes: string[], now: Date): TimeStatus {
|
||||
if (takenTimes.includes(scheduledTime)) return 'taken';
|
||||
if (skippedTimes.includes(scheduledTime)) return 'skipped';
|
||||
|
||||
const [h, m] = scheduledTime.split(':').map(Number);
|
||||
const scheduled = new Date(now);
|
||||
@@ -69,7 +71,9 @@ const formatSchedule = (med: Medication): string => {
|
||||
return `Every ${med.interval_days} days`;
|
||||
}
|
||||
if (med.frequency === 'as_needed') return 'As needed';
|
||||
if (med.frequency === 'twice_daily') return 'Twice daily';
|
||||
const timesCount = med.times?.length || 0;
|
||||
if (med.frequency === 'twice_daily' || timesCount === 2) return 'Twice daily';
|
||||
if (timesCount >= 3) return `${timesCount}x daily`;
|
||||
return 'Daily';
|
||||
};
|
||||
|
||||
@@ -134,8 +138,8 @@ export default function MedicationsPage() {
|
||||
}
|
||||
|
||||
for (const time of item.scheduled_times) {
|
||||
const status = getTimeStatus(time, item.taken_times, now);
|
||||
if (status === 'upcoming') {
|
||||
const status = getTimeStatus(time, item.taken_times, item.skipped_times || [], now);
|
||||
if (status === 'upcoming' || status === 'skipped') {
|
||||
upcoming.push({ item, time, status });
|
||||
} else {
|
||||
due.push({ item, time, status });
|
||||
@@ -144,7 +148,7 @@ export default function MedicationsPage() {
|
||||
}
|
||||
|
||||
// Sort due: overdue first, then due_now, then by time
|
||||
const statusOrder: Record<TimeStatus, number> = { overdue: 0, due_now: 1, taken: 2, upcoming: 3 };
|
||||
const statusOrder: Record<TimeStatus, number> = { overdue: 0, due_now: 1, taken: 2, skipped: 3, upcoming: 4 };
|
||||
due.sort((a, b) => statusOrder[a.status] - statusOrder[b.status] || a.time.localeCompare(b.time));
|
||||
upcoming.sort((a, b) => a.time.localeCompare(b.time));
|
||||
|
||||
@@ -197,6 +201,7 @@ export default function MedicationsPage() {
|
||||
if (status === 'overdue') return 'border-l-4 border-l-red-500';
|
||||
if (status === 'due_now') return 'border-l-4 border-l-amber-500';
|
||||
if (status === 'taken') return 'border-l-4 border-l-green-500';
|
||||
if (status === 'skipped') return 'border-l-4 border-l-gray-400';
|
||||
return '';
|
||||
};
|
||||
|
||||
@@ -245,6 +250,8 @@ export default function MedicationsPage() {
|
||||
<span className="text-green-600 font-medium flex items-center gap-1">
|
||||
<CheckIcon size={16} /> Taken
|
||||
</span>
|
||||
) : entry.status === 'skipped' ? (
|
||||
<span className="text-gray-400 font-medium">Skipped</span>
|
||||
) : (
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
|
||||
@@ -755,6 +755,7 @@ export const api = {
|
||||
};
|
||||
scheduled_times: string[];
|
||||
taken_times: string[];
|
||||
skipped_times?: string[];
|
||||
is_prn?: boolean;
|
||||
is_next_day?: boolean;
|
||||
is_previous_day?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user