Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation)...

25
Database for Premier Elder Care Team 2 Adrian Quiroz, Gerardo PachecoMontalvo, Sida Ye, Jonathan Lee, YuHao Jiang, Beril Burcak, Yee Tung Man, Tian Zou, Zak Koltun

Transcript of Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation)...

Page 1: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Database for Premier Elder Care

Team 2 Adrian Quiroz, Gerardo Pacheco Montalvo, Sida Ye, Jonathan Lee, YuHao Jiang, Beril Burcak, Yee Tung Man, Tian Zou, Zak Koltun

Page 2: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Introduction

Simplified EER Diagram

Rational Schema

Relational Design(Access implementation)

Normalization

Query and SQL implementation

Agenda

Page 3: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

IntroductionPremier Elder Care strives to provide high quality, reliable and affordable care to seniors, persons recovering from surgery, or those who are physically challenged in the comfort of their own homes with the highest possible level of independent living.

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 4: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Simplified EER Diagram

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 5: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Relational Design Schema1 Person (SSN, DOB, Gender, Email, Fname, Lname, MI, Str.Add, City, Phone,Age

a) Client(SSN, …, Account_Number.11)

b) Patient(SSN, …, PID, Condition, Service_Needed, Allergic_Reaction, IC_Name.4, EMCID.14a, SSN/PID.1a, Mname.2)

c) Employee(SSN, …, Type, Title, Hourly_Rate, Salary, Term_Contract, Start_Date, IC_Name.4, Mname.2)

d) Dependent(SSN, …, )

e) Prospective_Client(SSN, …, Condition, EID.3 )

2 Medication(Mname, Type, Components, Condition)

3 Event&Workshop(EID, Duration, Frequency_Per_Month, Cost, Location, Type, SchID.8, LID.12, At_Emp1)

4 Insurance_Company(IC_Name, Type, Address, Phone, Insurance_Programs

5 Payments(Pay_ID, Payment_Type, Date, Amount, Payed_By, Payed_To, IC_Name.4, Employee.1c, OID.13, EID.3

6 Service(SID, Duration, Difficulty_Level, Type, Date, Location, Performing_Employee,

a) Daily Activity(SID, …, Performing_Employee, Used_Medicine

b) Instrumental Activity(SID, …, Performing_Employee, Cost , Requirements

7 Contract(CID, Duration, Amount, SSN/PID.1b, S.Time.8, S.Days.8, SSN/PID.1c, SSN/PID.1a, Account_Number.11, LID.12

8 Schedule(S.Time, S.Days, Available_Employees, Patients_Needed

9 Inventory_Items(IID, OID.13, Product_Name, Type, Dimensions, Weight, Material, Supplied_by, Checked-in_by, 10 Supplier&Contractor(Supp_ID, Service_Name, Address, Phone, Items11 Account(Account_Number, Owner, Bank)12 Location(LID, Address, Place_Name, Cost, Open_Time )

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 6: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Relational Design Schema ( continued)

13Orders(OID, Items, Quantity, Cost, Ordered_By, Supp_ID.10) 14Emergency_Contact (EMCID, Phone

14a. Primary_Doctor(EMCID, Phone, License_Num, Specialty, Hospital_Name15 14b. Others(EMCID, Phone, Relationship16 Has(SSN/PID.1c, SSN/PID.1d )17Provides(SSN/PID.1c, SID.6 )18Takes(SSN/PID.1b, M.Name.2 )19Gives_Feedback(SSN/PID.1c, SSN/PID.1b, NoteByEmployee, NoteByPatient 20Receives(SID.6, SSN/PID.1b )21Consists(SID.6, CID.7 )21 Consists(SID.6, CID.7 )22 Contacts(SSN/PID.1b, EMCID.14 )23 Invited_To(SSN/PID.1, EID.3 )24 Related_To(SSN/PID.1b, EMCID.14b )25 Acquired_Through(EID.3, SSN/PID.1e )

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 7: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Access implementation of relational design

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 8: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Normalization

Functional dependencies:

1.Patient (SSN, DOB, Gender, Email, Fname, Lname, MI, Str.Add, City, Phone, Age, PID, Condition, Service_Needed, Allergic_Reaction, IC_Name.4, , SSN/PID.1a, Mname.2)

SSN Condition SSN Service_Needed

SSN Allergic_Reactio

n

SSN EMCID DOB Age

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 9: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

1NF:

Condition (SSN, ConditionID, Condition)

Service_Needed (SSN, ServiceID, Service_Needed )

Allegic_Reaction(SSN, AllergicID,

Allergic_Reaction)

EMCID (SSN, EMCID)

3NF:

Birthday (DOB, Age)

Patient (SSN, DOB, Gender, Email, Fname, Lname, MI, Str.Add, City, Phone, PID, IC_Name.4, SSN/PID.1a, Mname.2)

This is also in BCNF

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 10: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

1NF:

Type_details (IID, TypeID, description)

2NF:

Order details (OID, Supplied_by,

Checked_in_by)

3NF

Item_info(Product_Name, descripton)

Inventory_Items(IID, Product_Name, Dimensions,

Weight, Material)

This is also in BCNF

8. Inventory_Items(IID, OID.13, Product_Name, Type, Dimensions, Weight, Material, Supplied_by, Checked-in_by, descripton)

Functional dependencies: IID TypeOID

Supplied_by, Checked_in_by

Product_Name description

Introduction EER Diagram Schema Tables Normalization Query & SQL

Normalization( 2)

Page 11: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Query 1: Demand Corrections Each year, the care center will predict some expectations of demand for different

kinds of service and manage the employees into different services in order to improve the human capital’s efficiency. For example, the company expects that they are going to provide fifty service A, forty three service B and sixty seven service C. While the actual number they provide is fifty eight service A, thirty three service B and seventy service C. Thus, we can use the chi-square test to say whether the company needs to make some adjustments on its predication demands for different services. In this way, the company can decide whether to hire more employee for different services.

Chi-square equation:

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 12: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Q1:Demand Corrections SQL

[Query: Observed_Value]SELECT sid, count(sid) AS observed_serviceFROM daily_activityWHERE date like '**/**/2013'GROUP BY sid; [Query: Expected_Value]SELECT Daily_Activity.sid, Count(Daily_Activity.sid) AS total, (total/3) AS expected_valueFROM Daily_ActivityWHERE Daily_Activity.date Like '**/**/2013' OR '**/**/2012' OR '**/**/2011'GROUP BY Daily_Activity.sid;

SELECT sum((o.observed_service-e.expected_value)^2)/sum(e.expected_value) AS chisquare, iif (chisquare<3.84, "Do not need to adjust the demand", "Should adjust the demand") AS conclusionFROM daily_activity AS d, observed_value AS o, expected_value AS eWHERE o.sid=e.sid;

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 13: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Introduction EER Diagram Schema Tables Normalization Query & SQL

Q1:Demand Corrections Outcome

Page 14: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Query 2: Feedback ranking

The business justification for the query, how it will benefit their organizationAllows the management staff to access the service performance of each employee base on the quality index in selected date range.

The model you are using, give the mathematical formula explain variables, and provide a reference.The quality index is evaluated base on the total service hour an employee has completed and the total score each employee receives for each of the service in a certain date range. It can be evaluated as

where represents the score received at each service and

represents the hours provided at each service.

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 15: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Q2:Feedback ranking SQL & outcomeSELECT S.SSN_Employee, ROUND((SUM(G.Rate_Score)/SUM(S.Duration_hrs)), 3) AS quality_index

FROM Service AS S, Gives_Feedback AS GWHERE (((S.Date) Between [Start Date] And [End Date]))

GROUP BY S.SSN_EmployeeORDER BY quality_index DESC;

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 16: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Objective: To calculate the optimum number of a medicine to order to minimize inventory holding and ordering costs.

Justification: With this query, the user can see the amount of a medicine to order, the ordering cycle and when to place an order given the potential delays.

Q*

RL

Tt

Q

RL : Reorder LevelQ*: Optimum QuantityT: Ordering Cycle

Query 3: Economical order quantity

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 17: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

SELECT m. MID, Round(SQRT((2 * m.Demand * (o.OrderingCost+ o.ShippingCost+e.HourlyRate)/i.HoldingCost) AS

QUANTITY_TO_ORDER, Round(m.demand/

QUATITY_TO_ORDER) AS ORDERING_CYCLE, (m.DailyUsageRate * o.LeadTime) AS REORDER_LEVEL, i. RemainingQuantity ((m.price*

m.demand) + ((o.OrderingCost+ o.ShippingCost+ e.HourlyRate)/ ORDERING_CYCLE) + i.holdingCost*QUATITY_TO_ORDER/2), AS TOTAL_COSTFROM MEDICATION as m, INVENTORY_ITEM as i, EMPLOYEE as e, ORDER as o WHERE m.MID = I. IID_OID AND e.SSN=o.CSSN AND i.IID_OID=o.OIDGROUP BY m.MID;

Q3:EOQ SQL & outcome

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 18: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Purpose

Among these patients whom were introduced to the company through events and workshops to the company, find the correlation between their medical expenses with the firm and the severity of their conditions, i.e. what would be the estimated spending of a patient if we know his/her condition is at this level. (Assuming we are quantifying patients' condition from 1 to 10.)

Mathematical Model 

Query 4: Medical cost expectation

n= # of patients = count(p.SSN)a = condition = p.Conditionsum(a)= sum(p.Condition)b = a.Spendingsum(b) = sum(a.Spending)sum(ab) = sum(p.Condition*a.Spending)

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 19: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Q4:Cost expectation SQL & outcome SELECT (Count(p.ssn) * Sum(p.condition * a.spending) - Sum(p.condition) *Sum(a.spending) ) / ( Count(p.ssn) * Sum(p.condition^2) - Sum(p.condition)^2 ) AS coefficient, 1 / Count(p.ssn) * ( Sum(a.spending) - coefficient * Sum(p.condition) ) AS intercept FROM   patient p,  client c, account a, event e WHERE  p.ssn = c.ssn_patient AND a.patient_id = p.ssn AND c.ssn_client = a.clientid AND p.ssn IN (SELECT DISTINCT pc.ssn 

 FROM prospective_client pc) 

Sample Outcome

Enter the level of the patient’s condition, and the query will yield output of estimated cost for this patient.

 

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 20: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

0 2 4 6 8 10 12$0.00

$5,000.00

$10,000.00

$15,000.00

$20,000.00

$25,000.00

Estimation of Costs Based On Severity of Condition

Estimated CostsPredicted Estimated Costs

Condition

Esti

mate

d C

osts

Q4:Cost expectation outcome

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 21: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Query5: Optimized Employee Allocation Business Justification: This query will allow the allocation of employees to serve the needs of

customers while minimizing the distance traveled from employees to patients’ residences. Then, using an integer program employees are allocated to patients by minimizing the total distance traveled of the system. The benefits include savings in transportation time and a reduction in emergency response time to patients.

Mathematical Model: Initially, through use of a query every combination of patient and employee are retrieved. Each pair is labeled:

Where Y represents the allocation of employee j to patient i. These will be represent the decision variables in a Linear Program (LP). The travel times between candidate employees and the prospective patient are then determined from Google Maps. These values are used to fill a distance matrix, d.

Where d is the distance from candidate employee residence j to patient i residence. This results in the equation to be minimized, Z.

Where d is the distance from candidate employee residence j to patient i residence. This results in the equation to be minimized, Z.

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 22: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Q5: Optimized Employee Allocation outcomeCore SQL Code: SELECT P.ID,P.ZID,E.ID,E.ZID FROM Employee.E,Patient.P

Sample Output: From the Employee and Patient Tables, every combination of P.ID, E.ID, P.ZID and E.ZID are extracted.

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 23: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Distance Matrix Created on MATLAB calculating distances on Google Maps. Zip Code ID’s Assigned Instead zip code to facilitate matrix indexing in MATLAB

Distance Matrix:

Q5: Optimized Employee Allocation outcome

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 24: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Employees are allocated using Binary Integer Programming (BIP) on MATLAB y=[x zeros(length(x),1)];for i=1:length(y) y(i,end)=d(y(i,2),y(i,4));end A=[ones(1,5) zeros(1,25);zeros(1,5) ones(1,5) zeros(1,20); zeros(1,10) ones(1,5) zeros(1,15);zeros(1,15) ones(1,5) zeros(1,10);zeros(1,20) ones(1,5) zeros(1,5);zeros(1,25) ones(1,5)]; b=ones(6,1);f=y(:,end)'[s,fval]=bintprog(f,[],[],A,b,zeros(1,30),[])

Q5: Optimized Employee Allocation outcome

Introduction EER Diagram Schema Tables Normalization Query & SQL

Page 25: Introduction Simplified EER Diagram Rational Schema Relational Design (Access implementation) Normalization Query and SQL implementation Agenda.

Thank you