-- 创建序列
CREATE SEQUENCE "hisdev"."clinical_ticket_id_seq"
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 1
  CACHE 1;

-- 创建号源表clinical_ticket
CREATE TABLE "hisdev"."clinical_ticket" (
  "id" bigint NOT NULL DEFAULT nextval('hisdev.clinical_ticket_id_seq'::regclass),
  "bus_no" varchar(50) COLLATE "pg_catalog"."default" NOT NULL DEFAULT ''::character varying,
  "department" varchar(100) COLLATE "pg_catalog"."default" NOT NULL DEFAULT ''::character varying,
  "doctor" varchar(100) COLLATE "pg_catalog"."default" NOT NULL DEFAULT ''::character varying,
  "ticket_type" varchar(20) COLLATE "pg_catalog"."default" NOT NULL DEFAULT ''::character varying,
  "time" varchar(50) COLLATE "pg_catalog"."default" NOT NULL DEFAULT ''::character varying,
  "status" varchar(20) COLLATE "pg_catalog"."default" NOT NULL DEFAULT 'unbooked'::character varying,
  "fee" varchar(20) COLLATE "pg_catalog"."default" NOT NULL DEFAULT ''::character varying,
  "patient_id" bigint,
  "patient_name" varchar(100) COLLATE "pg_catalog"."default" DEFAULT ''::character varying,
  "medical_card" varchar(50) COLLATE "pg_catalog"."default" DEFAULT ''::character varying,
  "phone" varchar(20) COLLATE "pg_catalog"."default" DEFAULT ''::character varying,
  "appointment_date" timestamptz(6),
  "appointment_time" timestamptz(6),
  "department_id" bigint,
  "doctor_id" bigint,
  "create_by" varchar(32) COLLATE "pg_catalog"."default" NOT NULL DEFAULT ''::character varying,
  "create_time" timestamptz(6) NOT NULL,
  "update_by" varchar(32) COLLATE "pg_catalog"."default" DEFAULT ''::character varying,
  "update_time" timestamptz(6),
  "remark" varchar(500) COLLATE "pg_catalog"."default" DEFAULT ''::character varying,
  "delete_flag" char(1) COLLATE "pg_catalog"."default" NOT NULL DEFAULT 0,
  "tenant_id" bigint NOT NULL,
  PRIMARY KEY ("id")
)
WITH (
  OIDS = FALSE
)
;

ALTER SEQUENCE "hisdev"."clinical_ticket_id_seq" OWNED BY "hisdev"."clinical_ticket"."id";

-- 添加注释
COMMENT ON TABLE "hisdev"."clinical_ticket" IS '号源管理表';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."id" IS 'ID';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."bus_no" IS '号源编码';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."department" IS '科室名称';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."doctor" IS '医生姓名';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."ticket_type" IS '号源类型 (普通/专家)';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."time" IS '挂号时间';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."status" IS '状态 (unbooked:未预约, booked:已预约, checked:已取号, cancelled:已取消, locked:已锁定)';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."fee" IS '挂号费';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."patient_id" IS '患者ID';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."patient_name" IS '患者姓名';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."medical_card" IS '就诊卡号';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."phone" IS '手机号';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."appointment_date" IS '预约日期';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."appointment_time" IS '预约时间';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."department_id" IS '科室ID';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."doctor_id" IS '医生ID';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."create_by" IS '创建人';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."create_time" IS '创建时间';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."update_by" IS '更新人';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."update_time" IS '更新时间';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."remark" IS '备注';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."delete_flag" IS '删除状态';
COMMENT ON COLUMN "hisdev"."clinical_ticket"."tenant_id" IS '租户ID';