database management_ pharmacy tracking system
TRANSCRIPT
BYGB 7973, FALL2016, DATABASE MANAGEMENT
Project Phase 3
Instructor: Dr. W. RP Raghupathi
Sam Wilson: Qianxia Zhu, Hong Dai, Jian Jin, Duanrui Shi, Jianyu Pan
P a g e | 1
1. Revised Entity-Relationship Model for Pharmacy Database System
P a g e | 2
2. Assumptions of Entity-Relationship Model
Note: Directions, Rx Drug Quantity, Rx Date Filled, Number of Refills, Number of Refills
Remaining, Rx Total Price and Rx Drug Price are descriptive attributes that describe the
relationship between Drug and Prescription.
P a g e | 3
3. Data Dictionary of Entity Relationship Diagram for Pharmacy Database System
Entity Attributes Data type Length Primary Key
Physician Physician ID
Physician Name
Physician Street
Physician City
Physician Zipcode
Physician State
CHAR
CHAR
CHAR
CHAR
CHAR
CHAR
20
20
20
20
20
20
√
Patient Patient ID
Patient Name
Patient Street
Patient City
Patient Zipcode
Patient State
Patient Date of Birth
Patient Family Member Name
CHAR
CHAR
CHAR
CHAR
CHAR
CHAR
DATE
CHAR
20
20
20
20
20
20
Default
20
√
Prescription Rx ID
Rx Original Date
Number of Refills
Rx Drug Quantity D
Rx Date Filled D
Number of Refills Remaining D
Rx total Price D
CHAR
DATE
NUMERIC
NUMERIC
DATE
NUMERIC
NUMERIC
20
Default
5
5
Default
5
5
√
Insurance
Claim
Insurance Claim Number
Insurance Claim Date
Insurance Company Policy no.
Insurance Company Name
Amount Paid
Insured Name
CHAR
DATE
CHAR
CHAR
NUMERIC
CHAR
20
Default
20
20
5
20
√
P a g e | 4
Relationship to insured person CHAR 5
Drug Drug ID
Drug Name
Drug Form
Drug Strength
Drug Price
Quantity on Hand
Quantity on Order
Quantity on Order Date
Unit Cost
Controlled Substance Notation
Recorder Point
Directions D
CHAR
CHAR
CHAR
CHAR
NUMERIC
NUMERIC
NUMERIC
DATE
NUMERIC
CHAR
NUMERIC
CHAR
20
20
20
5
5
5
5
Default
5
20
5
20
√
Payment Payment Number
Payment Date
Payment Type
Amount Due
CHAR
DATE
CHAR
NUMERIC
20
Default
20
5
√
Supplier Supplier Name
Supplier Street
Supplier City
Supplier Zipcode
Supplier State
CHAR
CHAR
CHAR
CHAR
CHAR
20
20
20
20
20
√
P a g e | 5
4. Default Physical Data Model for Pharmacy Database System
P a g e | 6
5. Revised Physical Data Model for Pharmacy Database System
P a g e | 7
6. Normalized Physical Data Model for Pharmacy Database System
P a g e | 8
7. Assumptions for Normalized Physical Data Model
a) PatientFamilyMemberName is a repeating group that should be included in primary
key.
b) PatientName, PatientStreet, PatientCity, PatientZipcode, PatientState and
PatientDateofBirth depend only on PatientID.
c) PaymentType is a repeating group which should be included in primary key.
d) PaymentDate depends only on PaymentNumber.
e) AmountPaid depends only on PaymentType.
f) Amount Due should be deleted from table because it could be calculated.
a. Amount Due = (Rx-total-price) – (Amount Paid)
g) Insurance policy number depends on Insurance Company Name.
h) Insurance policy number is a repeating group that should be included in primary key.
i) Rx-total-price should be deleted from table because it could be calculated.
a. Rx-total-price = ∑ (𝑅𝑥𝐷𝑟𝑢𝑔𝑄𝑢𝑎𝑛𝑡𝑖𝑡𝑦 ∗ 𝑅𝑥𝐷𝑟𝑢𝑔𝑃𝑟𝑖𝑐𝑒)
j) NumberofRefillsRemaining should be deleted from table because it could be
calculated.
a. NumberofRefillsRemaining = NumberofRefills – Count(RxDatefilled)
P a g e | 9
10. Tables with Data
1. Drug
DRUG
ID
DRUGNA
ME
DRUGFO
RM
DRUGSTREN
GTH
QUANTITYON
HAND
QUANTITYONO
RDER
1 Tylenol Tablets 8 50 65
2 Alka Capsules 15 35 70
3 Pepto Elixirs 6 45 85
QUANTITYONOR
DERDATE
UNITCO
ST
CONTROLLEDSUBSTAN
CENOTATION
REODERP
OINT
SUPPLIER
NAME
10/22/2012 5 Yes 30 CVS
6/1/2013 6 No 50 DR
9/1/2015 7 Yes 45 PHA
2. Insurance Company
INSURANCECOMPANYNAME INSURANCEPOLICYNUMBER
Aetna 67851
Emblem 35627
United 56786
P a g e | 10
3. Insurance Claim
INSURANCE
CLAIMNUM
BER
INSURAN
CECLAIM
DATE
INSUR
EDNA
ME
RELATIONSHI
PTOINSUREDP
ERSON
INSURANCE
COMPANYN
AME
INSURANCE
POLICYNU
MBER
x2635 3/3/2015 John Father Emblem 35627
x5263 4/3/2015 Charlot
te
Mother United 56786
x1736 12/6/2015 Emma Daughter United 56786
4. Patient
PATIE
NTID
PATIEN
TNAME
PATIENTDAT
EOFBIRTH
PATIENT
STREET
PATIEN
TCITY
PATIENTZ
IPCODE
PATIENT
STATE
1 Tom 2/1/1985 10 St Chico 95928 CA
2 Kerry 4/22/1987 34 Ave Chico 95938 CA
3 Chen 3/1/1986 43 Lane Fremont 96928 CA
4 Harry
Potter
3/4/1988 4 way Fremont 91928 CA
5. Patient Family Member Name
PATIENTID PATIENTFAMILYMEMBERNAME
1 Tommy
2 Kerryae
4 Helen
6. Payment
PAYMENTNUMBER INSURANCECLAIMNUMBER PAYMENTTYPE
267398 x2635 CASH
837640 x5263 CREDIT
984620 x1736 DEBIT
P a g e | 11
7. Payment Number
PAYMENTNUMBER PAYMENTDATE
267398 12/24/2013
837640 11/22/2011
984620 3/12/2008
8. Payment Type
PAYMENTTYPE AMOUNTPAID
CASH 893
CREDIT 666
DEBIT 897
9. Physician
PHYSICI
ANID
PHYSICIAN
NAME
PHYSICIANS
TREET
PHYSICIA
NCITY
PHYSICIANZI
PCODE
PHYSICIAN
STATE
a2487 Thomas
Smith
62st New York
City
10011 New York
a7334 Paul Frank 55st Jersey 7094 New Jersey
a1819 Chery Mark 50st Secaucus 7095 New Jersey
10. Prescription
RX
ID
RXORIGIN
ALDATE
PHYSIC
IANID
PATIE
NTID
PAYMENTN
UMBER
PAYMEN
TTYPE
PATIENTFAMILYM
EMBERNAME
b24
87
3/27/2015 a2487 1 267398 CASH Tommy
b73
34
4/13/2015 a7334 2 837640 CREDIT Kerryae
b18
19
2/15/2015 a1819 4 984620 DEBIT Helen
P a g e | 12
11. Prescription_x_Drug
R
XI
D
DR
UGI
D
DIREC
TIONS
D
RXDRU
GPRICE
D
RXDATE
FILLED
D
RXDRUGQ
UANTITY
D
NUMBERO
FREFILLS
D
NUMBEROFREFI
LLSREMAINING
D
b2
48
7
1 Three
times a
day
5 11/11/201
2
55 10 5
b7
33
4
2 Every
eight
hours
6 10/31/201
0
65 15 8
b1
81
9
3 Two
times a
day
7 6/22/2013 45 10 8
12. Supplier
SUPPLIERNA
ME
SUPPLIERSTR
EET
SUPPLIERCI
TY
SUPPLIERZIPC
ODE
SUPPLIERSTA
TE
CVS 66st New York 10017 New York
DR 53st Jersey 7084 New Jersey
PHA 73st Atlantic 9033 New Jersey
P a g e | 13
11. The 10 Queries
i. English version: #List Drug Name, Drug Forms, Number of Refilled, Supplier City.
Select drug.drugname,drug.drugform,prescription_x_drug.NUMBEROFREFILLSD, supplier.su
ppliercity
From prescription, drug, supplier,prescription_x_drug
Where supplier.suppliername=drug.suppliername
And prescription.rxid=prescription_x_drug.rxid and
prescription_x_drug.drugid=drug.drugid
DRUGNAME DRUGFORM NUMBEROFREFILLSD SUPPLIERCITY
Tylenol Tablets 10 New York
Alka Capsules 15 Jersey
Pepto Elixirs 10 Atlantic
ii. English version: #List payment number, Insurance Claim Date, Insurance Company Name
and Relationship to Insured Person.
Select payment.paymentnumber,insuranceclaimdate,INSURANCECOMPANYNAME, RELATI
ONSHIPTOINSUREDPERSON
from prescription, insurance_claim,payment
P a g e | 14
Where payment.paymentnumber=prescription.paymentnumber
and insurance_claim.insuranceclaimnumber= payment.insuranceclaimnumber
PAYMENTN
UMBER
INSURANCECLA
IMDATE
INSURANCECOMP
ANYNAME
RELATIONSHIPTOINSU
REDPERSON
267398 3/3/2015 Emblem Father
837640 4/3/2015 United Mother
984620 12/6/2015 United Daughter
iii. English version: #List Drug Name, Drug Forms, Rx Original Date, Payment Number.
Select drug.drugname,drug.drugform,prescription.RXORIGINALDATE,payment.paymentnumb
er
From prescription, drug, payment,PRESCRIPTION_X_DRUG
Where payment.paymentnumber=prescription.paymentnumber
And prescription.rxid = PRESCRIPTION_X_DRUG.rxid
and PRESCRIPTION_X_DRUG.drugid=drug.drugid
DRUGNAME DRUGFORM RXORIGINALDATE PAYMENTNUMBER
Tylenol Tablets 3/27/2015 267398
Alka Capsules 4/13/2015 837640
Pepto Elixirs 2/15/2015 984620
P a g e | 15
iv. English version: #List Drug Name, Drug Form, Number of Refilled, Supplier city.
Select drugname,drugform,PRESCRIPTION_X_DRUG.NUMBEROFREFILLSD,suppliercity
From prescription, drug, supplier,PRESCRIPTION_X_DRUG
Where supplier.suppliername=drug.suppliername
And prescription.rxid=PRESCRIPTION_X_DRUG.rxid
and PRESCRIPTION_X_DRUG.drugid=drug.drugid
DRUGNAME DRUGFORM NUMBEROFREFILLSD SUPPLIERCITY
Tylenol Tablets 10 New York
Alka Capsules 15 Jersey
Pepto Elixirs 10 Atlantic
v. English version: #Calculate Rx Total Price of each Rx ID.
Select PRESCRIPTION_X_DRUG.rxid, (rxdrugquantityd*rxdrugpriced) as rxtotalprice from PRESCRIPTION_X_DRUG
vi.
RXID RXTOTALPRICE
B2487 275
B7334 390
B1819 315
P a g e | 16
vi. English version: #List Patient ID, Rx Original Date, ordered by Patient ID.
selectpatient.patientid, prescription.rxoriginaldate
from patient, prescription
where patient.patientid = prescription.patientid
order by patient.patientid
PATIENTID RXORIGINALDATE
1 3/27/2015
2 4/13/2015
4 2/15/2015
vii. English version: #List Number of Refills Used for each Rx ID.
select prescription.rxid,(NUMBEROFREFILLSD - NUMBEROFREFILLSREMAININGD) as n
umberofrefillsused
from PRESCRIPTION_X_DRUG, prescription
where PRESCRIPTION_X_DRUG.rxid =PRESCRIPTION.rxid
RXID NUMBEROFREFILLSUSED
b2487 5
b7334 7
b1819 2
P a g e | 17
viii. English version: #List Patient Name, Patient City, Rx ID who was born befor 1986-01-01.
selectpatientname,patientcity,prescription.rxid
from patient,prescription
where patient.patientid=prescription.patientid and patientdateofbirth< '1986-01-01'
PATIENTNAME PATIENTCITY RXID
Tom Chico b2487
ix. English version: #List Rx ID, Payment Number where Rx Original Date is later than 2014.
selectprescription.rxid,payment.paymentnumber
from prescription,payment
where prescription.paymentnumber = payment.paymentnumber
and year(prescription.rxoriginaldate)>2014
RXID PAYMENTNUMBER
b2487 267398
b7334 837640
b1819 984620
P a g e | 18
x. English version: #List PaymentType and count the number of each Paymenttype.
selectpayment.paymenttype,count(prescription.rxid) as numbers_of_prescription
from payment,prescription
where prescription.paymentnumber = payment.paymentnumber
group by payment.paymenttype
PAYMENTTYPE NUMBERS_OF_PRESCRIPTION
CASH 1
CREDIT 1
DEBIT 1