delete from telefon;
drop table pacientes;

SET default_with_oids = true;

CREATE TABLE pacientes (
    pac_id integer NOT NULL,
    pac_codigo integer DEFAULT 1 NOT NULL,
    pac_nombre character varying(100),
    pac_sexo integer DEFAULT 1 NOT NULL,
    pac_fecnac date,
    pac_tdoc character varying(5),
    pac_ndoc integer,
    pac_fecest timestamp without time zone DEFAULT now() NOT NULL,
    pac_civil integer,
    pac_domicilio character varying(65),
    pac_locali character varying(65),
    pac_codpos character varying(15),
    pac_provin integer,
    pac_operador integer,
    pac_grupo integer,
    pac_cliente integer,
    pac_trabajo integer,
    pac_siempre integer,
    pac_cuanttra numeric(8,2),
    pac_trabact integer,
    pac_cuanttraa numeric(8,2),
    pac_educacion integer,
    pac_eduanios integer,
    pac_tipedu integer,
    pac_nacion integer,
    pac_lateralidad integer,
    pac_zurderiaflia integer,
    pac_convivencia integer,
    pac_medrefer integer,
    pac_nommed character varying(65),
    pac_estado integer DEFAULT 1
);

ALTER TABLE public.pacientes OWNER TO onlop;

--
-- Name: pacientes_pac_id_seq; Type: SEQUENCE; Schema: public; Owner: onlop
--

CREATE SEQUENCE pacientes_pac_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.pacientes_pac_id_seq OWNER TO onlop;

--
-- Name: pacientes_pac_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: onlop
--

ALTER SEQUENCE pacientes_pac_id_seq OWNED BY pacientes.pac_id;

--
-- Name: pac_id; Type: DEFAULT; Schema: public; Owner: onlop
--

ALTER TABLE pacientes ALTER COLUMN pac_id SET DEFAULT nextval('pacientes_pac_id_seq'::regclass);

--
-- Name: pacientes; Type: ACL; Schema: public; Owner: onlop
--

REVOKE ALL ON TABLE pacientes FROM PUBLIC;
REVOKE ALL ON TABLE pacientes FROM onlop;
GRANT ALL ON TABLE pacientes TO onlop;
GRANT ALL ON TABLE pacientes TO nobody;


--
-- Name: pacientes_pac_id_seq; Type: ACL; Schema: public; Owner: onlop
--

REVOKE ALL ON SEQUENCE pacientes_pac_id_seq FROM PUBLIC;
REVOKE ALL ON SEQUENCE pacientes_pac_id_seq FROM onlop;
GRANT ALL ON SEQUENCE pacientes_pac_id_seq TO onlop;
GRANT UPDATE ON SEQUENCE pacientes_pac_id_seq TO nobody;








drop table antecedentes;


CREATE TABLE antecedentes (
    ant_paciente integer NOT NULL,
    ant_fecest timestamp without time zone DEFAULT now() NOT NULL,
    ant_concepto integer NOT NULL,
    ant_antiguedad numeric(8,2),
    ant_tratamiento integer DEFAULT 1 NOT NULL,
    ant_modo integer,
    ant_leyen1 character varying(60),
    ant_leyen2 character varying(60),
    ant_leyen3 character varying(60),
    ant_leyen4 character varying(60),
    ant_leyen5 character varying(60),
    ant_medicacion text
);


ALTER TABLE public.antecedentes OWNER TO onlop;

--
-- Name: antecedentes_pkey; Type: CONSTRAINT; Schema: public; Owner: onlop; Tablespace: 
--

ALTER TABLE ONLY antecedentes
    ADD CONSTRAINT antecedentes_pkey PRIMARY KEY (ant_paciente, ant_concepto, ant_fecest);


--
-- Name: antecedentes; Type: ACL; Schema: public; Owner: onlop
--

REVOKE ALL ON TABLE antecedentes FROM PUBLIC;
REVOKE ALL ON TABLE antecedentes FROM onlop;
GRANT ALL ON TABLE antecedentes TO onlop;
GRANT ALL ON TABLE antecedentes TO nobody;




drop table consultas;
drop table testh;
drop table testc;
drop table entrevh;
drop table entrevc;


SET default_with_oids = true;

CREATE TABLE consultas (
    con_id integer NOT NULL,
    con_paciente integer NOT NULL,
    con_fecha timestamp without time zone DEFAULT now() NOT NULL,
    con_nota text,
    con_doctor integer NOT NULL,
    con_estado integer DEFAULT 1
);


ALTER TABLE public.consultas OWNER TO onlop;

--
-- Name: consultas_con_id_seq; Type: SEQUENCE; Schema: public; Owner: onlop
--

CREATE SEQUENCE consultas_con_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.consultas_con_id_seq OWNER TO onlop;

--
-- Name: consultas_con_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: onlop
--

ALTER SEQUENCE consultas_con_id_seq OWNED BY consultas.con_id;

--
-- Name: con_id; Type: DEFAULT; Schema: public; Owner: onlop
--

ALTER TABLE consultas ALTER COLUMN con_id SET DEFAULT nextval('consultas_con_id_seq'::regclass);

--
-- Name: consultas; Type: ACL; Schema: public; Owner: onlop
--

REVOKE ALL ON TABLE consultas FROM PUBLIC;
REVOKE ALL ON TABLE consultas FROM onlop;
GRANT ALL ON TABLE consultas TO onlop;
GRANT ALL ON TABLE consultas TO nobody;


--
-- Name: consultas_con_id_seq; Type: ACL; Schema: public; Owner: onlop
--

REVOKE ALL ON SEQUENCE consultas_con_id_seq FROM PUBLIC;
REVOKE ALL ON SEQUENCE consultas_con_id_seq FROM onlop;
GRANT ALL ON SEQUENCE consultas_con_id_seq TO onlop;
GRANT UPDATE ON SEQUENCE consultas_con_id_seq TO nobody;






CREATE TABLE testh (
    th_id integer NOT NULL,
    th_consulta integer NOT NULL,
    th_paciente integer NOT NULL,
    th_fecha timestamp without time zone DEFAULT now() NOT NULL,
    th_aciertos integer,
    th_nota text,
    th_puntos numeric(15,5) DEFAULT 0,
    th_tiempo time without time zone,
    th_estado integer DEFAULT 1
);

ALTER TABLE public.testh OWNER TO onlop;

--
-- Name: testh_th_id_seq; Type: SEQUENCE; Schema: public; Owner: onlop
--

CREATE SEQUENCE testh_th_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.testh_th_id_seq OWNER TO onlop;

--
-- Name: testh_th_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: onlop
--

ALTER SEQUENCE testh_th_id_seq OWNED BY testh.th_id;


ALTER TABLE testh ALTER COLUMN th_id SET DEFAULT nextval('testh_th_id_seq'::regclass);


--
-- Name: testh; Type: ACL; Schema: public; Owner: onlop
--

REVOKE ALL ON TABLE testh FROM PUBLIC;
REVOKE ALL ON TABLE testh FROM onlop;
GRANT ALL ON TABLE testh TO onlop;
GRANT ALL ON TABLE testh TO nobody;


--
-- Name: testh_th_id_seq; Type: ACL; Schema: public; Owner: onlop
--

REVOKE ALL ON SEQUENCE testh_th_id_seq FROM PUBLIC;
REVOKE ALL ON SEQUENCE testh_th_id_seq FROM onlop;
GRANT ALL ON SEQUENCE testh_th_id_seq TO onlop;
GRANT UPDATE ON SEQUENCE testh_th_id_seq TO nobody;






CREATE TABLE testc (
    tc_id integer NOT NULL,
    tc_idth integer DEFAULT (-1) NOT NULL,
    tc_orden integer DEFAULT (-1) NOT NULL,
    tc_idtn integer,
    tc_respuesta character varying(80),
    tc_acierto integer,
    tc_ini timestamp without time zone,
    tc_fin timestamp without time zone,
    tc_tiempo time without time zone,
    tc_puntaje numeric(20,5),
    tc_estado integer DEFAULT 1
);



ALTER TABLE public.testc OWNER TO onlop;

--
-- Name: testc_tc_id_seq; Type: SEQUENCE; Schema: public; Owner: onlop
--

CREATE SEQUENCE testc_tc_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.testc_tc_id_seq OWNER TO onlop;

--
-- Name: testc_tc_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: onlop
--

ALTER SEQUENCE testc_tc_id_seq OWNED BY testc.tc_id;

ALTER TABLE testc ALTER COLUMN tc_id SET DEFAULT nextval('testc_tc_id_seq'::regclass);


--
-- Name: testc; Type: ACL; Schema: public; Owner: onlop
--

REVOKE ALL ON TABLE testc FROM PUBLIC;
REVOKE ALL ON TABLE testc FROM onlop;
GRANT ALL ON TABLE testc TO onlop;
GRANT ALL ON TABLE testc TO nobody;


--
-- Name: testc_tc_id_seq; Type: ACL; Schema: public; Owner: onlop
--

REVOKE ALL ON SEQUENCE testc_tc_id_seq FROM PUBLIC;
REVOKE ALL ON SEQUENCE testc_tc_id_seq FROM onlop;
GRANT ALL ON SEQUENCE testc_tc_id_seq TO onlop;
GRANT UPDATE ON SEQUENCE testc_tc_id_seq TO nobody;


