#用户表格
create table user
(
    userid      char(18)             not null
        primary key,
    username    varchar(64)          not null,
    password    varchar(255)         not null,
    phonenumber bigint               not null,
    address     varchar(255)         not null,
    enabled     tinyint(1) default 1 not null,
    did         char(18)             not null,
    gender      tinyint              null
);

create index user_userinhospital_userid_fk
    on user (did);

#医生表格
create table doctor
(
    userid        char(18)             not null
        primary key,
    username      varchar(64)          not null,
    password      varchar(255)         not null,
    phonenumber   bigint               not null,
    hospitalname  varchar(255)         not null,
    qualification mediumblob           null,
    enabled       tinyint(1) default 0 not null,
    description   text                 null,
    constraint userinhospital_userid_uindex
        unique (userid)
);

#管理员表格
create table worker
(
    userid        char(18)             not null
        primary key,
    username      varchar(64)          not null,
    password      varchar(255)         not null,
    phonenumber   bigint               not null,
    communityname varchar(255)         not null,
    qualification mediumblob           null,
    enabled       tinyint(1) default 0 not null,
    constraint userincommunity_userid_uindex
        unique (userid)
);

insert into worker (userid, username, password, phonenumber, communityname, enabled) VALUES
                    ('111111111111111111','管理员','123456','18604162024','蓝天社区',1);

#健康上报表格
create table dailyreport
(
    dailyreportid int auto_increment
        primary key,
    uid           char(18)                             not null,
    age           int                                  not null,
    height        double                               not null,
    temperature   double                               not null,
    lowpressure   int                                  not null,
    highpressure  int                                  not null,
    error         tinyint(1) default 0                 not null,
    heartRate     int                                  null,
    date          timestamp  default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
    weight        double                               null,
    covidtest     tinyint(1) default 0                 null,
    constraint dailyreport_user_userid_fk
        foreign key (uid) references user (userid)
);

#病历表格
create table medicalrecord
(
    mid        int auto_increment
        primary key,
    uid        char(18)                            not null,
    did        char(18)                            not null,
    symptom    varchar(255)                        null,
    recordtime timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
    diagnose   varchar(255)                        null
);

create index medicalrecord___doctorid
    on medicalrecord (did);

create index medicalrecord___patientid
    on medicalrecord (uid);

#处方表格
create table drugs
(
    id            int auto_increment
        primary key,
    name          varchar(255) null,
    specification varchar(255) null,
    number        int          null,
    way           varchar(255) null,
    dosage        varchar(255) null
);

#病历_处方关系表格
create table mrecord_drugs
(
    id  int auto_increment
        primary key,
    mid int not null,
    did int not null
);

create index mrecord_drugs___fk1
    on mrecord_drugs (mid);

create index mrecord_drugs___fk2
    on mrecord_drugs (did);

#消息表格
create table message
(
    senderid   char(18)                            not null,
    message    varchar(255)                        not null,
    receiverid char(18)                            not null,
    time       timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP
);




