Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Design Report

January 23, 2023

Prepared for
Drugs, Drugs, Drugs
Pharmacy Chain

Prepared By
Data and Stuff Consulting
Michael Cervantes, Robin Hurtado
Introduction

Purpose

Drugs, Drugs, Drugs is a chain drug store in need of a database to manage its prescriptions. They operate
multiple stores and need to track details of prescriptions and prescription fulfillment, as well as patients, doctors, and
pharmaceutical companies related to the prescriptions.

Restate Requirements

The details of prescription fulfillment need to be tracked. When a prescription is filled, we want to track the filling
pharmacy and date that it was fulfilled.

Each prescription is written on a specific date for one patient, by one doctor, for one drug, with the quantity of that drug
prescribed.

Every patient has a primary doctor; however, any doctor can write a prescription for any patient.

A drug is manufactured and sold by pharmaceutical company to retail pharmacies.

The drug has a generic name, and may also have a unique trade name specific to a pharmaceutical company.

If the prescription lists a drug by its generic name, then any drug with that formula name can be used to fulfill that
prescription. If prescription lists a drug by trade name, then only that specific trade name associated with a specific
pharmaceutical company can be used to fill that prescription.

A patient has a unique SSN, as well as a name, address, and age.

A doctor has a unique SSN, as well as a name, specialty, and years of experience.

A pharmaceutical company is identified by its name, and also has a phone number.

Each pharmacy has a name, address, and phone number.

Each pharmacy sells several drugs, and the price of an individual drug may vary by pharmacy.

Pharmaceutical companies have long-term contracts with pharmacies. A pharmacy can have contracts with multiple
pharmaceutical companies, and a pharmaceutical company can have contracts with multiple pharmacies.

A supervisor is appointed by the pharmacy for each contract. Each contract has a supervisor, but the supervisor may
change. One supervisor may be assigned to multiple contracts.
EER Diagram

The following is assumed in this Database:


To secure privacy, it is better to use an artificial primary key for Patient and Doctor tables rather than the natural key of
SSN.

Drug Quantity for Prescription is a positive integer greater than 1.

All phone numbers are US phone numbers and only require 9 digits.

Patient’s age is a positive integer no greater than 999.

Price is a positive number with 2 digits after the decimal point.

SSNs are standard 9 digits.

Required non- key attributes for patient entities are name andSSN.

Required non-key attributes for prescription entities are prescription number, date, and quantity.

Required non-key attribute for pharma company is company name.

Required non-key attributes for doctor entities are SSN, name, and years of experience.

Required non-key attribute for medication entity is generic name.

Required non-key attribute for pharmacy entity is pharmacy name.

Required non-key attributes for contract entities are start date, end date, and text.

Required non-key attribute for supervisor entity is supervisor name.

Max length of all varchar fields is 45.

The following constraint cannot be accomplished through SQL schema, and will need to be addressed through
application code:

If a prescription indicates a drug’s generic name, any drug with that formula name can be used to fill the prescription. If
the prescription indicates a drug’s trade name, then the specific drug from the specific associated pharmaceutical
company must be used to fill the prescription.
Relational Schema

-- MySQL Script generated by MySQL Workbench

-- Fri Feb 3 10:04:07 2023

-- Model: New Model Version: 1.0

-- 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='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION
_BY_ZERO,NO_ENGINE_SUBSTITUTION';

-- -----------------------------------------------------

-- Schema cst363

-- -----------------------------------------------------

-- DROP DATABASE IF EXISTS cst363;

-- -----------------------------------------------------

-- Schema cst363

-- -----------------------------------------------------

CREATE SCHEMA IF NOT EXISTS `testdb` DEFAULT CHARACTER SET utf8 ;

USE `cst363` ;

-- -----------------------------------------------------

-- Table `Doctor`

-- -----------------------------------------------------

-- CREATE TABLE IF NOT EXISTS `Doctor` (

-- `name` VARCHAR(45) NULL,

-- `specialty` VARCHAR(45) NULL,

-- PRIMARY KEY (`doctor_id`))

-- ENGINE = InnoDB;
-- Prof's schema for Dr table for java program

CREATE TABLE doctor (

id int NOT NULL AUTO_INCREMENT,

last_name varchar(50) NOT NULL,

first_name varchar(50) NOT NULL,

practice_since char(4) DEFAULT NULL,

specialty varchar(25) DEFAULT NULL,

ssn char(11) NOT NULL,

PRIMARY KEY (id)

);

-- DROP TABLE DOCTOR;

-- TRUNCATE DOCTOR;

-- -----------------------------------------------------

-- Table `Patient`

-- -----------------------------------------------------

CREATE TABLE IF NOT EXISTS `Patient` (

`patient_id` INT NOT NULL AUTO_INCREMENT,

`last_name` VARCHAR(45) NOT NULL,

`first_name` VARCHAR(45) NOT NULL,

`birthdate` DATE NULL,

`SSN` INT(11) NOT NULL,

`street` VARCHAR(45) NULL,

`city` VARCHAR(45) NULL,

`state` VARCHAR(45) NULL,

`zip` INT(5) NULL,

`doctor_id` INT NULL,

PRIMARY KEY (`patient_id`),

INDEX `fk_Patient_Doctor_idx` (`doctor_id` ASC) VISIBLE,


CONSTRAINT `fk_Patient_Doctor`

FOREIGN KEY (`doctor_id`)

REFERENCES `Doctor` (`id`)

ON DELETE NO ACTION

ON UPDATE NO ACTION)

ENGINE = InnoDB;

-- DROP TABLE PATIENT;

-- TRUNCATE PATIENT;

-- -----------------------------------------------------

-- Table `Drug`

-- -----------------------------------------------------

CREATE TABLE IF NOT EXISTS `Drug` (

`drug_id` int(11) NOT NULL,

`trade_name` varchar(100) DEFAULT NULL,

`formula` varchar(200) DEFAULT NULL,

PRIMARY KEY (`drug_id`))

ENGINE = InnoDB;

-- -----------------------------------------------------

-- Table `Prescription`

-- -----------------------------------------------------

CREATE TABLE IF NOT EXISTS `Prescription` (

`rxid` INT NOT NULL AUTO_INCREMENT,

`date_prescribed` DATE NULL,

`quantity` INT NULL,

`refills_allowed` INT NULL,

`patient_id` INT NOT NULL,

`doctor_id` INT NOT NULL,


`drug_id` INT NOT NULL,

PRIMARY KEY (`rxid`),

INDEX `fk_Prescription_Patient1_idx` (`patient_id` ASC) VISIBLE,

INDEX `fk_Prescription_Doctor1_idx` (`doctor_id` ASC) VISIBLE,

INDEX `fk_Prescription_Drug1_idx` (`drug_id` ASC) VISIBLE,

CONSTRAINT `fk_Prescription_Patient1`

FOREIGN KEY (`patient_id`)

REFERENCES `Patient` (`patient_id`)

ON DELETE NO ACTION

ON UPDATE NO ACTION,

CONSTRAINT `fk_Prescription_Doctor1`

FOREIGN KEY (`doctor_id`)

REFERENCES `Doctor` (`id`)

ON DELETE NO ACTION

ON UPDATE NO ACTION,

CONSTRAINT `fk_Prescription_Drug1`

FOREIGN KEY (`drug_id`)

REFERENCES `Drug` (`drug_id`)

ON DELETE NO ACTION

ON UPDATE NO ACTION)

ENGINE = InnoDB;

-- -----------------------------------------------------

-- Table `Pharmacy`

-- -----------------------------------------------------

CREATE TABLE IF NOT EXISTS `Pharmacy` (

`pharmacy_id` INT NOT NULL AUTO_INCREMENT,

`name` VARCHAR(45) NULL,

`street` VARCHAR(45) NULL,

`city` VARCHAR(45) NULL,

`state` VARCHAR(45) NULL,


`zip` INT(5) NULL,

`phone` INT(10) NULL,

PRIMARY KEY (`pharmacy_id`))

ENGINE = InnoDB;

-- -----------------------------------------------------

-- Table `Fill`

-- -----------------------------------------------------

CREATE TABLE IF NOT EXISTS `Fill` (

`fill_no` INT NOT NULL AUTO_INCREMENT,

`date_filled` DATE NOT NULL,

`rxid` INT NOT NULL,

`pharmacy_id` INT NOT NULL,

PRIMARY KEY (`fill_no`, `rxid`),

INDEX `fk_Fill_Prescription1_idx` (`rxid` ASC) VISIBLE,

INDEX `fk_Fill_Pharmacy1_idx` (`pharmacy_id` ASC) VISIBLE,

CONSTRAINT `fk_Fill_Prescription1`

FOREIGN KEY (`rxid`)

REFERENCES `Prescription` (`rxid`)

ON DELETE NO ACTION

ON UPDATE NO ACTION,

CONSTRAINT `fk_Fill_Pharmacy1`

FOREIGN KEY (`pharmacy_id`)

REFERENCES `Pharmacy` (`pharmacy_id`)

ON DELETE NO ACTION

ON UPDATE NO ACTION)

ENGINE = InnoDB;

-- -----------------------------------------------------

-- Table `PharmaCo`
-- -----------------------------------------------------

CREATE TABLE IF NOT EXISTS `PharmaCo` (

`pharmco_id` INT NOT NULL AUTO_INCREMENT,

`name` VARCHAR(45) NULL,

PRIMARY KEY (`pharmco_id`))

ENGINE = InnoDB;

-- -----------------------------------------------------

-- Table `Drug_has_PharmaCo`

-- -----------------------------------------------------

CREATE TABLE IF NOT EXISTS `Drug_has_PharmaCo` (

`pharmco_id` INT NOT NULL,

`drug_id` INT NOT NULL,

PRIMARY KEY (`pharmco_id`, `drug_id`),

INDEX `fk_PharmaCo_has_Drug_Drug1_idx` (`drug_id` ASC) VISIBLE,

INDEX `fk_PharmaCo_has_Drug_PharmaCo1_idx` (`pharmco_id` ASC) VISIBLE,

CONSTRAINT `fk_PharmaCo_has_Drug_PharmaCo1`

FOREIGN KEY (`pharmco_id`)

REFERENCES `PharmaCo` (`pharmco_id`)

ON DELETE NO ACTION

ON UPDATE NO ACTION,

CONSTRAINT `fk_PharmaCo_has_Drug_Drug1`

FOREIGN KEY (`drug_id`)

REFERENCES `Drug` (`drug_id`)

ON DELETE NO ACTION

ON UPDATE NO ACTION)

ENGINE = InnoDB;

-- -----------------------------------------------------

-- Table `Pharmacy_sells_Drug`
-- -----------------------------------------------------

CREATE TABLE IF NOT EXISTS `Pharmacy_sells_Drug` (

`pharmacy_id` INT NOT NULL,

`drug_id` INT NOT NULL,

`price` FLOAT NULL,

PRIMARY KEY (`pharmacy_id`, `drug_id`),

INDEX `fk_Pharmacy_has_Drug_Drug1_idx` (`drug_id` ASC) VISIBLE,

INDEX `fk_Pharmacy_has_Drug_Pharmacy1_idx` (`pharmacy_id` ASC) VISIBLE,

CONSTRAINT `fk_Pharmacy_has_Drug_Pharmacy1`

FOREIGN KEY (`pharmacy_id`)

REFERENCES `Pharmacy` (`pharmacy_id`)

ON DELETE NO ACTION

ON UPDATE NO ACTION,

CONSTRAINT `fk_Pharmacy_has_Drug_Drug1`

FOREIGN KEY (`drug_id`)

REFERENCES `Drug` (`drug_id`)

ON DELETE NO ACTION

ON UPDATE NO ACTION)

ENGINE = InnoDB;

-- -----------------------------------------------------

-- Table `Contract`

-- -----------------------------------------------------

CREATE TABLE IF NOT EXISTS `Contract` (

`pharmacy_id` INT NOT NULL,

`pharmco_id` INT NOT NULL,

`supervisor_name` VARCHAR(45) NULL,

`supervisor_email` VARCHAR(45) NULL,

`supervisor_phone` INT(9) NULL,

PRIMARY KEY (`pharmacy_id`, `pharmco_id`),

INDEX `fk_Pharmacy_has_PharmaCo_PharmaCo1_idx` (`pharmco_id` ASC) VISIBLE,


INDEX `fk_Pharmacy_has_PharmaCo_Pharmacy1_idx` (`pharmacy_id` ASC) VISIBLE,

CONSTRAINT `fk_Pharmacy_has_PharmaCo_Pharmacy1`

FOREIGN KEY (`pharmacy_id`)

REFERENCES `Pharmacy` (`pharmacy_id`)

ON DELETE NO ACTION

ON UPDATE NO ACTION,

CONSTRAINT `fk_Pharmacy_has_PharmaCo_PharmaCo1`

FOREIGN KEY (`pharmco_id`)

REFERENCES `PharmaCo` (`pharmco_id`)

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;
Patient Form

The Patient Register form has nine fields to enter. Patient’s SSN, first name, last name, birthdate, street, city,
state, zip code, and Primary Physician Name. Each field must have the correct input from the patient to be valid.

When the user enters an invalid entry the form throws an error to warn about the incorrect input.
Successful update and found patient.

When adding a New Prescription, we are encountering an error that will need to be corrected with an update patch.
Conclusions

Data and Stuff Consulting have built a database that doctors and patients can trust and have confidence in using.
With reliable software that can keep track of patients prescriptions. While doctors can prescribe medication to their
patients knowing the software can help deliver the needs of their patients. Data and Stuff Consulting looks forward to
building the bridge between a patient and their physician.

You might also like