Advanced Data Base Final
Advanced Data Base Final
Introduction…………………………………………………………………….4
Mission………………………………………………………………….……….4
Vision…………………………………………………………………………….4
Strategy…………………………………………………………………………..4
Existing System ………………………………………………………………....5
Statement Of Problem………………………………………………………..…5
Objective………………………………………………………………………....6
General Objective……………………………………………………………………....6
Specific Objective……………………………………………………………….6
Project Deliverables……………………………………………………………...6
Methodology……………………………………………………………………....6
Functional Requirements………………………………………………………..7
Database Design………………………………………………………………….7
Time Schedule…………………………………………………………………...10
Schema diagram…………………………………………………………………..14
Implementation…………………………………………………………………….22
References ………………………………………………………………………….35
Acknowledgment
We have a special thanks to our instructor Tsegaw. who give us this project and we have a great
thanks for our university Especially Poly Campus students Clinic system stockholders who give
us a detailed information about the system.
Background Of The System
Bihar Dar University institute of technology clinic system starts its service 1980 [Link] clinic system
was located in Amhara Region, Bahir Dar town, kifle ketema shumeabo, Keble 10, in the north direction
of BDU agricultural faculty building.
This system give a service for the whole students in the university .At this time this system has six nurses,
one lab technician, two clean servant, one information disk, one clinic manager and one
pharmacist ,totally twelve employees involved in the system.
Introduction
We are interested on Bahir Dar University institute of technology clinic system. Our project studies how
this clinic system gives the service for the students and what is its major purpose and limitation. These
things will be included in our project work.
Mission
Crudity focused on protection
Keeping the health condition of the students for safe learning until they graduate
Vision
To see healthy student
Strategy
Presenting drugs within the specified time
Fulfilling aim and vision of the clinic by presenting health masters having high performance and
good health condition
Existing System
The existing system of the clinic system of poly campus has working with the manual system.
The basic functionalities that are applied on the system is register patient by card officer ,treated
patient by physician ,give drug for patient by pharmacist for patient ,give lab test for patient by
lab_technician,report lab result to physician by lab_ technician. The above tasks are performed
in manual system that have different problem like insert,update ,delete,retrive and search patient
and different workers of the system.
Statement Of Problem
The clinic system of Bahir Dar University gives service for student’s but still now this system has
its own draw back and limitation.
Through giving this service the clinic system uses manual data handling system and labor force
for documentation process.
To solve the above problems in the system we need to change the current system service in to computer
based clinic system service to accomplish tasks effectively and efficiently.
Objective
General Objective
• As we stated above on statements of problem the main objective of our project is to
computerized the current manual system of Bahir Dar University in order to solve the above
problems.
Specific Objective
• To reviewing the current system and knowing the problem
There are many systems in Bahir Dar University, Poly campus. From those our project concerned on only
Poly campus clinic system of patient reservation.
• Bed reservation
Project Deliverables
• Physician can search registered patients and give appropriate treat
• Pharmacist can search registered patients and ordered drugs then give that drug to that patient
• Registered patient’s information can stored on the database permanently
Methodology
During developing this project we use some traditional method of data requirement gathering
listed follow.
• Interview
Diagramming tools
• Microsoft Visio
Functional Requirements
Our functional requirement is the proposed system which will be surrounded on the Entity-relationships.
Therefore our proposed system that will store the following functions. Basically:
Relationships (give_card,tes,treat,report_labresult,give_drug,give_patient
information,order,give_prescribed paper)
Time Schedule
Database Design
patient-entity
name Data type description
PID Varchar(50) Patient id is
primary key
Fname Varchar(50) patient first
name
Lname Varchar(50) patient last name
Sex Varchar(5) gender ofpatient
Card_officer
name Data type description
OFF_ID Varchar(50) Card officer id is primary key
Fname Varchar(50) Card officer first name
Lname Varchar(50) Card officer last name
Address Varchar(50) Address of card_officer
pharmacist-entity
name Data type description
Phy_ID Varchar(50) physicianid is
primary key
Fname Varchar(50) physicianfirst
name
Lname Varchar(50) physician last
name
Address Varchar(50) address of
physician
drug-entity
name Data type description
Lot int Lot the primary key of drug
Drug type Varchar(50) Drug type of the drug
Manf_date DateTime Manufactur date of drug
Exp_date DateTime Expired date of drug
Lab technician-entity
name Data type description
Tech_ID Varchar(50) Technician id is primary key
Fname Varchar(50) Technician first name
Lname Varchar(50) Technician last name
Treat_relation ship
name Data type description
P_id Varchar(50) P_id is foreign key of treat
relation ship
Phy_id Varchar(50) Physician id is foreign key of
treat relation ship
Appointment date Physician appoints patient
For each regular (strong) entity type E in the ER schema, create a relation R includes all the simple
attributes of E.
• Physician
• Pharmacist
• Lab technician
• Patient
• Card officer
• Drug
Physician
Pharmacist
Lab Technician
Patient
Card Officer
Drug
From the above ER we have the following are binary r/ship mapping:
CardOfficer_Physician
Physician_pharmacist
Test
Take
Order
Treat
N_Ary Mapping
Give_ Drug
Pid [Link] Lot: Date Cost
Multivalued Mapping
Address
Physician table
name Data type description
Phy_id Varchar(50) Physician id is primary key
Fname Varchar(50) Physician first name
Lname Varchar(50) physician last name
pharmacist table
name Data type description
Pha_id Varchar(50) Pharmacist id is primary key
Fname Varchar(50) pharmacist first name
L name Varchar(50) pharmacist last name
Lab_technician table
name Data type description
Tech_id Varchar(50) technician id is primary key
Fname Varchar(50) technician first name
Lname Varchar(50) technician last name
Patient table
name Data type description
P_id Varchar(50) patient id is primary key
Fname Varchar(50) patient first name
Drug table
name Data type Description
Lot int Lot
is primary key
Drug-type Varchar(50) Type of drug
Manf_date DateTime Manufacture date of drug
Exp_date DateTime Expired date of drug
physician_pharmacist table
name Data type description
Phy_id Varchar(50) Foreign key from physician
pha_id Varchar(50) Foreign key from pharmacist
Fname Varchar(50) physician first name
Test table
name Data type description
P_id Varchar(50) Patient id is primary key
Tech_id Varchar(50) technician Foreign key from
technician
Test type Varchar(50) type of lab test
take table
name Data type description
Lot int Lot is foreign key form drug
P_id Varchar(50) Patient id is foreign key from
pateint
Date DateTime Primary key of take
order table
name Data type description
Lot int Lot is foreign key form drug
Phy_id Varchar(50) physician id is foreign key from
physician
treat table
name Data type description
P_id Varchar(50) Patient id is foreign key form
patient
Phy_id Varchar(50) physician id is foreign key from
physician
Appointment Date time Physician appoints patient
Skill table
name Data type description
Pha_id Varchar(50) Pharmacist id is foreign key from
pharmacist
Phy_id Varchar(50) Physician id is foreign key from
physician
skill Varchar(50) Skill is primary key of skill
Address table
Normalization
Un Normalization Form
[Link] Fname Lname A ddress (place,email) Lot Drug. Type [Link] [Link]
Patient_Drug(Pid,[Link]) Patient
Drug
--1
create database clinic_PatientReservation
use clinic_PatientReservation
----------patient table------------------
create table patient(
p_id varchar(50) not null primary key,
fname varchar(50) not null,
lname varchar(50) not null,
sex char(1) constraint ck_sexn check(sex='m'or sex='f') not null,
)
update patient set fname='abebe' where p_id='p-12'
------------------------------------------------------------------------------
-----
select * from patient
------------------------------------------------------------------------------
--------------------physiciantable-------------
create table physician(
phy_id varchar(50) not null primary key,
fname varchar(50) not null,
lname varchar(50) not null,
skill varchar(50) not null,
address varchar(50) not null
)
-------------------------------sample physician values------------------
insert into physician(phy_id,fname,lname,skill,address) values('phy-
1','dor_miskir','adane','doctor','nazret')
insert into physician(phy_id,fname,lname,skill,address) values('phy-
2','ms_besa','zara','nurse','england')
insert into physician(phy_id,fname,lname,skill,address) values('phy-
3','dor_abel','samuel','pharmacist','addis abeba')
---------------------------------------------------------------------------
select * from physician
--------------------------------------------------------------
--lab_technician
create table lab_technician(
tech_id varchar(50) not null primary key,
fname varchar(50) not null,
lname varchar(50) not null,
address varchar(50) not null)
----------------------------sample lab_technician values--------------------
insert into lab_technician(tech_id,fname,lname,address)
values('tech_1','amare','alemu','kombolcha')
insert into lab_technician(tech_id,fname,lname,address)
values('tech_2','fasika','tadese','bdu')
insert into lab_technician(tech_id,fname,lname,address)
values('tech_3','rena','joghn','japan')
------------------------------------------------------------------------------
select * from lab_technician
------------------------------------------------------
--pharmacist
create table pharmacist(
pha_id varchar(50) not null primary key,
fname varchar(50) not null,
lname varchar(50) not null,
address varchar(50) not null,
)
-------------------------sample pharmacist values----------------------
insert into pharmacist(pha_id,fname,lname,address)
values('pha_1','hana','debas','wollo')
insert into pharmacist(pha_id,fname,lname,address)
values('pha_2','abrham','kedir','wolayita')
insert into pharmacist(pha_id,fname,lname,address)
values('pha_3','natanim','kibro','addis abeba')
-----------------------------------------------------------------------------
select * from pharmacist
--------------------------------
---------------------------------------------
--card officer
create table card_officer(
off_id varchar(50) not null primary key,
fname varchar(50) not null,
lname varchar(50) not null,
address varchar(50) not null,
)
--------------------------------------sample card_officer
values--------------------
insert into
card_officer(off_id,fname,lname,address)values('off_1','dagmiaw','tibebu','add
is abeba')
insert into
card_officer(off_id,fname,lname,address)values('off_2','hennok','tibebu','bdu'
)
insert into
card_officer(off_id,fname,lname,address)values('off_3','hayimanot','zelalem','
gonder')
------------------------------------------------------------------------------
--------
select * from card_officer
------------------------------------------------------------------
---
----------------drug----------------------------
--drug
create table drug(
lot int not null primary key,
drug_type varchar(50) not null ,
manu_date datetime not null,
exp_date datetime not null,
)
----------------------------sample drug values--------------------------------
insert into drug(lot,drug_type,manu_date,exp_date)
values(123,'pandol','12/08/2004','02/09/2006')
insert into drug(lot,drug_type,manu_date,exp_date)
values(456,'mezil','12/03/2005','02/04/2008')
insert into drug(lot,drug_type,manu_date,exp_date)
values(876,'amoxaslin','07/04/2004','02/11/2007')
------------------------------------------------------------------------------
------------
select * from drug
-----------------------------
-----------------------------------------
--lab_technician_physician
create table techphysician(
tech_id varchar(50) not null foreign key references lab_technician(tech_id) on
delete cascade on update cascade,
phy_id varchar(50) not null foreign key references physician(phy_id)on delete
cascade on update cascade,
fname varchar(50) not null,
lname varchar(50) not null,
constraint pk_techphysician primary key(tech_id,phy_id)
)
drop table techphysician
---------------------------------- tech_physician
values--------------------------------
insert into techphysician(tech_id,phy_id,fname,lname) values('tech_1','phy-
1','dor_miskir','adane')
insert into techphysician(tech_id,phy_id,fname,lname) values('tech_1','phy-
3','fasika','tadese')
insert into techphysician(tech_id,phy_id,fname,lname) values('tech_3','phy-
1','fasika','tadese')
------------------------------------------------------------------------------
-----
select * from techphysician
------------------------------------------------------------------------------
---
--cardofficer_physician
create table offcerphysician(
off_id varchar(50) not null foreign key references card_officer(off_id)on
delete cascade on update cascade,
phy_id varchar(50) not null foreign key references physician(phy_id)on delete
cascade on update cascade,
fname varchar(50) not null,
lname varchar(50) not null ,
constraint pk_offcerphysician primary key(off_id, phy_id)
)
----------------------------offcer_physician
values----------------------------------
insert into offcerphysician(off_id,phy_id,fname,lname) values('off_1','phy-
1','dagmiaw','tibebu' )
insert into offcerphysician(off_id,phy_id,fname,lname) values('off_2','phy-
3','hennok','tibebu' )
insert into offcerphysician(off_id,phy_id,fname,lname) values('off_2','phy-
1','hayimanot','zelalem' )
------------------------------------------------------------------------------
---------
select * from offcerphysician
-------------------------------------------------------------
--Test
create table test(
p_id varchar(50) not null foreign key references patient(p_id)on delete
cascade on update cascade,
tech_id varchar(50) not null foreign key references lab_technician(tech_id)on
delete cascade on update cascade,
test_type varchar(50) not null,
constraint pk_pateintlabtechniccian primary key(p_id, tech_id)
)
------------------------------------------------- pateint_labtechniccian
values--------------
insert into test(p_id,tech_id,test_type) values('p-12','tech_1','Gastrics')
insert into test(p_id,tech_id,test_type) values('p-20','tech_2','Stool')
insert into test(p_id,tech_id,test_type) values('p-12','tech_2','bloodtest')
------------------------------------------------------------------------------
------------------
select * from test
-----------------------------------------------
--------------------------------------------------------------------------
select * from take
--------------------------------------
--------------------------------------------------------
select * from treat
-------------------------------------------
--------------------------------------------------------------------
select * from givedruge
--------------------------------------------------
------------------------------------------------------------------------
create view pharm as select * from pharmacist where address like 'w%'
select*from pharm
---- ------------------------------------------------------------
create view dr as select * from drug where lot ='123'
select*from dr
------------------------------------------------------------------------------
-
create view tecp as select * from techphysician where fname like 'f%'
select*from tecp
------ delete
------------------------------------------------------------------------------
--------
create view tk as select * from take where lot =123
select*from treat
------------------------------------------------------------------------------
----------------------
create view gd as select [Link] from givedruge gd, patient p, drug d
,pharmacist pha where [Link] =[Link] and gd.p_id=p.p_id and
pha.pha_id=gd.pha_id and cost=10.5
select*from gd
create index ix_gd on givedruge(lot)
select [Link],[Link],[Link],[Link]
from patient p ,physician phy,pharmacist pha,drug d,treat t,givedruge gd where
p.p_id='p-54' and
phy.phy_id=t.phy_id and p.p_id=t.p_id and pha.pha_id=gd.pha_id and
p.p_id=gd.p_id and [Link]=[Link]
-------------ADVANCED-------------------
-----scallar function----
create function Tpatient()
returns int
as
begin
declare @tpaient int
set @tpaient=(select count (p.p_id) from patient p,drug d,take te where
d.drug_type='amoxaslin' and p.p_id=te.p_id and [Link]=[Link])
return @tpaient
end
select [Link]()
------------------------------------------------------------------------------
create function Fpatient()
returns int
as
begin
declare @f int
set @f=(select count (p.p_id )from patient p,physician phy, treat t where
[Link]='dor_miskir' and p.p_id=t.p_id and phy.phy_id=t.phy_id)
return @f
end
select [Link]()
drop function Fpatient
------------------------------------------------------------------------------
------------------------
create function costs(@p_id varchar(10))
returns float
as
begin
declare @cost float
set @cost=(select sum(cost) from givedruge gd,patient p, pharmacist pha where
p.p_id=gd.p_id and pha.pha_id=gd.pha_id and p.p_id=@p_id)
return @cost
end
select * from givedruge
select [Link]('p-54')
drop function costs
------------------------------------------------------------------------------
------------------------
------------------------------------------------------------------------------
-------------------------
create function costshering(@pha_id varchar(10))
returns float
as
begin
declare @coustshering float
set @coustshering=(select sum(cost) from givedruge gd,patient p, pharmacist
pha where p.p_id=gd.p_id and pha.pha_id=gd.pha_id and pha.pha_id=@pha_id)
return @coustshering
end
--drop function costshering
select [Link]('pha_3')
select * from givedruge
------------------------------------------------------------------------------
-------------------------
-----------------------------inline valued
table-------------------------------------------------------------------------
--
create function list()
returns table
as
return select [Link],phy.phy_id,[Link] from ordere o,physician phy,drug d
where
phy.phy_id=o.phy_id and [Link]=[Link]
select [Link]()
------------------------------------------------------------------------------
--------------------------
----------------------------------------------------------stored
procedur-------------------------------
create procedure usp_pharmacist(@sex char)
as
select p.p_id,d.drug_type,[Link] from patient p,take t,drug d where @sex=[Link]
and p.p_id=t.p_id and [Link]=[Link]
execute usp_pharmacist 'f'
go
create trigger trg_insert on take
for insert
as
if(select count([Link]) from take t, inserted i where t.p_id=i.p_id)>2
begin
raiserror('you can not take more than two druges',17,1)
rollback transaction
end
go
go
create trigger tr_insert on treat for insert
as
if(select count(t.p_id) from treat t, inserted i where t.phy_id=i.phy_id)>2
begin
raiserror('physician can not treat more than two patient perday',17,1)
rollback transaction
end
go
insert into treat values('04/24/2005','phy-3','p-20')
insert into treat values('','phy-3','p-77')
sp_droprolemember card_officers,wubit--test
---------------------------Transaction-------------------------------
CREATE PROCEDURE changeval (@oldskill varchar(30), @newskill varchar(30))
as
BEGIN TRANSACTION T1
Update skill set skill=@newskill where skill=@oldskill
If (@@error<>0)
Rollback transaction T1
Commit
update skill set skill='pharmacy' where skill='nurse'--test
If (@@error<>0)
Rollback transaction T1
Commit
update treat set appointment='01/02/2005' where p_id='p-54'--test
select * from treat
If (@@error<>0)
Rollback transaction T3
Commit
update drug set manu_date='05/10/2000' where lot=432--test
update drug set exp_date='09/05/2002' where lot=876--test
select * from drug
select * from drug
create login yengu with password='12'
sp_addsrvrolemember yengu,sysadmin
--------------------------------------------------------------------------
References
Fundamentals of database management system Emissary third and fourth edition text book.
thank you