summaryrefslogtreecommitdiff
path: root/sql/weight.sql
blob: e97bf05738036d9caf13a497e94cae8f30f1fc43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
create table weight.weight (
        measured_at              timestamp with time zone primary key default now(),
        value                    numeric(4,1) not null
);

create table weight.bp (
       measured_at               timestamp with time zone primary key default now(),
       systolic                  numeric(3, 0) not null,
       diastolic                 numeric(3, 0) not null,
       kind                      text check (kind in ('standard', 'home', 'doctor')) default 'standard' not null
);

create schema zqxjk;

create view zqxjk.weight as (
        select to_char(measured_at, 'YYYY-MM-DD"T"HH24:MI:SSOF') as _id,
               measured_at || ' ' || value as _display,
               value
        from   weight.weight
);

create view zqxjk.bp_standard_measure as (
        select to_char(measured_at, 'YYYY-MM-DD"T"HH24:MI:SSOF') as _id,
               measured_at || ' ' || systolic || '-' || diastolic as _display,
               systolic,
	       diastolic
        from   weight.bp
);

create view zqxjk.admin_weight as (
        select to_char(measured_at, 'YYYY-MM-DD"T"HH24:MI:SSOF') as _id,
               measured_at || ' ' || value as _display,
               measured_at,
               value
        from   weight.weight
);

create table zqxjk._tables (
        name                    text primary key,
        default_sort            text[]
);

insert into zqxjk._tables(name, default_sort) values ('weight', '{"_id", "desc"}');
insert into zqxjk._tables(name, default_sort) values ('admin_weight', '{"_id", "desc"}');
insert into zqxjk._tables(name, default_sort) values ('bp_standard_measure', '{"_id", "desc"}');