0% found this document useful (0 votes)
26 views19 pages

Team 14

Uploaded by

api-694081510
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views19 pages

Team 14

Uploaded by

api-694081510
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

123 Your Street

Your City, ST 12345


(123) 456-7890

Pharmaceutical Database
19 January 2023

CST 363: Into to Database Systems

Mike Divine

Benjamin Shafer

Russell Frost
Project Overview
A new drug store chain is opening up and needs a database with front-end access for employees
to use. This drugstore chain will work closely with doctors, physicians, patients, and
pharmaceutical companies. The database needs to store all the data that relates to patients'
prescriptions, contracts, registered doctors, and individual drugstores. Divine Design has been
tasked with consulting the drugstore chain in developing the database design.

Specifications
1. Each drugstore can sell several drugs at several price points.
2. The drug can be supplied by one or multiple pharmaceutical companies
3. Doctors are the only entity that can prescribe drugs to a patient.
4. Each prescription must have a unique RX number that relates to one drug, one patient,
and is written by one doctor.
5. When a prescription is written it must include a date. Along with the date if has a trade
name then it must be assigned to the specific drug from the specific pharmaceutical
company that produces it. If the prescription is for the generic version, it can be assigned
from any pharmaceutical company.
6. Every time a prescription has been filled the pharmacy that filled it, the date it was filled,
and the pharmaceutical company that supplied it should be tracked.
7. Pharmaceutical companies and pharmacies will create long-term contracts. The start date
and end dates of these contracts need to be tracked.
8. A pharmacy supervisor will be assigned to oversee each contract invoked between the
pharmacies and pharmaceutical companies. The supervisor that oversees these
contracts will need to be tracked. Every contract will have only one supervisor.

Customers
The customer of this pharmaceutical database is the new drugstore chain that is opening. This
drugstore chain will have many locations. Each location will have numerous employees who will
need to access and use the database. Pharmacists and Supervisors will be the main employees
of the drugstore chain that will interact with the front end of this database. Because drugstores
can be similar in their operating styles, this database can be modified to meet the requirements
of numerous other customers.
Database Structure
The construction of the database was a two-part sequence. First, MySQLWorkbench was used to
create an EER diagram. This is the step where the entities and attributes were decided. The
relationships between the entities were also established during this step with the inclusion of
primary keys and foreign keys. Throughout the process of the database design normalization
was the most prominent thought. The second step of our database design sequence was using
the Forward Engineering tool in MySQLWorkbench. This tool allowed us to generate the file
needed to create the database using the design we constructed in step one. This is an ongoing
process. If something needs to be changed/added the process starts again from the beginning
until all specifications are met.

Database Table Description

Patient Contains the patient’s information and their current doctor

Doctor Contains the doctor’s information and their start date

PharmaceuticalCo Contains the ID, name, and phone of the pharmaceutical


company

Pharmacy Contains the ID, name, address, and phone of the pharmacy

Drug Contains the ID, generic name, trade name if it exists, and
the pharmaceutical company who makes it

PharmacyDrugs Contains the pharmacy who is selling the drug, the drug
being sold, and the price it’s being sold for

Contract Aggregates the data from pharmacy and pharmaceutical


company related to the contract. Start date, end date,
supervisor, and contract text are stored here

Supervisor Contains the supervisor ID, pharmacy ID, and the name of
the supervisor

Prescriptions Contains the prescription ID, who the prescription is for,


who wrote the prescription, which drug it is for, which
pharmacy filled the prescription, the date it was filled, the
quantity given, and the Pharmaceutical Company who made
the drug
Appendices
Appendix A: EER Diagram for XYZ Drug Store Chain

Appendix B: Create File

Appendix C: Queries

Appendix D: ScreenShots of Web Applications

Appendix E: ScreenShots of JDBC Applications


APPENDIX A: EER Diagram for XYZ Drug Store Chain
APPENDIX B: Create File
-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;


SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE,
SQL_MODE='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,N
O_ENGINE_SUBSTITUTION';

-- -----------------------------------------------------
-- Schema DrugCo
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema DrugCo
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `DrugCo` DEFAULT CHARACTER SET utf8 ;
USE `DrugCo` ;

-- -----------------------------------------------------
-- Table `DrugCo`.`Doctor`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DrugCo`.`Doctor` (
`DoctorSSN` VARCHAR(9) NOT NULL,
`FName` VARCHAR(45) NOT NULL,
`LName` VARCHAR(45) NOT NULL,
`Specialty` VARCHAR(45) NOT NULL,
`StartDate` DATE NOT NULL,
PRIMARY KEY (`DoctorSSN`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DrugCo`.`Patient`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DrugCo`.`Patient` (
`PatientSSN` VARCHAR(9) NOT NULL,
`FName` VARCHAR(45) NOT NULL,
`LName` VARCHAR(45) NOT NULL,
`Birthdate` DATE NOT NULL,
`Street` VARCHAR(45) NOT NULL,
`City` VARCHAR(25) NOT NULL,
`State` VARCHAR(2) NOT NULL,
`Zip` VARCHAR(10) NOT NULL,
`DoctorSSN` VARCHAR(9) NOT NULL,
PRIMARY KEY (`PatientSSN`),
INDEX `DoctorSSN_idx` (`DoctorSSN` ASC) VISIBLE,
CONSTRAINT `PatDoctorSSN`
FOREIGN KEY (`DoctorSSN`)
REFERENCES `DrugCo`.`Doctor` (`DoctorSSN`)
ON DELETE NO ACTION
ON UPDATE CASCADE)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DrugCo`.`PharmaceuticalCo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DrugCo`.`PharmaceuticalCo` (
`PharmCoID` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(45) NOT NULL,
`Phone` VARCHAR(10) NULL,
PRIMARY KEY (`PharmCoID`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DrugCo`.`Pharmacy`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DrugCo`.`Pharmacy` (
`PharmacyID` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(45) NOT NULL,
`Street` VARCHAR(45) NULL,
`City` VARCHAR(25) NULL,
`State` VARCHAR(2) NULL,
`Zip` VARCHAR(10) NULL,
`Phone` VARCHAR(10) NULL,
PRIMARY KEY (`PharmacyID`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DrugCo`.`Drug`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DrugCo`.`Drug` (
`DrugID` INT NOT NULL,
`GenericName` VARCHAR(45) NOT NULL,
`TradeName` VARCHAR(45) NULL,
`PharmCoID` INT NOT NULL,
PRIMARY KEY (`DrugID`),
UNIQUE INDEX `TradeName_UNIQUE` (`TradeName` ASC) VISIBLE,
INDEX `PharmCoID_idx` (`PharmCoID` ASC) VISIBLE,
CONSTRAINT `DrugPharmCoID`
FOREIGN KEY (`PharmCoID`)
REFERENCES `DrugCo`.`PharmaceuticalCo` (`PharmCoID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DrugCo`.`PharmacyDrugs`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DrugCo`.`PharmacyDrugs` (
`DrugID` INT NOT NULL,
`PharmacyID` INT NOT NULL,
`Price` INT NOT NULL,
INDEX `DrugID_idx` (`DrugID` ASC) VISIBLE,
INDEX `PharmacyID_idx` (`PharmacyID` ASC) VISIBLE,
CONSTRAINT `PDDrugID`
FOREIGN KEY (`DrugID`)
REFERENCES `DrugCo`.`Drug` (`DrugID`)
ON DELETE NO ACTION
ON UPDATE CASCADE,
CONSTRAINT `PDPharmacyID`
FOREIGN KEY (`PharmacyID`)
REFERENCES `DrugCo`.`Pharmacy` (`PharmacyID`)
ON DELETE NO ACTION
ON UPDATE CASCADE)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DrugCo`.`Prescriptions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DrugCo`.`Prescriptions` (
`RX` INT NOT NULL AUTO_INCREMENT,
`PatientSSN` VARCHAR(9) NOT NULL,
`DoctorSSN` VARCHAR(9) NOT NULL,
`DrugID` INT NOT NULL,
`PharmacyID` INT NULL,
`DatePrescribed` DATE NOT NULL,
`DateFilled` DATE NULL,
`Qty` INT NOT NULL,
PRIMARY KEY (`RX`),
INDEX `PatientSSN_idx` (`PatientSSN` ASC) VISIBLE,
INDEX `DoctorSSN_idx` (`DoctorSSN` ASC) VISIBLE,
INDEX `DrugID_idx` (`DrugID` ASC) VISIBLE,
INDEX `PharmacyID_idx` (`PharmacyID` ASC) VISIBLE,
CONSTRAINT `PrePatientSSN`
FOREIGN KEY (`PatientSSN`)
REFERENCES `DrugCo`.`Patient` (`PatientSSN`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `PreDoctorSSN`
FOREIGN KEY (`DoctorSSN`)
REFERENCES `DrugCo`.`Doctor` (`DoctorSSN`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `PreDrugID`
FOREIGN KEY (`DrugID`)
REFERENCES `DrugCo`.`Drug` (`DrugID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `PrePharmacyID`
FOREIGN KEY (`PharmacyID`)
REFERENCES `DrugCo`.`Pharmacy` (`PharmacyID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `DrugCo`.`Supervisor`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DrugCo`.`Supervisor` (
`SupervisorID` INT NOT NULL,
`PharmacyID` INT NOT NULL,
`Name` VARCHAR(45) NOT NULL,
PRIMARY KEY (`SupervisorID`),
INDEX `PharmacyID_idx` (`PharmacyID` ASC) VISIBLE,
CONSTRAINT `SupPharmacyID`
FOREIGN KEY (`PharmacyID`)
REFERENCES `DrugCo`.`Pharmacy` (`PharmacyID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `DrugCo`.`Contract`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `DrugCo`.`Contract` (
`ContractID` INT NOT NULL AUTO_INCREMENT,
`PharmCoID` INT NULL,
`PharmacyID` INT NULL,
`StartDate` DATE NOT NULL,
`EndDate` DATE NOT NULL,
`ContractText` LONGTEXT NOT NULL,
`SupervisorID` INT NOT NULL,
PRIMARY KEY (`ContractID`),
INDEX `PharmCoID_idx` (`PharmCoID` ASC) VISIBLE,
INDEX `PharmacyID_idx` (`PharmacyID` ASC) VISIBLE,
INDEX `SupervisorID_idx` (`SupervisorID` ASC) VISIBLE,
CONSTRAINT `ConPharmCoID`
FOREIGN KEY (`PharmCoID`)
REFERENCES `DrugCo`.`PharmaceuticalCo` (`PharmCoID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `ConPharmacyID`
FOREIGN KEY (`PharmacyID`)
REFERENCES `DrugCo`.`Pharmacy` (`PharmacyID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `ConSupervisorID`
FOREIGN KEY (`SupervisorID`)
REFERENCES `DrugCo`.`Supervisor` (`SupervisorID`)
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;
APPENDIX C: Queries
------------------------------------------------------------
-- List the Price for each drug at a pharmacy compared to --
-- the average price across all Pharmacies. --
------------------------------------------------------------

SELECT d.genericname AS Drug, d.TradeName AS "Trade Name", store.price AS "Price at


pharmacy", FORMAT(AVG(pd.price),2) AS "Average Price"
FROM pharmacydrugs pd JOIN drug d ON pd.drugid = d.drugid
JOIN
(SELECT price, drugid
FROM pharmacydrugs
WHERE PharmacyID = 1) AS store ON store.drugid = pd.drugid
GROUP BY Drug, d.TradeName, store.price;

-- List the most popular pharmacies by the amount of prescriptions they fill

--------------------------------------------------------------
-- List the most popular pharmacies by the amount of --
-- prescriptions they fill. --
--------------------------------------------------------------

SELECT pha.Name AS "Pharmacy Name", COUNT(*) AS "Amount of Filled Prescriptions"


FROM pharmacy pha, prescriptions pre
WHERE pha.PharmacyID = pre.PharmacyID
GROUP BY pha.Name
ORDER BY COUNT(*) DESC;

--------------------------------------------------------------
-- List the drugs sold from a pharmacy and how much was --
-- sold and the total revenue from each. --
--------------------------------------------------------------

SELECT p.Name AS Pharmacy, d.genericname AS Drug, count(rx.drugid) AS


"Total prescriptions", SUM(rx.qty) AS "Total Pills", FORMAT(sum(pd.price
* rx.qty),2) AS Value
FROM prescriptions rx JOIN drug d ON rx.drugid = d.drugid
JOIN pharmacydrugs pd ON rx.PharmacyID = pd.PharmacyID
AND rx.drugid = pd.DrugID
JOIN pharmacy p ON rx.PharmacyID = p.PharmacyID
WHERE p.PharmacyID = 7
GROUP BY Drug
ORDER BY Drug;

--------------------------------------------------------------
-- List the drugs that have sold and how much revenue --
-- they have produced. --
--------------------------------------------------------------

SELECT d.GenericName, d.tradename, sum(pd.price * rx.qty) Value


FROM prescriptions rx JOIN pharmacydrugs pd ON rx.pharmacyid = pd.PharmacyID
AND rx.DrugID = pd.drugid
JOIN drug d ON pd.drugid = d.drugid
GROUP BY d.GenericName, d.tradename;

--------------------------------------------------------------
-- List the Total revenue for each pharmacy from greatest --
-- revenue to least. --
--------------------------------------------------------------

SELECT p.Name AS Pharmacy, sum(pd.price * rx.qty) AS Revenue


FROM prescriptions rx JOIN pharmacydrugs pd ON rx.pharmacyid = pd.PharmacyID
AND rx.DrugID = pd.drugid
JOIN pharmacy p ON rx.PharmacyID = p.PharmacyID
GROUP BY p.Name
ORDER by Revenue DESC;
APPENDIX D: ScreenShots of Web Applications
Main Menu: Update Dr. Profile:

Display Dr. Profile with Invalid SSN:

Register as New Dr. with invalid SSN:

Displaying Dr. Profile with valid SSN:


Register as New Dr. Successfully: Display Patient:

Update Doctor:

Update Patient:

Display Patient with Invalid SSN:


Register as new Patient with bad data: Registered as new Patient:

Registered as new Patient: New prescription with bad Dr. data:


Prescription created: Prescription filled:

Request Prescription be filled with bad RX:


APPENDIX E: ScreenShots of JDBC Application
Member 1 JDBC Application: Database Verification of Data Generator
Member 2 JDBC Application: Quantity of Drugs by Pharmacy
Member 3 JDBC Application: FDA Report - Drug amount per Doctor

You might also like