1. a question about coding calendar dates

I wish to write a simple console utility for my windows desktop. Its purpose is to accept as input various particulars about a prescription i've written for one of my patients, and output the earliest date on which s/he will need a new script (so that i can write it in good time for when it'll be needed).

Every script has the following particulars: date_of_script (eg 3 December 2013); drug_name (eg Amoraphene); dose_per_tablet (eg 5mg); tablets_per_day (eg 4 tabs/day); tablets_per_pack (eg 75 tabs/pack); repeats_per_script (eg 2 repeats). The drug_name and dose aren't really needed for this app. The effect of prescribing repeats is that s/he gains access to the original pack (of 75 tabs) plus the repeats (ie 2 * 75 tabs), ie 225 tabs in all. In this example, s/he will run out of tablets in 56 days at the earliest [ (75 + (2 * 75)) / 4, using integer division ]. Assume that s/he starts taking their tablets from the date of the prescription, and doesn't miss any doses or take any extra doses, and doesn't delay getting any repeats, so there are no delays or surprises or other complications. I'd like the app to tell me that the next script will be due no earlier than 29 January 2014 (ie 8 weeks from the script date).

When i tried to write this app i ran into difficulties with the change of year, and maybe also with due dates that fall on a leap year. I find working with calendars difficult, but this problem might be simple for those in the know. If so, i'd be grateful for your guidance.

Thank you,

Alex Caracatsanis

new topic     » topic index » view message » categorize

2. Re: a question about coding calendar dates

Suggest you study the Manual, 8.4 Date/Time... there is a function to do exactly what you require..

new topic     » goto parent     » topic index » view message » categorize

3. Re: a question about coding calendar dates

buzzo said...

Suggest you study the Manual, 8.4 Date/Time... there is a function to do exactly what you require..

new topic     » goto parent     » topic index » view message » categorize

4. Re: a question about coding calendar dates

buzzo said...

Suggest you study the Manual, 8.4 Date/Time... there is a function to do exactly what you require..

Thank you. Can you pls tell me which one?

Alex Caracatsanis

new topic     » goto parent     » topic index » view message » categorize

5. Re: a question about coding calendar dates

Here's an idea to try.

"Unix" time is seconds since an arbitrary start date. Functions make is possible to convert to and from Unix time.

Using seconds should make it easier for you to calculate the exact duration for each prescription.

include std/console.e 
include std/datetime.e 
 
	-- prescription details 
integer tabs = 75 -- tabs per issue 
integer reps = 2  -- refills allowed 
integer dailydose = 4 -- tabs per day  
 
	-- today's date  
datetime today_cal = now() 
atom today_unix = to_unix( today_cal  ) 
	display( "\t today's date is:") 
	display( today_cal ) display( "\n============\n" ) 
	 
 
atom sec_in_day = 24 * 60 * 60 -- hours * minutes * seconds  
datetime refill_day_cal  
atom days_to_consumed 
atom usable_days_to_consumed  
atom seconds_to_consumed 
 
atom refill_day_unix  
 
sequence msg = { 
	"initial issue", 
	"first refill", 
        "second refill", 
	"third refill", 
	$ 
} 
 
 
for dispense = 0 to reps do 
	days_to_consumed =  tabs*dispense / dailydose  
	usable_days_to_consumed = floor( days_to_consumed ) 
	seconds_to_consumed = usable_days_to_consumed * sec_in_day 
	refill_day_unix = today_unix + seconds_to_consumed 
	refill_day_cal = from_unix( refill_day_unix ) 
		display( "\t" & msg[dispense+1] ) 
		display( refill_day_cal ) 
end for	 
	 
	atom consumed_all_tabs = (tabs* (reps+1) )/dailydose * sec_in_day 
 
atom max_time_prescription_unix = today_unix + consumed_all_tabs 
datetime max_time_cal = from_unix( max_time_prescription_unix )  
display( "\n maximum duration of prescription") 
display( max_time_cal ) 
	 
new topic     » goto parent     » topic index » view message » categorize

6. Re: a question about coding calendar dates

Thanks _tom. I'll study it. Now i see why i found it hard to code!

Alex Caracatsanis

new topic     » goto parent     » topic index » view message » categorize

7. Re: a question about coding calendar dates

Nothing personal _tom but I think you're making this a lot more complicated than it needs to be. All that is really needed is to use the add function in datetime.e

include std/datetime.e 
datetime start_date, end_date 
start_date = new(2013, 12, 3, 0, 0, 0) 
end_date = add(start_date, 56, DAYS) 
? end_date 

As always, input/output and program logic are left as an exercise for the reader. :D

Lonny

new topic     » goto parent     » topic index » view message » categorize

8. Re: a question about coding calendar dates

Lnettnay said...

Nothing personal _tom but I think you're making this a lot more complicated than it needs to be. Lonny

Thanks. My tired eyes refused to find the add function.

(Then, I started thinking about how to account for extra tabs at the end of a prescription cycle.)

_tom

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu