Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date sensitive array?

Status
Not open for further replies.

bgode

Programmer
Jan 6, 2004
5
US
I currently maintain an Excel spreadsheet that contains fairly static information about some of the drugs used at our clinic. I save this spreadsheet as a csv file and read it into an array. I use the name of the drug as the key, and access the array to pull off manufacturer name, unit price, etc. My users now want to make this table date sensitive. For instance, unit price may change from time to time. The users are envisioning adding two more columns to the table to create an effective date range. Then based on the date that the drug was administered, the unit price, etc would be pulled for that date range. The name of the drug will no longer be unique to the table. Is there a way to make my array date sensitive and still keep the structure and programming fairly intact? Or would a rewrite using lists actually be simpler? My apologies for being so long-winded.
 
Hi

I would just dump the CSV & Excel idea and put the data where they should be : in a database.

This means some work to done, but adding new features in the further will be easier.

The data structure would be something like :
[tt]
drug price
id | name id | drugid | price | begin | end
---+----- ---+--------+-------+------------+-----------
1 | Foo 1 | 1 | 1.01 | 2012-01-01 | 2012-01-31
2 | Bar 2 | 2 | 2.01 | 2012-01-01 |
3 | 1 | 1.02 | 2012-02-01 |
[/tt]
Then you could query the prices like this :
Code:
[gray]-- get current prices[/gray]
[b]select[/b]
d[teal].[/teal]name[teal],[/teal]p[teal].[/teal]price
[b]from[/b] drug d
[b]inner[/b] [b]join[/b] price p [b]on[/b] p[teal].[/teal]drugid[teal]=[/teal]d[teal].[/teal]id
[b]where[/b] p[teal].[/teal]"end" [b]is[/b] [b]null[/b][teal];[/teal]

[gray]-- get prices valid on 2012-01-15[/gray]
[b]select[/b]
d[teal].[/teal]name[teal],[/teal]p[teal].[/teal]price
[b]from[/b] drug d
[b]inner[/b] [b]join[/b] price p [b]on[/b] p[teal].[/teal]drugid[teal]=[/teal]d[teal].[/teal]id
[b]where[/b] [green][i]'2012-01-15'[/i][/green] [b]between[/b] p[teal].[/teal]begin [b]and[/b] coalesce[teal]([/teal]p[teal].[/teal]"end"[teal],[/teal]now[teal]());[/teal]


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top