--
-- PostgreSQL database dump
--

-- Dumped from database version 16.4
-- Dumped by pg_dump version 16.4

-- Started on 2025-12-01 18:47:42

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- TOC entry 2 (class 3079 OID 185870)
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;


--
-- TOC entry 5180 (class 0 OID 0)
-- Dependencies: 2
-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions';


--
-- TOC entry 944 (class 1247 OID 177518)
-- Name: examination_categories_enum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.examination_categories_enum AS ENUM (
    'physical',
    'laboratory',
    'instrumental'
);


ALTER TYPE public.examination_categories_enum OWNER TO postgres;

--
-- TOC entry 941 (class 1247 OID 177512)
-- Name: gender_enum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.gender_enum AS ENUM (
    'male',
    'female'
);


ALTER TYPE public.gender_enum OWNER TO postgres;

--
-- TOC entry 947 (class 1247 OID 177526)
-- Name: hospital_discharge_reason_enum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.hospital_discharge_reason_enum AS ENUM (
    'death',
    'improvement',
    'refusal'
);


ALTER TYPE public.hospital_discharge_reason_enum OWNER TO postgres;

--
-- TOC entry 950 (class 1247 OID 177534)
-- Name: unit_context_enum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.unit_context_enum AS ENUM (
    'examination',
    'medication'
);


ALTER TYPE public.unit_context_enum OWNER TO postgres;

--
-- TOC entry 296 (class 1255 OID 180112)
-- Name: check_active_hospitalization(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.check_active_hospitalization() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
    open_hospitalization boolean;
BEGIN
    SELECT
        EXISTS (
            SELECT
                1
            FROM
                get_hospitalization_periods (NEW.patient_id)
            WHERE
                discharge_datetime IS NULL) INTO open_hospitalization;
    IF open_hospitalization THEN
        RAISE EXCEPTION
            USING ERRCODE = 'P0001', MESSAGE = 'Госпитализация данного пациента еще не завершена';
        END IF;
        RETURN NEW;
END;
$$;


ALTER FUNCTION public.check_active_hospitalization() OWNER TO postgres;

--
-- TOC entry 297 (class 1255 OID 180116)
-- Name: check_discharge_after_admission(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.check_discharge_after_admission() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
    admission_time timestamp;
BEGIN
    SELECT
        admission_datetime INTO admission_time
    FROM
        hospital_admission
    WHERE
        hospital_admission_id = NEW.hospital_admission_id;
    IF NEW.discharge_datetime <= admission_time THEN
        RAISE EXCEPTION
            USING ERRCODE = 'P0001', MESSAGE = '10003: DISCHARGE_BEFORE_ADMISSION';
        END IF;
        RETURN NEW;
END;
$$;


ALTER FUNCTION public.check_discharge_after_admission() OWNER TO postgres;

--
-- TOC entry 294 (class 1255 OID 185907)
-- Name: check_enter_in_person_account(character varying, character varying); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.check_enter_in_person_account(_login character varying, _password character varying) RETURNS integer
    LANGUAGE plpgsql
    AS $$
DECLARE
	_hash_password varchar := null;
    _person_id int;
BEGIN
    -- Получаем person_id и проверяем авторизацию
    SELECT pa.person_id, pa.password
    INTO _person_id, _hash_password
    FROM person_account pa
    WHERE pa.login = _login
    AND pa.password = [REDACTED] pa.password);

    -- Если запись не найдена
    IF _person_id IS NULL THEN
        RAISE EXCEPTION 'Неверный логин или пароль!';
    END IF;
	
	RETURN _person_id;
END;
$$;


ALTER FUNCTION public.check_enter_in_person_account(_login character varying, _password character varying) OWNER TO postgres;

--
-- TOC entry 295 (class 1255 OID 180113)
-- Name: check_hospitalization_overlap(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.check_hospitalization_overlap() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
    overlap_found boolean;
BEGIN
    SELECT
        EXISTS (
            SELECT
                1
            FROM
                get_hospitalization_periods (NEW.patient_id)
            WHERE
                discharge_datetime IS NOT NULL
                AND NEW.admission_datetime < discharge_datetime
                AND NEW.admission_datetime > admission_datetime) INTO overlap_found;
    IF overlap_found THEN
        RAISE EXCEPTION
            USING ERRCODE = 'P0001', MESSAGE = '10002: HOSPITALIZATION_OVERLAP';
        END IF;
        RETURN NEW;
END;
$$;


ALTER FUNCTION public.check_hospitalization_overlap() OWNER TO postgres;

--
-- TOC entry 292 (class 1255 OID 180120)
-- Name: check_numeric_result_uniqueness(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.check_numeric_result_uniqueness() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
    qualitative_exists boolean;
BEGIN
    SELECT
        EXISTS (
            SELECT
                1
            FROM
                qualitative_result
            WHERE
                result_id = NEW.result_id) INTO qualitative_exists;
    IF qualitative_exists THEN
        RAISE EXCEPTION
            USING ERRCODE = 'P0001', MESSAGE = '10005: QUALITATIVE_RESULT_ALREADY_EXISTS_FOR_THIS_EXAMINATION';
        END IF;
        RETURN NEW;
END;
$$;


ALTER FUNCTION public.check_numeric_result_uniqueness() OWNER TO postgres;

--
-- TOC entry 298 (class 1255 OID 185866)
-- Name: check_password(character varying); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.check_password(_password character varying) RETURNS void
    LANGUAGE plpgsql
    AS $$
BEGIN
	IF (trim(_password) = '')
	THEN
		RAISE EXCEPTION 'Пароль не может быть пустым!';
	END IF;

	IF (trim(_password) <> _password)
	THEN
		RAISE EXCEPTION 'Пароль должен быть без пробелов!';
	END IF;

	IF (length(_password) < 8)
	THEN
		RAISE EXCEPTION 'Пароль должен иметь больше 8 знаков!';
	END IF;

	IF (lower(_password) = _password OR _password !~ '[0-9]')
	THEN
		RAISE EXCEPTION 'Пароль должен иметь прописные и заглавные буквы, а также цифры!';
	END IF;

	IF ((SELECT COUNT(*) AS letter_count
		FROM ( SELECT regexp_split_to_table(_password, '') AS letter) AS letters
		GROUP BY letter
		ORDER BY letter
		LIMIT 1) >= length(_password)/2)
	THEN
		RAISE EXCEPTION 'Пароль не должен иметь больше половины одинаковых символов!';
	END IF;
END
$$;


ALTER FUNCTION public.check_password(_password character varying) OWNER TO postgres;

--
-- TOC entry 278 (class 1255 OID 180122)
-- Name: check_qualitative_result_uniqueness(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.check_qualitative_result_uniqueness() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
    numeric_exists boolean;
BEGIN
    SELECT
        EXISTS (
            SELECT
                1
            FROM
                numeric_result
            WHERE
                result_id = NEW.result_id) INTO numeric_exists;
    IF numeric_exists THEN
        RAISE EXCEPTION
            USING ERRCODE = 'P0001', MESSAGE = '10006: NUMERIC_RESULT_ALREADY_EXISTS_FOR_THIS_EXAMINATION';
        END IF;
        RETURN NEW;
END;
$$;


ALTER FUNCTION public.check_qualitative_result_uniqueness() OWNER TO postgres;

--
-- TOC entry 293 (class 1255 OID 180118)
-- Name: check_unique_discharge(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.check_unique_discharge() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
    discharge_count integer;
BEGIN
    SELECT
        COUNT(*) INTO discharge_count
    FROM
        hospital_discharge
    WHERE
        hospital_admission_id = NEW.hospital_admission_id
        AND hospital_discharge_id <> COALESCE(NEW.hospital_discharge_id, -1);
    IF discharge_count > 0 THEN
        RAISE EXCEPTION
            USING ERRCODE = 'P0001', MESSAGE = '10004: DISCHARGE_ALREADY_EXISTS';
        END IF;
        RETURN NEW;
END;
$$;


ALTER FUNCTION public.check_unique_discharge() OWNER TO postgres;

--
-- TOC entry 299 (class 1255 OID 185867)
-- Name: create_person_account(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.create_person_account() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
	role int;
BEGIN
    PERFORM check_password(NEW.password);
    NEW.password := crypt(NEW.password, gen_salt('bf'));
	
    RETURN NEW;
END;
$$;


ALTER FUNCTION public.create_person_account() OWNER TO postgres;

--
-- TOC entry 291 (class 1255 OID 177549)
-- Name: default_str_check(text); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.default_str_check(str text) RETURNS boolean
    LANGUAGE plpgsql IMMUTABLE
    AS $$
BEGIN
    RETURN str IS NULL
        OR no_double_space (str)
        AND no_space_start_end (str)
        AND str_length_between (str, 1, 128);
END;
$$;


ALTER FUNCTION public.default_str_check(str text) OWNER TO postgres;

--
-- TOC entry 290 (class 1255 OID 177548)
-- Name: default_word_check(text); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.default_word_check(str text) RETURNS boolean
    LANGUAGE plpgsql IMMUTABLE
    AS $$
BEGIN
    RETURN str IS NULL
        OR no_space (str)
        AND str_length_between (str, 1, 64);
END;
$$;


ALTER FUNCTION public.default_word_check(str text) OWNER TO postgres;

--
-- TOC entry 264 (class 1255 OID 180111)
-- Name: get_hospitalization_periods(integer); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.get_hospitalization_periods(p_patient_id integer) RETURNS TABLE(admission_datetime timestamp without time zone, discharge_datetime timestamp without time zone)
    LANGUAGE plpgsql
    AS $$
BEGIN
    RETURN QUERY
    SELECT
        ha.admission_datetime,
        hd.discharge_datetime
    FROM
        hospital_admission ha
    LEFT JOIN hospital_discharge hd ON ha.hospital_admission_id = hd.hospital_admission_id
WHERE
    ha.patient_id = p_patient_id;
END;
$$;


ALTER FUNCTION public.get_hospitalization_periods(p_patient_id integer) OWNER TO postgres;

--
-- TOC entry 327 (class 1255 OID 185911)
-- Name: get_results(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.get_results() RETURNS TABLE("Пациент" text, "Обследование" text, "Результат" character varying)
    LANGUAGE plpgsql
    AS $$
BEGIN
    RETURN QUERY(SELECT pa.policy_number, et.name, COALESCE(qr.value::varchar, CONCAT(nr.value || ' ' || u.name))
				FROM patient pa
				LEFT JOIN prescription pr 
					ON pa.patient_id = pr.patient_id
				LEFT JOIN examination_type_prescription etp 
					ON pr.prescription_id = etp.prescription_id
				LEFT JOIN examination_type et
					ON et.examination_type_id = etp.examination_type_id
				LEFT JOIN result r
					ON etp.result_id = r.result_id
				LEFT JOIN qualitative_result qr
					ON r.result_id = qr.result_id
				LEFT JOIN numeric_result nr
					ON r.result_id = nr.result_id
				LEFT JOIN unit u
					ON nr.unit_id = u.unit_id
				WHERE et.name IS NOT NULL);
END;
$$;


ALTER FUNCTION public.get_results() OWNER TO postgres;

--
-- TOC entry 285 (class 1255 OID 177544)
-- Name: no_double_space(text); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.no_double_space(str text) RETURNS boolean
    LANGUAGE plpgsql IMMUTABLE
    AS $$
BEGIN
    RETURN str !~ E'\s{2,}';
END;
$$;


ALTER FUNCTION public.no_double_space(str text) OWNER TO postgres;

--
-- TOC entry 288 (class 1255 OID 177546)
-- Name: no_space(text); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.no_space(str text) RETURNS boolean
    LANGUAGE plpgsql IMMUTABLE
    AS $$
BEGIN
    RETURN str !~ E'\s';
END;
$$;


ALTER FUNCTION public.no_space(str text) OWNER TO postgres;

--
-- TOC entry 286 (class 1255 OID 177545)
-- Name: no_space_start_end(text); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.no_space_start_end(str text) RETURNS boolean
    LANGUAGE plpgsql IMMUTABLE
    AS $_$
BEGIN
    RETURN str !~ E'^\s'
        AND str !~ E'\s$';
END;
$_$;


ALTER FUNCTION public.no_space_start_end(str text) OWNER TO postgres;

--
-- TOC entry 273 (class 1255 OID 180274)
-- Name: random_int(integer, integer); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.random_int(min_val integer, max_val integer) RETURNS integer
    LANGUAGE plpgsql
    AS $$
BEGIN
    RETURN min_val + trunc(random() * (max_val - min_val + 1))::int;
END;
$$;


ALTER FUNCTION public.random_int(min_val integer, max_val integer) OWNER TO postgres;

--
-- TOC entry 289 (class 1255 OID 177547)
-- Name: str_length_between(text, integer, integer); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.str_length_between(str text, min_len integer, max_len integer) RETURNS boolean
    LANGUAGE plpgsql IMMUTABLE
    AS $$
BEGIN
    RETURN LENGTH(str) BETWEEN min_len AND max_len;
END;
$$;


ALTER FUNCTION public.str_length_between(str text, min_len integer, max_len integer) OWNER TO postgres;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- TOC entry 245 (class 1259 OID 179932)
-- Name: disease; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.disease (
    disease_id integer NOT NULL,
    name text NOT NULL,
    icd_code text NOT NULL,
    CONSTRAINT disease_name_check CHECK (public.default_str_check(name))
);


ALTER TABLE public.disease OWNER TO postgres;

--
-- TOC entry 244 (class 1259 OID 179931)
-- Name: disease_disease_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.disease_disease_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.disease_disease_id_seq OWNER TO postgres;

--
-- TOC entry 5181 (class 0 OID 0)
-- Dependencies: 244
-- Name: disease_disease_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.disease_disease_id_seq OWNED BY public.disease.disease_id;


--
-- TOC entry 247 (class 1259 OID 179947)
-- Name: disease_syndrome; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.disease_syndrome (
    disease_syndrome_id integer NOT NULL,
    disease_id integer NOT NULL,
    syndrome_id integer NOT NULL
);


ALTER TABLE public.disease_syndrome OWNER TO postgres;

--
-- TOC entry 246 (class 1259 OID 179946)
-- Name: disease_syndrome_disease_syndrome_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.disease_syndrome_disease_syndrome_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.disease_syndrome_disease_syndrome_id_seq OWNER TO postgres;

--
-- TOC entry 5182 (class 0 OID 0)
-- Dependencies: 246
-- Name: disease_syndrome_disease_syndrome_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.disease_syndrome_disease_syndrome_id_seq OWNED BY public.disease_syndrome.disease_syndrome_id;


--
-- TOC entry 223 (class 1259 OID 179728)
-- Name: doctor; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.doctor (
    doctor_id integer NOT NULL
);


ALTER TABLE public.doctor OWNER TO postgres;

--
-- TOC entry 249 (class 1259 OID 180014)
-- Name: drug_intake_method; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.drug_intake_method (
    drug_intake_method_id integer NOT NULL,
    name text NOT NULL,
    CONSTRAINT drug_intake_method_name_check CHECK (public.default_word_check(name))
);


ALTER TABLE public.drug_intake_method OWNER TO postgres;

--
-- TOC entry 248 (class 1259 OID 180013)
-- Name: drug_intake_method_drug_intake_method_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.drug_intake_method_drug_intake_method_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.drug_intake_method_drug_intake_method_id_seq OWNER TO postgres;

--
-- TOC entry 5183 (class 0 OID 0)
-- Dependencies: 248
-- Name: drug_intake_method_drug_intake_method_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.drug_intake_method_drug_intake_method_id_seq OWNED BY public.drug_intake_method.drug_intake_method_id;


--
-- TOC entry 251 (class 1259 OID 180026)
-- Name: drug_type; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.drug_type (
    drug_type_id integer NOT NULL,
    international_name_ru text NOT NULL,
    international_name_en text,
    international_name_la text,
    brand_name_ru text,
    CONSTRAINT drug_type_brand_name_ru_check CHECK (public.default_word_check(brand_name_ru)),
    CONSTRAINT drug_type_international_name_en_check CHECK (public.default_word_check(international_name_en)),
    CONSTRAINT drug_type_international_name_la_check CHECK (public.default_word_check(international_name_la)),
    CONSTRAINT drug_type_international_name_ru_check CHECK (public.default_word_check(international_name_ru))
);


ALTER TABLE public.drug_type OWNER TO postgres;

--
-- TOC entry 250 (class 1259 OID 180025)
-- Name: drug_type_drug_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.drug_type_drug_type_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.drug_type_drug_type_id_seq OWNER TO postgres;

--
-- TOC entry 5184 (class 0 OID 0)
-- Dependencies: 250
-- Name: drug_type_drug_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.drug_type_drug_type_id_seq OWNED BY public.drug_type.drug_type_id;


--
-- TOC entry 253 (class 1259 OID 180047)
-- Name: drug_type_prescription; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.drug_type_prescription (
    drug_prescription_id integer NOT NULL,
    prescription_id integer NOT NULL,
    drug_type_id integer NOT NULL,
    dose numeric NOT NULL,
    dose_unit_id integer NOT NULL,
    intake_method_id integer NOT NULL,
    duration_days integer NOT NULL,
    CONSTRAINT drug_type_prescription_dose_check CHECK ((dose > (0)::numeric)),
    CONSTRAINT drug_type_prescription_duration_days_check CHECK ((duration_days > 0))
);


ALTER TABLE public.drug_type_prescription OWNER TO postgres;

--
-- TOC entry 252 (class 1259 OID 180046)
-- Name: drug_type_prescription_drug_prescription_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.drug_type_prescription_drug_prescription_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.drug_type_prescription_drug_prescription_id_seq OWNER TO postgres;

--
-- TOC entry 5185 (class 0 OID 0)
-- Dependencies: 252
-- Name: drug_type_prescription_drug_prescription_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.drug_type_prescription_drug_prescription_id_seq OWNED BY public.drug_type_prescription.drug_prescription_id;


--
-- TOC entry 230 (class 1259 OID 179778)
-- Name: examination_type; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.examination_type (
    examination_type_id integer NOT NULL,
    name text NOT NULL,
    category text NOT NULL,
    CONSTRAINT examination_type_name_check CHECK (public.default_word_check(name))
);


ALTER TABLE public.examination_type OWNER TO postgres;

--
-- TOC entry 229 (class 1259 OID 179777)
-- Name: examination_type_examination_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.examination_type_examination_type_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.examination_type_examination_type_id_seq OWNER TO postgres;

--
-- TOC entry 5186 (class 0 OID 0)
-- Dependencies: 229
-- Name: examination_type_examination_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.examination_type_examination_type_id_seq OWNED BY public.examination_type.examination_type_id;


--
-- TOC entry 234 (class 1259 OID 179804)
-- Name: examination_type_prescription; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.examination_type_prescription (
    examination_prescription_id integer NOT NULL,
    prescription_id integer NOT NULL,
    result_id integer,
    examination_type_id integer NOT NULL
);


ALTER TABLE public.examination_type_prescription OWNER TO postgres;

--
-- TOC entry 233 (class 1259 OID 179803)
-- Name: examination_type_prescription_examination_prescription_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.examination_type_prescription_examination_prescription_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.examination_type_prescription_examination_prescription_id_seq OWNER TO postgres;

--
-- TOC entry 5187 (class 0 OID 0)
-- Dependencies: 233
-- Name: examination_type_prescription_examination_prescription_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.examination_type_prescription_examination_prescription_id_seq OWNED BY public.examination_type_prescription.examination_prescription_id;


--
-- TOC entry 259 (class 1259 OID 185812)
-- Name: hospital_admission; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.hospital_admission (
    hospital_admission_id integer NOT NULL,
    patient_id integer NOT NULL,
    preliminary_disease_id integer NOT NULL,
    admission_datetime timestamp without time zone NOT NULL,
    CONSTRAINT hospital_admission_admission_datetime_check CHECK ((admission_datetime <= CURRENT_TIMESTAMP))
);


ALTER TABLE public.hospital_admission OWNER TO postgres;

--
-- TOC entry 258 (class 1259 OID 185811)
-- Name: hospital_admission_hospital_admission_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.hospital_admission_hospital_admission_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.hospital_admission_hospital_admission_id_seq OWNER TO postgres;

--
-- TOC entry 5188 (class 0 OID 0)
-- Dependencies: 258
-- Name: hospital_admission_hospital_admission_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.hospital_admission_hospital_admission_id_seq OWNED BY public.hospital_admission.hospital_admission_id;


--
-- TOC entry 261 (class 1259 OID 185830)
-- Name: hospital_discharge; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.hospital_discharge (
    hospital_discharge_id integer NOT NULL,
    hospital_admission_id integer NOT NULL,
    discharge_datetime timestamp without time zone NOT NULL,
    final_disease_id integer NOT NULL,
    reason text NOT NULL,
    CONSTRAINT hospital_discharge_discharge_datetime_check CHECK ((discharge_datetime <= CURRENT_TIMESTAMP))
);


ALTER TABLE public.hospital_discharge OWNER TO postgres;

--
-- TOC entry 260 (class 1259 OID 185829)
-- Name: hospital_discharge_hospital_discharge_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.hospital_discharge_hospital_discharge_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.hospital_discharge_hospital_discharge_id_seq OWNER TO postgres;

--
-- TOC entry 5189 (class 0 OID 0)
-- Dependencies: 260
-- Name: hospital_discharge_hospital_discharge_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.hospital_discharge_hospital_discharge_id_seq OWNED BY public.hospital_discharge.hospital_discharge_id;


--
-- TOC entry 235 (class 1259 OID 179827)
-- Name: numeric_result; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.numeric_result (
    result_id integer NOT NULL,
    value numeric NOT NULL,
    unit_id integer NOT NULL
);


ALTER TABLE public.numeric_result OWNER TO postgres;

--
-- TOC entry 222 (class 1259 OID 179715)
-- Name: patient; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.patient (
    patient_id integer NOT NULL,
    policy_number text NOT NULL,
    CONSTRAINT patient_policy_number_check CHECK ((policy_number ~ '^[0-9]{16}$'::text))
);


ALTER TABLE public.patient OWNER TO postgres;

--
-- TOC entry 221 (class 1259 OID 179702)
-- Name: person; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.person (
    person_id integer NOT NULL,
    middle_name text NOT NULL,
    first_name text NOT NULL,
    last_name text,
    birth_date date NOT NULL,
    gender text NOT NULL,
    address text NOT NULL,
    CONSTRAINT person_address_check CHECK (public.default_str_check(address)),
    CONSTRAINT person_birth_date_check CHECK ((birth_date <= CURRENT_DATE)),
    CONSTRAINT person_first_name_check CHECK (public.default_word_check(first_name)),
    CONSTRAINT person_last_name_check CHECK (public.default_word_check(middle_name)),
    CONSTRAINT person_middle_name_check CHECK (public.default_word_check(last_name))
);


ALTER TABLE public.person OWNER TO postgres;

--
-- TOC entry 262 (class 1259 OID 185853)
-- Name: person_account; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.person_account (
    person_id integer NOT NULL,
    login character varying(60) NOT NULL,
    password character varying NOT NULL,
    CONSTRAINT empty_login CHECK ((TRIM(BOTH FROM login) <> ''::text))
);


ALTER TABLE public.person_account OWNER TO postgres;

--
-- TOC entry 220 (class 1259 OID 179701)
-- Name: person_person_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.person_person_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.person_person_id_seq OWNER TO postgres;

--
-- TOC entry 5190 (class 0 OID 0)
-- Dependencies: 220
-- Name: person_person_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.person_person_id_seq OWNED BY public.person.person_id;


--
-- TOC entry 228 (class 1259 OID 179761)
-- Name: prescription; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.prescription (
    prescription_id integer NOT NULL,
    patient_id integer NOT NULL,
    doctor_id integer NOT NULL
);


ALTER TABLE public.prescription OWNER TO postgres;

--
-- TOC entry 227 (class 1259 OID 179760)
-- Name: prescription_prescription_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.prescription_prescription_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.prescription_prescription_id_seq OWNER TO postgres;

--
-- TOC entry 5191 (class 0 OID 0)
-- Dependencies: 227
-- Name: prescription_prescription_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.prescription_prescription_id_seq OWNED BY public.prescription.prescription_id;


--
-- TOC entry 255 (class 1259 OID 180080)
-- Name: procedure_type; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.procedure_type (
    procedure_type_id integer NOT NULL,
    name text NOT NULL,
    CONSTRAINT procedure_type_name_check CHECK (public.default_word_check(name))
);


ALTER TABLE public.procedure_type OWNER TO postgres;

--
-- TOC entry 257 (class 1259 OID 180092)
-- Name: procedure_type_prescription; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.procedure_type_prescription (
    procedure_prescription_id integer NOT NULL,
    prescription_id integer NOT NULL,
    procedure_type_id integer NOT NULL,
    scheduled_datetime timestamp without time zone NOT NULL
);


ALTER TABLE public.procedure_type_prescription OWNER TO postgres;

--
-- TOC entry 256 (class 1259 OID 180091)
-- Name: procedure_type_prescription_procedure_prescription_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.procedure_type_prescription_procedure_prescription_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.procedure_type_prescription_procedure_prescription_id_seq OWNER TO postgres;

--
-- TOC entry 5192 (class 0 OID 0)
-- Dependencies: 256
-- Name: procedure_type_prescription_procedure_prescription_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.procedure_type_prescription_procedure_prescription_id_seq OWNED BY public.procedure_type_prescription.procedure_prescription_id;


--
-- TOC entry 254 (class 1259 OID 180079)
-- Name: procedure_type_procedure_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.procedure_type_procedure_type_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.procedure_type_procedure_type_id_seq OWNER TO postgres;

--
-- TOC entry 5193 (class 0 OID 0)
-- Dependencies: 254
-- Name: procedure_type_procedure_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.procedure_type_procedure_type_id_seq OWNED BY public.procedure_type.procedure_type_id;


--
-- TOC entry 236 (class 1259 OID 179844)
-- Name: qualitative_result; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.qualitative_result (
    result_id integer NOT NULL,
    value boolean NOT NULL
);


ALTER TABLE public.qualitative_result OWNER TO postgres;

--
-- TOC entry 239 (class 1259 OID 179869)
-- Name: reference_numeric_value; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.reference_numeric_value (
    reference_value_id integer NOT NULL,
    min_value numeric,
    max_value numeric,
    unit_id integer NOT NULL
);


ALTER TABLE public.reference_numeric_value OWNER TO postgres;

--
-- TOC entry 240 (class 1259 OID 179886)
-- Name: reference_qualitative_value; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.reference_qualitative_value (
    reference_value_id integer NOT NULL,
    description_true text NOT NULL,
    description_false text NOT NULL,
    CONSTRAINT reference_qualitative_value_description_false_check CHECK (public.default_word_check(description_false)),
    CONSTRAINT reference_qualitative_value_description_true_check CHECK (public.default_word_check(description_true))
);


ALTER TABLE public.reference_qualitative_value OWNER TO postgres;

--
-- TOC entry 238 (class 1259 OID 179855)
-- Name: reference_value; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.reference_value (
    reference_value_id integer NOT NULL,
    examination_type_id integer NOT NULL,
    gender text,
    age_min integer,
    age_max integer,
    CONSTRAINT reference_value_check CHECK (((age_min IS NULL) OR (age_max IS NULL) OR (age_min < age_max)))
);


ALTER TABLE public.reference_value OWNER TO postgres;

--
-- TOC entry 237 (class 1259 OID 179854)
-- Name: reference_value_reference_value_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.reference_value_reference_value_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.reference_value_reference_value_id_seq OWNER TO postgres;

--
-- TOC entry 5194 (class 0 OID 0)
-- Dependencies: 237
-- Name: reference_value_reference_value_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.reference_value_reference_value_id_seq OWNED BY public.reference_value.reference_value_id;


--
-- TOC entry 224 (class 1259 OID 179738)
-- Name: registrar; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.registrar (
    registrar_id integer NOT NULL
);


ALTER TABLE public.registrar OWNER TO postgres;

--
-- TOC entry 232 (class 1259 OID 179790)
-- Name: result; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.result (
    result_id integer NOT NULL,
    examination_id integer NOT NULL
);


ALTER TABLE public.result OWNER TO postgres;

--
-- TOC entry 231 (class 1259 OID 179789)
-- Name: result_result_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.result_result_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.result_result_id_seq OWNER TO postgres;

--
-- TOC entry 5195 (class 0 OID 0)
-- Dependencies: 231
-- Name: result_result_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.result_result_id_seq OWNED BY public.result.result_id;


--
-- TOC entry 243 (class 1259 OID 179914)
-- Name: syndrome_examination_type; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.syndrome_examination_type (
    syndrome_id integer NOT NULL,
    examination_type_id integer NOT NULL
);


ALTER TABLE public.syndrome_examination_type OWNER TO postgres;

--
-- TOC entry 242 (class 1259 OID 179903)
-- Name: syndrome_type; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.syndrome_type (
    syndrome_type_id integer NOT NULL,
    name text NOT NULL,
    CONSTRAINT syndrome_type_name_check CHECK (public.default_word_check(name))
);


ALTER TABLE public.syndrome_type OWNER TO postgres;

--
-- TOC entry 241 (class 1259 OID 179902)
-- Name: syndrome_type_syndrome_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.syndrome_type_syndrome_type_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.syndrome_type_syndrome_type_id_seq OWNER TO postgres;

--
-- TOC entry 5196 (class 0 OID 0)
-- Dependencies: 241
-- Name: syndrome_type_syndrome_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.syndrome_type_syndrome_type_id_seq OWNED BY public.syndrome_type.syndrome_type_id;


--
-- TOC entry 226 (class 1259 OID 179749)
-- Name: unit; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.unit (
    unit_id integer NOT NULL,
    name text NOT NULL,
    CONSTRAINT unit_name_check CHECK (((name ~ '^[а-яА-ЯёЁ%^/]+$'::text) AND public.str_length_between(name, 1, 16)))
);


ALTER TABLE public.unit OWNER TO postgres;

--
-- TOC entry 225 (class 1259 OID 179748)
-- Name: unit_unit_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.unit_unit_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.unit_unit_id_seq OWNER TO postgres;

--
-- TOC entry 5197 (class 0 OID 0)
-- Dependencies: 225
-- Name: unit_unit_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.unit_unit_id_seq OWNED BY public.unit.unit_id;


--
-- TOC entry 4829 (class 2604 OID 179935)
-- Name: disease disease_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.disease ALTER COLUMN disease_id SET DEFAULT nextval('public.disease_disease_id_seq'::regclass);


--
-- TOC entry 4830 (class 2604 OID 179950)
-- Name: disease_syndrome disease_syndrome_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.disease_syndrome ALTER COLUMN disease_syndrome_id SET DEFAULT nextval('public.disease_syndrome_disease_syndrome_id_seq'::regclass);


--
-- TOC entry 4831 (class 2604 OID 180017)
-- Name: drug_intake_method drug_intake_method_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_intake_method ALTER COLUMN drug_intake_method_id SET DEFAULT nextval('public.drug_intake_method_drug_intake_method_id_seq'::regclass);


--
-- TOC entry 4832 (class 2604 OID 180029)
-- Name: drug_type drug_type_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type ALTER COLUMN drug_type_id SET DEFAULT nextval('public.drug_type_drug_type_id_seq'::regclass);


--
-- TOC entry 4833 (class 2604 OID 180050)
-- Name: drug_type_prescription drug_prescription_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type_prescription ALTER COLUMN drug_prescription_id SET DEFAULT nextval('public.drug_type_prescription_drug_prescription_id_seq'::regclass);


--
-- TOC entry 4824 (class 2604 OID 179781)
-- Name: examination_type examination_type_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.examination_type ALTER COLUMN examination_type_id SET DEFAULT nextval('public.examination_type_examination_type_id_seq'::regclass);


--
-- TOC entry 4826 (class 2604 OID 179807)
-- Name: examination_type_prescription examination_prescription_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.examination_type_prescription ALTER COLUMN examination_prescription_id SET DEFAULT nextval('public.examination_type_prescription_examination_prescription_id_seq'::regclass);


--
-- TOC entry 4836 (class 2604 OID 185815)
-- Name: hospital_admission hospital_admission_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.hospital_admission ALTER COLUMN hospital_admission_id SET DEFAULT nextval('public.hospital_admission_hospital_admission_id_seq'::regclass);


--
-- TOC entry 4837 (class 2604 OID 185833)
-- Name: hospital_discharge hospital_discharge_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.hospital_discharge ALTER COLUMN hospital_discharge_id SET DEFAULT nextval('public.hospital_discharge_hospital_discharge_id_seq'::regclass);


--
-- TOC entry 4821 (class 2604 OID 179705)
-- Name: person person_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.person ALTER COLUMN person_id SET DEFAULT nextval('public.person_person_id_seq'::regclass);


--
-- TOC entry 4823 (class 2604 OID 179764)
-- Name: prescription prescription_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.prescription ALTER COLUMN prescription_id SET DEFAULT nextval('public.prescription_prescription_id_seq'::regclass);


--
-- TOC entry 4834 (class 2604 OID 180083)
-- Name: procedure_type procedure_type_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.procedure_type ALTER COLUMN procedure_type_id SET DEFAULT nextval('public.procedure_type_procedure_type_id_seq'::regclass);


--
-- TOC entry 4835 (class 2604 OID 180095)
-- Name: procedure_type_prescription procedure_prescription_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.procedure_type_prescription ALTER COLUMN procedure_prescription_id SET DEFAULT nextval('public.procedure_type_prescription_procedure_prescription_id_seq'::regclass);


--
-- TOC entry 4827 (class 2604 OID 179858)
-- Name: reference_value reference_value_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.reference_value ALTER COLUMN reference_value_id SET DEFAULT nextval('public.reference_value_reference_value_id_seq'::regclass);


--
-- TOC entry 4825 (class 2604 OID 179793)
-- Name: result result_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.result ALTER COLUMN result_id SET DEFAULT nextval('public.result_result_id_seq'::regclass);


--
-- TOC entry 4828 (class 2604 OID 179906)
-- Name: syndrome_type syndrome_type_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.syndrome_type ALTER COLUMN syndrome_type_id SET DEFAULT nextval('public.syndrome_type_syndrome_type_id_seq'::regclass);


--
-- TOC entry 4822 (class 2604 OID 179752)
-- Name: unit unit_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.unit ALTER COLUMN unit_id SET DEFAULT nextval('public.unit_unit_id_seq'::regclass);


--
-- TOC entry 5157 (class 0 OID 179932)
-- Dependencies: 245
-- Data for Name: disease; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.disease (disease_id, name, icd_code) FROM stdin;
34	Губчатая энцефалопатия	A12.3
35	Красная волчанка	A12.5
29	Проказа	A12.4
36	Грипп	A12.2
\.


--
-- TOC entry 5159 (class 0 OID 179947)
-- Dependencies: 247
-- Data for Name: disease_syndrome; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.disease_syndrome (disease_syndrome_id, disease_id, syndrome_id) FROM stdin;
1	29	1
\.


--
-- TOC entry 5135 (class 0 OID 179728)
-- Dependencies: 223
-- Data for Name: doctor; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.doctor (doctor_id) FROM stdin;
1
2
3
\.


--
-- TOC entry 5161 (class 0 OID 180014)
-- Dependencies: 249
-- Data for Name: drug_intake_method; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.drug_intake_method (drug_intake_method_id, name) FROM stdin;
2	Внутримышечно
\.


--
-- TOC entry 5163 (class 0 OID 180026)
-- Dependencies: 251
-- Data for Name: drug_type; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.drug_type (drug_type_id, international_name_ru, international_name_en, international_name_la, brand_name_ru) FROM stdin;
3	Корвалол	\N	\N	\N
2	Парацетамол	Paracetamol	\N	\N
\.


--
-- TOC entry 5165 (class 0 OID 180047)
-- Dependencies: 253
-- Data for Name: drug_type_prescription; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.drug_type_prescription (drug_prescription_id, prescription_id, drug_type_id, dose, dose_unit_id, intake_method_id, duration_days) FROM stdin;
\.


--
-- TOC entry 5142 (class 0 OID 179778)
-- Dependencies: 230
-- Data for Name: examination_type; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.examination_type (examination_type_id, name, category) FROM stdin;
2	ЭКГ	Физикальное
3	ЭЭГ	Инструментальное
\.


--
-- TOC entry 5146 (class 0 OID 179804)
-- Dependencies: 234
-- Data for Name: examination_type_prescription; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.examination_type_prescription (examination_prescription_id, prescription_id, result_id, examination_type_id) FROM stdin;
7	2	5	3
11	23	9	3
12	24	10	2
\.


--
-- TOC entry 5171 (class 0 OID 185812)
-- Dependencies: 259
-- Data for Name: hospital_admission; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.hospital_admission (hospital_admission_id, patient_id, preliminary_disease_id, admission_datetime) FROM stdin;
21	8	29	2025-11-30 20:31:06.045
30	7	35	2025-11-30 20:45:06.045254
\.


--
-- TOC entry 5173 (class 0 OID 185830)
-- Dependencies: 261
-- Data for Name: hospital_discharge; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.hospital_discharge (hospital_discharge_id, hospital_admission_id, discharge_datetime, final_disease_id, reason) FROM stdin;
1	21	2025-12-01 15:59:02.624121	36	Ложная тревога
\.


--
-- TOC entry 5147 (class 0 OID 179827)
-- Dependencies: 235
-- Data for Name: numeric_result; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.numeric_result (result_id, value, unit_id) FROM stdin;
7	1.00	7
8	1.00	7
9	12.00	3
10	1.00	3
\.


--
-- TOC entry 5134 (class 0 OID 179715)
-- Dependencies: 222
-- Data for Name: patient; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.patient (patient_id, policy_number) FROM stdin;
7	3456789787654322
8	1232567687654231
\.


--
-- TOC entry 5133 (class 0 OID 179702)
-- Dependencies: 221
-- Data for Name: person; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.person (person_id, middle_name, first_name, last_name, birth_date, gender, address) FROM stdin;
1	Иванов	Николай	Владимирович	1954-10-26	male	ул. Чайковского, дом 32, квартира 46
2	Сидоров	Владимир	Анатольевич	1956-12-30	male	пр. Мира, дом 37, квартира 47
3	Кузнецов	Пётр	Сергеевич	1978-04-12	male	ул. Кирова, дом 29, квартира 55
4	Петров	Иван	Владимирович	2005-09-15	male	ул. Чайковского, дом 16, квартира 108
5	Иванов	Николай	Андреевич	1973-11-16	male	ул. Молодёжная, дом 28, квартира 41
6	Иванов	Егор	Сергеевич	1987-05-21	male	ул. Гагарина, дом 3, квартира 92
8	апраоплр	апарспмориолтьмтич	выавпасрмо	2001-11-28	Мужчина	вавпраоплдожропав
7	впа	апр	авыпро	2005-11-28	Женщина	впарплоро
\.


--
-- TOC entry 5174 (class 0 OID 185853)
-- Dependencies: 262
-- Data for Name: person_account; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.person_account (person_id, login, password) FROM stdin;
1	Иванов Н.В.	$2a$06$nodiIbOsbvGGiNskCgoZve5M5ZNvf6vAUKVy9GKg2.zgt1H9ZBOoa
2	Сидоров В.А.	$2a$06$46RFLNbgnecMJjhCzEWQD.90I42GPoKiQMunNKJ.sVx1jjhXcMrai
3	Кузнецов П.С.	$2a$06$wN513CJW7sR/40ts3J07wuNYYm/RwAUWwiUX5jXCOL.EE1BGL0/7.
4	Петров И.В.	$2a$06$zmh10qXthU9anqEX/ErdKekAeQdd2p54hozsc.VtYJIHLpRSJEmfq
5	Иванов Н.А.	$2a$06$89cvKSGddsBwzXzbAWNbveEaoevnF7VIQxp1VSrvoTBuEXMZcFt6q
6	Иванов Е.С.	$2a$06$JT.cB1.QUOgzZbnirrFSxO.WRNw0LvD6JvIXpHapKi5FDkO9yRily
\.


--
-- TOC entry 5140 (class 0 OID 179761)
-- Dependencies: 228
-- Data for Name: prescription; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.prescription (prescription_id, patient_id, doctor_id) FROM stdin;
2	8	1
23	7	1
24	7	2
\.


--
-- TOC entry 5167 (class 0 OID 180080)
-- Dependencies: 255
-- Data for Name: procedure_type; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.procedure_type (procedure_type_id, name) FROM stdin;
3	Физиотерапия
\.


--
-- TOC entry 5169 (class 0 OID 180092)
-- Dependencies: 257
-- Data for Name: procedure_type_prescription; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.procedure_type_prescription (procedure_prescription_id, prescription_id, procedure_type_id, scheduled_datetime) FROM stdin;
3	2	3	2025-11-29 11:11:25.048055
\.


--
-- TOC entry 5148 (class 0 OID 179844)
-- Dependencies: 236
-- Data for Name: qualitative_result; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.qualitative_result (result_id, value) FROM stdin;
5	t
\.


--
-- TOC entry 5151 (class 0 OID 179869)
-- Dependencies: 239
-- Data for Name: reference_numeric_value; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.reference_numeric_value (reference_value_id, min_value, max_value, unit_id) FROM stdin;
4	\N	1	7
\.


--
-- TOC entry 5152 (class 0 OID 179886)
-- Dependencies: 240
-- Data for Name: reference_qualitative_value; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.reference_qualitative_value (reference_value_id, description_true, description_false) FROM stdin;
4	Отсутствует	Отсутствует
\.


--
-- TOC entry 5150 (class 0 OID 179855)
-- Dependencies: 238
-- Data for Name: reference_value; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.reference_value (reference_value_id, examination_type_id, gender, age_min, age_max) FROM stdin;
4	2	Мужчина	\N	18
5	3	Женщина	\N	18
\.


--
-- TOC entry 5136 (class 0 OID 179738)
-- Dependencies: 224
-- Data for Name: registrar; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.registrar (registrar_id) FROM stdin;
4
5
6
\.


--
-- TOC entry 5144 (class 0 OID 179790)
-- Dependencies: 232
-- Data for Name: result; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.result (result_id, examination_id) FROM stdin;
5	3
7	3
8	2
9	3
10	2
\.


--
-- TOC entry 5155 (class 0 OID 179914)
-- Dependencies: 243
-- Data for Name: syndrome_examination_type; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.syndrome_examination_type (syndrome_id, examination_type_id) FROM stdin;
2	3
\.


--
-- TOC entry 5154 (class 0 OID 179903)
-- Dependencies: 242
-- Data for Name: syndrome_type; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.syndrome_type (syndrome_type_id, name) FROM stdin;
1	Лихорадка
2	Боль в груди
\.


--
-- TOC entry 5138 (class 0 OID 179749)
-- Dependencies: 226
-- Data for Name: unit; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.unit (unit_id, name) FROM stdin;
2	мг/л
3	г/л
4	ммоль/л
5	мкмоль/л
6	ед/л
7	%
8	тыс/мкл
9	мл
10	мм
\.


--
-- TOC entry 5198 (class 0 OID 0)
-- Dependencies: 244
-- Name: disease_disease_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.disease_disease_id_seq', 36, true);


--
-- TOC entry 5199 (class 0 OID 0)
-- Dependencies: 246
-- Name: disease_syndrome_disease_syndrome_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.disease_syndrome_disease_syndrome_id_seq', 2, true);


--
-- TOC entry 5200 (class 0 OID 0)
-- Dependencies: 248
-- Name: drug_intake_method_drug_intake_method_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.drug_intake_method_drug_intake_method_id_seq', 2, true);


--
-- TOC entry 5201 (class 0 OID 0)
-- Dependencies: 250
-- Name: drug_type_drug_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.drug_type_drug_type_id_seq', 3, true);


--
-- TOC entry 5202 (class 0 OID 0)
-- Dependencies: 252
-- Name: drug_type_prescription_drug_prescription_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.drug_type_prescription_drug_prescription_id_seq', 1, true);


--
-- TOC entry 5203 (class 0 OID 0)
-- Dependencies: 229
-- Name: examination_type_examination_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.examination_type_examination_type_id_seq', 3, true);


--
-- TOC entry 5204 (class 0 OID 0)
-- Dependencies: 233
-- Name: examination_type_prescription_examination_prescription_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.examination_type_prescription_examination_prescription_id_seq', 12, true);


--
-- TOC entry 5205 (class 0 OID 0)
-- Dependencies: 258
-- Name: hospital_admission_hospital_admission_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.hospital_admission_hospital_admission_id_seq', 31, true);


--
-- TOC entry 5206 (class 0 OID 0)
-- Dependencies: 260
-- Name: hospital_discharge_hospital_discharge_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.hospital_discharge_hospital_discharge_id_seq', 1, true);


--
-- TOC entry 5207 (class 0 OID 0)
-- Dependencies: 220
-- Name: person_person_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.person_person_id_seq', 8, true);


--
-- TOC entry 5208 (class 0 OID 0)
-- Dependencies: 227
-- Name: prescription_prescription_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.prescription_prescription_id_seq', 24, true);


--
-- TOC entry 5209 (class 0 OID 0)
-- Dependencies: 256
-- Name: procedure_type_prescription_procedure_prescription_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.procedure_type_prescription_procedure_prescription_id_seq', 7, true);


--
-- TOC entry 5210 (class 0 OID 0)
-- Dependencies: 254
-- Name: procedure_type_procedure_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.procedure_type_procedure_type_id_seq', 3, true);


--
-- TOC entry 5211 (class 0 OID 0)
-- Dependencies: 237
-- Name: reference_value_reference_value_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.reference_value_reference_value_id_seq', 5, true);


--
-- TOC entry 5212 (class 0 OID 0)
-- Dependencies: 231
-- Name: result_result_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.result_result_id_seq', 10, true);


--
-- TOC entry 5213 (class 0 OID 0)
-- Dependencies: 241
-- Name: syndrome_type_syndrome_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.syndrome_type_syndrome_type_id_seq', 2, true);


--
-- TOC entry 5214 (class 0 OID 0)
-- Dependencies: 225
-- Name: unit_unit_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.unit_unit_id_seq', 10, true);


--
-- TOC entry 4850 (class 2606 OID 180455)
-- Name: disease disease_icd_code_check; Type: CHECK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE public.disease
    ADD CONSTRAINT disease_icd_code_check CHECK ((icd_code ~ '^[A-Z][0-9]{2}\.[0-9]$'::text)) NOT VALID;


--
-- TOC entry 4910 (class 2606 OID 179945)
-- Name: disease disease_icd_code_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.disease
    ADD CONSTRAINT disease_icd_code_key UNIQUE (icd_code);


--
-- TOC entry 4912 (class 2606 OID 179943)
-- Name: disease disease_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.disease
    ADD CONSTRAINT disease_name_key UNIQUE (name);


--
-- TOC entry 4914 (class 2606 OID 179941)
-- Name: disease disease_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.disease
    ADD CONSTRAINT disease_pkey PRIMARY KEY (disease_id);


--
-- TOC entry 4916 (class 2606 OID 179954)
-- Name: disease_syndrome disease_syndrome_disease_id_syndrome_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.disease_syndrome
    ADD CONSTRAINT disease_syndrome_disease_id_syndrome_id_key UNIQUE (disease_id, syndrome_id);


--
-- TOC entry 4918 (class 2606 OID 179952)
-- Name: disease_syndrome disease_syndrome_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.disease_syndrome
    ADD CONSTRAINT disease_syndrome_pkey PRIMARY KEY (disease_syndrome_id);


--
-- TOC entry 4868 (class 2606 OID 179732)
-- Name: doctor doctor_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.doctor
    ADD CONSTRAINT doctor_pkey PRIMARY KEY (doctor_id);


--
-- TOC entry 4920 (class 2606 OID 180024)
-- Name: drug_intake_method drug_intake_method_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_intake_method
    ADD CONSTRAINT drug_intake_method_name_key UNIQUE (name);


--
-- TOC entry 4922 (class 2606 OID 180022)
-- Name: drug_intake_method drug_intake_method_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_intake_method
    ADD CONSTRAINT drug_intake_method_pkey PRIMARY KEY (drug_intake_method_id);


--
-- TOC entry 4924 (class 2606 OID 180045)
-- Name: drug_type drug_type_brand_name_ru_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type
    ADD CONSTRAINT drug_type_brand_name_ru_key UNIQUE (brand_name_ru);


--
-- TOC entry 4926 (class 2606 OID 180041)
-- Name: drug_type drug_type_international_name_en_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type
    ADD CONSTRAINT drug_type_international_name_en_key UNIQUE (international_name_en);


--
-- TOC entry 4928 (class 2606 OID 180043)
-- Name: drug_type drug_type_international_name_la_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type
    ADD CONSTRAINT drug_type_international_name_la_key UNIQUE (international_name_la);


--
-- TOC entry 4930 (class 2606 OID 180039)
-- Name: drug_type drug_type_international_name_ru_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type
    ADD CONSTRAINT drug_type_international_name_ru_key UNIQUE (international_name_ru);


--
-- TOC entry 4932 (class 2606 OID 180037)
-- Name: drug_type drug_type_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type
    ADD CONSTRAINT drug_type_pkey PRIMARY KEY (drug_type_id);


--
-- TOC entry 4934 (class 2606 OID 180056)
-- Name: drug_type_prescription drug_type_prescription_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type_prescription
    ADD CONSTRAINT drug_type_prescription_pkey PRIMARY KEY (drug_prescription_id);


--
-- TOC entry 4936 (class 2606 OID 180058)
-- Name: drug_type_prescription drug_type_prescription_prescription_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type_prescription
    ADD CONSTRAINT drug_type_prescription_prescription_id_key UNIQUE (prescription_id);


--
-- TOC entry 4878 (class 2606 OID 179788)
-- Name: examination_type examination_type_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.examination_type
    ADD CONSTRAINT examination_type_name_key UNIQUE (name);


--
-- TOC entry 4880 (class 2606 OID 179786)
-- Name: examination_type examination_type_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.examination_type
    ADD CONSTRAINT examination_type_pkey PRIMARY KEY (examination_type_id);


--
-- TOC entry 4884 (class 2606 OID 179809)
-- Name: examination_type_prescription examination_type_prescription_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.examination_type_prescription
    ADD CONSTRAINT examination_type_prescription_pkey PRIMARY KEY (examination_prescription_id);


--
-- TOC entry 4886 (class 2606 OID 179811)
-- Name: examination_type_prescription examination_type_prescription_prescription_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.examination_type_prescription
    ADD CONSTRAINT examination_type_prescription_prescription_id_key UNIQUE (prescription_id);


--
-- TOC entry 4946 (class 2606 OID 185818)
-- Name: hospital_admission hospital_admission_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.hospital_admission
    ADD CONSTRAINT hospital_admission_pkey PRIMARY KEY (hospital_admission_id);


--
-- TOC entry 4948 (class 2606 OID 185838)
-- Name: hospital_discharge hospital_discharge_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.hospital_discharge
    ADD CONSTRAINT hospital_discharge_pkey PRIMARY KEY (hospital_discharge_id);


--
-- TOC entry 4888 (class 2606 OID 179833)
-- Name: numeric_result numeric_result_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.numeric_result
    ADD CONSTRAINT numeric_result_pkey PRIMARY KEY (result_id);


--
-- TOC entry 4866 (class 2606 OID 179722)
-- Name: patient patient_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.patient
    ADD CONSTRAINT patient_pkey PRIMARY KEY (patient_id);


--
-- TOC entry 4950 (class 2606 OID 185860)
-- Name: person_account person_account_person_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.person_account
    ADD CONSTRAINT person_account_person_id_key UNIQUE (person_id);


--
-- TOC entry 4864 (class 2606 OID 179714)
-- Name: person person_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.person
    ADD CONSTRAINT person_pkey PRIMARY KEY (person_id);


--
-- TOC entry 4876 (class 2606 OID 179766)
-- Name: prescription prescription_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.prescription
    ADD CONSTRAINT prescription_pkey PRIMARY KEY (prescription_id);


--
-- TOC entry 4938 (class 2606 OID 180090)
-- Name: procedure_type procedure_type_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.procedure_type
    ADD CONSTRAINT procedure_type_name_key UNIQUE (name);


--
-- TOC entry 4940 (class 2606 OID 180088)
-- Name: procedure_type procedure_type_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.procedure_type
    ADD CONSTRAINT procedure_type_pkey PRIMARY KEY (procedure_type_id);


--
-- TOC entry 4942 (class 2606 OID 180097)
-- Name: procedure_type_prescription procedure_type_prescription_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.procedure_type_prescription
    ADD CONSTRAINT procedure_type_prescription_pkey PRIMARY KEY (procedure_prescription_id);


--
-- TOC entry 4944 (class 2606 OID 180099)
-- Name: procedure_type_prescription procedure_type_prescription_prescription_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.procedure_type_prescription
    ADD CONSTRAINT procedure_type_prescription_prescription_id_key UNIQUE (prescription_id);


--
-- TOC entry 4890 (class 2606 OID 179848)
-- Name: qualitative_result qualitative_result_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.qualitative_result
    ADD CONSTRAINT qualitative_result_pkey PRIMARY KEY (result_id);


--
-- TOC entry 4896 (class 2606 OID 179875)
-- Name: reference_numeric_value reference_numeric_value_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.reference_numeric_value
    ADD CONSTRAINT reference_numeric_value_pkey PRIMARY KEY (reference_value_id);


--
-- TOC entry 4898 (class 2606 OID 179896)
-- Name: reference_qualitative_value reference_qualitative_value_description_true_description_fa_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.reference_qualitative_value
    ADD CONSTRAINT reference_qualitative_value_description_true_description_fa_key UNIQUE (description_true, description_false);


--
-- TOC entry 4900 (class 2606 OID 179894)
-- Name: reference_qualitative_value reference_qualitative_value_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.reference_qualitative_value
    ADD CONSTRAINT reference_qualitative_value_pkey PRIMARY KEY (reference_value_id);


--
-- TOC entry 4892 (class 2606 OID 185773)
-- Name: reference_value reference_value_examination_type_id_gender_age_min_age_max_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.reference_value
    ADD CONSTRAINT reference_value_examination_type_id_gender_age_min_age_max_key UNIQUE (examination_type_id, gender, age_min, age_max);


--
-- TOC entry 4894 (class 2606 OID 179861)
-- Name: reference_value reference_value_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.reference_value
    ADD CONSTRAINT reference_value_pkey PRIMARY KEY (reference_value_id);


--
-- TOC entry 4870 (class 2606 OID 179742)
-- Name: registrar registrar_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.registrar
    ADD CONSTRAINT registrar_pkey PRIMARY KEY (registrar_id);


--
-- TOC entry 4882 (class 2606 OID 179795)
-- Name: result result_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.result
    ADD CONSTRAINT result_pkey PRIMARY KEY (result_id);


--
-- TOC entry 4906 (class 2606 OID 179920)
-- Name: syndrome_examination_type syndrome_examination_type_examination_type_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.syndrome_examination_type
    ADD CONSTRAINT syndrome_examination_type_examination_type_id_key UNIQUE (examination_type_id);


--
-- TOC entry 4908 (class 2606 OID 179918)
-- Name: syndrome_examination_type syndrome_examination_type_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.syndrome_examination_type
    ADD CONSTRAINT syndrome_examination_type_pkey PRIMARY KEY (syndrome_id);


--
-- TOC entry 4902 (class 2606 OID 179913)
-- Name: syndrome_type syndrome_type_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.syndrome_type
    ADD CONSTRAINT syndrome_type_name_key UNIQUE (name);


--
-- TOC entry 4904 (class 2606 OID 179911)
-- Name: syndrome_type syndrome_type_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.syndrome_type
    ADD CONSTRAINT syndrome_type_pkey PRIMARY KEY (syndrome_type_id);


--
-- TOC entry 4872 (class 2606 OID 179759)
-- Name: unit unit_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.unit
    ADD CONSTRAINT unit_name_key UNIQUE (name);


--
-- TOC entry 4874 (class 2606 OID 179757)
-- Name: unit unit_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.unit
    ADD CONSTRAINT unit_pkey PRIMARY KEY (unit_id);


--
-- TOC entry 4984 (class 2620 OID 185849)
-- Name: hospital_admission trg_check_active_hospitalization; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_check_active_hospitalization BEFORE INSERT ON public.hospital_admission FOR EACH ROW EXECUTE FUNCTION public.check_active_hospitalization();


--
-- TOC entry 4986 (class 2620 OID 185851)
-- Name: hospital_discharge trg_check_discharge_after_admission; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_check_discharge_after_admission BEFORE INSERT OR UPDATE ON public.hospital_discharge FOR EACH ROW EXECUTE FUNCTION public.check_discharge_after_admission();


--
-- TOC entry 4985 (class 2620 OID 185850)
-- Name: hospital_admission trg_check_hospitalization_overlap; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_check_hospitalization_overlap BEFORE INSERT ON public.hospital_admission FOR EACH ROW EXECUTE FUNCTION public.check_hospitalization_overlap();


--
-- TOC entry 4982 (class 2620 OID 180121)
-- Name: numeric_result trg_check_numeric_result_uniqueness; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_check_numeric_result_uniqueness BEFORE INSERT OR UPDATE ON public.numeric_result FOR EACH ROW EXECUTE FUNCTION public.check_numeric_result_uniqueness();


--
-- TOC entry 4983 (class 2620 OID 180123)
-- Name: qualitative_result trg_check_qualitative_result_uniqueness; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_check_qualitative_result_uniqueness BEFORE INSERT OR UPDATE ON public.qualitative_result FOR EACH ROW EXECUTE FUNCTION public.check_qualitative_result_uniqueness();


--
-- TOC entry 4987 (class 2620 OID 185852)
-- Name: hospital_discharge trg_check_unique_discharge; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_check_unique_discharge BEFORE INSERT OR UPDATE ON public.hospital_discharge FOR EACH ROW EXECUTE FUNCTION public.check_unique_discharge();


--
-- TOC entry 4988 (class 2620 OID 185868)
-- Name: person_account trigger_create_account; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trigger_create_account BEFORE INSERT ON public.person_account FOR EACH ROW EXECUTE FUNCTION public.create_person_account();


--
-- TOC entry 4969 (class 2606 OID 179955)
-- Name: disease_syndrome disease_syndrome_disease_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.disease_syndrome
    ADD CONSTRAINT disease_syndrome_disease_id_fkey FOREIGN KEY (disease_id) REFERENCES public.disease(disease_id) ON DELETE CASCADE;


--
-- TOC entry 4970 (class 2606 OID 179960)
-- Name: disease_syndrome disease_syndrome_syndrome_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.disease_syndrome
    ADD CONSTRAINT disease_syndrome_syndrome_id_fkey FOREIGN KEY (syndrome_id) REFERENCES public.syndrome_type(syndrome_type_id) ON DELETE CASCADE;


--
-- TOC entry 4952 (class 2606 OID 179733)
-- Name: doctor doctor_doctor_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.doctor
    ADD CONSTRAINT doctor_doctor_id_fkey FOREIGN KEY (doctor_id) REFERENCES public.person(person_id);


--
-- TOC entry 4971 (class 2606 OID 180069)
-- Name: drug_type_prescription drug_type_prescription_dose_unit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type_prescription
    ADD CONSTRAINT drug_type_prescription_dose_unit_id_fkey FOREIGN KEY (dose_unit_id) REFERENCES public.unit(unit_id) ON DELETE RESTRICT;


--
-- TOC entry 4972 (class 2606 OID 180064)
-- Name: drug_type_prescription drug_type_prescription_drug_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type_prescription
    ADD CONSTRAINT drug_type_prescription_drug_type_id_fkey FOREIGN KEY (drug_type_id) REFERENCES public.drug_type(drug_type_id) ON DELETE RESTRICT;


--
-- TOC entry 4973 (class 2606 OID 180074)
-- Name: drug_type_prescription drug_type_prescription_intake_method_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type_prescription
    ADD CONSTRAINT drug_type_prescription_intake_method_id_fkey FOREIGN KEY (intake_method_id) REFERENCES public.drug_intake_method(drug_intake_method_id) ON DELETE RESTRICT;


--
-- TOC entry 4974 (class 2606 OID 180059)
-- Name: drug_type_prescription drug_type_prescription_prescription_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.drug_type_prescription
    ADD CONSTRAINT drug_type_prescription_prescription_id_fkey FOREIGN KEY (prescription_id) REFERENCES public.prescription(prescription_id) ON DELETE CASCADE;


--
-- TOC entry 4957 (class 2606 OID 179822)
-- Name: examination_type_prescription examination_type_prescription_examination_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.examination_type_prescription
    ADD CONSTRAINT examination_type_prescription_examination_type_id_fkey FOREIGN KEY (examination_type_id) REFERENCES public.examination_type(examination_type_id) ON DELETE CASCADE;


--
-- TOC entry 4958 (class 2606 OID 179812)
-- Name: examination_type_prescription examination_type_prescription_prescription_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.examination_type_prescription
    ADD CONSTRAINT examination_type_prescription_prescription_id_fkey FOREIGN KEY (prescription_id) REFERENCES public.prescription(prescription_id) ON DELETE CASCADE;


--
-- TOC entry 4959 (class 2606 OID 179817)
-- Name: examination_type_prescription examination_type_prescription_result_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.examination_type_prescription
    ADD CONSTRAINT examination_type_prescription_result_id_fkey FOREIGN KEY (result_id) REFERENCES public.result(result_id) ON DELETE CASCADE;


--
-- TOC entry 4977 (class 2606 OID 185819)
-- Name: hospital_admission hospital_admission_patient_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.hospital_admission
    ADD CONSTRAINT hospital_admission_patient_id_fkey FOREIGN KEY (patient_id) REFERENCES public.patient(patient_id) ON DELETE CASCADE;


--
-- TOC entry 4978 (class 2606 OID 185824)
-- Name: hospital_admission hospital_admission_preliminary_disease_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.hospital_admission
    ADD CONSTRAINT hospital_admission_preliminary_disease_id_fkey FOREIGN KEY (preliminary_disease_id) REFERENCES public.disease(disease_id);


--
-- TOC entry 4979 (class 2606 OID 185844)
-- Name: hospital_discharge hospital_discharge_final_disease_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.hospital_discharge
    ADD CONSTRAINT hospital_discharge_final_disease_id_fkey FOREIGN KEY (final_disease_id) REFERENCES public.disease(disease_id);


--
-- TOC entry 4980 (class 2606 OID 185839)
-- Name: hospital_discharge hospital_discharge_hospital_admission_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.hospital_discharge
    ADD CONSTRAINT hospital_discharge_hospital_admission_id_fkey FOREIGN KEY (hospital_admission_id) REFERENCES public.hospital_admission(hospital_admission_id) ON DELETE CASCADE;


--
-- TOC entry 4960 (class 2606 OID 180445)
-- Name: numeric_result numeric_result_result_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.numeric_result
    ADD CONSTRAINT numeric_result_result_id_fkey FOREIGN KEY (result_id) REFERENCES public.result(result_id) NOT VALID;


--
-- TOC entry 4961 (class 2606 OID 179839)
-- Name: numeric_result numeric_result_unit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.numeric_result
    ADD CONSTRAINT numeric_result_unit_id_fkey FOREIGN KEY (unit_id) REFERENCES public.unit(unit_id) ON DELETE RESTRICT;


--
-- TOC entry 4951 (class 2606 OID 179723)
-- Name: patient patient_patient_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.patient
    ADD CONSTRAINT patient_patient_id_fkey FOREIGN KEY (patient_id) REFERENCES public.person(person_id);


--
-- TOC entry 4981 (class 2606 OID 185861)
-- Name: person_account person_account_person_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.person_account
    ADD CONSTRAINT person_account_person_id_fkey FOREIGN KEY (person_id) REFERENCES public.person(person_id);


--
-- TOC entry 4954 (class 2606 OID 179772)
-- Name: prescription prescription_doctor_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.prescription
    ADD CONSTRAINT prescription_doctor_id_fkey FOREIGN KEY (doctor_id) REFERENCES public.doctor(doctor_id) ON DELETE RESTRICT;


--
-- TOC entry 4955 (class 2606 OID 179767)
-- Name: prescription prescription_patient_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.prescription
    ADD CONSTRAINT prescription_patient_id_fkey FOREIGN KEY (patient_id) REFERENCES public.patient(patient_id) ON DELETE CASCADE;


--
-- TOC entry 4975 (class 2606 OID 180100)
-- Name: procedure_type_prescription procedure_type_prescription_prescription_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.procedure_type_prescription
    ADD CONSTRAINT procedure_type_prescription_prescription_id_fkey FOREIGN KEY (prescription_id) REFERENCES public.prescription(prescription_id) ON DELETE CASCADE;


--
-- TOC entry 4976 (class 2606 OID 180105)
-- Name: procedure_type_prescription procedure_type_prescription_procedure_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.procedure_type_prescription
    ADD CONSTRAINT procedure_type_prescription_procedure_type_id_fkey FOREIGN KEY (procedure_type_id) REFERENCES public.procedure_type(procedure_type_id) ON DELETE RESTRICT;


--
-- TOC entry 4962 (class 2606 OID 180450)
-- Name: qualitative_result qualitative_result_result_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.qualitative_result
    ADD CONSTRAINT qualitative_result_result_id_fkey FOREIGN KEY (result_id) REFERENCES public.result(result_id) NOT VALID;


--
-- TOC entry 4964 (class 2606 OID 179876)
-- Name: reference_numeric_value reference_numeric_value_reference_value_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.reference_numeric_value
    ADD CONSTRAINT reference_numeric_value_reference_value_id_fkey FOREIGN KEY (reference_value_id) REFERENCES public.reference_value(reference_value_id) ON DELETE CASCADE;


--
-- TOC entry 4965 (class 2606 OID 179881)
-- Name: reference_numeric_value reference_numeric_value_unit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.reference_numeric_value
    ADD CONSTRAINT reference_numeric_value_unit_id_fkey FOREIGN KEY (unit_id) REFERENCES public.unit(unit_id) ON DELETE RESTRICT;


--
-- TOC entry 4966 (class 2606 OID 179897)
-- Name: reference_qualitative_value reference_qualitative_value_reference_value_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.reference_qualitative_value
    ADD CONSTRAINT reference_qualitative_value_reference_value_id_fkey FOREIGN KEY (reference_value_id) REFERENCES public.reference_value(reference_value_id) ON DELETE CASCADE;


--
-- TOC entry 4963 (class 2606 OID 179864)
-- Name: reference_value reference_value_examination_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.reference_value
    ADD CONSTRAINT reference_value_examination_type_id_fkey FOREIGN KEY (examination_type_id) REFERENCES public.examination_type(examination_type_id) ON DELETE CASCADE;


--
-- TOC entry 4953 (class 2606 OID 179743)
-- Name: registrar registrar_registrar_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.registrar
    ADD CONSTRAINT registrar_registrar_id_fkey FOREIGN KEY (registrar_id) REFERENCES public.person(person_id);


--
-- TOC entry 4956 (class 2606 OID 179798)
-- Name: result result_examination_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.result
    ADD CONSTRAINT result_examination_id_fkey FOREIGN KEY (examination_id) REFERENCES public.examination_type(examination_type_id) ON DELETE CASCADE;


--
-- TOC entry 4967 (class 2606 OID 179926)
-- Name: syndrome_examination_type syndrome_examination_type_examination_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.syndrome_examination_type
    ADD CONSTRAINT syndrome_examination_type_examination_type_id_fkey FOREIGN KEY (examination_type_id) REFERENCES public.examination_type(examination_type_id) ON DELETE CASCADE;


--
-- TOC entry 4968 (class 2606 OID 179921)
-- Name: syndrome_examination_type syndrome_examination_type_syndrome_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.syndrome_examination_type
    ADD CONSTRAINT syndrome_examination_type_syndrome_id_fkey FOREIGN KEY (syndrome_id) REFERENCES public.syndrome_type(syndrome_type_id) ON DELETE CASCADE;


-- Completed on 2025-12-01 18:47:43

--
-- PostgreSQL database dump complete
--

