Skip to content

Latest commit

 

History

History
40 lines (33 loc) · 1.98 KB

databaseprojectschema.org

File metadata and controls

40 lines (33 loc) · 1.98 KB

Conceptual Design These are all in Postgres syntax.

Patient Record/Donor Database

AttributeDescription
idserial primary key
lastnamevarchar(255) not null
firstnamevarchar(255) not null
bloodtypevarchar(3) not null
addressvarchar(255)
testsdonetext[]
knowndiseasestext[]
lastdonationdatedate
phonechar(14)

Actual query to build table: create table donor(id serial primary key, lastname varchar(255) not null, firstname varchar(255) not null, bloodtype varchar(3) not null, address varchar(255), testsdone text[], knowndiseases text[], lastdonationdate date, phone char(14));

In order to append to an array, use “set array = array || ‘{newvalue}’”

Good format for new patients: insert into donor values (default, ‘lastname’, ‘firstname’, ‘bloodtype’, ‘address’, default, default, ‘YYYY-MM-DD’, ‘(XXX) XXX-XXXX’); the defaults are, in order: id, testsdone, knowndiseases

Generating the random data to get a number from 1950-1998: expr $RANDOM % 48 + 1950 1-12: expr $RANDOM % 12 + 1 1-28 (to avoid feb issues…): expr $RANDOM % 28 + 1 to get a random name from the file: sort -R file.txt | head -n 1

Inserting the data This data omits known diseases, addresses, and last donation date

With the values (in order) for lastname, firstname, bloodtype, tests done, diseases, and phonenumber in testdatafin.txt separated by commas and the table donor in testdb: cat testdatafin.txt | while read line; do firstname=`echo $line | cut -d_ -f2`; lastname=`echo $line | cut -d_ -f1`; bloodtype=`echo $line | cut -d_ -f3`; phonenumber=`echo $line | cut -d_ -f5`; diseases=`echo $line | cut -d_ -f4`; echo “insert into donor values (default, $lastname, $firstname, ‘$bloodtype’, default, $diseases, default, default, ‘$phonenumber’);”; done | psql bloodbank