Beruflich Dokumente
Kultur Dokumente
PART ONE
Project Idea
Carer Database Scheduling System is a project that allows Carer to specify their availability
for job scheduling. Each carer is assigned to clients based on the carers' availability by an
manager who is the manager of a Homecare Company. The carers can also schedule their
holidays and manager can either grant or deny the holiday for any holiday requests by any
carer. The manager can assign cover for a carer that is on holiday.
Business Rules
Carer is an employee of the company that takes care of the companys Clients.
Each Carer has manager and 1 manager can manage more than one Carers.
The Carer specifies his/her availability in the system, which in our case is a many-tomany relationship, so it was divided into 2 called Carer_Availability.
The Manager assigns Carer to different Clients by setting up a roster (called Visit in the
diagram)
A Carer can book many holidays in a year, based on the acceptance or rejection of the
Manager and number of holiday days the Carer is allowed by the Company.
The manager can either grant or deny holiday request by the Carer.
Once a Carer is on holiday, there is need for cover.
A Cover is also a Carer, except that he/she would be covering for someone on holiday.
A manager assigns visits, and a Carer can visit many Clients while 1 Clients can be
visited by many Carer.
A Carer can visit many times within a period.
A period is a range of days that a Carer is scheduled to visit some specific Clients, the
range of time could be 3 weeks range.
Clients have comments, apart from their names, address etc.
These Comments may include medication, personal care, Grooming/Dressing, Client
safety, house work, and other information needed by the Carer to take care of the
Client.
assigneddate,
Functional Dependencies
1. Manager(managerId, username, firstname, lastname, DateOfBirth, securityLevel, email,
dateCreated, dateUpdated)
2. Carer(carerId, username, firstname, lastname, sex, address, county, phone,
ppsNumber, adminNote, userStatus, DateOfBirth, email, dateCreated, dateUpdated)
1 to Many Relationship
1 Manager Grants Many Holidays
1 Manager assigns many visits
1 Carer has many holidays
1 Period involves many visits
1 cover can make many visits
1 to 1 Relationship
1 carer may be assigned 1 Company_Car
1 Client has 1 Comment
PART TWO
Note: The whole project is exported using expdp and it is attached as part of the document,
more information is in the log file.
Database Setup
Here, the 3rd normal form is demonstrated in the two tables above, with the use POSTCODES
as the foreign key in client table as well as carer table.
The POSTCODES column was made NOT NULL because we believe that all carer should have
address and all clients should have address that the carer will visit.
All other tables follow 3rd normal form too.
For instance, the table availability and table carer have many to many relationship that do not
split, so we have another table called carer_availability, that host the relationship between
the two tables, as shown in the ERDiagram above.
The tables are included in the sql document attached with this document.
Comments is a table that contains more information about a client that a carer will go visit.
Select * from comments
OPEN carer_avail_cursor;
FETCH carer_avail_cursor INTO selected_carer_avail_row;
DBMS_OUTPUT.PUT_LINE('LIST OF CARERS AND THEIR AVAILABILITY');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('FULLNAME' || CHR(9) || CHR(9) || CHR(9) || 'DAY OF THE
WEEK' || CHR(9)|| CHR(9) || 'FROM TIME' || CHR(9) || CHR(9) || 'TO TIME');
WHILE carer_avail_cursor%FOUND LOOP
DBMS_OUTPUT.PUT_LINE(selected_carer_avail_row.firstname || ' ' ||
selected_carer_avail_row.lastname || CHR(9) || CHR(9) || CHR(9) ||
selected_carer_avail_row.dayoftheweek ||
CHR(9) || CHR(9) || CHR(9) || CHR(9) ||CHR(9) ||
selected_carer_avail_row.fromtime || CHR(9) || CHR(9) ||CHR(9) || CHR(9) ||
selected_carer_avail_row.totime);
FETCH carer_avail_cursor INTO selected_carer_avail_row;
END LOOP;
CLOSE carer_avail_cursor;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No data to display, sorry!');
WHEN others THEN
DBMS_OUTPUT.PUT_LINE('Error!');
PKG_MISC_FUNCTIONS.ORA_RAISERROR(sqlcode, 'Error Just occur with error code
'||sqlcode, 25);
end;
The screenshot showing the anonymous procedure that run the procedure.
And the screenshot below shows the list of all the carers who has selected availability
INNER JOIN 2: We want to check the day of the week that a carer is available. i.e. if the
weekday (e.g. MONDAY) specified by the input date is one of the days that the carer
specified as his/her availability.
procedure prc_schedule_visit(var_carer_id number, client_id number, var_period_id
number,
var_manager_id number, var_date varchar2, var_from_time varchar2, var_to_time
varchar2)
as
add_result number;
var_v_count number;
var_p_count number;
var_count_mgr number;
var_from_date varchar2(50);
var_to_date varchar2(50);
var_to_in timestamp;
var_from_in timestamp;
var_given_day_of_week varchar2(15);
var_av_day_of_week NUMBER;
begin
var_from_date := var_date ||' ' || var_from_time;
var_to_date := var_date ||' ' || var_to_time;
var_from_in:= TO_DATE(var_from_date, 'MM/DD/YYYY HH24:MI');
var_to_in := TO_DATE(var_to_date, 'MM/DD/YYYY HH24:MI');
--check if the carer has been assigned to this client for this period and
this time before
--if yes show response if not, continue to the next line of action.
select count(1) into var_v_count from visit where periodid = var_period_id
and
carerid = var_carer_id and clientid = client_id and TRUNC(VISITFROM) =
TRUNC(TO_DATE(var_date, 'MM/DD/YYYY'))
and pkg_misc_functions.datepart('HH', VISITFROM) =
pkg_misc_functions.datepart('HH', var_from_in)
and pkg_misc_functions.datepart('MI', VISITFROM) =
pkg_misc_functions.datepart('MI', var_from_in)
and pkg_misc_functions.datepart('HH', VISITTO) =
pkg_misc_functions.datepart('HH', var_to_in)
and pkg_misc_functions.datepart('MI', VISITTO) =
pkg_misc_functions.datepart('MI', var_to_in);
DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.format_error_backtrace);
INNER JOIN 3 Description: It allows us to view all carers that are assigned to what clients by
what managers in what range of period and what range of time for visiting.
procedure prc_view_all_visit
is
CURSOR visit_all_cursor IS
--list all the list of carer, manager that assigned the carer, the clients they are
assigned to
--, etc at one glance.
SELECT C.FIRSTNAME || ' ' || C.LASTNAME CARER_NAME, CL.FIRSTNAME || ' ' ||
CL.LASTNAME CLIENT_NAME,
M.FIRSTNAME || ' ' || M.LASTNAME MANAGER_NAME, V.VISITFROM VISITING_FROM, V.VISITTO
VISITING_TO,
P.FROMDATETIME PERIOD_FROM, P.TODATETIME PERIOD_TO FROM CARER C INNER JOIN VISIT V
ON V.CARERID=C.CARERID INNER JOIN CLIENT CL ON V.CLIENTID = CL.CLIENTID
INNER JOIN PERIOD P ON V.PERIODID = P.PERIODID INNER JOIN MANAGER M ON
V.MANAGERID=M.MANAGERID;
selected_visit_row visit_all_cursor%ROWTYPE;
begin
OPEN visit_all_cursor;
FETCH visit_all_cursor INTO selected_visit_row;
DBMS_OUTPUT.PUT_LINE('LIST OF ALL ROSTERS');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('CARERNAME' || CHR(9) || CHR(9) || CHR(9) ||
'CLIENTNAME' || CHR(9) || CHR(9) || CHR(9) || 'MANAGERNAME' || CHR(9) || CHR(9) ||
CHR(9) || 'VISITING_FROM' || CHR(9) || CHR(9) || 'VISITING_TO'
|| CHR(9) || CHR(9) || CHR(9) || CHR(9) || 'PERIOD_FROM' || CHR(9) ||
CHR(9) || CHR(9) || 'PERIOD_TO');
WHILE visit_all_cursor%FOUND LOOP
DBMS_OUTPUT.PUT_LINE(selected_visit_row.CARER_NAME || CHR(9) ||
CHR(9) || CHR(9) || selected_visit_row.CLIENT_NAME || CHR(9) || CHR(9) || CHR(9) ||
selected_visit_row.MANAGER_NAME ||
CHR(9) || CHR(9) || CHR(9) || CHR(9) ||CHR(9) ||
selected_visit_row.VISITING_FROM || CHR(9) || CHR(9) ||CHR(9) || CHR(9) ||
selected_visit_row.VISITING_TO
|| CHR(9) || CHR(9) || CHR(9) || CHR(9) ||CHR(9) ||
selected_visit_row.PERIOD_FROM || CHR(9) || CHR(9) ||CHR(9) || CHR(9) ||
selected_visit_row.PERIOD_TO);
INNER JOIN 4 and description: This shows individual carers roster for a period of time. So a
carer can just supply the carer number and the period number to get the roster.
procedure prc_view_car_carer
is
CURSOR view_cursor IS
--list all the list of both carer and the car assigned and the car not assigned
SELECT CC.REG_NUMBER regno, CC.MODEL model, CC.ASSIGNED_DATE ass_date,
C.FIRSTNAME || ' ' || C.LASTNAME CARER_NAME FROM COMPANY_CAR CC FULL OUTER
JOIN CARER C ON
CC.ASSIGNED_TO_CARERID=C.CARERID;
selected_view_row view_cursor%ROWTYPE;
begin
OPEN view_cursor;
FETCH view_cursor INTO selected_view_row;
DBMS_OUTPUT.PUT_LINE('LIST OF ALL CARS AND CARERS');
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('REGISTRATION_NUMBER' || CHR(9) || CHR(9) || CHR(9) ||
'MODEL' || CHR(9) || CHR(9) || CHR(9) || 'ASSIGNED_DATE' || CHR(9) || CHR(9) ||
CHR(9) || 'CARER_NAME');
WHILE view_cursor%FOUND LOOP
DBMS_OUTPUT.PUT_LINE(selected_view_row.regno || CHR(9) || CHR(9) ||
CHR(9) || selected_view_row.model || CHR(9) || CHR(9) || CHR(9) ||
selected_view_row.ass_date ||
CHR(9) || CHR(9) || CHR(9) || CHR(9) ||CHR(9) ||
selected_view_row.carer_name);
FETCH view_cursor INTO selected_view_row;
END LOOP;
CLOSE view_cursor;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No data to display, sorry!');
WHEN others THEN
DBMS_OUTPUT.PUT_LINE('Error has occured please contact the admin!');
end;
FULL JOIN 2 and description: Show full list of all carers and the corresponding managers.
SELECT C.FIRSTNAME ||' ' || C.LASTNAME CARER_NAME, C.ADMINNOTE, M.FIRSTNAME ||' ' ||
M.LASTNAME MANAGER_NAME FROM CARER C FULL OUTER JOIN MANAGER M ON C.MANAGERID =
M.MANAGERID;
LEFT JOIN 1: and description: We want to list all the clients and some of their corresponding
comment information
LEFT JOIN 2: We want to know the list of holidays dates from and to, that were booked by
what carer so that we have in the database in order to make business decisions on approving
or rejecting them.
SELECT H.HOLIDAYFROMDATE,
C.LASTNAME FROM HOLIDAY
RIGHT JOIN 1: Here, we are interested in holidays date that all managers are involved in for
business decision
SELECT M.FIRSTNAME, M.LASTNAME, H.HOLIDAYFROMDATE, H.HOLIDAYTODATE FROM MANAGER M
RIGHT OUTER JOIN HOLIDAY H ON H.MANAGERID = M.MANAGERID
RIGHT JOIN 2: We are interested in getting the information about all carers who have applied
for holiday and their holiday approved or rejected, or who have not applied at all in order to
make business decision.
select H.HOLIDAYFROMDATE, H.HOLIDAYTODATE, H.NUMBEROFDAYS, H.STATUS, C.FIRSTNAME,
C.LASTNAME FROM holiday h RIGHT OUTER JOIN CARER C ON H.CARERID = C.CARERID;
5 examples of sub-queries
Sub-query 1: We want to get the number of days the carers hava taken in the booking year
before he/she is allowed to go to a new holiday. If the number of days for the year is greater
than the number allowed for that carer, we would report error.
select sum(numberofdays) into var_num_of_days from
holiday where carerid = selected_grant_row.carerid AND
PKG_MISC_FUNCTIONS.datepart('YY', HOLIDAYFROMDATE)=
(SELECT PKG_MISC_FUNCTIONS.datepart('YY', HOLIDAYFROMDATE) FROM
HOLIDAY WHERE
STATUS='BOOKED' AND CARERID = selected_grant_row.carerid);
DBMS_OUTPUT.PUT_LINE(' Number of days: ' || var_num_of_days);
select numberofdaysallowed into var_allowed from carer where
carerid = selected_grant_row.carerid;
begin
select count(1) into var_mgr_count from manager where managerid =
to_number(var_manager_id);
if(var_mgr_count > 0)then
begin
OPEN grant_cursor;
FETCH grant_cursor INTO selected_grant_row;
WHILE grant_cursor%FOUND LOOP
--We want to get the number of days the carers hava taken in the
--booking year before he/she is allowed to go to a new holiday
select sum(numberofdays) into var_num_of_days from
holiday where carerid = selected_grant_row.carerid AND
PKG_MISC_FUNCTIONS.datepart('YY', HOLIDAYFROMDATE)=
(SELECT PKG_MISC_FUNCTIONS.datepart('YY', HOLIDAYFROMDATE) FROM
HOLIDAY WHERE
STATUS='BOOKED' AND CARERID = selected_grant_row.carerid);
DBMS_OUTPUT.PUT_LINE(' Number of days: ' || var_num_of_days);
select numberofdaysallowed into var_allowed from carer where
carerid = selected_grant_row.carerid;
DBMS_OUTPUT.PUT_LINE('Days allowed: ' || var_allowed);
if(var_num_of_days > var_allowed) then
DBMS_OUTPUT.PUT_LINE('Sorry! carer with Id: '||
selected_grant_row.carerid
|| ' has either finished holiday for the year or picked too much
new holiday. Please review and rebook, thank you!');
else
SAVEPOINT UPDATE_AND_UNASSIGN;
var_status := 'APPROVED';
DBMS_OUTPUT.PUT_LINE('value to send to update holiday: ' ||
var_status || ', carer id: ' || selected_grant_row.carerid
|| ', manager id: ' || var_manager_id);
update_h_result :=
pkg_tables_update.cdss_update_holiday(selected_grant_row.carerid, var_manager_id,
var_status);
if(update_h_result = 0) then
select count(1) into var_count_ass_cr_car from company_car
where assigned_to_carerid = selected_grant_row.carerid;
if(var_count_ass_cr_car > 0)then
select reg_number into var_car_reg from company_car
where assigned_to_carerid = selected_grant_row.carerid;
update_ccr_result :=
pkg_tables_update.cdss_update_car(var_car_reg);
if(update_ccr_result = 0)then
DBMS_OUTPUT.PUT_LINE('The holiday of Carer of
Carer Id: ' || selected_grant_row.carerid || ' has been granted, but the car has
been deallocated');
COMMIT;
else
DBMS_OUTPUT.PUT_LINE('Sorry! we cannot
deallocate the car assigned to this carer with id: '|| selected_grant_row.carerid ||
'at the moment, and all the transactions are now rolled back for the carer.
Pls contact the administrator or try again
later.');
ROLLBACK TO UPDATE_AND_UNASSIGN;
end if;
else
DBMS_OUTPUT.PUT_LINE('The holiday of Carer of Carer
Id: ' || selected_grant_row.carerid || ' has been granted, and no car to
deallocate');
COMMIT;
end if;
else
DBMS_OUTPUT.PUT_LINE('Sorry! we cannot update the holiday
information for carer with id: '|| selected_grant_row.carerid || 'at the moment, and
all the transactions are now rolled back for the carer.
Pls contact the administrator or try again
later.');
ROLLBACK TO UPDATE_AND_UNASSIGN;
end if;
end if;
Sub-query 2: We are checking for carers who have applied for holiday more than once in a
given year, and we gave 2016 as an example.
--check for carers who have applied for holiday more than once in a given year in
this case, 2016
select C.FIRSTNAME, C.LASTNAME from carer c where c.carerid in
(select carerid from holiday WHERE pkg_misc_functions.datepart('YY',
HOLIDAYFROMDATE) = '2016' having count(numberofdays) > 1 Group by carerid);
Sub-query 3: This query with subqueries check if a carer who want to cover is also on holiday
before being assigned to cover another carer.
Sub-query 4: This query with subqueries check if a carer who want to cover has a visit at the
time too, since a carer cannot be at more than one places at a time, it is meaningless to let
them be able to assign any carer just any how.
Sub-query 5: We want to know the list of carers that have choosen their availability so that
we can assign them to clients. Only carers with availability Id would be assigned.
--all the Carer that have set up their availability
select firstname, lastname, dateofbirth from carer where carerid in
(select distinct carerid from carer_availability)
else
ROLLBACK TO UPDATE_AND_UNASSIGN;
DBMS_OUTPUT.PUT_LINE('Sorry! we cannot update the holiday
information for carer with id: '|| selected_grant_row.carerid || 'at the moment, and
all the transactions are now rolled back for the carer.
Pls contact the administrator or try again
later.');
end if;
end if;
We used grant holiday procedure below to grant all carers who are a being managed by a
manager 1000 holidays and unassign cars from them in order to assign it to another person for
work purpose.
begin
pkg_scheduling_assignments.prc_grant_holiday(1000);
end;
Procedure 2:
This procedure is used to assign a cover to a carer, the cover is also a carer but can only
cover for another if he/she is not on holiday and not having a client to attend to at the same
time of the cover.
COMMIT;
else
DBMS_OUTPUT.PUT_LINE('Oops! we cannot save cover information at
the moment. Please try again later!');
end if;
end if;
end if;
end;
Procedure 3:
This procedure is used to assign a carer to a availability. The carers can choose different days
of the week that they are going to be available for work.
Example:
begin
PKG_SCHEDULING_ASSIGNMENTS.PRC_ASSIGN_CARER_TO_AVAIL(1026, 27, 1033);
end;/
if(result = 0) then
COMMIT;
DBMS_OUTPUT.PUT_LINE('Carer availability has been successfully
inserted: ');
else
DBMS_OUTPUT.PUT_LINE('Sorry! the carer cannot be assigned at the
moment, we have error: '
|| result || ' please contact administrator');
end if;
end;
end if;
end;
else
DBMS_OUTPUT.PUT_LINE('Sorry! this manager id ' || var_manager_id ||
' does not exist, only existing manager can insert data');
end if;
end;
Procedure 4:
The procedure is used to assign carer to client with the help of the carer_availability selected
by the carer above and at a particular period. This is assigned by a manager assigned to the
carer.
Example of calling of the procedure:
declare
add_result number;
var_v_count number;
var_p_count number;
var_count_mgr number;
var_manager_id number;
var_from_date varchar2(50);
var_to_date varchar2(50);
var_to_in timestamp;
var_from_in timestamp;
var_given_day_of_week varchar2(15);
var_av_day_of_week NUMBER;
var_date varchar2(30);
var_from_time varchar2(30);
var_to_time varchar2(30);
var_carer_id number;
client_id number;
var_period_id number;
begin
var_carer_id:= 1003;
var_manager_id := 1002;
var_date := '4/4/2016';
var_from_time := '10:00';
var_to_time := '12:00';
client_id := 300;
var_period_id := 2;
pkg_scheduling_assignments.prc_schedule_visit(var_carer_id, client_id,
var_period_id,
var_manager_id, var_date, var_from_time, var_to_time);
end;
var_given_day_of_week varchar2(15);
var_av_day_of_week NUMBER;
begin
var_from_date := var_date ||' ' || var_from_time;
var_to_date := var_date ||' ' || var_to_time;
var_from_in:= TO_DATE(var_from_date, 'MM/DD/YYYY HH24:MI');
var_to_in := TO_DATE(var_to_date, 'MM/DD/YYYY HH24:MI');
--check if the carer has been assigned to this client for this period and
this time before
--if yes show response if not, continue to the next line of action.
select count(1) into var_v_count from visit where periodid = var_period_id
and
carerid = var_carer_id and clientid = client_id and TRUNC(VISITFROM) =
TRUNC(TO_DATE(var_date, 'MM/DD/YYYY'))
and pkg_misc_functions.datepart('HH', VISITFROM) =
pkg_misc_functions.datepart('HH', var_from_in)
and pkg_misc_functions.datepart('MI', VISITFROM) =
pkg_misc_functions.datepart('MI', var_from_in)
and pkg_misc_functions.datepart('HH', VISITTO) =
pkg_misc_functions.datepart('HH', var_to_in)
and pkg_misc_functions.datepart('MI', VISITTO) =
pkg_misc_functions.datepart('MI', var_to_in);
--check if the carer has been assigned to another client at the time, so he
does not get assigned
-- to 2 or more clients at a time
select count(1) into var_v_count_cl from visit where periodid = var_period_id
and
carerid = var_carer_id and TRUNC(VISITFROM) = TRUNC(TO_DATE(var_date,
'MM/DD/YYYY'))
and pkg_misc_functions.datepart('HH', VISITFROM) =
pkg_misc_functions.datepart('HH', var_from_in)
and pkg_misc_functions.datepart('MI', VISITFROM) =
pkg_misc_functions.datepart('MI', var_from_in)
and pkg_misc_functions.datepart('HH', VISITTO) =
pkg_misc_functions.datepart('HH', var_to_in)
and pkg_misc_functions.datepart('MI', VISITTO) =
pkg_misc_functions.datepart('MI', var_to_in);
--check if the time has been booked for that client with another carer
select count(1) into var_v_count_cr from visit where periodid = var_period_id
and
clientid = client_id and TRUNC(VISITFROM) = TRUNC(TO_DATE(var_date,
'MM/DD/YYYY'))
and pkg_misc_functions.datepart('HH', VISITFROM) =
pkg_misc_functions.datepart('HH', var_from_in)
and pkg_misc_functions.datepart('MI', VISITFROM) =
pkg_misc_functions.datepart('MI', var_from_in)
and pkg_misc_functions.datepart('HH', VISITTO) =
pkg_misc_functions.datepart('HH', var_to_in)
and pkg_misc_functions.datepart('MI', VISITTO) =
pkg_misc_functions.datepart('MI', var_to_in);
if(var_v_count > 0)then
--If carer already exist for the same client
DBMS_OUTPUT.PUT_LINE('Sorry!, the carer has already been setup for this
period, client and time');
elsif(var_v_count_cl > 0) then
--if carer has been scheduled with another client
--PKG_MISC_FUNCTIONS.ORA_RAISERROR(sqlcode,sqlerrm,33);
DBMS_OUTPUT.PUT_LINE('Sorry! Error has occurred please contact the admin! or try
again later');
DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.format_error_backtrace);
end;
When it is successful.
Procedure 5:
The procedure shows the list of rosters of one carer based on a range of period. So the carer
can specify the period id and his/her carer id in order to show it.
Example of calling of the procedure:
begin
pkg_scheduling_assignments.prc_view_all_visit(1003, 2);
end;/
There are other procedures in the other packages and in the package made use of in this
section.
2 PL/SQL functions
There are lots of functions made use of in this program, all the insertions are performed with
the use of functions. Then we have a miscellaneous function that is always in handy in the
application to get the day of the week, hours, minutes, seconds, days. Others also get
differences between 2 dates which might be hours difference, days difference, week
differences etc. I will just pick 2 of the functions to explain here.
Function 1.
During holiday booking, an anonymous plsql was written where a function cdss_add_holiday
belonging to pkg_tables_creation was called in order to book holiday by carers.
This allows carers to book holiday. Error is displayed if the user has already booked a holiday
that has not been approved or rejected.
Example:
declare
var_care_id number;
var_manager_id number;
var_status varchar2(30);
var_managerid number;
var_holiday_from_date date;
var_holiday_to_date DATE;
insert_result number;
v_count number;
begin
var_care_id := 1025;
var_manager_id := 1033;
var_status := 'BOOKED';
var_holiday_from_date := TO_DATE('4/5/2016', 'MM/DD/YYYY');
var_holiday_to_date := TO_DATE('4/14/2016', 'MM/DD/YYYY');
select count(1) into v_count from holiday where CARERID=var_care_id and
STATUS='BOOKED';
if(v_count > 0)then
DBMS_OUTPUT.PUT_LINE('Sorry, you still have a booking that has not been approved
yet');
Else
--function that calls the book holiday
insert_result := PKG_TABLES_CREATION.cdss_add_holiday(var_care_id,
var_manager_id, var_holiday_from_date, var_holiday_to_date, var_status);
if(insert_result = 0)then
COMMIT;
DBMS_OUTPUT.PUT_LINE('Holiday booking was successful the manager will access
it soon');
else
DBMS_OUTPUT.PUT_LINE('Error has occured during booking');
end if;
end if;
exception
when others then
DBMS_OUTPUT.PUT_LINE('Error has occured ');
DBMS_OUTPUT.PUT_LINE(DBMS_UTILITY.format_error_backtrace);
end;/
FUNCTION cdss_add_holiday(var_carerid
number, var_managerid number,
var_holiday_from_date
DATE, var_holiday_to_date DATE, var_status
varchar2
) return number
as
var_duration number;
no_rows exception;
v_l_retval number;
begin
begin
var_duration := PKG_MISC_FUNCTIONS.datediff('DD',
var_holiday_from_date, var_holiday_to_date);
INSERT INTO holiday
(
CARERID,
MANAGERID,
HOLIDAYFROMDATE,
NUMBEROFDAYS,
STATUS,
HOLIDAYTODATE
values
)
(
var_carerid,
var_managerid,
var_holiday_from_date,
var_duration,
var_status,
var_holiday_to_date
);
if sql%rowcount != 1 then
raise no_rows;
end if;
exception
when no_rows then
DBMS_OUTPUT.PUT_LINE('No rows inserted for cdss_add_holiday');
PKG_MISC_FUNCTIONS.ORA_RAISERROR(sqlcode, 'No rows inserted for
cdss_add_holiday', 22);
return 5694;
when others then
DBMS_OUTPUT.PUT_LINE('Insert failed for cdss_add_holiday');
PKG_MISC_FUNCTIONS.ORA_RAISERROR(sqlcode, 'Insert failed for
cdss_add_holiday', 25);
return sqlcode;
end;
return 0;
exception
when others then
DBMS_OUTPUT.PUT_LINE('Execution of cdss_add_holiday failed');
PKG_MISC_FUNCTIONS.ORA_RAISERROR(sqlcode, 'Execution of
cdss_add_holiday failed', 104);
return 95;
end;
When the carer has booked before and the manager has not reply (either approve or reject)
Function 2.
The datediff function is situated in pkg_misc_functions package it is used in the program
to get the duration between two dates which may be year, weeks, days, hours, minutes
or seconds difference. It was used inside the
)
(
var_carerid,
var_managerid,
var_holiday_from_date,
var_duration,
var_status,
var_holiday_to_date
);
if sql%rowcount != 1 then
raise no_rows;
end if;
exception
when no_rows then
DBMS_OUTPUT.PUT_LINE('No rows inserted for cdss_add_holiday');
PKG_MISC_FUNCTIONS.ORA_RAISERROR(sqlcode, 'No rows inserted for
cdss_add_holiday', 22);
return 5694;
when others then
DBMS_OUTPUT.PUT_LINE('Insert failed for cdss_add_holiday');
PKG_MISC_FUNCTIONS.ORA_RAISERROR(sqlcode, 'Insert failed for
cdss_add_holiday', 25);
return sqlcode;
end;
return 0;
exception
when others then
DBMS_OUTPUT.PUT_LINE('Execution of cdss_add_holiday failed');
PKG_MISC_FUNCTIONS.ORA_RAISERROR(sqlcode, 'Execution of
cdss_add_holiday failed', 104);
return 95;
end;
It was also used in function cdss_add_period in order to find the differences in weeks between
periods.
Another function is datename that was used in the application to get the name of the week
end if;
if (fmt = 'WK') then
rexp := to_char(miscdate,
end if;
if (fmt = 'DY') then
rexp := to_char(miscdate,
end if;
if (fmt = 'DW') then
rexp := to_char(miscdate,
end if;
if (fmt = 'Dw') then
rexp := to_char(miscdate,
end if;
if (fmt = 'dw') then
rexp := to_char(miscdate,
end if;
if (fmt = 'HH') then
rexp := to_char(miscdate,
end if;
if (fmt = 'MI') then
rexp := to_char(miscdate,
end if;
if (fmt = 'SS') then
rexp := to_char(miscdate,
end if;
return rexp;
end;
'WW');
'DDD');
'DAY');
'Day');
'day');
'HH24');
'MI');
'SS');
var_duration := PKG_MISC_FUNCTIONS.datediff('WK',
var_from_date_time, var_to_date_time);
DBMS_OUTPUT.PUT_LINE('The number of weeks between ' || var_from_date_time || ' and
' ||
var_to_date_time || ' is ' || var_duration);
Trigger 2
This trigger shows whenever a carer tries to select more than 20 days of holiday at once.
CREATE OR REPLACE TRIGGER HOL_GT_20
BEFORE INSERT OR UPDATE OF NUMBEROFDAYS ON HOLIDAY
FOR EACH ROW
WHEN (New.NUMBEROFDAYS > 20)
BEGIN
DBMS_OUTPUT.PUT_LINE('The carer with carer id: ' || :NEW.carerid || ' cannot have
more than 20 days holiday at once');
DBMS_OUTPUT.PUT_LINE('The Updated or Inserted number of days is: ' ||
:NEW.NUMBEROFDAYS);
END;
/
Trigger 3: This is an after trigger that triggers whenever there is an insert, update or delete
into company_car table, this is a companys asset and it needs to be monitored to know know
whenever someone makes a change to it. In the trigger, we captured the user that performed
the act too.
In the future, the application could be using username instead of ids which is easier to
remember by the carer.
Also, in the future, salary structure could be added to the functionality and feedback after
the visiting has been performed should be part of the application.