Things Got Fairly Complicated!

A medication can be daily, it can be weekly, it can have intervals, it can start on a certain date and stop on another, it can be updated later, it can run out and it can be re-filled. All that has to be taken into account by the application, that every given day has to know what medication should happen.

This requirement became the heart of the system. Medication history was initially modeled as a collection of all individual doses with their own time frames. When one is taken, it gets added to the list, and the same goes for the next one. What the application needed to know at any given day was not a list of medication doses but what exactly medications were supposed to happen at that time and what was the state of medication doses that have been taken, that have missed, that have passed.

The data model was updated to reflect days as a unit of measurement, which in turn affected databases both local and synchronized, affected schedules and histories. A medication that happens weekly has to define what weekly means – selecting days that it would happen on does not make every other day invalid for scheduling in the future, the app has to understand the nuances of the schedule and what medications apply to it on any given day.

Interval medication is the crossing days within the dose and dose interval for the app to process.

Another set of requirements concerned modifications to an existing medication. If the dose of a medication which already has a schedule associated has changed, the system must update its representation without perturbing the doses already taken. A deleted medication has to no longer exist in the schedule, and an added medication has to be in the right place with the right intervals. Logic needed to be developed to handle changes to medication schedules when considering the total medication schedule for the day. Inventory management was a similar set of problems. When a drug is out of stock the app should no longer show it in any of the future schedule segments. When it is re-filled, it has to be accounted for, but without creating extra doses. Need to know the inventory at any given point in time for the schedule of medication today.

Midnight is a critical boundary. One day ends and another begins. Anything that should have happened yesterday must be finalized. Anything scheduled for today must be generated correctly, and in the correct order. The application cannot assume a user is present to supervise the transition. That requirement led to background processing and synchronization.

The project has moved well beyond the original scope of sending a reminder.