Alex Williams wrote:> Hi guys, I need some help storing Medical Record history.
>
> Basically I will need any change in a row of data to be stored some
> where. All I can think of is to copy the row and the change and re-store
> it in the database. Example:
>
> fname: John
> lname: Smith
> Medical Record Num: 12312312
>
> then they change the number to: 23434333
>
> So now I need to save his old number, when it expired, the new number,
> and when it was activated.
>
> Please any ideas would be great. Thank you!
I think your approach is very sound. Because you probably do not only
need to record the changes. At some time someone will ask you "how did
the persons data look at <specific-time>".
One way to do this is create your table like this:
records
---------------
id : integer
ssn : string
fname : string
lname : string
medical_num : string/integer (whatever you need)
<other data>
valid_until: datetime (accept null values)
If your primary key would normally be "ssn" (Social Security Number),
you should now instead define your PK as a compasite key, containing
"ssn" and "medical_num".
When one or more fields are changed, make a copy of the record and
insert the new data in this copy. In the original record, set
"valid_until" = now()
Selecting current data is easy:
select *
from records
where ssn = ''xxxxxx'' and valid_until is null
Selecting data from a specific date/time:
select *
from records
where ssn = ''xxxxx'' and valid_until <= <the-date>
order by valid_until DESC
Hope this helps
- Carsten
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---