You are on page 1of 14

Running head: MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 1

Module 4: Database Schema-SQL Statements

Sujata Mathew

Grand Canyon University: HIM-650 Healthcare Data Management

June 9, 2020
MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 2

Module 4: Database Schema-SQL Statements

Create Table Patient

CREATE TABLE Patient(

PatientID Integer PRIMARY KEY,

FirstName Varchar(50),

MiddleName Varchar(50),

LastName Varchar(50),

Address1 varchar(100),

Address2 varchar(100),

City varchar(100),

State varchar(2),

Zip Integer(5)

);

Populating Table Patient

INSERT INTO Patient(PatientID, FirstName, MiddleName, LastName, Address1, Address2,

City, State, Zip)

VALUES('01','Joseph', 'Smith', 'Hillary', ' Melbourne 37th Ave', 'Opp Hilton Hotel', 'Melbourne',

'TZ', '41000');

INSERT INTO Patient(PatientID, FirstName, MiddleName, LastName, Address1, Address2,

City, State, Zip)


MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 3

VALUES('11','Mary', 'Jane', 'Alan', ' New York 37th Ave', 'NY Game Reserve', 'New York',

'NY', '00100')

INSERT INTO Patient(PatientID, FirstName, MiddleName, LastName, Address1, Address2,

City, State, Zip)

VALUES('21','Charles', 'Dawkins', 'Murray', 'California 5th Ave', 'Adj Junction Mall', 'Los

Angeles', 'CA', '00900')

INSERT INTO Patient(PatientID, FirstName, MiddleName, LastName, Address1, Address2,

City, State, Zip)

VALUES('31','Samuel', 'Harris', 'Festus', 'Maryland 22th Ave', 'Lounge Alfas', 'Baltimore', 'MA',

'00300')

Create Table Doctor

CREATE TABLE Doctor(

DoctorID integer PRIMARY KEY,

FirstName Varchar(50),

MiddleName Varchar(50),

LastName Varchar(50),

Address1 varchar(100),

Address2 varchar(100),

City varchar(100),

State varchar(2),
MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 4

Zip Integer(5)

);

Populating Table Doctor

INSERT INTO Doctor(DoctorID, FirstName, MiddleName, LastName, Address1, Address2,

City, State, Zip)

VALUES('101','Avery', 'Harper', 'Mason', 'Ilinois 7th Ave', 'Platinumz 44', 'Chicago', 'IL',

'10200')

INSERT INTO Doctor(DoctorID, FirstName, MiddleName, LastName, Address1, Address2,

City, State, Zip)

VALUES('111','Evelyn', 'Williams', 'Frank', 'Alabama 13th Ave', 'J.C. Place', 'Montgomery',

'AL', '37400')

INSERT INTO Doctor(DoctorID, FirstName, MiddleName, LastName, Address1, Address2,

City, State, Zip)

VALUES('121','Arthur', 'Josphat', 'Ephraim', 'Los Palace 13th Ave', 'Jos Delivarna', 'Los

Angeles', 'CA', '37920')

INSERT INTO Doctor(DoctorID, FirstName, MiddleName, LastName, Address1, Address2,

City, State, Zip)

VALUES('131','Smith', 'Jason', 'Bruce', 'Balimore 23th Ave', 'Mary Leaky Water', 'Baltimore',

'MA', '70020')
MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 5

Create Table Medication

CREATE TABLE Medication(

MedicationID Integer PRIMARY KEY,

BrandName varchar(150),

GenericName varchar(150),

PackageName varchar(150),

NDC11 varchar(11),

Dosage varchar(11),

Strength varchar(50)

);

Populating Table Medication

INSERT INTO medication(MedicationID, BrandName, GenericName, PackageName, NDC11,

Dosage,

Strength)

VALUES('1001','AlpraBeta', 'Alprazolam', 'AlpraBeta', 'NDC 012-928-399', '5mls', '500mg')

INSERT INTO medication(MedicationID, BrandName, GenericName, PackageName, NDC11,

Dosage,

Strength)

VALUES('1002','Metronidazole', 'Metronidazole', 'Metronidazole', 'NDC 432-939-222', '7.5mls',

'500mg')
MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 6

INSERT INTO medication(MedicationID, BrandName, GenericName, PackageName, NDC11,

Dosage,

Strength)

VALUES('1003','clindamycin', 'Clindesse', 'Clindesse Ultra', 'NDC 482-239-722', '7.5mls',

'100mg')

INSERT INTO medication(MedicationID, BrandName, GenericName, PackageName, NDC11,

Dosage,

Strength)

VALUES('1004','peramivir', 'Rapivab', 'Rapivab BioCryst', 'NDC 633-472-839', '10mls',

'600mg')

Create Table Prescription

CREATE TABLE Prescription(

PrescriptionID integer PRIMARY KEY,

MedicationID integer,

PatientID integer,

PrescriptionDate integer

);

Populating Table Prescription

INSERT INTO prescription(prescriptionID, medicationID, PatientID, prescriptionDate)


MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 7

VALUES('250','1004', '21', '2020/01/03')

INSERT INTO prescription(prescriptionID, medicationID, PatientID, prescriptionDate)

VALUES('2050','1002', '11', '2020/03/04')

INSERT INTO prescription(prescriptionID, medicationID, PatientID, prescriptionDate)

VALUES('20050','1001', '21', '2019/11/04')

INSERT INTO prescription(prescriptionID, medicationID, PatientID, prescriptionDate)

VALUES('200050','1001', '31', '2019/12/28')

Create Table Procedure

CREATE TABLE MedicalProcedure(

ProcedureID integer PRIMARY KEY,

PatientID integer,

DoctorID integer,

ProcedureDate Date,

CPT varchar(150),

ProcedureDescription varchar(150),

AdmissionID integer(8)

);

Populating Table Prescription


MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 8

INSERT INTO medicalprocedure(ProcedureID, PatientID, DoctorID, ProcedureDate, CPT,

ProcedureDescription, AdmissionID )

VALUES('1010','31', '111', '2019/12/28', 'moderate sedation', 'Relaxing and Calming',

'91827364');

INSERT INTO medicalprocedure(ProcedureID, PatientID, DoctorID, ProcedureDate, CPT,

ProcedureDescription, AdmissionID )

VALUES('2020','21', '121', '2019/11/04', 'Chest Wall and Shoulder Girdle Anaesthesia', 'Limb-

girdle muscular dystrophie', '83927502');

INSERT INTO medicalprocedure(ProcedureID, PatientID, DoctorID, ProcedureDate, CPT,

ProcedureDescription, AdmissionID )

VALUES('3030','11', '121', '2020/03/04', 'Preventive diagnostic/screening', 'Physical

Examinations', '57939592');

INSERT INTO medicalprocedure(ProcedureID, PatientID, DoctorID, ProcedureDate, CPT,

ProcedureDescription, AdmissionID )

VALUES('4040','21', '101', '2020/01/03', 'Multianalyte Assay', 'Algorithmic Procedure',

'53927473');

Create Table Billing

CREATE TABLE Billing(

BillingID integer PRIMARY KEY,


MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 9

MedicationID integer,

PatientID integer,

BillingDate date

);

Populating Table Prescription

INSERT INTO Billing(BillingID, MedicationID, PatientID, BillingDate)

VALUES('7007','1004', '21', '2020/01/03');

INSERT INTO Billing(BillingID, MedicationID, PatientID, BillingDate)

VALUES('7070','1002', '11', '2020/03/04');

INSERT INTO Billing(BillingID, MedicationID, PatientID, BillingDate)

VALUES('7700','1001', '21', '2020/01/03');

INSERT INTO Billing(BillingID, MedicationID, PatientID, BillingDate)

VALUES('7707','1010', '31', '2019/12/28');

Add Column “Deleted_Table”

ALTER TABLE billing ADD COLUMN Deleted_Date varchar(250)

ALTER TABLE doctor ADD COLUMN Deleted_Date varchar(250)

ALTER TABLE medicalprocedure ADD COLUMN Deleted_Date varchar(250)


MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 10

ALTER TABLE medication ADD COLUMN Deleted_Date varchar(250)

ALTER TABLE patient ADD COLUMN Deleted_Date varchar(250)

ALTER TABLE prescription ADD COLUMN Deleted_Date varchar(250)

A “Deleted_Date” Marker-Column

Database users can delete records mistakenly (Liu & Muse, 2017). This challenge affects

database maintenance due to its inability to reverse the action leading to unnecessary loss of data

and declined data integrity. Hence, the “Deleted_Date” column guarantee that the column is not

necessary deleted but rather marked as deleted. In this way, database users enjoy significant

tradeoffs such as having the provision to undo an unintentional deletion of a record (Lacher et

al., 2015). Moreover, the marker-column ensures that a permanent delete action can only be done

from the administrator’s side who can delete the CHECK constraint (Riefstahl, n.d.). With such

tradeoffs, database users are guaranteed of support against unintentional mistakes.

Questions

Question 1

SELECT Name FROM Doctor;

Question 2

SELECT COUNT(PatientID) FROM patient WHERE DoB < '1994/01/01';

Question 3
MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 11

SELECT Patient.PatientID, Patient.Name, Patient.DoB, prescription.PrescriberID FROM patient

INNER JOIN prescription ON prescription.PatientID = patient.PatientID;

Question 4

SELECT patient.Name, patient.DoB, medication.BrandName, prescription.PrescriberID

WHERE patient.PatientID = prescription.PatientID AND medication.MedicationID =

prescription.MedicationID;

Question 5

SELECT GenericName FROM Medication WHERE MedicationID IN

(SELECT TOP 1 MedicationID FROM (SELECT MedicationID, COUNT(MedicationID)

FROM Prescription GROUP BY MedicationID ORDER BY COUNT(MedicationID) DESC));


MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 12

SQL Queries

Question 1

SELECT Name FROM doctor;

Question 2

SELECT COUNT(PatientID) FROM patient WHERE DoB < '1994/01/01';

Question 3

SELECT Patient.PatientID, Patient.Name, Patient.DoB, prescription.PrescriberID FROM patient

INNER JOIN prescription ON prescription.PatientID = patient.PatientID;

Question 4

SELECT patient.Name, patient.DoB, medication.BrandName, prescription.PrescriberID FROM

prescription INNER JOIN patient ON patient.PatientID = prescription.PatientID JOIN

medication ON medication.MedicationID = prescription.MedicationID ORDER BY

Prescription.Date;

Question 5

SELECT prescription.MedicationID, Medication.BrandName FROM medication AS Bra1

INNER JOIN Prescription ON Prescription.MedicationID = Medication.MedicationID WHERE

MaxBrand =

(SELECT MAX(Bra2.Num) AS Max

FROM (SELECT COUNT(Prescription.MedicationID) AS Num FROM Prescription INNER

JOIN Medication ON Prescription.MedicationID = Medication.MedicationID GROUP BY

Prescription.MedicationID) AS Bra2) AND Bra1.MedicationID = Bra2.MedicationID;


MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 13

References

Lacher, L., Walia, G., Fagerholm, F., Pagels, M., Nygard, K., & Münch, J. (2015). A behavior

marker tool for measurement of the non-technical skills of software professionals: An empirical

investigation.

Liu, J., & Muse, S. V. (2017). PowerMarker V3. 0 Manual.

Riefstahl, F. (n.d.) FastGAPP v2. 0 Manual & Documentation.

Instructors Comments Database Schema-SQL Statements : Sujata, very good create table

statements, but all integer fields, like Patient ID and Medication ID, need a defined length. Your

create statements are also good but integer values are not enclosed in quotes. Very nice addition

of deleted_date.

Instructors Comments SQL Queries: Sujata, your first three queries are perfect in terms of

structure and nearly perfect in syntax. Query four requires the addition of Doctor and please see

the attached for challenging query five. 4. The prescription information along with patient name,

DOB, medication brand name, and prescribing doctor name sorted by most recent date. SELECT

Prescription.*, Patient.Name, Patient.DOB, Medication.BrandName, Doctor.Name FROM

( ((Prescription INNER JOIN Patient ON Prescription.PatientID=Patient.PatientID) INNER

JOIN Medication ON Medication.MedicationID=Prescription.MedicationID) INNER JOIN

Doctor ON Doctor.DoctorID=Prescription.PrescriberID) ORDER BY Prescription.Date DESC;

5. The most prescribed generic medication name. SELECT TOP 1 GenericName FROM
MODULE 4: DATABASE SCHEMA-SQL STATEMENTS 14

Medication INNER JOIN Prescription ON Medication.MedicationID=Prescription.MedicationID

GROUP BY GenericName ORDER BY COUNT (PrescriptionID) DESC;

You might also like