#!/usr/local/bin/perl ################################################################# # Database Definition Variables # ################################################################# #Columns of database $db{"gen_name"} = 0; $db{"trade_name"} = 1; $db{"drug_class"} = 2; $db{"indications"} = 3; $db{"pharmacodynamics"} = 4; $db{"side_effects"} = 5; $db{"pharmacokinetics"} = 6; $db{"routes"} = 7; $db{"similar"} = 8; $db{"remarks"} = 9; $db{"email"} = 10; $db{"modification_time"}= 11; $db{"who_modified"} = 12; $db{"group_modified"} = 13; $db{"db_id"} = 14; $index_for_email = 10; $index_of_field_to_be_sorted_by = "0"; $index_of_id = 14; #What is viewed by viewers @db_display_fields = ("Generic Name", "Trade Name", "Drug Class", "Indications", "Pharmacodynamics", "Side Effects", "Pharmacokinetics", "Administration Routes", "Similar Drugs", "Remarks", "Email"); @db_index_for_display = ($db{"gen_name"}, $db{"trade_name"}, $db{"drug_class"}, $db{"indications"}, $db{"pharmacodynamics"}, $db{"side_effects"}, $db{"pharmacokinetics"}, $db{"routes"}, $db{"similar"}, $db{"remarks"}, $db{"email"}); #possible searches of data @db_query_criteria = ("keywords|0,1,2,3,4,5,6,7,9|=|string", "gen_name|0|=|string", "trade_name|1|=|string", "drug_class|2|=|string", "indications|3|=|string", "pharmacodynamics|4|=|string", "side_effects|5|=|string", "pharmacokinetics|6|=|string", "routes|7|=|string", "similar|8|=|string", "remarks|9|=|string", "db_id|14|=|number"); ######################################################################### # Authentication Variables # ######################################################################### $should_i_authenticate = "yes"; $auth_lib = "./Library"; $auth_server = "off"; $auth_cgi = "on"; $auth_user_file = "./Users/drug.users"; $auth_alt_user_file = ""; $auth_default_group = "user"; $auth_add_register = "on"; $auth_allow_register = "on"; $auth_email_register = "off"; $auth_admin_from_address = "doyle\@cs.umn.edu"; $auth_admin_email_address = "doyle\@cs.umn.edu"; $auth_session_length = 2; $auth_session_dir = "./Session_files"; $auth_register_message = "Thanks, you may now logon with your new username and password."; $auth_allow_search = "off"; $auth_generate_password = "off"; $auth_check_duplicates = "on"; $auth_password_message = "Thanks for applying to our site, your password is"; @auth_extra_fields = ("auth_first_name", "auth_last_name", "auth_email"); @auth_extra_desc = ("First Name", "Last Name", "Email"); ################################################################# # Miscellaneous Variables # ################################################################# $data_file_path = "./Data_files/drug.data"; $max_rows_returned = "25"; $current_century = "20"; $this_script_url = "db_search.cgi"; ##### Specifically for ISAP ##### $MOD_DATE='9/22/97'; # Date last modified $HOME = 'index.cgi'; # $SCRIPT_AUTHOR='Dave Doyle'; # $AUTHOR_EMAIL='doyle@cs.umn.edu '; # $QUESTIONS_NAME='Len Lichtblau'; # Contact person $QUESTIONS_ADDR='len@phcl.umn.edu'; # ################################################################# # Add to Log Subroutine # ################################################################# sub add_to_log { local ($drug_to_log) = @_; @time = localtime(time); $mon = $time[4]+1; $time = "$time[2]:$time[1]-$mon/$time[3]/$time[5]"; ($user, $access_string, $random) = split(/:/, $form_data{'session_key'}); open (LOG, ">>admin/drug_log") || die "$0: can\'t open drug_log: $!\n"; print LOG "$drug_to_log $access_string $time\n"; close(LOG); } ################################################################# # output_html_query_form Subroutine # ################################################################# sub output_html_query_form { print qq~ Drug Database Search

Drug Search Engine

Please enter any search terms to find drugs within the database below. You may enter terms in specific fields, or within the generic "keywords" slot.

Keyword Searching
In the following text fields, you may search the database according to keywords.
Keyword

Generic Name
Trade Name
Drug Class
Sort by which field

--------
Script Author: $SCRIPT_AUTHOR
For Questions or Comments: $QUESTIONS_NAME
Script Last Updated: $MOD_DATE
~; } ################################################################# # Print Database Subroutine # ################################################################# sub print_db { print qq~ Drug Database Printout ~; foreach $row (@database_rows) { print ""; @fields = split (/\|/, $row); foreach $index (@db_index_for_display) { $fields[$index] =~ s/~p~/\|/g; $fields[$index] =~ s/~nl~/\n/g; if ($index != $index_for_email) { print qq~ \n ~; } } # End of foreach $index (@db_index_for_display) # print ""; print "
@db_display_fields[$index] $fields[$index]-

"; } print ""; } ################################################################# # Print Menu Subroutine # ################################################################# sub print_menu { local ($frame) = @_; print qq~ Drug Names

Drugs


~; # get names and id's of drugs for ($i=0; $i<$#database_rows;$i++) #foreach $sorted_drug (@sorted_drugs) { @fields = split(/\|/,$database_rows[$i]); if ($frame =~ /y/i) { print ""; } else { if ($i==0) { print "
\n"; } elsif ($i== ( int $#database_rows/2)) { print "\n" } print ""; } print "$fields[0]
\n"; } if (($frame =~ /[^y]/i) || ($frame =~ /^$/)) { print "
"; } print ""; } sub bad_file { print "can't find file $data_file_path"; } ################################################################# # search_results_header Subroutine # ################################################################# sub search_results_header { print qq~ Drug Database Search
~; foreach $key (keys(%db)) { if ($form_data{$key} ne "") { print qq~ ~; } } if ($form_data{keywords} ne "") { print qq~ ~; } } ################################################################# # search_results_multi Subroutine # ################################################################# sub search_results_multi { # Notice that in this subroutine we have access to the # $total_row_count hits variable if we want to display it. if ($total_row_count > $max_rows_returned) { print qq~ Your search turned up $total_row_count hits, but I am designed to only show you $max_rows_returned at a time. I suggest you narrow your search criteria a bit.

~; } else { print qq~ Your search turned up $total_row_count hits

~; } print qq~ ~; # Basically, we will display a simple HTML table to show # all of the rows which satisfied the search criteria # entered by the user. # # The idea is this. We will go through the @database_rows # (which was given to us by db-lib.pl and contains all of # the hits) one element at a time and convert the pipe # delimited database row into an HTML row. print ""; for ($i=0; $i<3; $i++) { print ""; } print ""; #log info $num_hits = $#database_rows+1; &add_to_log("multi - $num_hits hits"); foreach $row (@database_rows) { print ""; @fields = split (/\|/, $row); for ($i=0; $i<3; $i++) # foreach $index (@db_index_for_display) { $index= @db_index_for_display[$i]; $fields[$index] =~ s/~p~/\|/g; $fields[$index] =~ s/~nl~/\n/g; if($i==0) { $moddrug = $fields[$index]; $moddrug =~ s/[\s\[\]\(\)]/+/g; # print ""; print ""; } elsif($index < 3) { print "\n"; } else {} } # End of foreach $index (@db_index_for_display) print ""; } print "
@db_display_fields[$i]
"; print ""; print "$fields[$index]
\n"; print "
$fields[$index].
"; } ################################################################# # search_results_single Subroutine # ################################################################# sub search_results_single { # Notice that in this subroutine we have access to the # $total_row_count hits variable if we want to display it. print qq~ Expanded Drug Information

~; # Basically, we will display a simple HTML table to show # all of the rows which satisfied the search criteria # entered by the user. # # The idea is this. We will go through the @database_rows # (which was given to us by db-lib.pl and contains all of # the hits) one element at a time and convert the pipe # delimited database row into an HTML row. foreach $row (@database_rows) { @fields = split (/\|/, $row); &add_to_log("$fields[0]"); #log info foreach $index (@db_index_for_display) { $fields[$index] =~ s/~p~/\|/g; $fields[$index] =~ s/~nl~/\n/g; # Also, we will check to see if the current field being # displayed happens to be an email field. If so, we will # make it a clickable mailto link. # # Notice that you would use the exact same method for # making a clickable URL. print ""; if ($index == $index_for_email) { print qq~ \n ~; } else { print qq~ \n ~; } } # End of foreach $index (@db_index_for_display) # print ""; } print "
@db_display_fields[$index]$fields[$index] -
$fields[$index]-
"; } ################################################################# # search_results_footer Subroutine # ################################################################# sub multi_footer { print qq~

~; # In this subroutine we can include just a little bit of # logic in order to create a "See more hits button" # # The besic logic is that they either 1) still have more # than the $max_rows_returned hits to see, 2) have only 1 # more hit to see, 3) have less than $max_rows_returned # but more than 1 hit to see, or 4) have no hits left to # see. # # These cases are handled in three if tests (the 4th case, # in which there are no more hits to see just defaults to # the tags since no submit button need be # created.) if (($total_row_count >= $new_hits_seen) && (($total_row_count-$new_hits_seen) > $max_rows_returned)) { print qq~

~; } elsif (($total_row_count-$new_hits_seen) == 1) { $rows_left_to_view = $total_row_count-$new_hits_seen; print qq~

~; } elsif ((($total_row_count-$new_hits_seen) < $max_rows_returned) && (($total_row_count-$new_hits_seen) > 0)) { $rows_left_to_view = $total_row_count-$new_hits_seen; print qq~

~; } print "

"; } sub footer { print qq~

Search Again?

--------
Script Author: $SCRIPT_AUTHOR
For Questions or Comments: $QUESTIONS_NAME
Script Last Updated: $MOD_DATE
~; } ################################################################# # no_hits_message Subroutine # ################################################################# sub no_hits_message { print qq~

I am sorry, but it appears that there were no records in the database that matched your search criteria, please try again.
~; }