Database schema design strategy for pharmacy and drug prescriptions - sql-server

I am in the process of designing a small database application for a health center in my local community. The health center can receive both In & Out-Patients.
The one area i am not sure of how best it should be implemented is how to bill the patient automatically from the drugs/medication they have be given. I don't want the user to type in the name and price of the drugs given to the patient. I want to automate it with a list of all available drugs and their CURRENT prices in a table so that the user just selects a drug from a list & i the software should be able to determine the total.
I also want to maintain the history of drugs over time. Some thing like drug XXX was selling at $1234 in January, $4567 in September, $12 in 2008. So if i am to print a receipt for a patient who visited in 2008, the patient should be billed at the rates of 2008 not the drug current rate.
I am just asking for some general guidance and suggestions on the best database schema of a scenario related to my problem description above.
Thanks a lot.

With a table of drugprices
DrugPriceID DrugID PriceStartDate DrugPrice
1 1 1-1-2008 1234
2 1 1-9-2008 4567
which links to a table of drugs on DrugID. The price applies until it is superseded by a new price.
A table of Patients, which links to a table of PatientOrders,
PatientOrderID PatientID OrderDate
5 3 4-5-2008
and a further table of OrderDrugs
OrderDrugID PatientOrderID DrugID
6 5 1

Related

How do you answer a question when asked what is the granularity of the data you worked on?

I have been asked the above question but i know only its meaning that its the finest level of data. for example, if you have name in fact table, then its detail such email, phone number,etc can be found in dimensions table. I have sample dataset and its area level analysis which i have worked on, Please explain granularity of data based upon this data.
Dataset:
itemid
item
RID
Rname
Area
Time_Availability>70%
6222589
peanut banana
1000
Cafe adda
gachibowli
True
6355784
chocolate fudge
2000
Santosh hotel
Attapur
False
Area level of analysis of restaurant on boarding to a platform
Area
Total Ingested restaurants
Available
items_Available >=5
Gachibowli
5
4
2
Attapur
5
4
2
Thank you
The granularity of a fact table is the minimum set of attributes that will uniquely identify a measure.
For example (and I'm not saying this is a real world example), if you had a sales fact table and there could only be one sale per customer per day then "per customer per day" would be the granularity of that fact table. You might have other dimensions such as the store that the sale occurred in or the country where the transaction took place - but these would not affect the granularity if you could still only have one sale per customer per day, regardless of which store or country that transaction took place in

How to get the missing courses for each employee in Transact SQL (SQL Server)?

I currently have the information of all the employees and the courses they've taken, what I need is to have both the data of who have taken the courses and who hasn't in Power BI. The idea is to measure how is the organization doing with the trainings and to be able to speak with bosses to arrange trainings to for the employees who haven't taken them.
This is the structure right now:
Table Employees
ID_Employee Names Age Job title Department ...
1 Robert 44 Chief Procurement Officer Procurement ...
2 James 32 Warehouse Supervisor Operations ...
3 Natalie 47 Sales Manager Commercial ...
4 John 29 Planning Executive Operations ...
5 Matthew 33 Finance Executive Finance ...
Table Courses
ID_Course Course
1 Cybersecurity
2 Effective Negotiation
3 Safety Policies
4 Performance Analysis
Table EmployeexCourses
ID_Employee ID_Course Date_Taken
1 1 20201015
1 3 20201018
2 4 20201020
3 2 20201020
3 3 20201018
4 1 20201015
What I'm not sure is how to proceed, I can easily get who has taken each course because that's a table itself (EmployeesxCourses) and I was using a Pivot Table to have each employee in EmployeexCourses with all the courses in columns with their dates as values. I want to use this data in Power BI, so I have a question, what should I do to have the most flexible data in Power BI? Should I do a Pivot table with all the employees and all the courses (this number is small and is fixed for a while), it'd be a 1500 rows table and there would be multiple rows with no values in the columns (employees who've not taken any course). I'm a bit confused in the how of this table with all employees, because I'd need to use 'EmployeexCourses' and 'Employees' and then turn it into a Pivot Table (I'm sure I can I just haven't done it). Or should I get a separate table for all the employees with their missing courses?
Which option is better? Or do you think of another option? I need it to be efficient and flexible in Power BI for easy use (filter by area, by course missing and such). Any idea is welcome, TIA.

Create a relationship across multiple tables that allows only one entry per date

I am trying to create a database that will be used by multiple teams in my company that displays their daily stats.
When you open up the database I have a combo box that allows you to select your team name. Once you make your selection, your form appears with your team stats for the day. (In reality it's just one form that has a subform with a query. The query is updated when you select your team from the combo box)
Each team has their own separate set of stats for each day and they are only allowed one entry per day. Not every single team has the same category of stats. This is an example of some of my tables
Quality Stats Table:
Team Name | Daily # | Actual # | Goal # | DateOfEntry
Productivity Table:
Team Name | Percentage | DateOfEntry
Stop Ship Table:
Team Name | Yes/No | DateOfEntry
How do I make it so that each team can only have one entry in each table per day?
I have my Team Names linked across all the tables, but I am having a hard time enforcing the one entry per date restriction
I am very new at access and I am still trying to figure it out. I would greatly appreciate it if someone can point me in the right direction
Create a multiple-field unique index on each of those tables. Here is an example for the Quality Stats table ...
strSQL = "CREATE UNIQUE INDEX idxQualTeamDate ON [Quality Stats] ([Team Name], DateOfEntry)"
CurrentProject.Connection.Execute strSQL
The same thing can also be done through the Access user interface. If you prefer to go that route, it might still be helpful to execute the CREATE UNIQUE INDEX statement I gave you and then open the table in Design View to see how Access presents it there.

Drawing ERD for this Sample Database

Consider a system where employee record is kept. The database should store employee name,department etc. Every employee has a reporting manager to whom he has to report.
There are 4 levels of employee –
Junior Engineer
Senior Engineer
Team Lead
Senior Team Lead
Every junior engineer has to report to Senior engineer. Every senior Developer has to report to team lead. Every team lead has to report to senior team lead.
I came to this idea:-
There will be two table
1.Employee
2.Reporting
Employee table would contain necessary information like EmployeeID,Employee Name,Department Name etc.; primary key is EmployeeID
Reporting Table would contain two columns EmployeeID and ReportingMangerID ;EmployeeID is foreign key related to Primarykey of Employee Table.
I dont know if I am correct.
If the following is true:
one employee reports to 0..1 other employees
one employee has 0..n reports
Then you can have "manager" as an attribute for the employee table.
If the following is true:
one employee reports to 0..n other employees
one employee has 0..n reports
Then you need to have your structure.

How to get a proper table design( 0NF) for my database

I have to design tables in 0NF for my project, I am required to design the tables in 0NF form first then proceed to normalization and then draw the ERD. However it has been a real challenge for me to obtain the 0NF forms of my tables, lots of time has been wasted trying to redesign so I thought of asking help from people who might be more experienced in database design.
My database is of a Car Rental System. The system should keep records of customers,cars,employees, details of each rental and also the company is supposed to have multiple branches at different locations and each branch must have their own set of unique(identified by their license plate number) cars available.
One customer can have multiple rental records(i.e. made a rental in January then another in March .e.t.c) but one rental record is related to only one customer
A customer can book multiple cars in a single rental
Each rental is made through a single booking agent(an employee)
Employees is divided between Managers and booking agents. Each branch has a single manager but multiple booking agents.
Each branch has multiple cars located there but each car can be located at a single branch
So far, I've come up with these 0NF tables, they don't look correct to me though:
Cars(CarID,LicensePlateNo,Make,Model,Year,Color,mileage,Capacity,seats,Availability, Rate, BranchID,BranchLocation)
Customer(CustomerID, FirstName,LastName, Address ,ContactNo,Gender,DOB,NIC,RentalID,DateRented,RentalCost)
Agent(AgentID,FirstName,LastName,Address,ContactNo,Gender,DOB,NIC,MonthlyRentals,Salary,ManagerID,ManagerName,MangerLastName,ManagerAddress,ManagerContact,BranchID,BranchLocation)
Rental(RentalID,DateRented,Duration,RentalCost,Discount,AgentID,CarID,LicensePlateNo,Make,Model)
Branch(BranchID,BranchName,BranchLocation,ContactNumber,ManagerID)
I have replaced the Agent table with the Employee table and I have added 2 new columns (Position and Manager) to it. I believe the position column should store either 'Agent' or 'Manager'. If employee is an Agent, the Manager field should contain the ID of his/her Manager (EmployeeID). If employee is Manager, most probably the Manager column should be left NULL. I have also removed all other columns which were being repeated(Example BranchLocation in cars table etc...)
Cars(CarID,LicensePlateNo,Make,Model,Year,Color,Mileage,Capacity,Seats,Availability, Rate, BranchID)
Customer(CustomerID, FirstName,LastName,Address,ContactNo,Gender,DOB,NIC,RentalID)
Rental(RentalID,DateRented,Duration,RentalCost,Discount,EmployeeID,CarID)
Branch(BranchID,BranchName,BranchLocation,ContactNumber,EmployeeID)
Employee(EmployeeID,FirstName,LastName,Address,ContactNo,Gender,DOB,NIC,MonthlyRentals,Salary,BranchID,Position,Manager)
Thanks

Resources