Professional Documents
Culture Documents
Database Project Part 1
Database Project Part 1
CST363-30_SP23
January 23, 2023
Our Team:
The Drug Store Database’s goal is to efficiently keep track of our client’s entities and records that
they interact with on a daily basis. Our client, a drug store chain, is responsible for making sure
that their patients’ prescriptions are fulfilled accurately and in a timely manner. However, with all
the moving parts that are involved, our company is excited to implement the database that we
have developed to help streamline their processes.
This process begins with a patient and their primary physician. As many of us are familiar, we visit
our doctor when we are not feeling well. The result of this doctor’s visit could be a prescription for
medication to help our condition improve. Our database will make sure to keep track of every
patient, physician and prescription that is written by a doctor for a patient. We also make sure that
each record is unique from one another so that there aren’t any mix ups as to which prescription
is for which patient.
After the prescription is written, it is then sent to the pharmacy for fulfillment. However, to
determine which pharmacy will fulfill the prescription depends on what the drug is and whether it
should be the generic or brand name version. The selection of drugs that are sold at each
pharmacy is determined by a contract between a pharmacy and pharmaceutical company (the
manufacturer of the drugs). A supervisor manages these contracts for each pharmacy to ensure
the correct/desired drugs are being purchased from the pharmaceutical companies and in stock
at the pharmacy.
If the physician has indicated on the prescription that the drug can be generic, then the
prescription can be fulfilled with any drug of the same name, manufactured from any
pharmaceutical company. However, if the physician indicated that the drug should be brand
name, the fulfillment is stricter and can only be fulfilled by that drug name from a specific
pharmaceutical company. With our database, these rules can be enforced with the information
stored from various related tables.
Once the appropriate pharmacy has filled the patient’s prescription, the date and pharmacy that
filled it is recorded on the patient’s original prescription. With the drug that was used to fill the
prescription, we can also trace back to which pharmaceutical company was the manufacturer of
the drug. As seen with many of our client’s other entities, our database relates all of them in one
way or another, allowing to dot walk to different pieces of data when needed,
Now that the patient knows which pharmacy to go pick up their prescription, another important
factor to determine is how much their drug will cost. A drug may not cost the same price,
depending on which pharmacy the patient picks it up from. To keep track of the cost differences,
our database will store the different prices based on the combination of the drug and the
pharmacy it's sold at.
When a patient is anxiously waiting to pick up their prescription in hopes to feel better, the last
thing that they, their doctor or the pharmacy should have to worry about is delays due to
misplaced or scattered information. Our company’s goal is to help keep our clients’ data clean,
organized and easily accessible!
1
ER Model
How the entities, attributes and relationships in our design address the requirements:
There are a total of nine tables to address the requirements of the client. Pharmaceutical
company and pharmacy tables are linked with a main table known as contract via foreign keys.
Similarly, the prices table serves a link between the pharmacy and drug tables also through
foreign keys. Above shows the full diagram of the tables, attributes, and their relationships.
pharmaceutical_co Contains information about pharmaceutical companies and how to get in touch
mpany with them via telephone
pharmacy Contains detailed information of the pharmacy retail, their location, and their
2
telephone number
contract Serves as the main link between pharmaceutical companies and pharmacy retails
and contains detail about their partnership and how long it will continue.
prices Serves as the main link between drug and pharmacy retails and contains
information about the set prices of generic drug vs branded drugs.
prescriptions Contains detailed information on which doctor prescribed what drug to which of
their patients.
drug Contains detail about drugs who have a “generic” formula and drugs that were
developed by branded pharmaceutical companies
The database allows the client to bring up information of doctors and their patients. Information
from the database on the doctors ranges from their SSN, years of expertise, and their specialty.
Since every patient has one primary physician, they are able to list out which client seeks
attention from which physician. Also, the client would be able to gather information if a doctor has
prescribed drugs, generic or branded, to their patients. If the drug that is branded was prescribed,
the client would be able to track back to which pharmaceutical company that developed the drug.
Since any physician can prescribe as many medications the patient needs, every prescription
would include the following: RX number, quantity amount per bottle, doctor who prescribed it, the
patient, and date it was filled. In addition, the information about the drug can show if it contains a
generic formula or a branded one. If the drug contains a generic formula, it can be sold at various
stores at varying prices.
In order for pharmaceutical companies and pharmacy retailers to work together properly, they
create a contract between them. Each contract lists out the details of how they will operate
together and how long they will do business with each. Along with each contract, there is an
appointed supervisor who will oversee the terms of the contract being fulfilled.
SET @OLD_SQL_MODE=@@SQL_MODE,
SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERRO
R_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
USE `mydb` ;
-- -----------------------------------------------------
-- Table `doctor`
-- -----------------------------------------------------
4
UNIQUE INDEX `doctor_SSN_UNIQUE` (`doctor_SSN` ASC) VISIBLE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `patient`
-- -----------------------------------------------------
CONSTRAINT `fk_patient_doctor1`
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- -----------------------------------------------------
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `pharmacy`
-- -----------------------------------------------------
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `drug`
-- -----------------------------------------------------
ON DELETE NO ACTION
ON UPDATE NO ACTION)
6
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `perscription`
-- -----------------------------------------------------
CONSTRAINT `fk_perscription_patient1`
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_perscription_drug1`
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_perscription_doctor1`
7
FOREIGN KEY (`doctorid`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_perscription_pharmacy1`
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `prices`
-- -----------------------------------------------------
CONSTRAINT `fk_drug_has_pharmacy_drug1`
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_drug_has_pharmacy_pharmacy1`
ON DELETE NO ACTION
8
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `supervisor`
-- -----------------------------------------------------
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `contract`
-- -----------------------------------------------------
CONSTRAINT `fk_companyid`
ON DELETE NO ACTION
9
ON UPDATE NO ACTION,
CONSTRAINT `fk_contract_pharmacy1`
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_contract_supervisor1`
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
10
5 Interesting Questions for Management
Query 1 text: List the drugid’s produced by X pharmaceutical company that are sold at Y
pharmacy
Query 1 SQL statement:
select drug.drugid
Query 2 text: Which drug did doctor X write the most prescriptions for?
Query 2 SQL statement:
select drug.drugid
from drug
Query 3 text: Which pharmaceutical company does pharmacy X have contracts with?
Query 3 SQL statement:
select pc.companyid
11
Query 4 text: How many different pharmacies can patient X fill their prescription from?
Query 4 SQL statement:
select COUNT(pharmacy.pharmacyid)
Query 5 text: On average, how much does each patient spend on drugs?
Query 5 SQL statement:
select patient.patientid, AVG(prices.brand_prices)
group by patient.patientid;
12
Design Normalization
Check your design for normalization and what actions (if any) you took and why.
Because this was a top-down design, we were able to keep our relational schema in 3NF fairly
easy. As we designed and created each relation, if any relation had one column and then
additional columns after it where the information was always the same, a new relation was
created. For example, in the patient relation, there is one column for the patient’s primary
physician (doctorid). However, instead of including additional columns in the patient relation for
the doctor’s name, SSN, etc., this was created into a separate relation (doctor). That way, the
patient relation refers to the doctor table, but information about the doctor is stored in a separate
relation. We did not identify any unnormalized tables in our schema. Also, because we did not
identify any unnormalized tables, we also did not find any potential for update anomalies.
Conclusions
Our group has created a database schema that keeps track of tables commonly used in
the pharmaceutical industry. By connecting many different data tables together, clients will be
able to easily fill prescriptions for patients quickly and efficiently.
This project gave our group more hands-on experience in creating schemas using MySQL
Workbench. Creating a diagram in MySQL first helped us visualize how the tables should be
relating to each other, which made it easier to write the question queries. In the future, we will be
able to graph out the broad ideas before moving on to write each individual part.
13