CASE STUDY: DOCTORS SURGERY TASKS The following Case

advertisement
CASE STUDY:
DOCTORS SURGERY
PRACTICAL
TASKS
The following Case Study
a. Derive an Entity Relationship Diagram (ERD) showing the entities of interest
and associated attributes, relationships, dependency and indicate primary and
foreign keys
b. Implement the tables in MS SQL Server 2005 by draw the ERD in MS SQL
Server 2005
c. Populate the tables with the sample data.
d. Provide sample SQL code to demonstrate and understanding of DDL and DML
SQL statements.
You may decide to modify the data requirements or generate additional data attributes
to assist in your design of the database. Write down details of any assumptions you
have made that you feel are important.
You may decide to follow the ERD’s in Answer Points.
CASE STUDY:
DOCTORS SURGERY
A team of doctors in a group general practice offer health care to their patients. Each
patient is officially assisgned to one doctor but when their patients visit the surgery
most of them are happy to consult whichever doctor happens to be available at the
time. The practice maintains prescription records for all its patients. A sample record
form is shown below :
y789654c
F.Bloggs
Patient no
Name
Sex
12-june-1959 Doctor No d45
M
Date of Birth
Prescribing Doctor Date
Drug-Code Drug-Name
Doctor Name
d3
11-jan-1997 5634
tomoxyneoprene J.Smith
d45
22-may-1997 65456
mycotoxybenzene G.Parry
Patient No., Doctor No., and Drug Code are unique identifiers within the system for
patients, doctors, and drugs respectively. The dosage of a prescribed drug will, in
general, vary considerably from patient to patient, though it remains constant for a
given patient from one prescription to another.
Constraints
All instances of entities must be uniquely identified. (Primary Key constraint)
All attribute domains must be defined (Domain constraints-implemented as check
constraints in less capable systems)
Referential actions have to be defined all foreign keys. Requires considerations likeCASE STUDY:
DOCTORS SURGERY
1
CASE STUDY:
DOCTORS SURGERY
If a patient is removed from the database what happens to that persons’ consultations
and prescriptions? Are all the prescriptions and consultations removed when the
patient is removed, or patients removed after all prescriptions and consultation
removed? Does the order matter?
If a doctor is removed from the database what happens to the consultations-are they
removed as well? If so, does it matter that information on patient consultations has
been removed? What are the appropriate referential actions in this case?
Cardinalities must be enforced – note the cardinality of ‘issued_at’. These are not
unconnected to referential actions e.g. if cardinality says that a consultation must be
conducted by a doctor, doctors cannot be deleted from the database until there are no
consultations in the database involving them.
General Constraints
Dates_of_issue and consultation_dates for any patient must be greater than the
date_of_birth.
Any doctor must not issue more than 36 prescriptions in one day without
authorization.
There must be a minimum of five minutes between each prescription issue.
At least one consultation must be with the patient’s registered doctor.
CASE STUDY:
DOCTORS SURGERY
2
CASE STUDY:
DOCTORS SURGERY
Answer Pointers
INITIAL DRAFT
ASCENT DIAGRAM : ER Model for DOCTORS SURGERY
ASCENT DIAGRAM : ER Model for PATIENT DRUG
ADMINISTRATION
ASCENT DIAGRAM : ER Model for OUT PATIENTS
A patient registers with a doctor
CASE STUDY:
DOCTORS SURGERY
3
CASE STUDY:
DOCTORS SURGERY
Registered_with
patient
doctor
0.. *
0..1
Minimum no. of patients registered with each doctor?
Maximum no. of patients registered with each doctor?
Minimum no. of doctors for each patient?
Maximum no. of patients for each doctor?
A patient consults a doctor
Consults_a
patient
doctor
0.. *
0..*
Minimum no. of patients that consult with each doctor?
Maximum no. of patients that consult with each doctor?
Maximum no. of doctors for each patient?
Minimum no. of doctors for each patient?
Many-Many relationship
PK is doctor_no, NI_no
conducts
_a
doctor
consultation
1..1
1..*
PK is doctor_no
0..*
has_a
1..1
PK is NI_no
patient
Many drugs may be prescribed on a consultation.
CASE STUDY:
DOCTORS SURGERY
4
CASE STUDY:
DOCTORS SURGERY
Prescribes_a
consultation
drug
0.. *
1..*
Becomes…..
PK is drug_no NI_no, doctor_no, consultation_date
Prescription_item
drug
0..*
for_a
0..*
1..1
PK is
Issues_a
1..1
consultation
CASE STUDY:
DOCTORS SURGERY
PK is NI_no, doctor_no, consultation_date
5
CASE STUDY:
DOCTORS SURGERY
FULL ERD MODEL
Drug
0..1
for
1..*
Patient
1..*
Prescriptio
0..1
n_item
Has_a
registered
_with
Consists_of
s
1..*
0..1
Issued_at
Prescription
Consultation
1..1
0..3
1..*
Conducts_a
0..1
Doctor
CASE STUDY:
1..*
DOCTORS SURGERY
6
CASE STUDY:
DOCTORS SURGERY
Work though example dd.cs.DoctorsSolution
SQL TABLES
Create table doctor
(doc_no char(7),
Name varchar(25),
Constraint dockey primary key(doc_no));
Create table consultation
(doc_no char(7),
NI_no char(10),
Consultation_date datetime
Constraint conskey primary key(doc_no, NI_no, consultation_date)
Constraint has_a foreign key (NI_no) references patient,
Constraint conducts_a foreign key (doc_no) references doctor);
Create table prescription_item
(drug_no char(6),
NI_no char(10),
Doc_no char(7),
Consultation_date datetime,
Dosage integer,
Constraint route_key primary key (drug_no, NI_no, doc_no,consultation_date)
Constraint issues foreign key (Ni_no, doc_no, consultation_date) references
consultation,
Constraint for_a foreign key (drug_no) references drug));
Create table drug
(drug_no char(6),
name varchar(30),
Constraint drug_key primary key (drug_no));
CASE STUDY:
DOCTORS SURGERY
7
Download