Professional Documents
Culture Documents
Database Systems @G3
Database Systems @G3
I. Abstract 2
II. Introduction 2
1. About the organization: 2
2. Requirement Analysis 3
3. Business Narrative 6
Analyzing and designing the database 7
1. Explanation of E-R Diagram 7
2. Relational schema and normalization 10
III. Some useful reports and information 18
III. Conclusion 34
I. Abstract
Pharmacy Management System is a Database Management System for managing both
billing and drug inventory which helps in maintaining the records of medicines,
employees, and customers and also reduces the work of searching the medicine. The
main aim of this system is to apply technology to support the pharmacists and the stores
to reduce the human effort in searching and automation the billing. This system can be
used by any store to automate the process of manually maintaining pharmacy-related
records. The system uses the insurance of patients and can also notify employees of
events performed in the pharmacy.
II. Introduction
1. About the organization:
- DB Pharmacy was established in 2022. DB is a GPP standard pharmacy with
modern and advanced facilities, full of necessary equipment and facilities for drug
preservation: self-recorded thermometers, air conditioners, refrigerators, and
operating dehumidifiers 24/24 to ensure drug storage conditions as required. In
addition, the pharmacy also meets the standards of personnel. In charge of the
pharmacy is a university pharmacist with a certificate of pharmacy practice with
many years of experience working in a famous hospital. The DB also meets the
standard of performance: accurate and secure record keeping and record keeping.
Buy drugs and control the quality of drugs fully.
- Mission: To help our patieConfidentialitynts get better and live healthier lives, we
provide the best quality medical supplies and medicines along with expert advice
on the safest and most effective use of medicines for our patients.
- Vision: To become the nation’s leading pharmacy by providing a healthy and
quality life for patients.
- Our values:
+ Customer focus
+ Competency
+ Compassion
+ Confidentiality
+ Community minded
+ Continuous provided
- Project main purpose: We create a pharmacy management system with the main
purpose of managing the pharmacy in the most effective way. This system
includes all information about prescriptions, sales, inventory quantities to ensure
customer orders as well as order status and daily purchases. In addition, the system
also manages customers. The necessary information to track customer orders
during purchase or delivery. Avoid giving the wrong order or selling at the wrong
price, or quantity deviation in stock.
2. Requirement Analysis
Methods for investigating business rules:
The information used in this report is gathered from the following sources
Website
The database is designed mainly based on the information referenced from Pharmacy.
Documents
Before customers buy and pay for products, they must provide their name, phone number
and payment method. We use these references to create our tables.
Observation
The experience of selling offline at Pharmacy drug stores helps us partially design this
database.
The pharmacy requirements to be achieved based on our research and understanding are:
Customer
When patients arrive at the store, we will obtain their health ID and identify them based
on their health ID. If they are a new patient, we will collect data such as name, date of
birth, address, health ID, phone number, gender, and insurance Id. The patient will have a
prescription using which order will be created and the patient will then pay the bill
Employee
An employee has an employee id, role, license, phone no, salary and name employee can
be a cashier or pharmacist. If an employee is preparing the order then his/her ID will be
used in the order. The employee authorizes the disposal ines. Employees will be notified
of orders and disposals.
An employee has to have one of the following roles:
1. Pharmacist
2. Pharmacy technician
3. Pharmacy assistant
4. Pharmacy clerk
5. Pharmacy Dispenser
6. Nuclear pharmacist
7. Chemotherapy pharmacist
Prescription
When customers come, they will be asked to give prescriptions stamped and signed by
the doctor who gives those drugs, then our pharmacy will take the correct medicine and
dosage as the doctor has prescribed. The prescription contains the customer's number and
the id of the doctor prescribing the drug. Absolutely do not take more than the prescribed
amount.
Prescribed Drug
Every prescription contains prescribed drugs and their information. The drug’s, name,
quantity and refill limit must be stated on the prescription,
Bill
After the customer confirms the drug and quantity to go to the payment step, the bill will
be printed with the information of the drug price, quantity and information of the buyer.
Customers are kindly requested to keep the receipt in case of any circumstances that can
be brought to exchange with the pharmacy.
Notifications
The system will send a notification to the pharmacist:
-Stock for medicine is low (less than 100 tablets)
-Some medicine will expire in the next 60 days
-Drugs are marked for disposal
-Drugs are successfully disposed
Medicine (inventory)
It is beneficial to store an updated inventory for record-keeping and to know when we are
short of stock. The inventory will contain all the information on the medicines in the
pharmacy the name of the medicine, the type of medicine, the manufacturer, the expiry
date, the price, the quantity in stock, and the batch number. When a medicine approaches
its expiration date, it will be disposed of.
Insurance
In case the patient has health insurance, the pharmacy will note that insurance ID
including company name, start-end date, patient name, and insurance percentage. Based
on that, the pharmacy will calculate the amount to be paid by the insurance company and
the patient.
Order
The prescription will generate an order and each order will be identified by a unique
order ID. This includes the drug ID, employee ID, order date, name of the drug, quantity,
and batch number. This is the information required to place an order.
3. Business Narrative
3.1 Business Rules
Patients only buy drugs according to the prescription that the doctor has prescribed or
according to the instructions and advice of the pharmacist at the pharmacy. Only a certain
amount of medicine can be purchased, some prescription drugs must be purchased at the
hospital.
3.2. Business Narrative
● Each DB customer will have a unique number and their personal information is
stored and secured.
● Each drug contains a fixed amount of data with Dru_Code as the identifier.
● An employee can receive many notifications, a notification can be sent to many
different employees, here is a many-to-many relationship.
● Each patient can have different prescriptions, while each prescription belongs only
to one patient.
● Each prescription is written by a doctor and a doctor can write many prescriptions
for different patients.
● An order can contain one or more different drugs, it is a one-to-many relationship.
But an order has only one invoice. So, the relationship of the order and the invoice
is one-to-one.
● A patient can have many different orders, so the relation between them is
one-to-many.
● Although each drug has a different unique ID in the reserve, but it can be in many
prescriptions.
● An employee can throw away many drugs, many employees can also throw many
drugs, so the relationship here is many to many.
III. Analyzing and designing the database
A patient can have many prescriptions. However, a prescription can only belong to a
single patient. Thus the relationship between Patient and Prescription entity is one to
many. Each patient will have a prescription and each prescription belongs to a patient so
the participation is Total of both sides.
A patient can claim one insurance and insurance can only insure one patient. Thus the
relationship between Insurance and Patient is one-to-one. A patient may not have
insurance so patient participation in insurance is partial. However, each insurance belongs
to a patient so insurance participation is total in insurance.
A patient can pay several bills, but a bill will only be paid by a single patient. Thus, the
relationship between Patient and Bill is one to many. Each patient pays for his bill and
each bill is paid by a patient so the participation is Total of both sides.
A prescription may have several prescribed drugs but a drug with an order id will be on
only one prescription so the relationship between prescription and prescribed drug is one
to many. Each prescription will have a prescribed drug on it and each prescribed drug will
be on a prescription, so the participation is Total of both sides.
A prescription can generate multiple orders but an order will only be generated using
single prescription. Thus, the relationship between Prescription and order is one to many.
Each prescription will be used for some order and each order will be generated using a
prescription. So the participation is Total of both sides.
An order can only generate one bill and a bill be generated for only one order so the
relationship between the order and bill is one-to-one. Each order will generate a bill and
each bill will be generated for an order so the participation is Total of both sides.
An order can contain multiple ordered drugs but an ordered drug with its order ID and
drug name will be only be in an order. Thus the relationship between order and ordered
drugs is one to many. Each order will contain some drugs and each ordered drugs will be
in some order. So the participation is Total of both sides.
A medicine will be fetched by an ordered drug and an ordered drug will fetch only one
medicine. So the relationship between ordered drugs and medicine is one to one. Each
ordered drug will fetch some medicine but every medicine will not be fetched so the
participation of ordered drugs in fetched is Total but the participation of medicine in
fetched is partial.
Disposal is weak entity and is dependent on Medicine so the relationship between them
disposed of is weak relationship. Disposal uses foreign key drug name and batches no as
its primary key. Every disposed of drug is from medicine so the participation of disposal
is total in disposes of. Not every medicine is disposed so the participation of medicine in
disposes is partial.
An employee can authorize many disposals and disposal can be authorized by many
employees. So the relationship between them is many to many. Not every employee
authorizes disposal so the participation of employees in authorizes is partial. Each
disposal is authorized by an employee so the participation of disposal in authorization is
Total.
An employee can receive many notifications and a notification can be sent to many
employees so the relationship between them is many to many. Not every employee
receives a notification, but every notification is sent to some employees so the
participation of employees in isNotified is partial and the participation of notification in
isNotified is Total.
Relations
The final relations are listed below:
Customer
Custome First Last Phone Gender Address Date of Insuran
r ID Name Name Birth ce ID
Primary Key: Customer ID
Foreign Key: Customer(Insurance ID) 🡪 Insurance(Insurance ID)
Insurance
Insurance Company Start End Co
ID Name Date Date Insurance
Prescription
Prescripti Custome Doctor Prescription
on ID r ID ID Date
Primary Key: Prescription ID
Foreign Key: Prescription(Customer ID) 🡪 Customer(Customer ID)
Prescribed Drugs
Prescripti Drug Prescribed Refill
on ID Name Quantity Limit
Primary Key: Prescription ID, Drug Name
Foreign Key: Prescribed Drugs(Prescription ID) 🡪 Prescription(Prescription ID)
Order
Order ID Prescripti EmployeeI Order
on ID D Date
Ordered Drugs
Order Drug Batch Quantity Price
ID Name Number
Primary Key: Order ID, Drug Name, Batch Number
Foreign Key: Ordered Drugs(Order ID) 🡪 Order(Order ID), Ordered
Drugs(Drug Name, Batch Number) 🡪 Medicine(Drug Name, Batch
Number)
Bill
Order ID CustomerCu Total Customer Insurance
stomer ID Amount Payment Payment
Medicine
Drug Batch Medicine Manufacture Quantit Expiry Price
Name Number Type r y Date
Primary Key: Drug Name,
Batch Number
Disposed Drugs
Drug Batch Quantit Compan
Name Number y y
Primary Key: Drug Name, Batch Number
Foreign Key: Disposed Drugs(Drug Name, Batch Number) 🡪
Medicine(Drug Name, Batch Number)
Notification
ID Message Type
Primary Key: ID
Employee_Disposed Drugs
Emplo Drug Batch Disposal
yee ID Name Number Date
Primary Key: Employee ID, Drug Name, Batch Number, Disposal Date
Foreign Key: Employee_Disposed Drugs(Employee ID) 🡪 Employee
(Employee ID), Employee_Disposed Drugs(Drug Name, Batch Number)
🡪 Disposed Drugs(Drug Name, Batch Number)
Employee Notification
Emplo Notificat
yee ID ion ID
Primary: Employee ID, Notification ID
Foregin Key: Employee Notification(Employee ID) 🡪
Employee(ID), Employee Notification(Notification ID) 🡪
Notification(Notification ID)
Normalization
The following dependencies exist in our schema:
--3. Find the customer with the last name Nguyễn and sorts by ascending
select *from Customer
where fullname like N'Nguyễn%'
ORDER BY fullname ASC;
--7/ Retrieve the information when customer payment is between $10 and $40.
CREATE PROCEDURE ListBill_byprice @minprice int, @maxprice int
AS
BEGIN
SELECT order_id, customer_payment
FROM Bill WHERE customer_payment between @minprice and @maxprice
END
--9/ --Write a trigger so that every time you delete the prescription id in the prescription
table,
--it will automatically delete the corresponding lines in the Bill table
create trigger delete_Prescription_ID
on Prescription
for DELETE
AS
BEGIN
delete from PRESCRIBED_DRUGS
where Prescription_ID in (
select Prescription_ID
from deleted)
END
--10/ Find the order with the Expiry Date < 2023-12-12 and make disposal notification
SELECT drug_name , batch_number, Manufacturer, expiry_date
FROM Medicine
WHERE expiry_date < '2023-12-12'
ORDER BY expiry_date ASC;
---B101
SELECT Order_ID
FROM ORDERED_DRUGS
WHERE batch_number = 'B101'
--O110
INSERT INTO Notification (Notification_ID , Message , Action)
VALUES (value1, value2, value3, ...);
UPDATE Employee
set salary = 10000
where Employee_ID = 'E102'
--11/ When updating the salary of Employee, check that there is no higher salary with the
same role
CREATE TRIGGER LowerSalaryCheck
UPDATE salary
ON Employee
REFERENCING OLD ROW AS OldTuple
NEW ROW AS NewTuple
FOR EACH ROW
WHEN(NOT(NewTuple.salary <= ALL(SELECT salary FROM Employee WHERE
License = NewTuple.License)))
BEGIN
DELETE FROM Employee
WHERE (Employee_ID, License, Full_name, role , salary, phone_number, date_of_birth
) = NewTuple;
INSERT INTO Employee VALUES(OldTuple.Employee_ID, OldTuple.License,
OldTuple.Full_name,OldTuple.role, OldTuple.phone_number, OldTuple.date_of_birth);
END;
--12/ When inserting a new order, check that the order id exists in Customer
SELECT Order_ID
FROM Customer
WHERE EXISTS
(SELECT order_id FROM Prescription WHERE order_id = 'O103');
10/ Count the number of each address and visual it as a treemap diagram
2. LÂM TƯỜNG PART
–1. Get the information to view medicine information (from medicine table) and disposed
drugs ?
--3. Find the manufacturer of drug are from Traphaco Joint Stock Company and sorts by
ascending
select *from Medicine
where Manufacturer like N'Traphaco Joint Stock Company%'
ORDER BY Manufacturer ASC;
Send Notifications
--4. Retrieve the information when customer payment is between $30 and $100.
CREATE PROCEDURE ListBill_byprice @minprice int, @maxprice int
AS
BEGIN
SELECT order_id, customer_payment
FROM Bill WHERE customer_payment between @minprice and @maxprice
END
–6. Find the order with the Expiry Date < 2023-12-20 and make disposal notification
SELECT drug_name , batch_number, Manufacturer, expiry_date
FROM Medicine
WHERE expiry_date < '2023-12-20'
ORDER BY expiry_date ASC;
---B101
SELECT Order_ID
FROM ORDERED_DRUGS
WHERE batch_number = 'B101'
–7. Count the number of Drug with Expiry Date between December 11th and December
31st
SELECT Expiry_Date, COUNT(*) AS NumberOfExpiryDatedDrug
FROM Medicine
WHERE Expiry_Date
BETWEEN ('2023-12-11') AND ('2023-12-31')
GROUP BY Expiry_Date;
–9.
When inserting a new order, check that the order id exists in "ORDERED_DRUGS"
SELECT order_id
FROM "ORDERED_DRUGS"
WHERE EXISTS
(SELECT order_id FROM Bill WHERE order_id = 'O111');
--5. Employee Validation
When an employee is added, the employee type should be one of:
1. Pharmacist
2. CPhT
3.Pharmacy clerk
4. Pharmacy assistant
Except Pharmacy clerk , every other role requires a license.
–3. Find the customer with the last name Bùi and sorts by ascending
select *from Customer
where fullname like B 'Bùi%'
ORDER BY fullname ASC;
–5. Retrieve the information when customer payment is between $20 and $50.
CREATE PROCEDURE ListBill_byprice @minprice int, @maxprice int
AS
BEGIN
SELECT order_id, customer_payment
FROM Bill WHERE customer_payment between @minprice and @maxprice
END
–7. Count the number of customers with birthday between May 2rd and July 8th
SELECT Date_of_birth, COUNT(*) AS NumberOfCusWithBirthday
FROM CUSTOMER
WHERE Date_of_birth
BETWEEN ('2002-05-02') AND ('2002-07-08')
GROUP BY Date_of_birth;
–8. Find the order with the Expiry Date < 2023-12-21 and make disposal notification
SELECT drug_name , batch_number, Manufacturer, expiry_date
FROM Medicine
WHERE expiry_date < ‘2023-12-21’
ORDER BY expiry_date ASC;
---B110
SELECT Order_ID
FROM ORDERED_DRUGS
WHERE batch_number = 'B110'
–9. Count the number of customers who live in Cau Giay District
SELECT Customer.address, COUNT(*) AS NUMBEROFCUSTOMER
FROM CUSTOMER
INNER JOIN "ORDER"
ON Customer.order_id = "Order".order_id
GROUP BY Customer.address
HAVING Customer.address = 'Cầu Giấy’
ORDER BY Customer.address DESC;
This report is created with our own experience after thorough research. Nevertheless, we
are well aware of the shortcomings and limited scope of our study since we are only
undergraduates. This database can help Pharmacy store and manage both billing and drug
inventory which helps in maintaining the records of medicines, employees, and
customers and also reduces the work of searching the medicine
V. Contributions