File: gmDemographics.de.sql

package info (click to toggle)
gnumed-server 22.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 46,268 kB
  • sloc: sql: 1,217,633; python: 15,878; sh: 1,590; makefile: 20
file content (161 lines) | stat: -rw-r--r-- 5,275 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
-- GNUmed

-- license: GPL v2 or later

-- demographics tables specific for Germany

-- ===================================================================
-- force terminate + exit(3) on errors if non-interactive
\set ON_ERROR_STOP 1

-- ===================================================================
create schema de_de authorization "gm-dbo";
grant usage on schema de_de to group "gm-doctors";

-- ===================================================================
-- tables related to the German Krankenversichtenkarte KVK
create table de_de.kvk (
	pk serial
		primary key,
	fk_patient integer
		not null
		references dem.identity(pk),

	-- eigentliche KVK-Felder
	-- Datenbereich (020h-0FFh)				--  Feldtag	Länge	Feldname				Optional
	KK_Name varchar(28) not null,			--  0x80	2-28	Krankenkassenname		nein
	KK_Nummer character(7) not null,		--  0x81	7		Krankenkassennummer		nein
	KVK_Nummer character(5),				--  0x8F	5		Versichertenkarten-Nr.	ja
	Mitgliedsnummer varchar(12) not null,	--  0x82	6-12	Versichertennummer		nein
	Mitgliedsstatus varchar(4) not null,	--  0x83	1/4		Versichertenstatus		nein
	Zusatzstatus varchar(3),				--  0x90	1-3		Statusergänzung			ja
	Titel varchar(15),						--  0x84	3-15	Titel					ja
	Vorname varchar(28),					--  0x85	2-28	Vorname					ja
	Namenszuatz varchar(15),				--  0x86	1-15	Namenszusatz			ja
	Familienname varchar(28) not null,		--  0x87	2-28	Familienname			nein
	Geburtsdatum character(8) not null,		--  0x88	8		Geburtsdatum			nein
	Strasse varchar(28),					--  0x89	1-28	Straßenname				ja
	Landescode  varchar(3),					--  0x8A	1-3		Wohnsitzländercode		ja
	PLZ varchar(7) not null,				--  0x8B	4-7		Postleitzahl			nein
	Ort varchar(23) not null,				--  0x8C	2-23	Ortsname				nein
	Gueltigkeit character(4),				--  0x8D	4		Gültigkeitsdatum		ja
	CRC character(1) not null,				--  0x8E	1		Prüfsumme				nein

	is_valid_address boolean default true,

	valid_since timestamp with time zone not null,
	presented timestamp with time zone [] not null,
	invalidated timestamp with time zone default null
);

-- Der Datenbereich ist wie folgt gegliedert:
--  1. Feldtag (1 Byte)
--  2. Feldlaenge (1 Byte)
--  3. ASCII-codierter Text (der angegebenen Feldlaenge, 1 Zeichen=1 Byte )

comment on table de_de.kvk is
	'Speichert die Daten einer bestimmten KVK. Wir trennen die KVK-Daten von
	 den Daten ueber Person, Wohnort, Kassenzugehoerigkeit, Mitgliedsstatus und
	 Abrechnungsfaellen. Diese Daten werden jedoch a) als Vorgaben fuer die
	 eigentlichen Personendaten und b) als gueltig fuer abrechnungstechnische
	 Belange angesehen.';

comment on column de_de.kvk.invalidated is
	'Kann durchaus vor Ende von "Gueltigkeit" liegen. Zeitpunkt des
	 Austritts aus der Krankenkasse. Beim Setzen dieses Feldes muss
	 auch die Zuzahlungsbefreiung auf NULL gesetzt werden.';

-- ---------------------------------------------
--create table de_de.kvk_presented (
--	id serial primary key,
--	id_kvk integer not null references kvk(id),
--	presented timestamp with time zone not null,
--	unique (id_kvk, presented)
--);

-- ---------------------------------------------
create table de_de.zuzahlungsbefreiung (
	id serial primary key,
	id_patient integer references dem.identity(pk),

	Medikamente date default null,
	Heilmittel date default null,
	Hilfsmittel date default null,

	presented timestamp with time zone not null default CURRENT_TIMESTAMP
);

-- =============================================
-- Praxisgebuehr
-- ---------------------------------------------
create table de_de.beh_fall_typ (
	pk serial primary key,
	code text unique not null,
	kurzform text unique not null,
	name text unique not null
) inherits (audit.audit_fields);

select audit.add_table_for_audit('de_de', 'beh_fall_typ');

comment on table de_de.beh_fall_typ is
	'Art des Behandlungsfalls (MuVo/Impfung/...)';

-- ---------------------------------------------
create table de_de.behandlungsfall (
	pk serial primary key,
	fk_patient integer
		not null
		references dem.identity(pk)
		on delete restrict
		on update cascade,
	fk_falltyp integer
		not null
		references de_de.beh_fall_typ(pk)
		on delete restrict
		on update cascade,
	started date
		not null
		default CURRENT_DATE,
	must_pay_prax_geb boolean
		not null
		default true
);

select audit.add_table_for_audit('de_de', 'behandlungsfall');

-- ---------------------------------------------
-- this general table belongs elsewhere
create table de_de.payment_method (
	pk serial primary key,
	description text unique not null
);

-- ---------------------------------------------
create table de_de.prax_geb_paid (
	pk serial primary key,
	fk_fall integer
		not null
		references de_de.behandlungsfall(pk)
		on delete restrict
		on update cascade,
	paid_amount numeric
		not null
		default 0,
	paid_when date
		not null
		default CURRENT_DATE,
	paid_with integer
		not null
		references de_de.payment_method(pk)
		on delete restrict
		on update cascade
) inherits (audit.audit_fields);

select audit.add_table_for_audit('de_de', 'prax_geb_paid');

comment on table de_de.prax_geb_paid is
	'';

-- =============================================
-- do simple revision tracking
INSERT INTO gm_schema_revision (filename, version) VALUES('$RCSfile: gmDemographics.de.sql,v $', '$Revision: 1.10 $');