DoenaSoft.PillRefresh
1.0.0
See the version list below for details.
dotnet add package DoenaSoft.PillRefresh --version 1.0.0
NuGet\Install-Package DoenaSoft.PillRefresh -Version 1.0.0
<PackageReference Include="DoenaSoft.PillRefresh" Version="1.0.0" />
<PackageVersion Include="DoenaSoft.PillRefresh" Version="1.0.0" />
<PackageReference Include="DoenaSoft.PillRefresh" />
paket add DoenaSoft.PillRefresh --version 1.0.0
#r "nuget: DoenaSoft.PillRefresh, 1.0.0"
#:package DoenaSoft.PillRefresh@1.0.0
#addin nuget:?package=DoenaSoft.PillRefresh&version=1.0.0
#tool nuget:?package=DoenaSoft.PillRefresh&version=1.0.0
PillRefreshLib
A .NET library for calculating medication supply duration and generating calendar reminders with automatic weekend and holiday avoidance.
Description
PillRefreshLib provides core functionality for managing medication schedules by calculating when prescriptions need to be refilled. The library automatically adjusts reminder dates to avoid weekends and regional holidays, ensuring reminders occur on business days when prescriptions can actually be filled.
Features
- Calculate remaining medication supply duration based on current pills and daily dosage
- Generate iCalendar (.ics) files compatible with Outlook, Google Calendar, and other applications
- Automatic reminder date adjustment to avoid:
- Weekends (Saturday/Sunday)
- Public holidays (country and region-specific)
- Mondays (optional, to account for medical provider schedules)
- Flexible user interaction interface for easy integration
- Support for decimal pill counts and dosages
- Multi-language support via resource files
Installation
Install via NuGet Package Manager:
Install-Package DoenaSoft.PillRefresh
Or via .NET CLI:
dotnet add package DoenaSoft.PillRefresh
Target Frameworks
This library supports:
- .NET 10.0
- .NET Framework 4.7.2
- .NET Standard 2.0
Dependencies
- Ical.Net (>= 5.2.1): iCalendar file format support
- mitoSoft.Holidays (>= 2.0.6): Holiday calendar data for multiple countries and regions
Usage
Basic Example
using DoenaSoft.PillRefresh;
// Implement the IInteraction interface for your application
public class ConsoleInteraction : IInteraction
{
public void WriteLine(string message = null)
{
Console.WriteLine(message);
}
public string ReadLine()
{
return Console.ReadLine();
}
}
// Use the PillCalculator
var interaction = new ConsoleInteraction();
var calculator = new PillCalculator(interaction);
// Get user input
double pillCount = calculator.GetPillCount();
double dailyDosage = calculator.GetDosageCount();
// Calculate final day
DateTime finalDay = DateTime.Now.Date.AddDays(Math.Floor(pillCount / dailyDosage) - 1);
// Get reminder day (adjusted for holidays and weekends)
DateTime reminderDay = calculator.GetReminderDay(finalDay, "us", "California");
// Get event name
string eventName = calculator.GetEventName();
// Create calendar event
string icsFilePath = calculator.CreateEvent(finalDay, reminderDay, eventName);
// The .ics file is now ready to be imported into any calendar application
Advanced Integration
For GUI or web applications, implement the IInteraction interface to match your UI framework:
public class WpfInteraction : IInteraction
{
private readonly TextBox outputTextBox;
private readonly Func<string> inputProvider;
public WpfInteraction(TextBox output, Func<string> inputFunc)
{
outputTextBox = output;
inputProvider = inputFunc;
}
public void WriteLine(string message = null)
{
outputTextBox.AppendText(message + Environment.NewLine);
}
public string ReadLine()
{
return inputProvider();
}
}
Automated Scenarios
For testing or automated workflows, create a mock interaction:
public class MockInteraction : IInteraction
{
private readonly Queue<string> responses;
private readonly List<string> output;
public MockInteraction(params string[] inputResponses)
{
responses = new Queue<string>(inputResponses);
output = new List<string>();
}
public void WriteLine(string message = null)
{
output.Add(message);
}
public string ReadLine()
{
return responses.Dequeue();
}
public IReadOnlyList<string> Output => output;
}
// Usage in tests
var mock = new MockInteraction("30", "2", "7", "Refill Medication");
var calculator = new PillCalculator(mock);
// ... perform calculations
API Reference
IInteraction Interface
public interface IInteraction
{
void WriteLine(string message = null);
string ReadLine();
}
Implement this interface to integrate the library with your application's UI framework.
PillCalculator Class
Constructor
public PillCalculator(IInteraction interaction)
Creates a new instance of the PillCalculator with the specified interaction interface.
Parameters:
interaction: Implementation of IInteraction for user communication
Methods
GetPillCount()
public double GetPillCount()
Prompts the user for the number of pills remaining.
Returns: The number of pills left (decimal value allowed)
GetDosageCount()
public double GetDosageCount()
Prompts the user for the daily dosage.
Returns: The number of pills taken per day (decimal value allowed)
GetReminderDay()
public DateTime GetReminderDay(DateTime finalDay, string countryCode, string administrativeDivision)
Calculates the reminder day, automatically avoiding weekends and holidays.
Parameters:
finalDay: The date when pills will run outcountryCode: Country code for holiday lookup (e.g., "us", "de", "gb")administrativeDivision: State/region for regional holidays (e.g., "California", "Bayern")
Returns: The calculated reminder date, adjusted for weekends and holidays
GetEventName()
public string GetEventName()
Prompts the user for the reminder event name.
Returns: The name for the calendar event
CreateEvent()
public string CreateEvent(DateTime finalDay, DateTime reminderDay, string eventName)
Creates an iCalendar (.ics) file with an event and reminder.
Parameters:
finalDay: The date when the pills will run outreminderDay: The date for the reminder alarmeventName: The name/summary of the calendar event
Returns: The file path to the generated .ics file (created in system temp directory)
GetDoAnotherCalculation()
public bool GetDoAnotherCalculation()
Prompts the user whether they want to perform another calculation.
Returns: true if the user wants another calculation; otherwise, false
Holiday Support
The library uses the mitoSoft.Holidays package to support holidays for numerous countries and regions. Common country codes include:
de- Germany (with states like Bayern, RheinlandPfalz, etc.)us- United States (with states like California, Texas, etc.)gb- United Kingdomfr- Francech- Switzerland (with cantons)at- Austria
If no holiday calendar is found for the specified country, the library will continue without holiday adjustment and notify via the IInteraction interface.
Calendar Compatibility
Generated .ics files are compatible with:
- Microsoft Outlook
- Google Calendar
- Apple Calendar
- Mozilla Thunderbird
- Any application supporting the iCalendar (RFC 5545) standard
The events are created with:
- All-day event on the final medication day
- Reminder alarm on the calculated reminder date
- "Free" busy status for Outlook compatibility
- Unique UID for proper event tracking
Localization
The library includes built-in support for multiple languages through resource files:
- English (default)
- German (de)
Add additional languages by including culture-specific resource files in your application.
Examples
Calculate Days Until Refill
var calculator = new PillCalculator(interaction);
double pills = 60;
double dosage = 2.5;
int daysLeft = (int)Math.Floor(pills / dosage) - 1;
DateTime refillDate = DateTime.Now.Date.AddDays(daysLeft);
Create Event Without User Interaction
// Use a preset interaction or mock
var finalDay = DateTime.Now.AddDays(20);
var reminderDay = calculator.GetReminderDay(finalDay, "de", "Bayern");
string icsFile = calculator.CreateEvent(finalDay, reminderDay, "Medication Refill");
Thread Safety
The PillCalculator class is not thread-safe. Create separate instances for concurrent operations.
License
This library is licensed under the MIT License. See LICENSE file for details.
Author
Copyright (c) 2022 DJ Doena
Support
For issues, questions, or feature requests, please visit: https://github.com/DJDoena/PillRefresh
Version History
1.0.0
- Initial release
- Core calculation functionality
- iCalendar event generation
- Holiday and weekend awareness
- Multi-framework support (.NET 10.0, .NET Framework 4.7.2, .NET Standard 2.0)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.7.2
- Ical.Net (>= 5.2.1)
- mitoSoft.Holidays (>= 2.0.6)
-
.NETStandard 2.0
- Ical.Net (>= 5.2.1)
- mitoSoft.Holidays (>= 2.0.6)
-
net10.0
- Ical.Net (>= 5.2.1)
- mitoSoft.Holidays (>= 2.0.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release with core functionality for medication supply calculation and calendar event generation.