Lab19 Web App SQL
Lab19 Web App SQL
Lab19 Web App SQL
June 4, 2024
ER diagram:
Introduction:
This database was designed to facilitate the tracking of patient prescriptions for
pharmacies. Along with prescription data, the database also manages doctor and
patient information. This design efficiently manages validation of doctor, patient, and
drug information. The database also tracks prescription fills and refills as well as
variations in pricing from different pharmacies.
Requirements:
● All doctors who have registered with the application must be tracked.
A Doctor table is created in the database to hold all of the information pertaining to the
doctors registered on the application.
● All patients who have registered with the application must be tracked.
A Patient table is created in the database to hold all of the information pertaining to the
patients registered on the application.
A Drug table is created in the database to hold a list of all of the prescription drugs
offered.
The Drug_Cost table holds the information for the cost of a drug at a given pharmacy.
The Drug_Cost table connects the Pharmacy and Drug tables. The cost attribute is
assigned the price that the particular pharmacy charges for the drug, and the
unit_amount attribute holds the number of tablets sold at the given price.
● Each time a prescription is filled, the database must track the pharmacy that
filled the prescription, the total cost, and the date it was filled.
The Prescription_Fill table tracks the pharmacy that filled the prescription, the total cost,
and the date the prescription was filled. The total cost is calculated with the cost
attribute in the Drug_Cost table and the quantity of the drug in the Prescription table.
Name: doctor
Description: A doctor is any doctor that has been registered on the web application.
Each doctor has an auto generated primary key for identification. The table records the
doctor’s unique social security number (ssn), first name and last name. Doctors may
also specify a specialty, and the date when they first started practicing. Each doctor may
have many patients and may write many prescriptions.
Name: patient
Description: A patient is a person registered under the care of a doctor. Each patient
has an auto generated primary key for identification. The table records the unique social
security number (ssn), first name, last name, birth date, and the street, city, state, and
zip code of the patient. The state is recorded as a two character abbreviation. Every
patient must have one primary doctor and may have many prescriptions.
Name: prescription
Name: drug
Description: A drug represents any drug tracked in the database. Each drug has a
name. Each drug can be prescribed multiple times.
Name: pharmacy
Name: drug_cost
Description: The Drug_Cost table tracks the cost each pharmacy charges for a set
amount of a drug. It records the cost that a particular pharmacy charges, and unit
amount of the drug sold at that price.
Name: prescription_fill
Description: The Prescription_Fill table connects the Pharmacy and Prescription tables.
It also records the cost to the patient, and the date the prescription was filled.
SQL schema:
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_DA
TE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTI
ON';
-- -----------------------------------------------------
-- Schema prescription
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema prescription
-- -----------------------------------------------------
USE `prescription` ;
-- -----------------------------------------------------
-- Table `prescription`.`doctor`
-- -----------------------------------------------------
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `prescription`.`patient`
-- -----------------------------------------------------
CONSTRAINT `fk_Patient_Doctor`
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- ----------------------------------------------------
-- Table `prescription`.`drug`
-- -----------------------------------------------------
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `prescription`.`prescription`
-- -----------------------------------------------------
CONSTRAINT `fk_Prescription_Doctor1`
FOREIGN KEY (`doctor_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Prescription_Patient1`
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Prescription_Drug1`
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `prescription`.`pharmacy`
-- -----------------------------------------------------
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `prescription`.`drug_cost`
-- -----------------------------------------------------
CONSTRAINT `fk_Pharmacy_has_Drug_Pharmacy1`
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Pharmacy_has_Drug_Drug1`
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `prescription`.`prescription_fill`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `prescription`.`prescription_fill` (
CONSTRAINT `fk_table1_Prescription1`
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_table1_Pharmacy1`
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;
Screenshots:
Register as a new patient with last name “Simpson”, city “Rockville”, zip code 62701
and a doctor with name “Spock”. Show a successful registration.
Attempt to register as a new patient with last name “Burns” but with a doctor name that
does not exist. Show a screenshot of the patient register form with the error message.
Create a prescription for the patient “Simpson” and doctor “Spock” for a drug “lisinopril”
and quantity 90. Show the screen with the success message and prescription display.
Attempt to create a prescription with an invalid drug name. Show a screen with the
create prescription form and error message.
Attempt to fill a prescription with an invalid pharmacy name.
Get the profile for patient “Simpson” and edit the patient record for “Simpson” and
change city to Springfield and zip code to 61705. Show the web page of the successful
update.
Edit the patient record for “Simpson”. Attempt to change the doctor’s name to a doctor
that does not exist. Show the error message and edit patient form.