x
1
procedure pr_recent_Healthkit_dailydata (program_start_date date := '01-APR-2023')
2
-- use AUTHID CURRENT_USER to execute with the privileges and
3
-- schema context of the calling user
4
AUTHID CURRENT_USER AS
5
6
begin
7
execute immediate 'truncate table healthkit_dailydata';
8
insert into healthkit_dailydata
9
select
10
PARTICIPANTIDENTIFIER
11
,trunc(RECORD_DATE) as record_date
12
,'sleep' as type
13
from HEALTHKITSAMPLES_SLEEPANALYSISINTERVAL
14
where VALUE = 'InBed'
15
and STARTDATE >= program_start_date --4/6/2022: added to limit data from the program start date
16
and RECORD_DATE > STARTDATE
17
and trunc(RECORD_DATE) > trunc(sysdate) - 90
18
union all
19
select
20
PARTICIPANTIDENTIFIER
21
,trunc(StartDATE) as record_date
22
,'step' as type
23
from HEALTHKITSTATISTICS_DAILYSTEPS
24
--where TYPE = 'DailySteps'
25
where VALUE > 0
26
and STARTDATE >= program_start_date --4/6/2022: added to limit data from the program start date
27
and trunc(StartDATE) > trunc(sysdate) - 90
28
;
29
commit;
30
end;