2013 Computer Science 3754 Project Hospital miniworld using MySQL and EER diagrams and relation models Olanrewaju Okunlola 201040292 4/1/2013 Table of Contents 1 Goal of Project .......................................................................................................................... 1 1.1 Project Description............................................................................................................ 1 1.2 Report................................................................................................................................ 1 1.2.1 Test Data: ................................................................................................................... 1 1.2.2 Experiences ............................................................................................................... 6 1.3 Analysis, summarizations and conclusions ......................................................................7 1|Page 1 Goal of Project The project is to create a mini world of a hospital and the various entities in it. These are are; patients, doctors, nurses, medical labs, scientists, lab tests, lab reports, diagnosis test, Treatments and billing among other data. Once these are created it wish to gain experience using MySQl to create and modify the database system using several commands and print a report based on successes of these commands. 1.1 Project Description A patient is admitted into a hospital at a specific date. This hospital is in a region close to where the patient lives. This patients address has its name and address key (primary key). Each hospitals is managed by staff(scientists, doctors, nurses) who have their own staff id and has a maximum recommended capacity. In the hospital one is either a patient or a staff member. A hospital contains different wings and has a number of them. A wing has a set maximum patient capacity and a wing id(primary key) however. Each patient is assigned to a wing in the hospital. A patient's personal records are stored separately from their hospital specific and includes Name Address, age MCP number, email address and phone number. The hospital staff are either lab scientists, doctors or nurses. All staff are grouped by categories of role. A doctor is assigned one or more patients, is identified by their name, doctor id(primary key) which references their staff id in the general system. A doctor also has an area of speciality, even if that area is general. This doctor consults a medical lab identified by its Wing id -which is the primary key), lab id and name about a patient. Each lab is run by lab scientists who have their own name, scientist_id(primary key) which references their staff id in the general system and lab they work in. The lab runs a diagnostic using tests. These tests can be anything and there can be more than one been run and they are performed by lab scientists within a specific medical lab. These diagnostics are identified by a patient who it is for a test id and also include a reference which has comments by that lab scientist including its own diagnostic id as a primary key. The diagnostics are compiled into reports based on report id, name, diagnostic id, lab name, Treatment name and date. These reports are requested by doctors and the patient is shown information it contains. A treatment id maps to specific recommended treatments for the patient (there may be more than one). While the patient is admitted they are assigned a room and therefore the who attends to them in their hospital room. Each patient room is specified by a floor, patient id (primary key) and room id(primary key). Patient personal records such as age, sex, address, email address and phone number including patient id are stored about a patient separately from information about their admittance to the hospital. The nurse is specified by a name, nurse id(primary key) which references their staff id in the general system. Nurses are assigned to patient rooms and each room can have multiple nurses attending to it. Each medical test is specified by the lab location, and test_id(primary key) who is running such test and name of the test. All staff take shifts in the hospital and have a start time and number of hours they usually attend to and that includes the shift id numbers. Each staff also had staff records associated with them. The records include: staff id(primary key), address, pay-class, birth date, sex, MCP number, phone number, email. All staff in the hospital are assigned a wing. A patient their bill. The bill has a name and amount associated with it. 1.2 Report 1.2.1 Tables: Hospital Test Data: 2|Page Name Region Capacity St clare Labrador 600 Patient Name MCP no Patient id Admission date Room id Hospital name Doctor id Mike 123456789 123000 1998-11-12 3 StClare 9009 Luu 333444555 345000 1997-09-07 9 St Clare 9007 Patient Record Name Address Birthdate Email Mike 55 pepper street, 1960-09-11 1954-12-29 Phone no Patient_id sex aabb@gmail.com 709222333 123000 Male bbcc@gmail.com 345000 Male lab city Luu 87 violin avenue, lab city Nurse Nurse_id Name 40404 Marrisa 50505 Jane 30303 Alice Doctor Name Doctor_id Douglas 9009 Toby 9007 Doctor Speciality Doctor_id speciality 9009 General 9007 General Scientist Name Scientist_id Lab_id Chris 1000 100 Gordon 1001 200 Luke 2000 100 709333444 3|Page Room_Assign Nurse_id Room_id 40404 3 50505 9 30303 80 40404 9 50505 3 Room Room_id Wing_id Floor Nurse_id 003 1 3 40404 009 1 4 50505 080 2 3 30303 Staff_id Category Hospital_name Wing_id 40404 Nurse St clare 1 50505 Nurse St clare 1 30303 Nurse St clare 2 9009 Doctor St clare 1 9007 Doctor St clare 1 1000 Scientist St clare 1 1001 Scientist St clare 2 2000 scientist St clare 1 Staff Staff_Records Phone no. Email Sex MCP no. Staff_id address birthdate 709100200 abc@clare.com Female 001001001 40404 12 Pike avenue, 1986-04-06 Goose bay 709200300 bcd@clare.com Female 002002002 50505 21 Spoon street, 1983-10-25 Goose bay 709300400 cde@clare.com Female 003003003 30303 12 lakeview 1958-05-03 terrace, Lab city 709600600 fgh@clare.com Male 0006006006 9009 21 lab city fort, 1942-02-28 lab city 709006007 ghi@clare.com Male 007007007 9007 12 jackal cove, 1988-12-30 Churchill Falls 709800900 ijk@clare.com Male 009009009 1000 21 Mikie street, 1967-05-05 Lab city 709900100 jkl@clare.com Male 101101101 1001 11 four street, 1990-01-01 4|Page Lab city 709900200 klm@clare.com Male 110110110 2000 10 fifety avenue, Lab City Wing Wing_id Name Capacity Hospital name 1 North 100 St clare 2 South 200 St clare 3 East 100 St clare 4 West 200 St clare Lab_id Wing_id name 100 1 Markus Lab 200 2 Grey Lab 300 1 Markey Lab Shift_id Starttime Hours 1001 21:00:00 9 2002 17:00:00 9 3003 03:00:00 9 4004 08:00:00 9 5005 12:00:00 9 Bil_id Patient_id Amount 00020 123000 30000 00030 345000 50000 Medical_lab Shift Bill Shift_Assign Shift_id Staff_id 1001 40404 2002 50505 1980-09-12 5|Page 3003 30303 4004 9009 5005 9007 4004 1000 4004 1001 4004 2000 Report Name Report_id Patient_id Doctor_id Diagnostic_id Date Blood thining 01011 123000 9009 419 1998-11-23 High 02011 345000 9007 519 1997-10-01 Cholesterol Diagnostic Patient_id Test_id Diagnostic_id Reference Lab_id 123000 747 419 ‘sickle cells 100 discovered in patient, low thickness too’ 345000 787 519 “Dangerous level of fat build-up around heart a on neck” Test Testname Test_id Lab_id Blood Check 747 100 Fat test 787 200 Urine test 618 100 Treatment_id Report_id name 7005 01011 Blood transfusion Treatment with A blood type within the next week 8905 02011 Recommended fat 200 6|Page loss diet admittance to bi-pass surgery Works on Scientist_id Test_id 1000 747 1001 787 2000 618 2000 747 1000 618 1.2.2 Experiences As this was my first time using MySQL I had trouble getting the syntax correct for a lot of my commands, i received many errors when entering, manipulating the updating my database. The following are a collection of these such errors: mysql> alter table Staff_Recordss add primary key(staff_id); ERROR 1146 (42S02): Table 'hospital_project.staff_recordss' doesn't exist mysql> alter table Staff_Records add primary key(staff_id); Query OK, 0 rows affected (0.11 sec) mysql> alter table Staff_Records add foreign key(staff_id) references Staff(staf f_id); ERROR 1215 (HY000): Cannot add foreign key constraint mysql> alter table Staff Records add foreign key(staff_id); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Recor ds add foreign key(staff_id)' at line 1 mysql> alter table Staff Records add foreign key(staff_id) references Staff(staf f_id); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Recor ds add foreign key(staff_id) references Staff(staff_id)' at line 1 mysql> alter table Staff_Records add foreign key(staff_id) references Staff(staf 7|Page f_id); ERROR 1215 (HY000): Cannot add foreign key constraint mysql> alter table Staff_Records add staff_id; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 mysql> alter table Staff_Record add foreign_key(staff_id) references Staff(staff _id); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(staf f_id) references Staff(staff_id)' at line 1 As a whole using the internet, particularly w3schools.com , roseindia.net and stackoverflow.com i was able to learn the mysql constraints and syntax for correcting using the database structure. 1.3 Analysis, summarizations and conclusions Overall the database designed is very robust and while it does not cater the entire needs of a typical hospital is a well formed template of such a type of entity. The description and EER diagram of my database had to be adopted several times in my project to remove redundancies and several present constraints in the database.