-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from davewalker5/medication-actions
Show simple per-medication actions in the output
- Loading branch information
Showing
31 changed files
with
312 additions
and
59 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/MedicineTracker.BusinessLogic/Properties/Resources.resx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root> | ||
<resheader name="resmimetype"> | ||
<value>text/microsoft-resx</value> | ||
</resheader> | ||
<resheader name="version"> | ||
<value>2.0</value> | ||
</resheader> | ||
<resheader name="reader"> | ||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<resheader name="writer"> | ||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<data name="TakeDoseAction" xml:space="preserve"> | ||
<value>Take dose</value> | ||
</data> | ||
<data name="OrderMoreAction" xml:space="preserve"> | ||
<value>Order more</value> | ||
</data> | ||
</root> |
46 changes: 46 additions & 0 deletions
46
src/MedicineTracker.BusinessLogic/Stock/ActionGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using MedicineTracker.Entities.Tracker; | ||
using MedicineTracker.Entities.Interfaces; | ||
using MedicineTracker.Entities.Configuration; | ||
using System.Resources; | ||
using System.Reflection; | ||
|
||
namespace MedicineTracker.BusinessLogic.Stock | ||
{ | ||
public class ActionGenerator : IActionGenerator | ||
{ | ||
private readonly ResourceManager _resources = new("MedicineTracker.BusinessLogic.Properties.Resources", Assembly.GetExecutingAssembly()); | ||
private readonly ApplicationSettings _settings; | ||
|
||
public ActionGenerator(ApplicationSettings settings) | ||
=> _settings = settings; | ||
|
||
/// <summary> | ||
/// Return a list of actions for a medication | ||
/// </summary> | ||
/// <param name="medication"></param> | ||
/// <returns></returns> | ||
public IList<string> GetActions(Medication medication) | ||
{ | ||
var actions = new List<string>(); | ||
|
||
if (medication.LastTaken < MedicineTrackerDateUtils.TodayWithoutTime()) | ||
{ | ||
string action = _resources.GetString("TakeDoseAction"); | ||
actions.Add(action); | ||
} | ||
|
||
if (medication.DaysRemaining() <= _settings.WarningDays) | ||
{ | ||
string action = _resources.GetString("OrderMoreAction"); | ||
actions.Add(action); | ||
} | ||
|
||
return actions; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
19 changes: 19 additions & 0 deletions
19
src/MedicineTracker.BusinessLogic/Stock/MedicineTrackerDateUtils.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace MedicineTracker.BusinessLogic.Stock | ||
{ | ||
public static class MedicineTrackerDateUtils | ||
{ | ||
/// <summary> | ||
/// Return a date with the time components set to 0 | ||
/// </summary> | ||
/// <param name="date"></param> | ||
/// <returns></returns> | ||
public static DateTime DateWithoutTime(DateTime date) | ||
=> new(date.Year, date.Month, date.Day, 0, 0, 0, 0); | ||
|
||
/// <summary> | ||
/// Return todays date with the time components set to 0 | ||
/// </summary> | ||
public static DateTime TodayWithoutTime() | ||
=> DateWithoutTime(DateTime.Now); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using MedicineTracker.Entities.Tracker; | ||
|
||
namespace MedicineTracker.Entities.Interfaces | ||
{ | ||
public interface IActionGenerator | ||
{ | ||
IList<string> GetActions(Medication medication); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using MedicineTracker.BusinessLogic.Stock; | ||
using MedicineTracker.Entities.Configuration; | ||
using MedicineTracker.Entities.Tracker; | ||
|
||
namespace MedicineTracker.Tests | ||
{ | ||
[TestClass] | ||
public class ActionGeneratorTest | ||
{ | ||
private const int WarningDays = 14; | ||
private const string TakeDoseAction = "Take dose"; | ||
private const string OrderMoreAction = "Order more"; | ||
|
||
private ActionGenerator _generator; | ||
|
||
[TestInitialize] | ||
public void Initialise() | ||
{ | ||
_generator = new(new ApplicationSettings{WarningDays = WarningDays}); | ||
} | ||
|
||
[TestMethod] | ||
public void NoRelevantActionsTest() | ||
{ | ||
var medication = new Medication | ||
{ | ||
LastTaken = MedicineTrackerDateUtils.TodayWithoutTime(), | ||
DailyDose = 1, | ||
Stock = WarningDays + 1 | ||
}; | ||
|
||
var actions = _generator.GetActions(medication); | ||
Assert.AreEqual(0, actions.Count); | ||
} | ||
|
||
[TestMethod] | ||
public void TakeDoseTest() | ||
{ | ||
var medication = new Medication | ||
{ | ||
LastTaken = MedicineTrackerDateUtils.TodayWithoutTime().AddDays(-1), | ||
DailyDose = 1, | ||
Stock = WarningDays + 1 | ||
}; | ||
|
||
var actions = _generator.GetActions(medication); | ||
Assert.AreEqual(1, actions.Count); | ||
Assert.IsTrue(actions.Contains(TakeDoseAction, StringComparer.OrdinalIgnoreCase)); | ||
} | ||
|
||
[TestMethod] | ||
public void OrderMoreTest() | ||
{ | ||
var medication = new Medication | ||
{ | ||
LastTaken = MedicineTrackerDateUtils.TodayWithoutTime(), | ||
DailyDose = 1, | ||
Stock = WarningDays | ||
}; | ||
|
||
var actions = _generator.GetActions(medication); | ||
Assert.AreEqual(1, actions.Count); | ||
Assert.IsTrue(actions.Contains(OrderMoreAction, StringComparer.OrdinalIgnoreCase)); | ||
} | ||
|
||
[TestMethod] | ||
public void MultipleActionTest() | ||
{ | ||
var medication = new Medication | ||
{ | ||
LastTaken = MedicineTrackerDateUtils.TodayWithoutTime().AddDays(-1), | ||
DailyDose = 1, | ||
Stock = WarningDays | ||
}; | ||
|
||
var actions = _generator.GetActions(medication); | ||
Assert.AreEqual(2, actions.Count); | ||
Assert.IsTrue(actions.Contains(TakeDoseAction, StringComparer.OrdinalIgnoreCase)); | ||
Assert.IsTrue(actions.Contains(OrderMoreAction, StringComparer.OrdinalIgnoreCase)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using MedicineTracker.BusinessLogic.Stock; | ||
|
||
namespace MedicineTracker.Tests | ||
{ | ||
[TestClass] | ||
public class MedicineTrackerDateUtilsTest | ||
{ | ||
[TestMethod] | ||
public void DateWithoutTimeTest() | ||
{ | ||
var date = MedicineTrackerDateUtils.DateWithoutTime(new(2023, 4, 6, 13, 56, 22)); | ||
Assert.AreEqual(2023, date.Year); | ||
Assert.AreEqual(4, date.Month); | ||
Assert.AreEqual(6, date.Day); | ||
Assert.AreEqual(0, date.Hour); | ||
Assert.AreEqual(0, date.Minute); | ||
Assert.AreEqual(0, date.Second); | ||
} | ||
|
||
[TestMethod] | ||
public void TodayWithoutTimeTest() | ||
{ | ||
var today = DateTime.Now; | ||
var date = MedicineTrackerDateUtils.TodayWithoutTime(); | ||
Assert.AreEqual(today.Year, date.Year); | ||
Assert.AreEqual(today.Month, date.Month); | ||
Assert.AreEqual(today.Day, date.Day); | ||
Assert.AreEqual(0, date.Hour); | ||
Assert.AreEqual(0, date.Minute); | ||
Assert.AreEqual(0, date.Second); | ||
} | ||
} | ||
} |
Oops, something went wrong.