
insert into sequpdate_state(updateid,uid) values('survey',6.0);

  CREATE TABLE public.survey (
	id serial4 NOT NULL,
	title varchar NOT NULL,
	description varchar NULL,
	"type" int4 NOT NULL,
	status int4 NOT NULL,
	begindate timestamptz(0) NULL,
	enddate timestamptz(0) NULL,
	"comment" varchar NULL,
	conclusion varchar NULL
);

CREATE TABLE public.survey_field (
	id serial4 NOT NULL,
	"content" varchar NULL,
	"type" int4 NOT NULL,
	survey_id int4 NOT NULL,
	"position" int4 NOT NULL
);

CREATE TABLE public.survey_field_type (
	id serial4 NOT NULL,
	"name" varchar NOT NULL
);

CREATE TABLE public.survey_resp (
	id serial4 NOT NULL,
	survey_id int4 NOT NULL,
	rdate timestamptz(0) NULL
);

CREATE TABLE public.survey_resp_field (
	id serial4 NOT NULL,
	field_id int4 NOT NULL,
	value int4 NOT NULL,
	resp_id int4 NOT NULL,
	value_text varchar NULL
);

CREATE TABLE public.survey_type (
	id serial4 NOT NULL,
	"name" varchar NOT NULL
);

CREATE OR REPLACE VIEW public.v_survey
AS SELECT survey_field.survey_id,
    survey_field.id AS field_id,
    survey_field.type AS field_type,
    survey_field."position"
   FROM survey,
    survey_field
  WHERE survey.id = survey_field.survey_id;

INSERT INTO public.survey_type
(id, "name")
VALUES(1, 'Patient');

INSERT INTO public.survey_field_type
(id, "name")
VALUES(2, 'Yes-No');
INSERT INTO public.survey_field_type
(id, "name")
VALUES(3, '5 smileys');
INSERT INTO public.survey_field_type
(id, "name")
VALUES(4, 'Header Yes-No');
INSERT INTO public.survey_field_type
(id, "name")
VALUES(5, 'Header 5 smileys');
INSERT INTO public.survey_field_type
(id, "name")
VALUES(1, 'Main header');
INSERT INTO public.survey_field_type
(id, "name")
VALUES(6, 'Header');
INSERT INTO public.survey_field_type
(id, "name")
VALUES(7, 'String');
INSERT INTO public.survey_field_type
(id, "name")
VALUES(8, 'Text');
