-- 创建 lab_specimen 检验标本表
CREATE TABLE hisdev.lab_specimen (
    id BIGINT NOT NULL,
    service_id BIGINT,
    tenant_id BIGINT,
    specimen_definition_id BIGINT,
    collection_status_enum INTEGER,
    collection_date TIMESTAMP WITHOUT TIME ZONE,
    received_date TIMESTAMP WITHOUT TIME ZONE,
    specimen_volume VARCHAR(50),
    specimen_unit VARCHAR(20),
    create_by VARCHAR(50),
    create_time TIMESTAMP WITHOUT TIME ZONE,
    update_by VARCHAR(50),
    update_time TIMESTAMP WITH TIME ZONE,
    PRIMARY KEY (id)
);

COMMENT ON TABLE hisdev.lab_specimen IS '检验标本表';
COMMENT ON COLUMN hisdev.lab_specimen.id IS '主键ID';
COMMENT ON COLUMN hisdev.lab_specimen.service_id IS '服务请求ID(关联wor_service_request)';
COMMENT ON COLUMN hisdev.lab_specimen.tenant_id IS '租户ID';
COMMENT ON COLUMN hisdev.lab_specimen.specimen_definition_id IS '标本定义ID(关联adm_specimen_definition)';
COMMENT ON COLUMN hisdev.lab_specimen.collection_status_enum IS '采集状态(1:待采集 2:已采集 3:已接收)';
COMMENT ON COLUMN hisdev.lab_specimen.collection_date IS '采集时间';
COMMENT ON COLUMN hisdev.lab_specimen.received_date IS '接收时间';
COMMENT ON COLUMN hisdev.lab_specimen.specimen_volume IS '标本量';
COMMENT ON COLUMN hisdev.lab_specimen.specimen_unit IS '标本单位';
COMMENT ON COLUMN hisdev.lab_specimen.create_by IS '创建人';
COMMENT ON COLUMN hisdev.lab_specimen.create_time IS '创建时间';
COMMENT ON COLUMN hisdev.lab_specimen.update_by IS '更新人';
COMMENT ON COLUMN hisdev.lab_specimen.update_time IS '更新时间';

-- 创建 adm_specimen_definition 标本定义表
CREATE TABLE hisdev.adm_specimen_definition (
    id BIGINT NOT NULL,
    code VARCHAR(50),
    name VARCHAR(100),
    specimen_name VARCHAR(100),
    delete_flag CHAR(1) DEFAULT '0',
    create_by VARCHAR(50),
    create_time TIMESTAMP WITHOUT TIME ZONE,
    update_by VARCHAR(50),
    update_time TIMESTAMP WITH TIME ZONE,
    PRIMARY KEY (id)
);

COMMENT ON TABLE hisdev.adm_specimen_definition IS '标本定义表';
COMMENT ON COLUMN hisdev.adm_specimen_definition.id IS '主键ID';
COMMENT ON COLUMN hisdev.adm_specimen_definition.code IS '标本编码';
COMMENT ON COLUMN hisdev.adm_specimen_definition.name IS '标本名称';
COMMENT ON COLUMN hisdev.adm_specimen_definition.specimen_name IS '标本显示名称';
COMMENT ON COLUMN hisdev.adm_specimen_definition.delete_flag IS '删除标志(0:正常 1:删除)';

-- 创建 adm_observation_definition 检验项目定义表
CREATE TABLE hisdev.adm_observation_definition (
    id BIGINT NOT NULL,
    code VARCHAR(50),
    name VARCHAR(100),
    category VARCHAR(50),
    unit VARCHAR(20),
    reference_range VARCHAR(200),
    normal_range VARCHAR(200),
    delete_flag CHAR(1) DEFAULT '0',
    create_by VARCHAR(50),
    create_time TIMESTAMP WITHOUT TIME ZONE,
    update_by VARCHAR(50),
    update_time TIMESTAMP WITH TIME ZONE,
    PRIMARY KEY (id)
);

COMMENT ON TABLE hisdev.adm_observation_definition IS '检验项目定义表';
COMMENT ON COLUMN hisdev.adm_observation_definition.id IS '主键ID';
COMMENT ON COLUMN hisdev.adm_observation_definition.code IS '项目编码';
COMMENT ON COLUMN hisdev.adm_observation_definition.name IS '项目名称';
COMMENT ON COLUMN hisdev.adm_observation_definition.category IS '项目类别';
COMMENT ON COLUMN hisdev.adm_observation_definition.unit IS '单位';
COMMENT ON COLUMN hisdev.adm_observation_definition.reference_range IS '参考范围';
COMMENT ON COLUMN hisdev.adm_observation_definition.normal_range IS '正常范围';
COMMENT ON COLUMN hisdev.adm_observation_definition.delete_flag IS '删除标志(0:正常 1:删除)';

-- 创建索引
CREATE INDEX idx_lab_specimen_service_id ON hisdev.lab_specimen(service_id);
CREATE INDEX idx_lab_specimen_specimen_def ON hisdev.lab_specimen(specimen_definition_id);
CREATE INDEX idx_adm_specimen_definition_code ON hisdev.adm_specimen_definition(code);
CREATE INDEX idx_adm_observation_definition_code ON hisdev.adm_observation_definition(code);